Skip to content

Commit

Permalink
Add comments explaining why nullptr is passed for dev arg
Browse files Browse the repository at this point in the history
  • Loading branch information
hdelan committed Feb 1, 2024
1 parent 7725cc9 commit 3245288
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sycl/source/detail/buffer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ buffer_impl::getNativeVector(backend BackendName) const {
}

pi_native_handle Handle;
// When doing buffer interop we don't know what device the memory should be
// resident on, so pass nullptr for Device param. Buffer interop may not be
// supported by all backends.
Plugin->call<PiApiKind::piextMemGetNativeHandle>(NativeMem, /*Dev*/ nullptr,
&Handle);
Handles.push_back(Handle);
Expand Down
6 changes: 6 additions & 0 deletions sycl/source/detail/memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ void memBufferCreateHelper(const PluginPtr &Plugin, pi_context Ctx,
// Always use call_nocheck here, because call may throw an exception,
// and this lambda will be called from destructor, which in combination
// rewards us with UB.
// When doing buffer interop we don't know what device the memory should
// be resident on, so pass nullptr for Device param. Buffer interop may
// not be supported by all backends.
Plugin->call_nocheck<PiApiKind::piextMemGetNativeHandle>(
*RetMem, /*Dev*/ nullptr, &Ptr);
emitMemAllocEndTrace(MemObjID, (uintptr_t)(Ptr), Size, 0 /* guard zone */,
Expand All @@ -168,6 +171,9 @@ void memReleaseHelper(const PluginPtr &Plugin, pi_mem Mem) {
// Do not make unnecessary PI calls without instrumentation enabled
if (xptiTraceEnabled()) {
pi_native_handle PtrHandle = 0;
// When doing buffer interop we don't know what device the memory should be
// resident on, so pass nullptr for Device param. Buffer interop may not be
// supported by all backends.
Plugin->call<PiApiKind::piextMemGetNativeHandle>(Mem, /*Dev*/ nullptr,
&PtrHandle);
Ptr = (uintptr_t)(PtrHandle);
Expand Down

0 comments on commit 3245288

Please sign in to comment.