Skip to content

Commit 7eb40a6

Browse files
let's pretend it all has been done in one commit
1 parent b37d0d4 commit 7eb40a6

File tree

14 files changed

+996
-6
lines changed

14 files changed

+996
-6
lines changed

unified-runtime/source/adapters/level_zero/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ if(UR_BUILD_ADAPTER_L0_V2)
165165
${CMAKE_CURRENT_SOURCE_DIR}/v2/memory.hpp
166166
${CMAKE_CURRENT_SOURCE_DIR}/v2/lockable.hpp
167167
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_api.hpp
168+
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_batched.hpp
168169
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_immediate_in_order.hpp
169170
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_immediate_out_of_order.hpp
170171
${CMAKE_CURRENT_SOURCE_DIR}/v2/usm.hpp
@@ -181,6 +182,7 @@ if(UR_BUILD_ADAPTER_L0_V2)
181182
${CMAKE_CURRENT_SOURCE_DIR}/v2/kernel.cpp
182183
${CMAKE_CURRENT_SOURCE_DIR}/v2/memory.cpp
183184
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_api.cpp
185+
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_batched.cpp
184186
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_create.cpp
185187
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_immediate_in_order.cpp
186188
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_immediate_out_of_order.cpp

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ ur_result_t ur_command_list_manager::appendGenericFillUnlocked(
6161
return UR_RESULT_SUCCESS;
6262
}
6363

64+
v2::raii::command_list_unique_handle &&
65+
ur_command_list_manager::releaseCommandList() {
66+
return std::move(zeCommandList);
67+
}
68+
69+
void ur_command_list_manager::replaceCommandList(
70+
v2::raii::command_list_unique_handle &&cmdlist) {
71+
zeCommandList = std::move(cmdlist);
72+
}
73+
6474
ur_result_t ur_command_list_manager::appendGenericCopyUnlocked(
6575
ur_mem_buffer_t *src, ur_mem_buffer_t *dst, bool blocking, size_t srcOffset,
6676
size_t dstOffset, size_t size, uint32_t numEventsInWaitList,
@@ -129,6 +139,7 @@ wait_list_view ur_command_list_manager::getWaitListView(
129139
numWaitEvents + (additionalWaitEvent != nullptr ? 1 : 0);
130140
waitList.resize(totalNumWaitEvents);
131141
for (uint32_t i = 0; i < numWaitEvents; i++) {
142+
phWaitEvents[i]->runBatch();
132143
waitList[i] = phWaitEvents[i]->getZeEvent();
133144
}
134145
if (additionalWaitEvent != nullptr) {

unified-runtime/source/adapters/level_zero/v2/command_list_manager.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ struct ur_command_list_manager {
231231
const ur_event_handle_t *phEventWaitList,
232232
ur_event_handle_t phEvent);
233233

234+
v2::raii::command_list_unique_handle &&releaseCommandList();
235+
236+
void replaceCommandList(v2::raii::command_list_unique_handle &&cmdlist);
237+
234238
private:
235239
ur_result_t appendGenericCommandListsExp(
236240
uint32_t numCommandLists, ze_command_list_handle_t *phCommandLists,

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "../ur_interface_loader.hpp"
2121

22+
ur_event_generation_t unbatchedQueue = 1;
23+
2224
static uint64_t adjustEndEventTimestamp(uint64_t adjustedStartTimestamp,
2325
uint64_t endTimestamp,
2426
uint64_t timestampMaxValue,
@@ -123,10 +125,20 @@ void ur_event_handle_t_::setQueue(ur_queue_t_ *hQueue) {
123125
profilingData.reset();
124126
}
125127

128+
void ur_event_handle_t_::setBatch(ur_event_generation_t batch_generation) {
129+
this->batchGeneration = batch_generation;
130+
}
131+
126132
void ur_event_handle_t_::setCommandType(ur_command_t commandType) {
127133
this->commandType = commandType;
128134
}
129135

136+
void ur_event_handle_t_::runBatch() {
137+
if (batchGeneration != unbatchedQueue) {
138+
hQueue->runBatchIfActive(batchGeneration);
139+
}
140+
}
141+
130142
void ur_event_handle_t_::recordStartTimestamp() {
131143
// queue and device must be set before calling this
132144
assert(hQueue);
@@ -192,6 +204,10 @@ ur_event_handle_t_::getEventEndTimestampAndHandle() {
192204

193205
ur_queue_t_ *ur_event_handle_t_::getQueue() const { return hQueue; }
194206

207+
ur_event_generation_t ur_event_handle_t_::getBatch() const {
208+
return batchGeneration;
209+
}
210+
195211
ur_context_handle_t ur_event_handle_t_::getContext() const { return hContext; }
196212

197213
ur_command_t ur_event_handle_t_::getCommandType() const { return commandType; }

unified-runtime/source/adapters/level_zero/v2/event.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include "common/ur_ref_count.hpp"
2121
#include "event_provider.hpp"
2222

23+
using ur_event_generation_t = int64_t;
24+
extern ur_event_generation_t unbatchedQueue;
25+
2326
namespace v2 {
2427
class event_pool;
2528
}
@@ -68,7 +71,9 @@ struct ur_event_handle_t_ : ur_object {
6871

6972
// Set the queue and command that this event is associated with
7073
void setQueue(ur_queue_t_ *hQueue);
74+
void setBatch(ur_event_generation_t batch_generation);
7175
void setCommandType(ur_command_t commandType);
76+
void runBatch();
7277

7378
void reset();
7479
ze_event_handle_t getZeEvent() const;
@@ -98,6 +103,8 @@ struct ur_event_handle_t_ : ur_object {
98103
// Get the type of the command that this event is associated with
99104
ur_command_t getCommandType() const;
100105

106+
ur_event_generation_t getBatch() const;
107+
101108
// Get the device associated with this event
102109
ur_device_handle_t getDevice() const;
103110

@@ -129,6 +136,8 @@ struct ur_event_handle_t_ : ur_object {
129136
// queue and commandType that this event is associated with, set by enqueue
130137
// commands
131138
ur_queue_t_ *hQueue = nullptr;
139+
// default for non-batched queues
140+
ur_event_generation_t batchGeneration = unbatchedQueue; //-1;
132141
ur_command_t commandType = UR_COMMAND_FORCE_UINT32;
133142
ur_device_handle_t hDevice = nullptr;
134143

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void event_pool::free(ur_event_handle_t event) {
5050

5151
event->reset();
5252
freelist.push_back(event);
53+
event->setBatch(unbatchedQueue); //-1);
5354

5455
// The event is still in the pool, so we need to increment the refcount
5556
assert(event->RefCount.getCount() == 0);

unified-runtime/source/adapters/level_zero/v2/queue_api.hpp

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)