Skip to content

Commit 834a25f

Browse files
committed
[SYCL][Docs] Fix sycl_ext_oneapi_peer_access implementation and extension
This commit fixes the following bugs in the specification and extension: * Changes the exceptions from repeat calls to enabling and disabling to undefined behavior. The implementation did not properly issue the specified exception before. * Implement the exception from attempting to enable access between devices that do not support peer access between them. * Make the access support query return false for backends that do not support it. * Specify and implement the relaxation that the access can be enabled when both devices are the same, even if the backend doesn't support P2P. * Specify that devices need to be from the same platform, rather than with the same backend. * Add the missing feature test macro. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 8128c0c commit 834a25f

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

sycl/doc/extensions/supported/sycl_ext_oneapi_peer_access.asciidoc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ This extension is implemented and fully supported by DPC++.
4949
This extension is currently implemented in DPC++ for all GPU devices and
5050
backends; however, only the CUDA, HIP and Level Zero backends allows peer to
5151
peer memory access. Other backends report false from the
52-
`ext_oneapi_can_access_peer` query. Peer-Peer memory access is only possible
53-
between two devices from the same backend.
52+
`ext_oneapi_can_access_peer` query, unless both devices are the same. Peer
53+
memory access is only possible between two devices from the same SYCL platform.
5454

5555
== Overview
5656

@@ -153,13 +153,17 @@ functions may access USM device allocations on the peer device subject to the
153153
normal rules about context as described in the core SYCL specification.
154154
If this device does not support peer access (as defined by
155155
`peer_access::access_supported`), throws an `exception` with the
156-
`errc::feature_not_supported` error code. If access is already enabled,
157-
throws an exception with the `errc::invalid` error code.
156+
`errc::feature_not_supported` error code.
157+
158+
Calling this function with `peer` for which access has already been enabled will
159+
result in undefined behavior.
158160

159161

160162
|void ext_oneapi_disable_peer_access(const device &peer)
161-
|Disables access to the peer device's memory from this device. If peer access
162-
is not enabled, throws an `exception` with the `errc::invalid` error code.
163+
|Disables access to the peer device's memory from this device.
164+
165+
Calling this function with `peer` for which access is not enabled will result in
166+
undefined behavior.
163167

164168
|===
165169

sycl/source/device.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ void device::ext_oneapi_enable_peer_access(const device &peer) {
220220
ur_device_handle_t Device = impl->getHandleRef();
221221
ur_device_handle_t Peer = peer.impl->getHandleRef();
222222
if (Device != Peer) {
223+
if (!ext_oneapi_can_access_peer(peer))
224+
throw sycl::exception(make_error_code(errc::invalid),
225+
"Peer access is not allowed between the devices.");
223226
detail::adapter_impl &Adapter = impl->getAdapter();
224227
Adapter.call<detail::UrApiKind::urUsmP2PEnablePeerAccessExp>(Device, Peer);
225228
}
@@ -255,9 +258,14 @@ bool device::ext_oneapi_can_access_peer(const device &peer,
255258
}();
256259
detail::adapter_impl &Adapter = impl->getAdapter();
257260
int value = 0;
258-
Adapter.call<detail::UrApiKind::urUsmP2PPeerAccessGetInfoExp>(
259-
Device, Peer, UrAttr, sizeof(int), &value, nullptr);
261+
auto Err =
262+
Adapter.call_nocheck<detail::UrApiKind::urUsmP2PPeerAccessGetInfoExp>(
263+
Device, Peer, UrAttr, sizeof(int), &value, nullptr);
260264

265+
// If the backend doesn't support P2P access, neither does its devices.
266+
if (Err == UR_RESULT_ERROR_UNSUPPORTED_FEATURE)
267+
return false;
268+
checkUrResult<errc>(Err);
261269
return value == 1;
262270
}
263271

sycl/source/feature_test.hpp.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ inline namespace _V1 {
124124
#define SYCL_KHR_DEFAULT_CONTEXT 1
125125
#define SYCL_EXT_INTEL_EVENT_MODE 1
126126
#define SYCL_EXT_ONEAPI_TANGLE 1
127+
#define SYCL_EXT_ONEAPI_PEER_ACCESS 1
127128

128129
// Unfinished KHR extensions. These extensions are only available if the
129130
// __DPCPP_ENABLE_UNFINISHED_KHR_EXTENSIONS macro is defined.

sycl/test-e2e/USM/P2P/p2p_access.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// REQUIRES: cuda || hip || level_zero
21
// RUN: %{build} -o %t.out
32
// RUN: %{run} %t.out
43

sycl/test-e2e/USM/P2P/p2p_atomics.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// REQUIRES: cuda || hip || level_zero
21
// RUN: %{build} %if target-nvidia %{ -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_61 %} -o %t.out
32
// RUN: %{run} %t.out
43

0 commit comments

Comments
 (0)