C Specification

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

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 Info 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 is used to specify the size in bytes of memory pointed to by param_value. This size must be ≥ size of return type as described in the Memory Object Info table.

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

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_VALUE if param_name is not valid, or if size in bytes specified by param_value_size is < size of return type as described in the Memory Object Info 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-2023 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.