Last active
April 8, 2016 06:23
-
-
Save nathan-osman/963e800c5735334ce0ec to your computer and use it in GitHub Desktop.
Enumerate OpenCL platforms available
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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