Skip to content

Commit 9ffb5ff

Browse files
authored
Merge pull request #2686 from igchor/fix_context_dtor
[L0 v2] reorder context members
2 parents 7e92f84 + 57161d2 commit 9ffb5ff

File tree

8 files changed

+26
-21
lines changed

8 files changed

+26
-21
lines changed

source/adapters/level_zero/v2/command_buffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ urCommandBufferCreateExp(ur_context_handle_t context, ur_device_handle_t device,
6565
uint32_t queueGroupOrdinal =
6666
device->QueueGroup[queue_group_type::Compute].ZeOrdinal;
6767
v2::raii::command_list_unique_handle zeCommandList =
68-
context->commandListCache.getRegularCommandList(device->ZeDevice, true,
69-
queueGroupOrdinal, true);
68+
context->getCommandListCache().getRegularCommandList(
69+
device->ZeDevice, true, queueGroupOrdinal, true);
7070

7171
*commandBuffer = new ur_exp_command_buffer_handle_t_(
7272
context, device, std::move(zeCommandList), commandBufferDesc);

source/adapters/level_zero/v2/command_list_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ur_command_list_manager::ur_command_list_manager(
1919
v2::raii::command_list_unique_handle &&commandList, v2::event_flags_t flags,
2020
ur_queue_t_ *queue)
2121
: context(context), device(device),
22-
eventPool(context->eventPoolCache.borrow(device->Id.value(), flags)),
22+
eventPool(context->getEventPoolCache().borrow(device->Id.value(), flags)),
2323
zeCommandList(std::move(commandList)), queue(queue) {
2424
UR_CALL_THROWS(ur::level_zero::urContextRetain(context));
2525
UR_CALL_THROWS(ur::level_zero::urDeviceRetain(device));

source/adapters/level_zero/v2/context.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ ur_context_handle_t_::ur_context_handle_t_(ze_context_handle_t hContext,
4848
uint32_t numDevices,
4949
const ur_device_handle_t *phDevices,
5050
bool ownZeContext)
51-
: commandListCache(hContext),
51+
: hContext(hContext, ownZeContext),
52+
hDevices(phDevices, phDevices + numDevices), commandListCache(hContext),
5253
eventPoolCache(this, phDevices[0]->Platform->getNumDevices(),
5354
[context = this, platform = phDevices[0]->Platform](
5455
DeviceId deviceId, v2::event_flags_t flags)
@@ -65,8 +66,6 @@ ur_context_handle_t_::ur_context_handle_t_(ze_context_handle_t hContext,
6566
nativeEventsPool(this, std::make_unique<v2::provider_normal>(
6667
this, v2::QUEUE_IMMEDIATE,
6768
v2::EVENT_FLAGS_PROFILING_ENABLED)),
68-
hContext(hContext, ownZeContext),
69-
hDevices(phDevices, phDevices + numDevices),
7069
p2pAccessDevices(populateP2PDevices(
7170
phDevices[0]->Platform->getNumDevices(), this->hDevices)),
7271
defaultUSMPool(this, nullptr) {}

source/adapters/level_zero/v2/context.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,31 @@ struct ur_context_handle_t_ : _ur_object {
2626

2727
inline ze_context_handle_t getZeHandle() const { return hContext.get(); }
2828
ur_platform_handle_t getPlatform() const;
29+
2930
const std::vector<ur_device_handle_t> &getDevices() const;
3031
ur_usm_pool_handle_t getDefaultUSMPool();
32+
3133
const std::vector<ur_device_handle_t> &
3234
getP2PDevices(ur_device_handle_t hDevice) const;
3335

36+
v2::event_pool &getNativeEventsPool() { return nativeEventsPool; }
37+
v2::event_pool_cache &getEventPoolCache() { return eventPoolCache; }
38+
v2::command_list_cache_t &getCommandListCache() { return commandListCache; }
39+
3440
// Checks if Device is covered by this context.
3541
// For that the Device or its root devices need to be in the context.
3642
bool isValidDevice(ur_device_handle_t Device) const;
3743

44+
private:
45+
const v2::raii::ze_context_handle_t hContext;
46+
const std::vector<ur_device_handle_t> hDevices;
3847
v2::command_list_cache_t commandListCache;
3948
v2::event_pool_cache eventPoolCache;
4049

4150
// pool used for urEventCreateWithNativeHandle when native handle is NULL
4251
// (uses non-counter based events to allow for signaling from host)
4352
v2::event_pool nativeEventsPool;
4453

45-
private:
46-
const v2::raii::ze_context_handle_t hContext;
47-
const std::vector<ur_device_handle_t> hDevices;
48-
4954
// P2P devices for each device in the context, indexed by device id.
5055
const std::vector<std::vector<ur_device_handle_t>> p2pAccessDevices;
5156

source/adapters/level_zero/v2/event.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,10 @@ urEventCreateWithNativeHandle(ur_native_handle_t hNativeEvent,
391391
const ur_event_native_properties_t *pProperties,
392392
ur_event_handle_t *phEvent) try {
393393
if (!hNativeEvent) {
394-
assert((hContext->nativeEventsPool.getFlags() & v2::EVENT_FLAGS_COUNTER) ==
395-
0);
394+
assert((hContext->getNativeEventsPool().getFlags() &
395+
v2::EVENT_FLAGS_COUNTER) == 0);
396396

397-
*phEvent = hContext->nativeEventsPool.allocate();
397+
*phEvent = hContext->getNativeEventsPool().allocate();
398398
ZE2UR_CALL(zeEventHostSignal, ((*phEvent)->getZeEvent()));
399399
} else {
400400
*phEvent = new ur_event_handle_t_(hContext, hNativeEvent, pProperties);

source/adapters/level_zero/v2/memory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void ur_integrated_mem_handle_t::unmapHostPtr(
149149
static ur_result_t synchronousZeCopy(ur_context_handle_t hContext,
150150
ur_device_handle_t hDevice, void *dst,
151151
const void *src, size_t size) {
152-
auto commandList = hContext->commandListCache.getImmediateCommandList(
152+
auto commandList = hContext->getCommandListCache().getImmediateCommandList(
153153
hDevice->ZeDevice, true,
154154
hDevice
155155
->QueueGroup[ur_device_handle_t_::queue_group_info_t::type::Compute]

source/adapters/level_zero/v2/queue_immediate_in_order.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ur_queue_immediate_in_order_t::ur_queue_immediate_in_order_t(
6565
: hContext(hContext), hDevice(hDevice), flags(pProps ? pProps->flags : 0),
6666
commandListManager(
6767
hContext, hDevice,
68-
hContext->commandListCache.getImmediateCommandList(
68+
hContext->getCommandListCache().getImmediateCommandList(
6969
hDevice->ZeDevice, true, getZeOrdinal(hDevice),
7070
true /* always enable copy offload */,
7171
ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS,

test/adapters/level_zero/v2/command_list_cache_test.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,14 @@ TEST_P(CommandListCacheTest, CommandListsAreReusedByQueues) {
198198
}
199199
}
200200

201-
ASSERT_EQ(context->commandListCache.getNumImmediateCommandLists(), 0);
202-
ASSERT_EQ(context->commandListCache.getNumRegularCommandLists(), 0);
201+
ASSERT_EQ(context->getCommandListCache().getNumImmediateCommandLists(),
202+
0);
203+
ASSERT_EQ(context->getCommandListCache().getNumRegularCommandLists(), 0);
203204
} // Queues scope
204205

205-
ASSERT_EQ(context->commandListCache.getNumImmediateCommandLists(),
206+
ASSERT_EQ(context->getCommandListCache().getNumImmediateCommandLists(),
206207
NumUniqueQueueTypes);
207-
ASSERT_EQ(context->commandListCache.getNumRegularCommandLists(), 0);
208+
ASSERT_EQ(context->getCommandListCache().getNumRegularCommandLists(), 0);
208209
}
209210
}
210211

@@ -229,7 +230,7 @@ TEST_P(CommandListCacheTest, CommandListsCacheIsThreadSafe) {
229230
ASSERT_EQ(urQueueCreate(context, device, &QueueProps, Queue.ptr()),
230231
UR_RESULT_SUCCESS);
231232

232-
ASSERT_LE(context->commandListCache.getNumImmediateCommandLists(),
233+
ASSERT_LE(context->getCommandListCache().getNumImmediateCommandLists(),
233234
NumThreads);
234235
}
235236
});
@@ -239,6 +240,6 @@ TEST_P(CommandListCacheTest, CommandListsCacheIsThreadSafe) {
239240
Thread.join();
240241
}
241242

242-
ASSERT_LE(context->commandListCache.getNumImmediateCommandLists(),
243+
ASSERT_LE(context->getCommandListCache().getNumImmediateCommandLists(),
243244
NumThreads);
244245
}

0 commit comments

Comments
 (0)