C Specification

To free a shared virtual memory buffer allocated using clSVMAlloc, call the function

void clSVMFree(
    cl_context context,
    void* svm_pointer);
clSVMFree is missing before version 2.0.


  • context is a valid OpenCL context used to create the SVM buffer. If no devices in context support SVM, no action occurs.

  • svm_pointer must be the value returned by a call to clSVMAlloc. If a NULL pointer is passed in svm_pointer, no action occurs.


Note that clSVMFree does not wait for previously enqueued commands that may be using svm_pointer to finish before freeing svm_pointer. It is the responsibility of the application to make sure that enqueued commands that use svm_pointer have finished before freeing svm_pointer. This can be done by enqueuing a blocking operation such as clFinish, clWaitForEvents, clEnqueueReadBuffer or by registering a callback with the events associated with enqueued commands and when the last enqueued command has finished freeing svm_pointer.

The behavior of using svm_pointer after it has been freed is undefined. In addition, if a buffer object is created using clCreateBuffer or clCreateBufferWithProperties with svm_pointer, the buffer object must first be released before the svm_pointer is freed.

The clEnqueueSVMFree API can also be used to enqueue a callback to free the shared virtual memory buffer allocated using clSVMAlloc or a shared system memory pointer.

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