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 <iostream>
#include <cstdlib>
In the main() routine we iterate over all OpenCL platforms and print the full device information for each OpenCL device found.
Retrieve the platforms and iterate:
typedef std::vector< viennacl::ocl::platform > platforms_type;
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 << "ViennaCL Device Architecture: " << iter->architecture_family() << std::endl;
std::cout << " -----------------------------------------" << std::endl;
}
std::cout << std::endl;
std::cout << "###########################################" << std::endl;
std::cout << std::endl;
}
return EXIT_SUCCESS;
}
Full Example Code
#include <iostream>
#include <cstdlib>
{
typedef std::vector< viennacl::ocl::platform > platforms_type;
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);
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;
}
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 << "ViennaCL Device Architecture: " << iter->architecture_family() << std::endl;
std::cout << " -----------------------------------------" << std::endl;
}
std::cout << std::endl;
std::cout << "###########################################" << std::endl;
std::cout << std::endl;
}
return EXIT_SUCCESS;
}