C Specification

#pragma OPENCL EXTENSION cl_khr_initialize_memory : enable


Memory is allocated in various forms in OpenCL both explicitly (global memory) or implicitly (local, private memory). This allocation so far does not provide a straightforward mechanism to initialize the memory on allocation. In other words what is lacking is the equivalent of calloc for the currently supported malloc like capability. This functionality is useful for a variety of reasons including ease of debugging, application controlled limiting of visibility to previous contents of memory and in some cases, optimization.

This extension adds support for initializing local and private memory before a kernel begins execution. This extension name is cl_khr_initialize_memory.

Add a new context property to table 4.5 in section 4.4 (see clCreateContext):

cl_context_properties enum Property value Description



Describes which memory types for the context must be initialized. This is a bit-field, where the following values are currently supported:

+ * CL_CONTEXT_MEMORY_INITIALIZE_LOCAL_KHR - Initialize local memory to zeros. * CL_CONTEXT_MEMORY_INITIALIZE_PRIVATE_KHR - Initialize private memory to zeros.

Updates to section 6.9 - Restrictions:

If the context is created with CL CONTEXT MEMORY INITIALIZE KHR, appropriate memory locations as specified by the bit-field is initialized with zeroes, prior to the start of execution of any kernel. The driver chooses when, prior to kernel execution, the initialization of local and/or private memory is performed. The only requirement is there should be no values set from outside the context, which can be read during a kernel execution.

See Also

No cross-references are available

Document Notes

For more information, see the OpenCL Extension Specification at URL

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