Commit e2e57bf
committed
[UR][L0] Memory resident limit to enabled peers
Previously, USM memory was made resident on all peer devices regardless
of whether peer access had been explicitly enabled by the user. This
change limits memory residency to only those peer devices for which
peer access has been enabled via urUsmP2PEnablePeerAccessExp.
To support this, a per-device `peers` vector is introduced
(ur_device_handle_t_::PeerStatus) that tracks the peer-access state
(ENABLED, DISABLED, NO_CONNECTION) for every device on the platform.
The vector is populated at platform initialisation time using
zeDeviceGetP2PProperties and updated atomically when
urUsmP2PEnablePeerAccessExp / urUsmP2PDisablePeerAccessExp are called.
Key changes:
- device.hpp / device.cpp: introduce the PeerStatus enum
(ENABLED, DISABLED, NO_CONNECTION) and peers vector on
ur_device_handle_t_; add stream operators for logging device id and
PeerStatus values.
- platform.cpp: populate `peers` for every device during device-cache
initialisation.
- v2/context.cpp: add changeResidentDevice(),
getDevicesWhoseAllocationsCanBeAccessedFrom(), and
getDevicesWhichCanAccessAllocationsPresentOn() to update memory
residency in existing USM pools when peer-access state changes.
Fix urContextRelease to only remove the context from
Platform->Contexts and delete it when the reference count actually
reaches zero, preventing live contexts from being missed during
subsequent peer-access updates.
Replace UR_ASSERT with a conditional erase so that contexts created
via urContextCreateWithNativeHandle (which are not tracked in
Platform->Contexts) are released without error.
Fix changeResidentDevice to hold a shared lock on the context Mutex
while iterating usmPoolHandles, preventing a data race with
concurrent addUsmPool/removeUsmPool calls.
Fix a data race in getDevicesWhichCanAccessAllocationsPresentOn where
peerCandidateDevice->peers.size() was read in UR_FASSERT before the
scoped_lock was acquired; the lock is now moved before the assert,
consistent with getDevicesWhoseAllocationsCanBeAccessedFrom.
- v2/usm.cpp: build the resident-devices list from the source device
plus only the explicitly enabled peer devices (via
getDevicesWhichCanAccessAllocationsPresentOn), instead of passing
all platform devices to umfLevelZeroMemoryProviderParamsSetResidentDevices.
The previous code computed the enabled-peer set but discarded it,
making memory resident on all devices unconditionally.
- v2/usm_p2p.cpp: new file implementing urUsmP2PEnablePeerAccessExp,
urUsmP2PDisablePeerAccessExp, and urUsmP2PPeerAccessGetInfoExp for
the v2 adapter. Fix a data race where peers[] was written under a
shared (read) lock; changed to an exclusive scoped_lock.
Copy Platform->Contexts under ContextsMutex and iterate outside the
critical section to avoid holding the mutex during heavy
changeResidentDevice calls, reducing deadlock risk.
- CMakeLists.txt: move usm_p2p.cpp from the v1 build into v2/usm_p2p.cpp
in the v2 build so the v2 adapter uses its own P2P implementation.
- usm_p2p.cpp (v1): add diagnostic log messages to
urUsmP2PEnablePeerAccessExp and urUsmP2PDisablePeerAccessExp
clarifying that the operations are no-ops in v1 because P2P is
always enabled there.
- sycl/source/device.cpp: add a cross-platform check in
ext_oneapi_enable_peer_access / ext_oneapi_disable_peer_access and
throw sycl::exception(errc::invalid) when the two devices belong to
different platforms. Fix exception messages: "Can not" -> "Cannot".
- ur_pool_manager.hpp: propagate resident-devices information through
pool descriptors.
- backtrace.hpp / backtrace_lin.cpp: replace #define MAX_BACKTRACE_FRAMES
in backtrace.hpp with a static constexpr int; remove the now-redundant
redeclaration from backtrace_lin.cpp. This avoids macro leakage and
improves type safety.
- test/memory_residency.cpp: fix memory leak in
allocationExistsOnPeerWithEnabledAccess by freeing the USM allocation.
Co-authored-by: Łukasz Ślusarczyk <lukasz.slusarczyk@intel.com>
Co-authored-by: Lukasz Dorau <lukasz.dorau@intel.com>
Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>1 parent 929fd90 commit e2e57bf
17 files changed
Lines changed: 454 additions & 111 deletions
File tree
- sycl/source
- unified-runtime
- source
- adapters/level_zero
- v2
- common
- test/adapters/level_zero/v2
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
216 | | - | |
217 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
218 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
219 | 226 | | |
220 | 227 | | |
221 | 228 | | |
222 | 229 | | |
223 | 230 | | |
224 | | - | |
225 | | - | |
226 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
227 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
228 | 242 | | |
229 | 243 | | |
230 | 244 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
154 | 153 | | |
155 | 154 | | |
156 | 155 | | |
| |||
194 | 193 | | |
195 | 194 | | |
196 | 195 | | |
| 196 | + | |
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2353 | 2353 | | |
2354 | 2354 | | |
2355 | 2355 | | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
| 2360 | + | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
264 | 270 | | |
265 | 271 | | |
266 | 272 | | |
267 | 273 | | |
268 | 274 | | |
269 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
270 | 281 | | |
271 | 282 | | |
272 | 283 | | |
273 | 284 | | |
274 | 285 | | |
| 286 | + | |
275 | 287 | | |
276 | 288 | | |
277 | 289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
746 | 746 | | |
747 | 747 | | |
748 | 748 | | |
749 | | - | |
750 | | - | |
751 | | - | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
752 | 752 | | |
753 | 753 | | |
754 | 754 | | |
| |||
914 | 914 | | |
915 | 915 | | |
916 | 916 | | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
917 | 955 | | |
918 | 956 | | |
919 | 957 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
105 | 104 | | |
106 | 105 | | |
107 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
22 | | - | |
23 | | - | |
| 25 | + | |
| 26 | + | |
24 | 27 | | |
25 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
26 | 32 | | |
27 | 33 | | |
28 | 34 | | |
| |||
0 commit comments