C Specification
To create an OpenCL context from a specific device type [1], call the function:
// Provided by CL_VERSION_1_0
cl_context clCreateContextFromType(
const cl_context_properties* properties,
cl_device_type device_type,
void (CL_CALLBACK* pfn_notify)(const char* errinfo, const void* private_info, size_t cb, void* user_data),
void* user_data,
cl_int* errcode_ret);
Parameters
-
properties specifies a list of context property names and their corresponding values. Each property name is immediately followed by the corresponding desired value. The list of supported properties, and their default values if not present in properties, is described in the Context Properties table. properties can be
NULL, in which case all properties take on their default values. -
device_type is a bit-field that identifies the type of device and is described in the Device Types table.
-
pfn_notify and user_data are described in clCreateContext.
-
errcode_ret will return an appropriate error code. If errcode_ret is
NULL, no error code is returned.
Description
Only devices that are returned by clGetDeviceIDs for device_type are used to create the context. The context does not reference any sub-devices that may have been created from these devices.
clCreateContextFromType returns a valid non-zero context and errcode_ret
is set to CL_SUCCESS if the context is created successfully.
Otherwise, it returns a NULL value with the following error values
returned in errcode_ret:
-
CL_INVALID_PLATFORM -
if no platform is specified in properties and no platform could be selected
-
if the platform specified in properties is not a valid platform
-
-
CL_INVALID_PROPERTY -
if a context property name in properties is not a supported property name
-
if the value specified for a supported property name is not valid
-
if the same property name is specified more than once
-
-
CL_INVALID_VALUE -
if pfn_notify is
NULLand user_data is notNULL
-
-
CL_INVALID_DEVICE_ TYPE -
if device_type is not a valid value
-
-
CL_DEVICE_NOT_ AVAILABLE -
if no devices that match device_type and property values specified in properties are currently available
-
-
CL_DEVICE_NOT_ FOUND -
if no devices that match device_type and property values specified in properties were found
-
-
CL_OUT_OF_ RESOURCES -
if there is a failure to allocate resources required by the OpenCL implementation on the device
-
-
CL_OUT_OF_ HOST_ MEMORY -
if there is a failure to allocate resources required by the OpenCL implementation on the host
-
The following errors may be returned if the cl_khr_
extension is supported:
-
CL_INVALID_DX9_ MEDIA_ ADAPTER_ KHR -
if any of the values of the properties
CL_CONTEXT_,ADAPTER_ D3D9_ KHR CL_CONTEXT_orADAPTER_ D3D9EX_ KHR CL_CONTEXT_is non-ADAPTER_ DXVA_ KHR NULLand does not specify a valid media adapter with which the cl_device_ids against which this context is to be created may interoperate
-
The following errors may be returned if the cl_khr_
extension is supported:
-
CL_INVALID_D3D10_ DEVICE_ KHR -
if the value of the property
CL_CONTEXT_is non-D3D10_ DEVICE_ KHR NULLand does not specify a valid Direct3D 10 device with which the cl_device_ids against which this context is to be created may interoperate
-
-
CL_INVALID_OPERATION -
if Direct3D 10 interoperability is specified by setting
CL_INVALID_to a non-D3D10_ DEVICE_ KHR NULLvalue and interoperability with another graphics API is also specified
-
The following errors may be returned if the cl_khr_
extension is supported:
-
CL_INVALID_D3D11_ DEVICE_ KHR -
if the value of the property
CL_CONTEXT_is non-D3D11_ DEVICE_ KHR NULLand does not specify a valid Direct3D 11 device with which the cl_device_ids against which this context is to be created may interoperate
-
-
CL_INVALID_OPERATION -
if Direct3D 11 interoperability is specified by setting
CL_INVALID_to a non-D3D11_ DEVICE_ KHR NULLvalue and interoperability with another graphics API is also specified
-
The following errors may be returned if the cl_khr_
extension is supported:
-
CL_INVALID_GL_ SHAREGROUP_ REFERENCE_ KHR -
if a context was specified for an OpenGL or OpenGL ES implementation using the EGL, GLX, or WGL binding APIs, as described for
clCreateContext; and any of the following conditions hold:-
The specified display and context properties do not identify a valid OpenGL or OpenGL ES context.
-
The specified context does not support buffer and renderbuffer objects.
-
The specified context is not compatible with the OpenCL context being created (for example, it exists in a physically distinct address space, such as another hardware device; or it does not support sharing data with OpenCL due to implementation restrictions).
-
-
-
CL_INVALID_GL_ SHAREGROUP_ REFERENCE_ KHR -
if a share group was specified for a CGL-based OpenGL implementation by setting the property
CL_CGL_, and the specified share group does not identify a valid CGL share group objectSHAREGROUP_ KHR
-
-
CL_INVALID_OPERATION -
if a context was specified as described above and any of the following conditions hold:
-
A context or share group object was specified for one of CGL, EGL, GLX, or WGL and the OpenGL implementation does not support that window-system binding API.
-
More than one of the properties
CL_CGL_,SHAREGROUP_ KHR CL_EGL_,DISPLAY_ KHR CL_GLX_, andDISPLAY_ KHR CL_WGL_is set to a non-default value.HDC_ KHR -
Both of the properties
CL_CGL_andSHAREGROUP_ KHR CL_GL_are set to non-default values.CONTEXT_ KHR -
Any of the devices specified in the devices argument cannot support OpenCL objects which share the data store of an OpenGL object.
-
-
-
CL_INVALID_PROPERTY -
if both
CL_CONTEXT_, and any of the properties defined by theINTEROP_ USER_ SYNC cl_khr_extension are defined in propertiesgl_ sharing
-
Document Notes
For more information, see the OpenCL Specification
This page is extracted from the OpenCL Specification. Fixes and changes should be made to the Specification, not directly.