Description
#1332 introduces a number of PI API functions for creating various PI objects from native objects (piext*CreateWithNativeHandle
.) However, given that the CUDA backend is unable to share a reference count between the native object and the native object, like the OpenCL backend does, two solutions were proposed:
-
The user keeps ownership of the native object, which would require the CUDA backend to have a special case for PI objects that would not destroy the native object upon its own destruction. This would require the user to keep the native object alive while using the corresponding PI objects.
-
The created PI object takes ownership of the native object, which doesn't require change to neither of the backends, but can be implemented by not having these functions retain the native objects in the OpenCL BE. This requires that the user keeps the PI object alive while the native object is alive.
Of these options the second was chosen. With this implementation, in order to adhere to the requirement from the SYCL 1.2.1 specification that interoperability constructor must retain the OpenCL object, cl*Retain
is called in those constructors.
Currently these constructors are the only ones using the piext*CreateWithNativeHandle
at the moment, though they are expected to be a somewhat directly called by a future make
function similar to the new get_native
functions. At that point, the lifetime choices made for native objects with piext*CreateWithNativeHandle
becomes exposed to the user.
The point of this issue is to review these choices and make sure we reach a solution that we are happy with before this is directly exposed to the SYCL users. See discussion on the subject here: #1332 (comment).