5.3 Initializing and creating OpenCL contexts

When you know the available OpenCL devices on the machine and have at least one valid device ID, you can create an OpenCL context. The context groups the devices together to enable memory objects to be shared across different compute devices.

To share work between devices, or to have interdependencies on operations submitted to more than one command queue, create a context containing all the devices you want to use in this way.
Pass the device information to the clCreateContext() function. For example:
// Create an OpenCL context

context = clCreateContext(NULL, 1, &device_id, notify_function, NULL, &err);
if (err != CL_SUCCESS)
{
       Cleanup();
       return 1;
}
You can optionally specify an error notification callback function when you create an OpenCL context. When you leave this parameter as a NULL value the system does not register an error notification.
To receive runtime errors for the particular OpenCL context, provide the callback function. For example:
//        Optionally user_data can contain contextual information
//        Implementation specific data of size cb, can be returned in private_info

void context_notify(const char *notify_message, const void *private_info,
                     size_t cb, void *user_data)
{
          printf("Notification:\n\t%s\n", notify_message);
}
Non-ConfidentialPDF file icon PDF versionARM 100614_0300_00_en
Copyright © 2012, 2013, 2015, 2016 ARM. All rights reserved.