C Specification

To get information that is common to all memory objects (buffer and image objects), call the function

// Provided by CL_VERSION_1_0
cl_int clGetMemObjectInfo(
    cl_mem memobj,
    cl_mem_info param_name,
    size_t param_value_size,
    void* param_value,
    size_t* param_value_size_ret);

Parameters

  • memobj specifies the memory object being queried.

  • param_name specifies the information to query. The list of supported param_name types and the information returned in param_value by clGetMemObjectInfo is described in the Memory Object Queries table.

  • 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 Memory Object 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

Table 1. List of supported param_names by clGetMemObjectInfo
Memory Object Info Return type Description

CL_MEM_TYPE

cl_mem_object_type

Returns one of the following values:

CL_MEM_OBJECT_BUFFER if memobj is created with clCreateBuffer, clCreateBufferWithProperties, or clCreateSubBuffer.

CL_MEM_OBJECT_IMAGE2D if memobj is created with clCreateImage2D.

CL_MEM_OBJECT_IMAGE3D if memobj is created with clCreateImage3D.

The value of image_descimage_type if memobj is created with clCreateImage or clCreateImageWithProperties.

CL_MEM_OBJECT_PIPE if memobj is created with clCreatePipe.

CL_MEM_FLAGS

cl_mem_flags

Return the flags argument value specified when memobj is created with clCreateBuffer,
clCreateBufferWithProperties,
clCreateSubBuffer,
clCreateImage,
clCreateImageWithProperties,
clCreateImage2D,
clCreateImage3D, or
clCreatePipe.

If memobj is a sub-buffer the memory access qualifiers inherited from parent buffer is also returned.

CL_MEM_SIZE

size_t

Return actual size of the data store associated with memobj in bytes.

CL_MEM_HOST_PTR

void*

If memobj is created with clCreateBuffer, clCreateBufferWithProperties, clCreateImage, clCreateImageWithProperties, clCreateImage2D, or clCreateImage3D, and CL_MEM_USE_HOST_PTR is specified in mem_flags, return the host_ptr argument value specified when memobj is created.

Otherwise, if memobj is created with clCreateSubBuffer, and memobj is created from a buffer that was created with CL_MEM_USE_HOST_PTR specified in mem_flags, return the host_ptr passed to clCreateBuffer or clCreateBufferWithProperties, plus the origin value specified in buffer_create_info when memobj is created.

Otherwise, returns NULL.

CL_MEM_MAP_COUNT [1]

cl_uint

Map count.

CL_MEM_REFERENCE_COUNT [2]

cl_uint

Return memobj reference count.

CL_MEM_CONTEXT

cl_context

Return context specified when memory object is created. If memobj is created using clCreateSubBuffer, the context associated with the memory object specified as the buffer argument to clCreateSubBuffer is returned.

CL_MEM_ASSOCIATED_MEMOBJECT

missing before version 1.1.

cl_mem

Return memory object from which memobj is created.

This returns the memory object specified as buffer argument to clCreateSubBuffer if memobj is a subbuffer object created using clCreateSubBuffer.

This returns image_descmem_object if memobj is an image object created using clCreateImage or clCreateImageWithProperties.

Otherwise, returns NULL.

CL_MEM_OFFSET

missing before version 1.1.

size_t

Return offset if memobj is a sub-buffer object created using clCreateSubBuffer.

This return 0 if memobj is not a subbuffer object.

CL_MEM_USES_SVM_POINTER

missing before version 2.0.

cl_bool

Return CL_TRUE if memobj is a buffer object that was created with CL_MEM_USE_HOST_PTR or is a sub-buffer object of a buffer object that was created with CL_MEM_USE_HOST_PTR and the host_ptr specified when the buffer object was created is a SVM pointer; otherwise returns CL_FALSE.

CL_MEM_PROPERTIES

missing before version 3.0.

cl_mem_properties[]

Return the properties argument specified in clCreateBufferWithProperties or clCreateImageWithProperties.

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

If memobj was created using clCreateBuffer, clCreateSubBuffer, clCreateImage, clCreateImage2D, or clCreateImage3D, or if the properties argument specified in clCreateBufferWithProperties or clCreateImageWithProperties was NULL, the implementation must return param_value_size_ret equal to 0, indicating that there are no properties to be returned.

CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR

provided by the cl_khr_dx9_media_sharing extension.

cl_dx9_media_adapter_type_khr

If memobj was created using clCreateFromDX9MediaSurfaceKHR, returns the adapter_type argument specified when memobj was created.

CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR

provided by the cl_khr_dx9_media_sharing extension.

cl_dx9_surface_info_khr

If memobj was created using clCreateFromDX9MediaSurfaceKHR, returns the surface_info argument specified when memobj was created.

CL_MEM_D3D10_RESOURCE_KHR

provided by the cl_khr_d3d10_sharing extension.

ID3D10Resource *

If memobj was created using clCreateFromD3D10BufferKHR, clCreateFromD3D10Texture2DKHR, or clCreateFromD3D10Texture3DKHR, returns the resource argument specified when memobj was created.

CL_MEM_D3D11_RESOURCE_KHR

provided by the cl_khr_d3d11_sharing extension.

ID3D11Resource *

If memobj was created using clCreateFromD3D11BufferKHR, clCreateFromD3D11Texture2DKHR, or clCreateFromD3D11Texture3DKHR, returns the resource argument specified when memobj was created.

CL_MEM_DEVICE_ADDRESS_EXT

provided by the cl_ext_buffer_device_address extension.

cl_mem_device_address_ext[]

If memobj was created using clCreateBufferWithProperties with the CL_MEM_DEVICE_PRIVATE_ADDRESS_EXT property set to CL_TRUE, returns a list of device addresses for the buffer, one for each device in the context in the same order as the list of devices passed to clCreateContext.

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

  • CL_INVALID_MEM_OBJECT if memobj is a not a valid memory object.

  • CL_INVALID_OPERATION is returned for the CL_MEM_DEVICE_ADDRESS_EXT query if the cl_ext_buffer_device_address is not supported or if the buffer was not allocated with CL_MEM_DEVICE_PRIVATE_ADDRESS_EXT.

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

The following errors may be returned if the cl_khr_dx9_media_sharing extension is supported:

  • CL_INVALID_DX9_MEDIA_SURFACE_KHR if param_name is CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR and memobj was not created by calling clCreateFromDX9MediaSurfaceKHR from a Direct3D9 surface.

The following errors may be returned if the cl_khr_d3d10_sharing extension is supported:

  • CL_INVALID_D3D10_RESOURCE_KHR if param_name is CL_MEM_D3D10_RESOURCE_KHR and memobj was not created by calling clCreateFromD3D10BufferKHR, clCreateFromD3D10Texture2DKHR, or clCreateFromD3D10Texture3DKHR.

The following errors may be returned if the cl_khr_d3d11_sharing extension is supported:

  • CL_INVALID_D3D11_RESOURCE_KHR if param_name is CL_MEM_D3D11_RESOURCE_KHR and memobj was not created by calling clCreateFromD3D11BufferKHR, clCreateFromD3D11Texture2DKHR, or clCreateFromD3D11Texture3DKHR.

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 map count returned should be considered immediately stale. It is unsuitable for general use in applications. This feature is provided for debugging.
2. 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.