Last active
          January 6, 2021 05:50 
        
      - 
      
- 
        Save Foadsf/3ca81a9b6f4b5c51e93dcee34b434342 to your computer and use it in GitHub Desktop. 
    printing the platform information in OpenCL following this SO post https://stackoverflow.com/a/50667352/4999991
  
        
  
    
      This file contains hidden or 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 3.1) | |
| project(OpenCL_Example) | |
| find_package(OpenCL REQUIRED) | |
| include_directories(${OpenCL_INCLUDE_DIRS}) | |
| link_directories(${OpenCL_LIBRARY}) | |
| add_executable(main main.c) | |
| target_include_directories(main PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | |
| target_link_libraries(main ${OpenCL_LIBRARY}) | 
  
    
      This file contains hidden or 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 <stdio.h> //printf | |
| #ifdef __APPLE__ | |
| #include <OpenCL/cl.h> | |
| #else | |
| #include <CL/cl.h> | |
| #endif | |
| int main(int argc, char const* argv[]) { | |
| cl_int err; | |
| cl_uint numPlatforms; | |
| cl_platform_id* platforms; | |
| err = clGetPlatformIDs(0, NULL, &numPlatforms); | |
| if(err != CL_SUCCESS || numPlatforms == 0) { | |
| printf("Couldn't identify a platform"); | |
| return EXIT_FAILURE; | |
| } | |
| printf("Number of platfroms: %d\n", numPlatforms); | |
| platforms= (cl_platform_id*) malloc(sizeof(cl_platform_id) * numPlatforms); | |
| err = clGetPlatformIDs(numPlatforms, platforms, NULL); | |
| if(err != CL_SUCCESS) { | |
| printf("Couldn't get platforms"); | |
| return EXIT_FAILURE; | |
| } | |
| cl_platform_info Param_Name[5]={CL_PLATFORM_PROFILE, CL_PLATFORM_VERSION, CL_PLATFORM_NAME, CL_PLATFORM_VENDOR,CL_PLATFORM_EXTENSIONS}; | |
| cl_platform_info param_name; | |
| size_t param_value_size; | |
| for(int i=0;i<numPlatforms;i++){ | |
| for(int j=0;j<5;j++){ | |
| param_name=Param_Name[j]; | |
| err = clGetPlatformInfo( platforms[i], param_name, 0, NULL, ¶m_value_size); | |
| char* param_value = (char*)malloc( sizeof(char) * param_value_size); | |
| err = clGetPlatformInfo( platforms[i], param_name, param_value_size, param_value, NULL ); | |
| printf("%s\n", param_value); | |
| free(param_value); | |
| } | |
| } | |
| free(platforms); | |
| return 0; | |
| } | 
  
    
      This file contains hidden or 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
    
  
  
    
  | OS := $(shell uname) | |
| OPTIONS:= | |
| ifeq ($(OS),Darwin) | |
| OPTIONS += -framework OpenCL | |
| else | |
| OPTIONS += -l OpenCL | |
| endif | |
| all: main.c | |
| gcc -Wall -g main.c -o main $(OPTIONS) | |
| clean: | |
| rm -rf main | 
hi, many thanks for your code. By the way, stdlib.h should be included,
how to run this on linux
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Thanks for the code. It's very useful for me.