ViennaCL - The Vienna Computing Library  1.6.0
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Device Informations

This tutorial prints informations about the OpenCL backend and therefore only works with OpenCL enabled. See the viennacl::ocl::device class for full information about which information can be queried from devices.

We start with including required headers:

// include necessary system headers
#include <iostream>
#include <cstdlib>
//include ViennaCL headers

In the main() routine we iterate over all OpenCL platforms and print the full device information for each OpenCL device found.

int main()
{

Retrieve the platforms and iterate:

typedef std::vector< viennacl::ocl::platform > platforms_type;
platforms_type platforms = viennacl::ocl::get_platforms();
bool is_first_element = true;
for (platforms_type::iterator platform_iter = platforms.begin();
platform_iter != platforms.end();
++platform_iter)
{
typedef std::vector<viennacl::ocl::device> devices_type;
devices_type devices = platform_iter->devices(CL_DEVICE_TYPE_ALL);

Print some platform information

std::cout << "# =========================================" << std::endl;
std::cout << "# Platform Information " << std::endl;
std::cout << "# =========================================" << std::endl;
std::cout << "#" << std::endl;
std::cout << "# Vendor and version: " << platform_iter->info() << std::endl;
std::cout << "#" << std::endl;
if (is_first_element)
{
std::cout << "# ViennaCL uses this OpenCL platform by default." << std::endl;
is_first_element = false;
}

Traverse the devices and print all information available using the convenience member function full_info():

std::cout << "# " << std::endl;
std::cout << "# Available Devices: " << std::endl;
std::cout << "# " << std::endl;
for (devices_type::iterator iter = devices.begin(); iter != devices.end(); iter++)
{
std::cout << std::endl;
std::cout << " -----------------------------------------" << std::endl;
std::cout << iter->full_info();
std::cout << " -----------------------------------------" << std::endl;
}
std::cout << std::endl;
std::cout << "###########################################" << std::endl;
std::cout << std::endl;
}
return EXIT_SUCCESS;
}

Full Example Code

Informations