Skip to content

Commit eeb0a8a

Browse files
committed
Make device lookup when failing
Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 02e9613 commit eeb0a8a

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

sycl/doc/extensions/experimental/sycl_ext_oneapi_inter_process_communication.asciidoc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,17 @@ handle_data_t get(void *ptr, const sycl::context &ctx)
134134
!====
135135

136136
_Preconditions:_ `ptr` is a pointer to USM device memory on some device _D_ in
137-
context `ctx` and device _D_ returns `true` for
138-
`device::has(aspect::ext_oneapi_ipc_memory)`.
137+
context `ctx`. `ctx` is the same context as `ptr` was allocated against, using
138+
the USM device memory allocation routines.
139139

140140
_Returns:_ An IPC "handle" to this USM memory allocation. The bytes of this
141141
handle can be transferred to another process on the same system, and the other
142142
process can use the handle to get a pointer to the same USM allocation through a
143143
call to the `open` function.
144144

145+
_Throws:_ An exception with the `errc::feature_not_supported` error code if
146+
device _D_ does not have `aspect::ext_oneapi_ipc_memory`.
147+
145148
!====
146149
a!
147150
[source]

sycl/source/ipc_memory.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <detail/adapter_impl.hpp>
1010
#include <detail/context_impl.hpp>
1111
#include <sycl/context.hpp>
12+
#include <sycl/usm/usm_pointer_info.hpp>
1213
#include <sycl/ext/oneapi/experimental/ipc_memory.hpp>
1314

1415
namespace sycl {
@@ -19,13 +20,32 @@ __SYCL_EXPORT handle_data_t get(void *Ptr, const sycl::context &Ctx) {
1920
auto CtxImpl = sycl::detail::getSyclObjImpl(Ctx);
2021
sycl::detail::adapter_impl &Adapter = CtxImpl->getAdapter();
2122

23+
// If the API fails, check that the device actually supported it. We only do
24+
// this if UR fails to avoid the device-lookup overhead.
25+
auto CheckDeviceSupport = [Ptr, &Ctx]() {
26+
sycl::device Dev = get_pointer_device(Ptr, Ctx);
27+
if (!Dev.has(aspect::ext_oneapi_ipc_memory))
28+
throw sycl::exception(
29+
sycl::make_error_code(errc::feature_not_supported),
30+
"Device does not support aspect::ext_oneapi_ipc_memory.");
31+
};
32+
2233
size_t HandleSize = 0;
23-
Adapter.call<sycl::detail::UrApiKind::urIPCGetMemHandleExp>(
24-
CtxImpl->getHandleRef(), Ptr, nullptr, &HandleSize);
34+
auto UrRes =
35+
Adapter.call_nocheck<sycl::detail::UrApiKind::urIPCGetMemHandleExp>(
36+
CtxImpl->getHandleRef(), Ptr, nullptr, &HandleSize);
37+
if (UrRes != UR_RESULT_SUCCESS) {
38+
CheckDeviceSupport();
39+
Adapter.checkUrResult(UrRes);
40+
}
2541

2642
handle_data_t Res(HandleSize);
27-
Adapter.call<sycl::detail::UrApiKind::urIPCGetMemHandleExp>(
43+
UrRes = Adapter.call_nocheck<sycl::detail::UrApiKind::urIPCGetMemHandleExp>(
2844
CtxImpl->getHandleRef(), Ptr, Res.data(), nullptr);
45+
if (UrRes != UR_RESULT_SUCCESS) {
46+
CheckDeviceSupport();
47+
Adapter.checkUrResult(UrRes);
48+
}
2949
return Res;
3050
}
3151

0 commit comments

Comments
 (0)