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
1415namespace 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