Skip to content

Instantly share code, notes, and snippets.

@nathan-osman
Last active April 8, 2016 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathan-osman/963e800c5735334ce0ec to your computer and use it in GitHub Desktop.
Save nathan-osman/963e800c5735334ce0ec to your computer and use it in GitHub Desktop.
Enumerate OpenCL platforms available
#include <iostream>
#include <CL/cl.h>
const cl_uint PlatformEntriesLen = 16;
const size_t PlatformProfileLen = 256;
int main(int argc, char *argv[])
{
// Enumerate all of the platforms
cl_platform_id platforms[PlatformEntriesLen];
cl_uint num_platforms = 0;
if (clGetPlatformIDs(PlatformEntriesLen,
platforms,
&num_platforms)
!= CL_SUCCESS) {
std::cerr << "[ERROR] Unable to enumerate platforms." << std::endl;
return 1;
}
// List all of the platforms
std::cout << "Platforms:" << std::endl;
for (cl_uint i = 0; i < num_platforms; ++i) {
char platformProfile[PlatformProfileLen];
size_t platformProfileRet = 0;
if (clGetPlatformInfo(platforms[i],
CL_PLATFORM_NAME,
PlatformProfileLen,
platformProfile,
&platformProfileRet)
!= CL_SUCCESS) {
std::cerr << "[ERROR] Unable to obtain platform info";
return 1;
}
std::cout << " " << i << ". ";
std::cout.write(platformProfile, platformProfileRet);
std::cout << std::endl;
}
return 0;
}
cmake_minimum_required(VERSION 2.8.11)
project(cltest)
find_package(OpenCL REQUIRED)
add_executable(cltest cltest.cpp)
include_directories(cltest ${OpenCL_INCLUDE_DIRS})
target_link_libraries(cltest ${OpenCL_LIBRARIES})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment