| 321 | } |
| 322 | |
| 323 | bool createSubDeviceContext(cl_context* context, cl_int numComputeUnits) //work in progress |
| 324 | { |
| 325 | cl_int errorNumber = 0; |
| 326 | cl_uint numberOfPlatforms = 0; |
| 327 | cl_platform_id firstPlatformID = 0; |
| 328 | |
| 329 | /* Retrieve a single platform ID. */ |
| 330 | if (!checkSuccess(clGetPlatformIDs(1, &firstPlatformID, &numberOfPlatforms))) |
| 331 | { |
| 332 | cerr << "Retrieving OpenCL platforms failed. " << __FILE__ << ":"<< __LINE__ << endl; |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | if (numberOfPlatforms <= 0) |
| 337 | { |
| 338 | cerr << "No OpenCL platforms found. " << __FILE__ << ":"<< __LINE__ << endl; |
| 339 | return false; |
| 340 | } |
| 341 | |
| 342 | /* Get a context with a GPU device from the platform found above. */ |
| 343 | cl_context_properties contextProperties [] = {CL_CONTEXT_PLATFORM, (cl_context_properties)firstPlatformID, 0}; |
| 344 | |
| 345 | cl_uint numDevices; |
| 346 | cl_device_id device_id; |
| 347 | |
| 348 | // Get Device ID from selected platform: |
| 349 | clGetDeviceIDs( firstPlatformID, CL_DEVICE_TYPE_ACCELERATOR, 1, &device_id, &numDevices); |
| 350 | |
| 351 | // Create two sub-device properties: Partition By Counts |
| 352 | /* Examples: |
| 353 | cl_device_partition_property props[] = { CL_DEVICE_PARTITION_BY_COUNTS, 4, CL_DEVICE_PARTITION_BY_COUNTS_LIST_END, 0}; |
| 354 | cl_device_partition_property props[] = { CL_DEVICE_PARTITION_EQUALLY, 8, 0}; |
| 355 | */ |
| 356 | #ifdef CL_VERSION_1_1 |
| 357 | //cl_device_partition_property_ext pprops[] = { CL_DEVICE_PARTITION_BY_COUNTS_EXT, 4, 4, CL_PROPERTIES_LIST_END_EXT, 0}; |
| 358 | #else |
| 359 | //cl_device_partition_property pprops[] = { CL_DEVICE_PARTITION_BY_COUNTS, 4, CL_DEVICE_PARTITION_BY_COUNTS_LIST_END, 0}; |
| 360 | #endif /* CL_VERSION_1_1 */ |
| 361 | |
| 362 | |
| 363 | |
| 364 | cl_device_id subdevice_id; |
| 365 | // Create the sub-devices: |
| 366 | #ifdef CL_VERSION_1_1 |
| 367 | //if (!checkSuccess(clCreateSubDevicesEXT(device_id, pprops, 1, &subdevice_id, &numDevices))) |
| 368 | #else |
| 369 | //if (!checkSuccess(clCreateSubDevices(device_id, pprops, 1, &subdevice_id, &numDevices))) |
| 370 | #endif /* CL_VERSION_1_1 */ |
| 371 | { |
| 372 | cerr << "Creating an OpenCL Sub Device failed. " << __FILE__ << ":"<< __LINE__ << endl; |
| 373 | return false; |
| 374 | } |
| 375 | // Create the context: |
| 376 | *context = clCreateContext(contextProperties, 1, &subdevice_id, NULL, NULL, &errorNumber); |
| 377 | if (!checkSuccess(errorNumber)) |
| 378 | { |
| 379 | cerr << "Creating an OpenCL context failed. " << __FILE__ << ":"<< __LINE__ << endl; |
| 380 | return false; |
nothing calls this directly
no test coverage detected