Querying OpenCL™ Platform ID

The following example shows how to query the OpenCL platforms to get the platform ID:

cl_platform_id * platforms = NULL;
        char vendor_name[128] = {0};
        cl_uint num_platforms = 0;
// get number of available platforms
        cl_int err = clGetPlatformIDs(0, NULL, & num_platforms);
        if (CL_SUCCESS != err)
        {
                // handle error
        }
        platforms = (cl_platform_id*)malloc(
                              sizeof(cl_platform)* num_platforms);
        if (NULL == platforms)
        {
                // handle error
        }
        err = clGetPlatformIDs(num_platforms, platforms, NULL);
        if (CL_SUCCESS != err) 
        {
                // handle error
        }
        for (cl_uint ui=0; ui< num_platforms; ++ui)
        {
                err = clGetPlatformInfo(platforms[ui],
                              CL_PLATFORM_VENDOR, 
                              128 * sizeof(char), 
                              vendor_name, 
                              NULL);
                if (CL_SUCCESS != err) 
                {
                        // handle error
                }
                if (vendor_name != NULL)
                {
                        if (!strcmp(vendor_name, "Intel(R) Corporation"))
                        {
                                return platforms[ui];
                        }
                }
        }
        // handle error