'\" t .\" Title: clSetMemObjectDestructorCallback .\" Author: The Khronos Group .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 01/14/2021 .\" Manual: OpenCL Manual .\" Source: The Khronos Group .\" Language: English .\" .TH "CLSETMEMOBJECTDESTRU" "3clc" "01/14/2021" "The Khronos Group" "OpenCL Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" clSetMemObjectDestructorCallback \- Registers a user callback function with a memory object\&. .SH "" .HP \w'cl_int\ clSetMemObjectDestructorCallback('u .BI "cl_int clSetMemObjectDestructorCallback(cl_mem\ " "memobj" ", void\ (CL_CALLBACK\ *" "pfn_notify" ")\ (cl_mem\ \fImemobj\fR, void\ *" "user_data" "), void\ *" "user_data" ");" .SH "PARAMETERS" .PP \fImemobj\fR .RS 4 A valid memory object\&. .RE .PP \fIpfn_notify\fR .RS 4 The callback function that can be registered by the application\&. This callback function may be called asynchronously by the OpenCL implementation\&. It is the application\*(Aqs responsibility to ensure that the callback function is thread\-safe\&. The parameters to this callback function are: .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \fImemobj\fR: the memory object being deleted\&. When the user callback is called by the implementation, this memory object is no longer valid\&. \fImemobj\fR is only provided for reference purposes\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \fIuser_data\fR: a pointer to user supplied data\&. .RE .RE .PP \fIuser_data\fR .RS 4 Data which will be passed as the \fIuser_data\fR argument when \fIpfn_notify\fR is called\&. \fIuser_data\fR can be NULL\&. .RE .SH "NOTES" .PP Each call to \fBclSetMemObjectDestructorCallback\fR registers the specified user callback function on a callback stack associated with \fImemobj\fR\&. The registered user callback functions are called in the reverse order in which they were registered\&. The user callback functions are called and then the memory object\*(Aqs resources are freed and the memory object is deleted\&. This provides a mechanism for the application (and libraries) using \fImemobj\fR to be notified when the memory referenced by \fIhost_ptr\fR, specified when the memory object is created and used as the storage bits for the memory object, can be reused or freed\&. .PP When the user callback function is called by the implementation, the contents of the memory region pointed to by \fIhost_ptr\fR (if the memory object is created with \fBCL_MEM_USE_HOST_PTR\fR) are undefined\&. The callback function is typically used by the application to either free or reuse the memory region pointed to by \fIhost_ptr\fR\&. .PP The behavior of calling expensive system routines, OpenCL API calls to create contexts or command\-queues, or blocking OpenCL operations from the following list below, in a callback is undefined\&. .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \fBclFinish\fR(3clc).RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \fBclWaitForEvents\fR(3clc).RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} blocking calls to \fBclEnqueueReadBuffer\fR(3clc), \fBclEnqueueReadBufferRect\fR(3clc), \fBclEnqueueWriteBuffer\fR(3clc), \fBclEnqueueWriteBufferRect\fR(3clc).RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} blocking calls to \fBclEnqueueReadImage\fR(3clc) and \fBclEnqueueWriteImage\fR(3clc).RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} blocking calls to \fBclEnqueueMapBuffer\fR(3clc) and \fBclEnqueueMapImage\fR(3clc).RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} blocking calls to \fBclBuildProgram\fR(3clc), \fBclCompileProgram\fR(3clc), or \fBclLinkProgram\fR(3clc).RE .PP If an application needs to wait for completion of a routine from the above list in a callback, please use the non\-blocking form of the function, and assign a completion callback to it to do the remainder of your work\&. Note that when a callback (or other code) enqueues commands to a command\-queue, the commands are not required to begin execution until the queue is flushed\&. In standard usage, blocking enqueue calls serve this role by implicitly flushing the queue\&. Since blocking calls are not permitted in callbacks, those callbacks that enqueue commands on a command queue should either call \fBclFlush\fR(3clc) on the queue before returning or arrange for \fBclFlush\fR(3clc) to be called later on another thread\&. .PP The user callback function may not call OpenCL APIs with the memory object for which the callback function is invoked and for such cases the behavior of OpenCL APIs is considered to be undefined\&. .SH "ERRORS" .PP Returns CL_SUCCESS if the function is executed successfully\&. Otherwise, it returns one of the following errors: .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_MEM_OBJECT if \fImemobj\fR is not a valid memory object\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_VALUE if \fIpfn_notify\fR is NULL\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL implementation on the device\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host\&. .RE .SH "SPECIFICATION" .PP \m[blue]\fBOpenCL Specification\fR\m[]\&\s-2\u[1]\d\s+2 .SH "SEE ALSO" .PP \fBclCreateCommandQueue\fR(3clc), \fBclGetCommandQueueInfo\fR(3clc), \fBclReleaseCommandQueue\fR(3clc), \fBclRetainCommandQueue\fR(3clc) .SH "AUTHORS" .PP \fBThe Khronos Group\fR .SH "COPYRIGHT" .br Copyright \(co 2007-2011 The Khronos Group Inc. .br Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials. .sp .SH "NOTES" .IP " 1." 4 OpenCL Specification .RS 4 \%page 119, section 5.4.1 - Retaining and Releasing Memory Objects .RE