OpenCL-Docs icon indicating copy to clipboard operation
OpenCL-Docs copied to clipboard

Clarify svm_ptr argument to clEnqueueSVMMemFill

Open bashbaug opened this issue 8 months ago • 0 comments

Found while discussing and developing the unified SVM extension: the current description for the svm_ptr argument to clEnqueueSVMMemFill is confusing and should be improved. For reference, the current text is:

svm_ptr is a pointer to a memory region that will be filled with pattern. It must be aligned to pattern_size bytes. If svm_ptr is allocated using clSVMAlloc then it must be allocated from the same context from which command_queue was created. Otherwise the behavior is undefined.

There are three specific svm_ptr cases I believe we need to document:

  1. svm_ptr is unaligned. This is a CL_INVALID_VALUE error.
  2. svm_ptr is NULL. This is a CL_INVALID_VALUE error.
  3. svm_ptr was allocated using clSVMAlloc from a different context. This is undefined behavior (note: even if the device supports system SVM?).
  4. svm_ptr was not allocated using clSVMAlloc. This is valid if the device associated with the command_queue supports system SVM, otherwise this is undefined behaivor.
  5. svm_ptr was allocated using clSVMAlloc from the same context. This is a valid.

Debatably cases (3) and (4) should be errors instead of undefined behavior, but this would be a change compared to the current spec. Note though:

  • It is possible for an implementation to return an error in these cases (because behavior is undefined), but this would not be required.
  • If we really wanted to, we could consider tightening the behavior for implementations supporting unified SVM.

bashbaug avatar Apr 16 '25 22:04 bashbaug