Skip to content

Commit 531952b

Browse files
committed
[UR][L0] Disable USM residency P2P restriction by default
Disable the "Restrict USM residency to peers with enabled P2P access" feature by default: P2P access is now treated as enabled for all connectable peer devices out of the box, so USM allocations are made resident on all of them without requiring an explicit ext_oneapi_enable_peer_access() call. When the restriction is disabled, urUsmP2P(Enable|Disable)PeerAccessExp become no-ops that always return success, matching the behavior of the Level Zero V1 adapter. Add the SYCL_UR_L0_RESTRICT_USM_RESIDENCY_TO_P2P environment variable to opt back into the restrictive behavior on demand, requiring P2P access to be explicitly enabled for a peer before USM allocations become resident on it, and enforcing the enable/disable state machine. Update the tests that exercise this feature (sycl/test-e2e/USM/P2P/p2p_usm_residency.cpp and unified-runtime/test/adapters/level_zero/v2/memory_residency.cpp) to set the new environment variable so they keep testing the restrictive behavior. Document the new variable in EnvironmentVariables.md. Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
1 parent 1d40d57 commit 531952b

6 files changed

Lines changed: 48 additions & 5 deletions

File tree

sycl/doc/EnvironmentVariables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ older hardware or when SYCL_UR_USE_LEVEL_ZERO_V2=0 is set.</span>
294294
| `SYCL_PI_LEVEL_ZERO_IMMEDIATE_COMMANDLISTS_EVENT_CLEANUP_THRESHOLD` | Integer | If non-negative then the threshold is set to this value. If negative, the threshold is set to INT_MAX. Whenever the number of events associated with an immediate command list exceeds this threshold, a check is made for signaled events and these events are recycled. Setting this threshold low causes events to be checked more often, which could result in unneeded events being recycled sooner. However, more frequent event status checks may cost time. The default is 1000. | Legacy |
295295
| `SYCL_PI_LEVEL_ZERO_USM_RESIDENT` | Integer | Bit-mask controls if/where to make USM allocations resident at the time of allocation. Input value is of the form 0xHSD, where 4-bits of D control device allocations, 4-bits of S control shared allocations, and 4-bits of H control host allocations. Each 4-bit component is holding one of the following values: "0" - then no special residency is forced, "1" - then allocation is made resident at the device of allocation, or "2" - then allocation is made resident on all devices in the context of allocation that have P2P access to the device of allocation. Default is 0x002, i.e. force full residency for device allocations only. | Legacy |
296296
| `SYCL_PI_LEVEL_ZERO_USE_NATIVE_USM_MEMCPY2D` | Integer | When set to a positive value enables the use of Level Zero USM 2D memory copy operations. Default is 0. | Legacy |
297+
| `SYCL_UR_L0_RESTRICT_USM_RESIDENCY_TO_P2P` | Any(\*) | By default, USM device allocations are made resident on all peer devices and `ext_oneapi_enable_peer_access`/`ext_oneapi_disable_peer_access` are no-ops. Setting this variable restricts USM allocation residency to only those peer devices that have had P2P access explicitly enabled via `ext_oneapi_enable_peer_access`, requiring it to be enabled before an allocation is made resident on a peer and allowing it to be disabled again. | V2 |
297298

298299
`(*) Note: Any means this environment variable is effective when set to any non-null value.`
299300

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// UNSUPPORTED-INTENDED: Test is specific to the Level Zero v2 adapter.
3030
//
3131
// RUN: %{build} -o %t.out
32-
// RUN: env UR_LOADER_USE_LEVEL_ZERO_V2=1 %{run} %t.out
32+
// RUN: env UR_LOADER_USE_LEVEL_ZERO_V2=1 SYCL_UR_L0_RESTRICT_USM_RESIDENCY_TO_P2P=1 %{run} %t.out
3333

3434
#include <iostream>
3535
#include <vector>

unified-runtime/source/adapters/level_zero/device.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,26 @@
2121
#include "adapters/level_zero/platform.hpp"
2222
#include "common.hpp"
2323
#include "common/ur_ref_count.hpp"
24+
#include "ur_util.hpp"
2425
#include <unified-runtime/ur_ddi.h>
2526
#include <ur/ur.hpp>
2627
#include <ze_api.h>
2728
#include <zes_api.h>
2829

