diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index dc206b55dac44..6796060dda3de 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -236,6 +236,12 @@ void device::ext_oneapi_disable_peer_access(const device &peer) { bool device::ext_oneapi_can_access_peer(const device &peer, ext::oneapi::peer_access attr) { + // Peer access cannot be granted across platforms, but the handles could + // potentially mimic device handles from other adapters, so we need to avoid + // calling the adapters with handles from other platforms. + if (peer.get_platform() != get_platform()) + return false; + ur_device_handle_t Device = impl->getHandleRef(); ur_device_handle_t Peer = peer.impl->getHandleRef(); diff --git a/sycl/test-e2e/USM/P2P/p2p_access_across_platforms.cpp b/sycl/test-e2e/USM/P2P/p2p_access_across_platforms.cpp new file mode 100644 index 0000000000000..a2759d51ff21c --- /dev/null +++ b/sycl/test-e2e/USM/P2P/p2p_access_across_platforms.cpp @@ -0,0 +1,28 @@ +// RUN: %{build} -o %t.out +// RUN: %{run} %t.out + +// Tests that P2P access is not reported as possible across platforms. + +#include +#include +#include + +int main() { + sycl::device D1; + sycl::device D2 = D1; + for (sycl::platform P : sycl::platform::get_platforms()) { + if (P != D1.get_platform() && !P.get_devices().empty()) { + D2 = P.get_devices()[0]; + break; + } + } + + if (D1 == D2) { + std::cout << "There are no devices from different platforms. Skipping." + << std::endl; + return 0; + } + + assert(!D1.ext_oneapi_can_access_peer(D2)); + return 0; +}