Skip to content

Instantly share code, notes, and snippets.

@Foadsf
Last active January 6, 2021 05:50
Show Gist options
  • Save Foadsf/3ca81a9b6f4b5c51e93dcee34b434342 to your computer and use it in GitHub Desktop.
Save Foadsf/3ca81a9b6f4b5c51e93dcee34b434342 to your computer and use it in GitHub Desktop.

Revisions

  1. Foadsf revised this gist Jun 9, 2020. No changes.
  2. Foadsf revised this gist Jun 9, 2020. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions CMakeLists.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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})
  3. Foadsf revised this gist Jun 3, 2018. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions main.c
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    #include <stdio.h> //printf

    #ifdef __APPLE__ //or? MAC or? APPLE
    //or? #if defined(MAC) || defined(__APPLE__)
    #ifdef __APPLE__
    #include <OpenCL/cl.h>
    #else
    #include <CL/cl.h>
    @@ -21,7 +20,7 @@ int main(int argc, char const* argv[]) {

    platforms= (cl_platform_id*) malloc(sizeof(cl_platform_id) * numPlatforms);
    err = clGetPlatformIDs(numPlatforms, platforms, NULL);
    if(err != CL_SUCCESS) {// clGetPlatformIDs returns CL_INVALID_VALUE or CL_SUCCESS
    if(err != CL_SUCCESS) {
    printf("Couldn't get platforms");
    return EXIT_FAILURE;
    }
  4. Foadsf created this gist Jun 3, 2018.
    14 changes: 14 additions & 0 deletions MakeFile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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
    45 changes: 45 additions & 0 deletions main.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    #include <stdio.h> //printf

    #ifdef __APPLE__ //or? MAC or? APPLE
    //or? #if defined(MAC) || defined(__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) {// clGetPlatformIDs returns CL_INVALID_VALUE or 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, &param_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;
    }