|
| 1 | +//===--- test_sycl_peer_access.cpp - Test cases for device peer access ===// |
| 2 | +// |
| 3 | +// Data Parallel Control (dpctl) |
| 4 | +// |
| 5 | +// Copyright 2020-2025 Intel Corporation |
| 6 | +// |
| 7 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +// you may not use this file except in compliance with the License. |
| 9 | +// You may obtain a copy of the License at |
| 10 | +// |
| 11 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +// |
| 13 | +// Unless required by applicable law or agreed to in writing, software |
| 14 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +// See the License for the specific language governing permissions and |
| 17 | +// limitations under the License. |
| 18 | +// |
| 19 | +//===----------------------------------------------------------------------===// |
| 20 | +/// |
| 21 | +/// \file |
| 22 | +/// This file has unit test cases for peer access functions defined in |
| 23 | +/// dpctl_sycl_device_interface.h. |
| 24 | +/// |
| 25 | +//===----------------------------------------------------------------------===// |
| 26 | + |
| 27 | +#include "dpctl_sycl_device_interface.h" |
| 28 | +#include "dpctl_sycl_device_selector_interface.h" |
| 29 | +#include "dpctl_sycl_platform_interface.h" |
| 30 | +#include "dpctl_utils_helper.h" |
| 31 | + |
| 32 | +#include <gtest/gtest.h> |
| 33 | +#include <sycl/sycl.hpp> |
| 34 | + |
| 35 | +struct TestDPCTLPeerAccess : public ::testing::TestWithParam<const char *> |
| 36 | +{ |
| 37 | + DPCTLSyclPlatformRef P = nullptr; |
| 38 | + DPCTLSyclDeviceVectorRef DV = nullptr; |
| 39 | + |
| 40 | + TestDPCTLPeerAccess() |
| 41 | + { |
| 42 | + auto DS = DPCTLFilterSelector_Create(GetParam()); |
| 43 | + if (DS) { |
| 44 | + EXPECT_NO_FATAL_FAILURE(P = DPCTLPlatform_CreateFromSelector(DS)); |
| 45 | + } |
| 46 | + DPCTLDeviceSelector_Delete(DS); |
| 47 | + if (P) { |
| 48 | + DV = DPCTLPlatform_GetDevices(P); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + void SetUp() |
| 53 | + { |
| 54 | + if (!P || !DV) { |
| 55 | + auto message = "Skipping as no devices of type " + |
| 56 | + std::string(GetParam()) + "."; |
| 57 | + GTEST_SKIP_(message.c_str()); |
| 58 | + } |
| 59 | + |
| 60 | + if (DPCTLDeviceVector_Size(DV) < 2) { |
| 61 | + auto message = "Peer access tests require more than one device."; |
| 62 | + GTEST_SKIP_(message.c_str()); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + ~TestDPCTLPeerAccess() |
| 67 | + { |
| 68 | + DPCTLDeviceVector_Delete(DV); |
| 69 | + DPCTLPlatform_Delete(P); |
| 70 | + } |
| 71 | +}; |
| 72 | + |
| 73 | +TEST_P(TestDPCTLPeerAccess, ChkAccessSupported) |
| 74 | +{ |
| 75 | + auto D0 = DPCTLDeviceVector_GetAt(DV, 0); |
| 76 | + auto D1 = DPCTLDeviceVector_GetAt(DV, 1); |
| 77 | + ASSERT_TRUE(D0 != nullptr); |
| 78 | + ASSERT_TRUE(D1 != nullptr); |
| 79 | + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_CanAccessPeer( |
| 80 | + D0, D1, DPCTLPeerAccessType::access_supported)); |
| 81 | +} |
| 82 | + |
| 83 | +TEST_P(TestDPCTLSyclDeviceInterface, ChkAtomicsSupported) |
| 84 | +{ |
| 85 | + auto D0 = DPCTLDeviceVector_GetAt(DV, 0); |
| 86 | + auto D1 = DPCTLDeviceVector_GetAt(DV, 1); |
| 87 | + ASSERT_TRUE(D0 != nullptr); |
| 88 | + ASSERT_TRUE(D1 != nullptr); |
| 89 | + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_CanAccessPeer( |
| 90 | + D0, D1, DPCTLPeerAccessType::atomics_supported)); |
| 91 | +} |
| 92 | + |
| 93 | +TEST_P(TestDPCTLSyclDeviceInterface, ChkPeerAccess) |
| 94 | +{ |
| 95 | + auto D0 = DPCTLDeviceVector_GetAt(DV, 0); |
| 96 | + auto D1 = DPCTLDeviceVector_GetAt(DV, 1); |
| 97 | + ASSERT_TRUE(D0 != nullptr); |
| 98 | + ASSERT_TRUE(D1 != nullptr); |
| 99 | + bool canEnable = false; |
| 100 | + EXPECT_NO_FATAL_FAILURE(canEnable = DPCTLDevice_CanAccessPeer( |
| 101 | + D0, D1, DPCTLPeerAccessType::access_supported)); |
| 102 | + if (canEnable) { |
| 103 | + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_EnablePeerAccess(D0, D1)); |
| 104 | + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_DisablePeerAccess(D0, D1)); |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +INSTANTIATE_TEST_SUITE_P(DPCTLDeviceFns, |
| 109 | + TestDPCTLSyclDeviceInterface, |
| 110 | + ::testing::Values("level_zero", "cuda", "hip")); |
| 111 | + |
| 112 | +struct TestDPCTLPeerAccessNullArgs : public ::testing::Test |
| 113 | +{ |
| 114 | + DPCTLSyclDeviceRef Null_DR0 = nullptr; |
| 115 | + DPCTLSyclDeviceRef Null_DR1 = nullptr; |
| 116 | +}; |
| 117 | + |
| 118 | +TEST_F(TestDPCTLPeerAccessNullArgs, ChkAccessSupported) |
| 119 | +{ |
| 120 | + bool accessSupported = true; |
| 121 | + EXPECT_NO_FATAL_FAILURE( |
| 122 | + accessSupported = DPCTLDevice_CanAccessPeer( |
| 123 | + Null_DR0, Null_DR1, DPCTLPeerAccessType::access_supported)); |
| 124 | + ASSERT_FALSE(accessSupported); |
| 125 | +} |
| 126 | + |
| 127 | +TEST_F(TestDPCTLPeerAccessNullArgs, ChkAtomicsSupported) |
| 128 | +{ |
| 129 | + bool accessSupported = true; |
| 130 | + EXPECT_NO_FATAL_FAILURE( |
| 131 | + accessSupported = DPCTLDevice_CanAccessPeer( |
| 132 | + Null_DR0, Null_DR1, DPCTLPeerAccessType::atomics_supported)); |
| 133 | + ASSERT_FALSE(accessSupported); |
| 134 | +} |
| 135 | + |
| 136 | +TEST_F(TestDPCTLPeerAccessNullArgs, ChkPeerAccess) |
| 137 | +{ |
| 138 | + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_EnablePeerAccess(Null_DR0, Null_DR1)); |
| 139 | + EXPECT_NO_FATAL_FAILURE(DPCTLDevice_DisablePeerAccess(Null_DR0, Null_DR1)); |
| 140 | +} |
0 commit comments