Skip to content

Commit 3abc64c

Browse files
committed
[L0] Remove SingleRootDevice from context
This variable is not initialized in any way and it is set to nullptr by default.
1 parent 78ccd5d commit 3abc64c

File tree

3 files changed

+15
-67
lines changed

3 files changed

+15
-67
lines changed

source/adapters/level_zero/context.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,6 @@ ur_result_t urContextSetExtendedDeleter(
192192
} // namespace ur::level_zero
193193

194194
ur_result_t ur_context_handle_t_::initialize() {
195-
196-
// We may allocate memory to this root device so create allocators.
197-
if (SingleRootDevice &&
198-
DeviceMemPools.find(SingleRootDevice->ZeDevice) == DeviceMemPools.end()) {
199-
createUSMAllocators(SingleRootDevice);
200-
}
201-
202195
// Create the immediate command list to be used for initializations.
203196
// Created as synchronous so level-zero performs implicit synchronization and
204197
// there is no need to query for completion in the plugin
@@ -209,7 +202,7 @@ ur_result_t ur_context_handle_t_::initialize() {
209202
// D2D migartion, if no P2P, is broken since it should use
210203
// immediate command-list for the specfic devices, and this single one.
211204
//
212-
ur_device_handle_t Device = SingleRootDevice ? SingleRootDevice : Devices[0];
205+
ur_device_handle_t Device = Devices[0];
213206

214207
// Prefer to use copy engine for initialization copies,
215208
// if available and allowed (main copy engine with index 0).

source/adapters/level_zero/context.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,6 @@ struct ur_context_handle_t_ : _ur_object {
9898
// compute and copy command list caches.
9999
ur_mutex ZeCommandListCacheMutex;
100100

101-
// If context contains one device or sub-devices of the same device, we want
102-
// to save this device.
103-
// This field is only set at ur_context_handle_t creation time, and cannot
104-
// change. Therefore it can be accessed without holding a lock on this
105-
// ur_context_handle_t.
106-
ur_device_handle_t SingleRootDevice = nullptr;
107-
108101
// Cache of all currently available/completed command/copy lists.
109102
// Note that command-list can only be re-used on the same device.
110103
//

source/adapters/level_zero/memory.cpp

Lines changed: 14 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,9 +1592,7 @@ ur_result_t urMemImageCreate(
15921592
// own the image.
15931593
// TODO: Implement explicit copying for acessing the image from other devices
15941594
// in the context.
1595-
ur_device_handle_t Device = Context->SingleRootDevice
1596-
? Context->SingleRootDevice
1597-
: Context->Devices[0];
1595+
ur_device_handle_t Device = Context->Devices[0];
15981596
ze_image_handle_t ZeImage;
15991597
ZE2UR_CALL(zeImageCreate,
16001598
(Context->ZeContext, Device->ZeDevice, &ZeImageDesc, &ZeImage));
@@ -2154,58 +2152,22 @@ ur_result_t _ur_buffer::getZeHandle(char *&ZeHandle, access_mode_t AccessMode,
21542152
LastDeviceWithValidAllocation = Device;
21552153
return UR_RESULT_SUCCESS;
21562154
}
2157-
// Reads user setting on how to deal with buffers in contexts where
2158-
// all devices have the same root-device. Returns "true" if the
2159-
// preference is to have allocate on each [sub-]device and migrate
2160-
// normally (copy) to other sub-devices as needed. Returns "false"
2161-
// if the preference is to have single root-device allocations
2162-
// serve the needs of all [sub-]devices, meaning potentially more
2163-
// cross-tile traffic.
2164-
//
2165-
static const bool SingleRootDeviceBufferMigration = [] {
2166-
const char *UrRet =
2167-
std::getenv("UR_L0_SINGLE_ROOT_DEVICE_BUFFER_MIGRATION");
2168-
const char *PiRet =
2169-
std::getenv("SYCL_PI_LEVEL_ZERO_SINGLE_ROOT_DEVICE_BUFFER_MIGRATION");
2170-
const char *EnvStr = UrRet ? UrRet : (PiRet ? PiRet : nullptr);
2171-
if (EnvStr)
2172-
return (std::stoi(EnvStr) != 0);
2173-
// The default is to migrate normally, which may not always be the
2174-
// best option (depends on buffer access patterns), but is an
2175-
// overall win on the set of the available benchmarks.
2176-
return true;
2177-
}();
21782155

21792156
// Peform actual device allocation as needed.
21802157
if (!Allocation.ZeHandle) {
2181-
if (!SingleRootDeviceBufferMigration && UrContext->SingleRootDevice &&
2182-
UrContext->SingleRootDevice != Device) {
2183-
// If all devices in the context are sub-devices of the same device
2184-
// then we reuse root-device allocation by all sub-devices in the
2185-
// context.
2186-
// TODO: we can probably generalize this and share root-device
2187-
// allocations by its own sub-devices even if not all other
2188-
// devices in the context have the same root.
2189-
UR_CALL(getZeHandle(ZeHandle, AccessMode, UrContext->SingleRootDevice,
2190-
phWaitEvents, numWaitEvents));
2191-
Allocation.ReleaseAction = allocation_t::keep;
2192-
Allocation.ZeHandle = ZeHandle;
2193-
Allocation.Valid = true;
2194-
return UR_RESULT_SUCCESS;
2195-
} else { // Create device allocation
2196-
if (DisjointPoolConfigInstance.EnableBuffers) {
2197-
Allocation.ReleaseAction = allocation_t::free;
2198-
ur_usm_desc_t USMDesc{};
2199-
USMDesc.align = getAlignment();
2200-
ur_usm_pool_handle_t Pool{};
2201-
UR_CALL(ur::level_zero::urUSMDeviceAlloc(
2202-
UrContext, Device, &USMDesc, Pool, Size,
2203-
reinterpret_cast<void **>(&ZeHandle)));
2204-
} else {
2205-
Allocation.ReleaseAction = allocation_t::free_native;
2206-
UR_CALL(ZeDeviceMemAllocHelper(reinterpret_cast<void **>(&ZeHandle),
2207-
UrContext, Device, Size));
2208-
}
2158+
// Create device allocation
2159+
if (DisjointPoolConfigInstance.EnableBuffers) {
2160+
Allocation.ReleaseAction = allocation_t::free;
2161+
ur_usm_desc_t USMDesc{};
2162+
USMDesc.align = getAlignment();
2163+
ur_usm_pool_handle_t Pool{};
2164+
UR_CALL(ur::level_zero::urUSMDeviceAlloc(
2165+
UrContext, Device, &USMDesc, Pool, Size,
2166+
reinterpret_cast<void **>(&ZeHandle)));
2167+
} else {
2168+
Allocation.ReleaseAction = allocation_t::free_native;
2169+
UR_CALL(ZeDeviceMemAllocHelper(reinterpret_cast<void **>(&ZeHandle),
2170+
UrContext, Device, Size));
22092171
}
22102172
Allocation.ZeHandle = ZeHandle;
22112173
} else {

0 commit comments

Comments
 (0)