C Specification

To create an OpenCL context from a specific device type10, call the function:

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 is described in the Context Properties table. properties can also be NULL in which case the platform that is selected is implementation-defined.

  • device_type is a bit-field that identifies the type of device and is described in the Device Categories 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.

10

clCreateContextFromType may return all or a subset of the actual physical devices present in the platform and that match device_type.

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 properties is NULL and no platform could be selected or if platform value specified in properties is not a valid platform.

  • CL_​INVALID_​PROPERTY if context property name in properties is not a supported property name, if the value specified for a supported property name is not valid, or if the same property name is specified more than once. This error code is missing before version 1.1.

  • CL_​INVALID_​VALUE if pfn_notify is NULL but user_data is not NULL.

  • 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.

See Also

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.

Copyright (c) 2014-2020 Khronos Group. This work is licensed under a Creative Commons Attribution 4.0 International License.