Create an OpenCL context from a device type that identifies the specific device(s) to use.
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) |
Specifies a list of context property names and their corresponding values. Each property name is immediately followed by the corresponding desired value. The list is terminated with 0. properties
can be NULL in which case the platform that is selected is implementation-defined. The list of supported properties is described in the table below.
cl_context_properties enum | Property value | Description |
---|---|---|
CL_CONTEXT_PLATFORM
|
cl_platform_id | Specifies the platform to use. |
CL_CONTEXT_D3D10_DEVICE_KHR
|
ID3D10Device* | If the cl_khr_d3d10_sharing extension is enabled, specifies the ID3D10Device* to use for Direct3D 10 interoperability. The default value is NULL. |
|
Available if the cl_khr_gl_sharing extension is enabled. |
A bit-field that identifies the type of device and is described in the table below.
cl_device_type | Description |
---|---|
CL_DEVICE_TYPE_CPU
|
An OpenCL device that is the host processor. The host processor runs the OpenCL implementations and is a single or multi-core CPU. |
CL_DEVICE_TYPE_GPU
|
An OpenCL device that is a GPU. By this we mean that the device can also be used to accelerate a 3D API such as OpenGL or DirectX. |
CL_DEVICE_TYPE_ACCELERATOR
|
Dedicated OpenCL accelerators (for example the IBM CELL Blade). These devices communicate with the host processor using a peripheral interconnect such as PCIe. |
CL_DEVICE_TYPE_DEFAULT
|
The default OpenCL device in the system. |
CL_DEVICE_TYPE_ALL
|
All OpenCL devices available in the system. |
pfn_notify
A callback function that can be registered by the application. This callback function will be used by the OpenCL implementation to report information on errors that occur in this context. This callback function may be called asynchronously by the OpenCL implementation.
It is the application's responsibility to ensure that the callback function is thread-safe. If pfn_notify
is NULL, no callback function is registered. The parameters to this callback function are:
errinfo
is a pointer to an error string.
private_info
and cb
represent a pointer to binary data that is returned by the OpenCL implementation that can be used to log additional information helpful in debugging the error.
user_data
is a pointer to user supplied data.
There are a number of cases where error notifications need to be delivered due to an error that occurs outside a context. Such notifications may not be delivered through the pfn_notify
callback. Where these notifications go is implementation-defined.
user_data
Passed as the user_data
argument when pfn_notify
is called. user_data can be NULL.
errcode_ret
Return an appropriate error code. If errcode_ret is NULL, no error code is returned.
clCreateContextFromType
may return all or a subset of the actual physical devices present in the platform and that match device_type
.
clCreateContextFromType
and clCreateContext perform an implicit retain. This is very helpful for 3rd party libraries, which typically get a context passed to them by the application.
However, it is possible that the application may delete the context without informing the library.
Allowing functions to attach to (i.e. retain) and release a context solves the problem of a context
being used by a library no longer being valid.
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 vlaues returned in errcode_ret
:
properties
is NULL and no platform could be selected or
if platform value specified in properties
is not a valid platform. (If the extension cl_khr_gl_sharing is enabled, then see error "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR" below.)
properties
is not a supported property
name, or if the value specified for a supported property name is not valid, or if the same property name is specified more than once.
pfn_notify
is NULL but user_data
is not NULL.
device_type
is not a valid value.
device_type
and property values
specified in properties
are currently available.
device_type
and property values
specified in properties
were found.
cl_device_ids
against which this context
is to be created may interoperate (if the
cl_khr_d3d10_sharing extension is enabled).
properties
if the cl_khr_gl_sharing extension is enabled.
clCreateContext, clGetContextInfo, clReleaseContext, clRetainContext, clGetContextInfo, Cardinality Diagram