@@ -56,7 +56,7 @@ class interop_handle {
5656#else
5757 (void )Acc;
5858 // we believe this won't be ever called on device side
59- return nullptr ;
59+ return 0 ;
6060#endif
6161 }
6262
@@ -89,7 +89,7 @@ class interop_handle {
8989 getNativeQueue ());
9090#else
9191 // we believe this won't be ever called on device side
92- return nullptr ;
92+ return 0 ;
9393#endif
9494 }
9595
@@ -104,7 +104,7 @@ class interop_handle {
104104 getNativeDevice ());
105105#else
106106 // we believe this won't be ever called on device side
107- return nullptr ;
107+ return 0 ;
108108#endif
109109 }
110110
@@ -119,7 +119,7 @@ class interop_handle {
119119 getNativeContext ());
120120#else
121121 // we believe this won't be ever called on device side
122- return nullptr ;
122+ return 0 ;
123123#endif
124124 }
125125
@@ -142,8 +142,26 @@ class interop_handle {
142142 auto getMemImpl (detail::Requirement *Req) const ->
143143 typename interop<BackendName,
144144 accessor<DataT, Dims, Mode, Target, IsPlh>>::type {
145- return reinterpret_cast <typename interop<
146- BackendName, accessor<DataT, Dims, Mode, Target, IsPlh>>::type>(
145+ /*
146+ Do not update this cast: a C-style cast is required here.
147+
148+ This function tries to cast pi_native_handle to the native handle type.
149+ pi_native_handle is a typedef of uintptr_t. It is used to store opaque
150+ pointers, such as cl_device, and integer handles, such as CUdevice. To
151+ convert a uintptr_t to a pointer type, such as cl_device, reinterpret_cast
152+ must be used. However, reinterpret_cast cannot be used to convert
153+ uintptr_t to a different integer type, such as CUdevice. For this,
154+ static_cast must be used. This function must employ a cast that is capable
155+ of reinterpret_cast and static_cast depending on the arguments passed to
156+ it. A C-style cast will achieve this. The compiler will attempt to
157+ interpret it as a static_cast, and will fall back to reinterpret_cast
158+ where appropriate.
159+
160+ https://en.cppreference.com/w/cpp/language/reinterpret_cast
161+ https://en.cppreference.com/w/cpp/language/explicit_cast
162+ */
163+ return (typename interop<BackendName,
164+ accessor<DataT, Dims, Mode, Target, IsPlh>>::type)(
147165 getNativeMem (Req));
148166 }
149167
0 commit comments