KhronosGroup / OpenCL-Docs

OpenCL API, OpenCL C, Extensions, SPIR-V Environment Specs, Ref page, and C++ for OpenCL doc sources.
Other
349 stars 109 forks source link

valid values for clSetKernelExecInfo #1152

Open bashbaug opened 2 months ago

bashbaug commented 2 months ago

One of our engineers raised a question internally: if a set of indirectly accesseed SVM (or USM) pointers are set using clSetKernelExecInfo(CL_KERNEL_EXEC_INFO_SVM_PTRS), how are they "un-set"? To "un-set" all SVM pointers should an empty set be passed to clSetKernelExecInfo, specifically one where param_value_size is zero (and, possibly, param_value is nullptr)?

For reference: https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_API.html#clSetKernelExecInfo

The spec describes an error condition for invalid values, but never describes what values are considered invalid.

CL_INVALID_VALUE if param_name is not valid, if param_value is NULL or if the size specified by param_value_size is not valid.

I think we should clarify:

  1. The empty set is valid and is the proper way to "un-set" any previously set SVM (or USM) pointers. Specifically:
  2. When param_name is CL_KERNEL_EXEC_INFO_SVM_PTRS, passing zero for param_value_size is valid.
  3. When param_name is CL_KERNEL_EXEC_INFO_SVM_PTRS, passing nullptr for param_value is valid if and only if param_value_size is zero.

TBD: When param_name is CL_KERNEL_EXEC_INFO_SVM_PTRS, is it valid to pass zero for param_value_size, and a non-nullptr value for param_value, or is this an error?

bashbaug commented 2 months ago

Discussed in the April 16th teleconference:

bashbaug commented 1 month ago
  • Need to check if there is precedent for other APIs to mandate nullptr when the size is zero, or whether it is preferable to ignore the pointer when the size is zero.

I did a quick check and as far as I can see we usually mandate nullptr when the size is zero. Some examples:

I didn't find any pointer values that are ignored when a size is zero.

Therefore, unless someone wants to argue strongly that we break precedent and allow a non-NULL pointer in this case, I think we should require a NULL pointer, even if it requires special-case handling for an empty std::vector.