C Specification

To query information about a context, call the function:

// Provided by CL_VERSION_1_0
cl_int clGetContextInfo(
    cl_context context,
    cl_context_info param_name,
    size_t param_value_size,
    void* param_value,
    size_t* param_value_size_ret);

Parameters

  • context specifies the OpenCL context being queried.

  • param_name is an enumeration constant that specifies the information to query.

  • param_value is a pointer to memory where the appropriate result being queried is returned. If param_value is NULL, it is ignored.

  • param_value_size specifies the size in bytes of memory pointed to by param_value. This size must be greater than or equal to the size of the return type specified in the Context Queries table. If param_value is NULL, it is ignored.

  • param_value_size_ret returns the actual size in bytes of data being queried by param_name. If param_value_size_ret is NULL, it is ignored.

Description

The list of supported param_name values and the information returned in param_value by clGetContextInfo is described in the Context Queries table.

Table 1. List of supported param_names by clGetContextInfo
Context Info Return Type Description

CL_CONTEXT_REFERENCE_COUNT [1]

cl_uint

Return the context reference count.

CL_CONTEXT_NUM_DEVICES

missing before version 1.1.

cl_uint

Return the number of devices in context.

CL_CONTEXT_DEVICES

cl_device_id[]

Return the list of devices and sub-devices in context.

CL_CONTEXT_PROPERTIES

cl_context_properties[]

Return the properties argument specified in clCreateContext or clCreateContextFromType.

If the properties argument specified in clCreateContext or clCreateContextFromType used to create context was not NULL, the implementation must return the values specified in the properties argument in the same order and without including additional properties.

If the properties argument specified in clCreateContext or clCreateContextFromType used to create context was NULL, the implementation must return param_value_size_ret equal to 0, indicating that there are no properties to be returned.

CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR

provided by the cl_khr_d3d10_sharing extension.

cl_bool

Returns CL_TRUE if Direct3D 10 resources created as shared by setting MiscFlags to include D3D10_RESOURCE_MISC_SHARED will perform faster when shared with OpenCL, compared with resources which have not set this flag. Otherwise returns CL_FALSE.

CL_CONTEXT_D3D11_PREFER_SHARED_RESOURCES_KHR

provided by the cl_khr_d3d11_sharing extension.

cl_bool

Returns CL_TRUE if Direct3D 11 resources created as shared by setting MiscFlags to include D3D11_RESOURCE_MISC_SHARED will perform faster when shared with OpenCL, compared with resources which have not set this flag. Otherwise returns CL_FALSE.

clGetContextInfo returns CL_SUCCESS if the function is executed successfully. Otherwise, it returns one of the following errors:

  • CL_INVALID_CONTEXT if context is not a valid context.

  • CL_INVALID_VALUE if param_name is not one of the supported values, or if the size in bytes specified by param_value_size is less than size of the return type specified in the Context Queries table and param_value is not NULL.

  • 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 2014-2025 The Khronos Group Inc.

SPDX-License-Identifier: CC-BY-4.0


1. The reference count returned should be considered immediately stale. It is unsuitable for general use in applications. This feature is provided for identifying memory leaks.