cl_device_id selectDefaultClDeviceOfType(cl_device_type device_type, cl_platform_id* platform) { if (DEBUG) printf("selectDefaultClDeviceOfType\n"); cl_int ret; cl_device_id device_id; cl_uint num_devices; ret = clGetDeviceIDs( *platform, // Selected platform device_type, // Type of device (CPU/GPU) 0, // Limit NULL, // Devices destination &num_devices // Count destination ); cl_device_id* devices = calloc(sizeof(cl_device_id), num_devices); ret = clGetDeviceIDs( *platform, // Selected platform device_type, // Type of device (CPU/GPU) num_devices, // Limit devices, // Devices destination NULL // Count destination ); if (ret != CL_SUCCESS) printf("clGetDeviceIDs %s\n", oclErrorString(ret)); if (DEBUG) { displayDeviceInfo(num_devices, devices); printf("Selecting Device 1.\n"); } device_id = devices[0]; free(devices); return device_id; }
int main() { displayDeviceInfo(); printf("Beetle Blinky Application\n"); while(1) { led = !led; wait_ms(100); } return 0; }
int main() { /* OpenCL 1.1 data structures */ cl_platform_id* platforms; /* OpenCL 1.1 scalar data types */ cl_uint numOfPlatforms; cl_int error; /* Get the number of platforms Remember that for each vendor's SDK installed on the computer, the number of available platform also increased. */ error = clGetPlatformIDs(0, NULL, &numOfPlatforms); if(error != CL_SUCCESS) { perror("Unable to find any OpenCL platforms"); exit(1); } // Allocate memory for the number of installed platforms. // alloca(...) occupies some stack space but is automatically freed on return platforms = (cl_platform_id*) alloca(sizeof(cl_platform_id) * numOfPlatforms); printf("Number of OpenCL platforms found: %d\n", numOfPlatforms); error = clGetPlatformIDs(numOfPlatforms, platforms, NULL); if(error != CL_SUCCESS) { perror("Unable to find any OpenCL platforms"); exit(1); } // We invoke the API 'clPlatformInfo' twice for each parameter we're trying to extract // and we use the return value to create temporary data structures (on the stack) to store // the returned information on the second invocation. for(cl_uint i = 0; i < numOfPlatforms; ++i) { displayPlatformInfo( platforms[i], CL_PLATFORM_PROFILE, "CL_PLATFORM_PROFILE" ); displayPlatformInfo( platforms[i], CL_PLATFORM_VERSION, "CL_PLATFORM_VERSION" ); displayPlatformInfo( platforms[i], CL_PLATFORM_NAME, "CL_PLATFORM_NAME" ); displayPlatformInfo( platforms[i], CL_PLATFORM_VENDOR, "CL_PLATFORM_VENDOR" ); displayPlatformInfo( platforms[i], CL_PLATFORM_EXTENSIONS, "CL_PLATFORM_EXTENSIONS" ); // Assume that we don't know how many devices are OpenCL compliant, we locate everything ! displayDeviceInfo( platforms[i], CL_DEVICE_TYPE_ALL ); } return 0; }