Skip to content

Commit 7416a8b

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 53161f8 commit 7416a8b

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
@@ -190,13 +190,6 @@ ur_result_t urContextSetExtendedDeleter(
190190
} // namespace ur::level_zero
191191

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

212205
// Prefer to use copy engine for initialization copies,
213206
// 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
@@ -1524,9 +1524,7 @@ ur_result_t urMemImageCreate(
15241524
// own the image.
15251525
// TODO: Implement explicit copying for acessing the image from other devices
15261526
// in the context.
1527-
ur_device_handle_t Device = Context->SingleRootDevice
1528-
? Context->SingleRootDevice
1529-
: Context->Devices[0];
1527+
ur_device_handle_t Device = Context->Devices[0];
15301528
ze_image_handle_t ZeImage;
15311529
ZE2UR_CALL(zeImageCreate,
15321530
(Context->ZeContext, Device->ZeDevice, &ZeImageDesc, &ZeImage));
@@ -2073,58 +2071,22 @@ ur_result_t _ur_buffer::getZeHandle(char *&ZeHandle, access_mode_t AccessMode,
20732071
LastDeviceWithValidAllocation = Device;
20742072
return UR_RESULT_SUCCESS;
20752073
}
2076-
// Reads user setting on how to deal with buffers in contexts where
2077-
// all devices have the same root-device. Returns "true" if the
2078-
// preference is to have allocate on each [sub-]device and migrate
2079-
// normally (copy) to other sub-devices as needed. Returns "false"
2080-
// if the preference is to have single root-device allocations
2081-
// serve the needs of all [sub-]devices, meaning potentially more
2082-
// cross-tile traffic.
2083-
//
2084-
static const bool SingleRootDeviceBufferMigration = [] {
2085-
const char *UrRet =
2086-
std::getenv("UR_L0_SINGLE_ROOT_DEVICE_BUFFER_MIGRATION");
2087-
const char *PiRet =
2088-
std::getenv("SYCL_PI_LEVEL_ZERO_SINGLE_ROOT_DEVICE_BUFFER_MIGRATION");
2089-
const char *EnvStr = UrRet ? UrRet : (PiRet ? PiRet : nullptr);
2090-
if (EnvStr)
2091-
return (std::stoi(EnvStr) != 0);
2092-
// The default is to migrate normally, which may not always be the
2093-
// best option (depends on buffer access patterns), but is an
2094-
// overall win on the set of the available benchmarks.
2095-
return true;
2096-
}();
20972074

20982075
// Peform actual device allocation as needed.
20992076
if (!Allocation.ZeHandle) {
2100-
if (!SingleRootDeviceBufferMigration && UrContext->SingleRootDevice &&
2101-
UrContext->SingleRootDevice != Device) {
2102-
// If all devices in the context are sub-devices of the same device
2103-
// then we reuse root-device allocation by all sub-devices in the
2104-
// context.
2105-
// TODO: we can probably generalize this and share root-device
2106-
// allocations by its own sub-devices even if not all other
2107-
// devices in the context have the same root.
2108-
UR_CALL(getZeHandle(ZeHandle, AccessMode, UrContext->SingleRootDevice,
2109-
phWaitEvents, numWaitEvents));
2110-
Allocation.ReleaseAction = allocation_t::keep;
2111-
Allocation.ZeHandle = ZeHandle;
2112-
Allocation.Valid = true;
2113-
return UR_RESULT_SUCCESS;
2114-
} else { // Create device allocation
2115-
if (DisjointPoolConfigInstance.EnableBuffers) {
2116-
Allocation.ReleaseAction = allocation_t::free;
2117-
ur_usm_desc_t USMDesc{};
2118-
USMDesc.align = getAlignment();
2119-
ur_usm_pool_handle_t Pool{};
2120-
UR_CALL(ur::level_zero::urUSMDeviceAlloc(
2121-
UrContext, Device, &USMDesc, Pool, Size,
2122-
reinterpret_cast<void **>(&ZeHandle)));
2123-
} else {
2124-
Allocation.ReleaseAction = allocation_t::free_native;
2125-
UR_CALL(ZeDeviceMemAllocHelper(reinterpret_cast<void **>(&ZeHandle),
2126-
UrContext, Device, Size));
2127-
}
2077+
// Create device allocation
2078+
if (DisjointPoolConfigInstance.EnableBuffers) {
2079+
Allocation.ReleaseAction = allocation_t::free;
2080+
ur_usm_desc_t USMDesc{};
2081+
USMDesc.align = getAlignment();
2082+
ur_usm_pool_handle_t Pool{};
2083+
UR_CALL(ur::level_zero::urUSMDeviceAlloc(
2084+
UrContext, Device, &USMDesc, Pool, Size,
2085+
reinterpret_cast<void **>(&ZeHandle)));
2086+
} else {
2087+
Allocation.ReleaseAction = allocation_t::free_native;
2088+
UR_CALL(ZeDeviceMemAllocHelper(reinterpret_cast<void **>(&ZeHandle),
2089+
UrContext, Device, Size));
21282090
}
21292091
Allocation.ZeHandle = ZeHandle;
21302092
} else {

0 commit comments

Comments
 (0)