Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,023 questions

51,974 answers

573 users

How to get a list of OpenCL platforms in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>

//#define CL_USE_DEPRECATED_OPENCL_2_0_APIS

#include "opencl.h"
//#include "CL/cl.h"


int main() {
    cl_uint TotalPlatforms;
    clGetPlatformIDs(5, NULL, &TotalPlatforms);

    cl_platform_id* platforms;
    platforms = (cl_platform_id*)malloc(sizeof(cl_platform_id) * TotalPlatforms);
    clGetPlatformIDs(TotalPlatforms, platforms, NULL);

    char* infobuf = NULL;
    size_t bufSize;

    const cl_platform_info platformInfoTypes[5] = { CL_PLATFORM_NAME, CL_PLATFORM_VENDOR,
                         CL_PLATFORM_VERSION, CL_PLATFORM_PROFILE, CL_PLATFORM_EXTENSIONS };

    const char* platformInfoNames[5] = { "Name", "Vendor", "Version", "Profile", "Extensions" };
    const int attributeCount = sizeof(platformInfoNames) / sizeof(char*);

    for (int i = 0; i < TotalPlatforms; i++) {
        for (int j = 0; j < attributeCount; j++) {
            clGetPlatformInfo(platforms[i], platformInfoTypes[j], 0, NULL, &bufSize);
            infobuf = (char*)malloc(bufSize);

            clGetPlatformInfo(platforms[i], platformInfoTypes[j], bufSize, infobuf, NULL);

            printf("Platform %s: %s\n", platformInfoNames[j], infobuf);
            free(infobuf);

        }
        printf("\n");
    }
    free(platforms);

    char ch = getchar();

    return 0;
}



/*
run:

Platform Name: NVIDIA CUDA
Platform Vendor: NVIDIA Corporation
Platform Version: OpenCL 3.0 CUDA 11.6.127
Platform Profile: FULL_PROFILE
Platform Extensions: cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics 
cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_fp64 
cl_khr_3d_image_writes cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing 
cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll 
cl_nv_d3d10_sharing cl_khr_d3d10_sharing cl_nv_d3d11_sharing cl_nv_copy_opts 
cl_nv_create_buffer cl_khr_int64_base_atomics cl_khr_int64_extended_atomics 
cl_khr_device_uuid cl_khr_pci_bus_info cl_khr_external_semaphore 
cl_khr_external_memory cl_khr_external_semaphore_win32 cl_khr_external_memory_win32

*/

 



answered Mar 27, 2022 by avibootz

Related questions

...