30+
// Controls whether USM device memory residency on peer devices is restricted
31+
// to peers with explicitly enabled P2P access (see
32+
// urUsmP2P(Enable|Disable)PeerAccessExp). This is disabled by default, which
33+
// means P2P access is treated as enabled for all connectable peers and USM
34+
// allocations are made resident on all of them. Set
35+
// SYCL_UR_L0_RESTRICT_USM_RESIDENCY_TO_P2P=1 to opt into the restrictive
36+
// behavior, requiring P2P access to be explicitly enabled for a peer before
37+
// USM allocations become resident on it.
38+
inline bool restrictUsmResidencyToP2P() {
39+
static const bool RestrictUsmResidencyToP2P =
40+
getenv_tobool("SYCL_UR_L0_RESTRICT_USM_RESIDENCY_TO_P2P", false);
41+
return RestrictUsmResidencyToP2P;
42+
}
43+
2944
enum EventsScope {
3045
// All events are created host-visible.
3146
AllHostVisible,

unified-runtime/source/adapters/level_zero/platform.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,9 +1119,22 @@ ur_result_t ur_platform_handle_t_::populateDeviceCacheIfNeeded() {
11191119
continue;
11201120
}
11211121

1122-
UR_LOG(INFO, "p2p access to memory of dev:{} from dev:{} can be enabled",
1123-
peerId, dev->Id.value());
1124-
dev->peers[peerId] = ur_device_handle_t_::PeerStatus::DISABLED;
1122+
// By default (i.e. unless SYCL_UR_L0_RESTRICT_USM_RESIDENCY_TO_P2P is
1123+
// set), P2P access is treated as enabled for all connectable peers, so
1124+
// that USM allocations are made resident on all of them without
1125+
// requiring the user to call urUsmP2PEnablePeerAccessExp explicitly.
1126+
if (restrictUsmResidencyToP2P()) {
1127+
UR_LOG(INFO,
1128+
"p2p access to memory of dev:{} from dev:{} can be enabled",
1129+
peerId, dev->Id.value());
1130+
dev->peers[peerId] = ur_device_handle_t_::PeerStatus::DISABLED;
1131+
} else {
1132+
UR_LOG(INFO,
1133+
"p2p access to memory of dev:{} from dev:{} is enabled by "
1134+
"default",
1135+
peerId, dev->Id.value());
1136+
dev->peers[peerId] = ur_device_handle_t_::PeerStatus::ENABLED;
1137+
}
11251138
}
11261139
}
11271140

unified-runtime/source/adapters/level_zero/v2/usm_p2p.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ static ur_result_t urUsmP2PChangePeerAccessExp(ur_device_handle_t commandDevice,
4747
UR_LOG(INFO, "user tries to {} peer access to memory of {} from {}",
4848
(isAdding ? "enable" : "disable"), *peerDevice, *commandDevice);
4949

50+
if (!restrictUsmResidencyToP2P()) {
51+
// The restrictive P2P/residency feature is disabled (the default), so
52+
// P2P access is always considered enabled for connectable peers and USM
53+
// allocations are always resident on all of them. Ignore the requested
54+
// state change and report success, matching the behavior of the Level
55+
// Zero V1 adapter.
56+
UR_LOG(INFO,
57+
"ignored {} peer access to memory of {} from {}, because P2P is "
58+
"always enabled unless SYCL_UR_L0_RESTRICT_USM_RESIDENCY_TO_P2P is "
59+
"set",
60+
(isAdding ? "enabling" : "disabling"), *peerDevice, *commandDevice);
61+
return UR_RESULT_SUCCESS;
62+
}
63+
5064
{
5165
const auto expectedPeerStatus =
5266
isAdding ? ur_device_handle_t_::PeerStatus::DISABLED

unified-runtime/test/adapters/level_zero/v2/memory_residency.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

6-
// RUN: %with-v2 ZES_ENABLE_SYSMAN=1 ./memory_residency-test
6+
// RUN: %with-v2 ZES_ENABLE_SYSMAN=1 SYCL_UR_L0_RESTRICT_USM_RESIDENCY_TO_P2P=1 ./memory_residency-test
77
// REQUIRES: v2
88

99
#include "uur/fixtures.h"

0 commit comments

Comments
 (0)