Enumerating platforms:
Code:
#include [opencl header here]
#include <sstream>
#include <string>
#define MAX_PLATFORM_IDS 8
using namespace std;
int main()
{
cl_int num_platforms;
cl_platform_id *platforms = new cl_platform_id[MAX_PLATFORM_IDS];
// Get list of platforms.
if(clGetPlatformIDs(MAX_PLATFORM_IDS, platforIDs, &num_platforms) != CL_SUCCESS)
{
cerr << "Error: clGetPlatformIDs() returns error" << endl;
abort();
}
cout << "Available Platforms:" << endl;
for(int platform = 0;i < num_platforms;platform++)
{
char *param_value = new char[256];
string platform_name, platform_vendor, platform_extensions;
// Get CL_PLATFORM_NAME
if(clGetPlatformInfo(platform, CL_PLATFORM_NAME, 256, param_value, NULL) == CL_SUCCESS)
platform_name = param_value;
else
{
cerr << "Error: clGetPlatformInfo() returns error" << endl;
abort();
}
// Get CL_PLATFORM_VENDOR
if(clGetPlatformInfo(platform, CL_PLATFORM_VENDOR, 256, param_value, NULL) == CL_SUCCESS)
platform_vendor = param_value;
else
{
cerr << "Error: clGetPlatformInfo() returns error" << endl;
abort();
}
// Get CL_PLATFORM_EXTENSIONS
if(clGetPlatformInfo(platform, CL_PLATFORM_EXTENSIONS, 256, param_value, NULL) == CL_SUCCESS)
platform_extensions = param_value;
else
{
cerr << "Error: clGetPlatformInfo() returns error" << endl;
abort();
}
cout << platform << ":" << endl << "\tPlatform name: " << platform_name << endl << "\tPlatform vendor: " << platform_vendor << endl << "\tPlatform extensions: " << platform_extensions << endl;
}
return 0;
}