Skip to content

Commit 649dc1d

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

File tree

19 files changed

+1115
-74
lines changed

19 files changed

+1115
-74
lines changed

devops/scripts/benchmarks/utils/compute_runtime.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,20 @@ def build_compute_runtime(self):
203203
# Remove -Werror...
204204
replace_in_file(cmakelists_path, r"\s-Werror(?:=[a-zA-Z]*)?", "")
205205

206-
log.info("Building Compute Runtime...")
207-
extra_config_args = [
208-
"-DNEO_ENABLE_i915_PRELIM_DETECTION=1",
209-
"-DNEO_ENABLE_I915_PRELIM_DETECTION=1",
210-
"-DNEO_SKIP_UNIT_TESTS=1",
211-
f"-DGMM_DIR={self.gmmlib}",
212-
f"-DLEVEL_ZERO_ROOT={self.level_zero}",
213-
]
214-
if options.build_igc:
215-
extra_config_args.append(f"-DIGC_DIR={self.igc}")
206+
log.info("Building Compute Runtime...")
207+
configure_command = [
208+
"cmake",
209+
f"-B {self.compute_runtime_build}",
210+
f"-S {self.compute_runtime_repo}",
211+
"-DCMAKE_BUILD_TYPE=Debug",
212+
"-DNEO_ENABLE_i915_PRELIM_DETECTION=1",
213+
"-DNEO_ENABLE_I915_PRELIM_DETECTION=1",
214+
"-DNEO_SKIP_UNIT_TESTS=1",
215+
f"-DGMM_DIR={self.gmmlib}",
216+
f"-DLEVEL_ZERO_ROOT={self.level_zero}",
217+
]
218+
if options.build_igc:
219+
configure_command.append(f"-DIGC_DIR={self.igc}")
216220

217221
project.configure(extra_args=extra_config_args)
218222
project.build()

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/adapter.cpp

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -506,72 +506,71 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
506506
bool forceLoadedAdapter = ur_getenv("UR_ADAPTERS_FORCE_LOAD").has_value();
507507
if (!forceLoadedAdapter) {
508508
#ifdef UR_ADAPTER_LEVEL_ZERO_V2
509-
auto [useV2, reason] = shouldUseV2Adapter();
510-
if (!useV2) {
511-
UR_LOG(INFO, "Skipping L0 V2 adapter: {}", reason);
512-
return;
513-
}
509+
auto [useV2, reason] = shouldUseV2Adapter();
510+
if (!useV2) {
511+
UR_LOG(INFO, "Skipping L0 V2 adapter: {}", reason);
512+
return;
513+
}
514514
#else
515-
auto [useV1, reason] = shouldUseV1Adapter();
516-
if (!useV1) {
517-
UR_LOG(INFO, "Skipping L0 V1 adapter: {}", reason);
518-
return;
519-
}
515+
auto [useV1, reason] = shouldUseV1Adapter();
516+
if (!useV1) {
517+
UR_LOG(INFO, "Skipping L0 V1 adapter: {}", reason);
518+
return;
519+
}
520520
#endif
521521
}
522522

523-
// Check if the user has enabled the default L0 SysMan initialization.
524-
const int UrSysmanZesinitEnable = [&UserForcedSysManInit] {
525-
const char *UrRet = std::getenv("UR_L0_ENABLE_ZESINIT_DEFAULT");
526-
if (!UrRet)
527-
return 0;
528-
UserForcedSysManInit &= 2;
529-
return std::atoi(UrRet);
530-
}();
531-
532-
bool ZesInitNeeded = UrSysmanZesinitEnable && !UrSysManEnvInitEnabled;
533-
// Unless the user has forced the SysMan init, we will check the device
534-
// version to see if the zesInit is needed.
535-
if (UserForcedSysManInit == 0 && checkDeviceIntelGPUIpVersionOrNewer(
536-
0x05004000) == UR_RESULT_SUCCESS) {
537-
if (UrSysManEnvInitEnabled) {
538-
setEnvVar("ZES_ENABLE_SYSMAN", "0");
539-
}
540-
ZesInitNeeded = true;
541-
}
542-
if (ZesInitNeeded) {
523+
// Check if the user has enabled the default L0 SysMan initialization.
524+
const int UrSysmanZesinitEnable = [&UserForcedSysManInit] {
525+
const char *UrRet = std::getenv("UR_L0_ENABLE_ZESINIT_DEFAULT");
526+
if (!UrRet)
527+
return 0;
528+
UserForcedSysManInit &= 2;
529+
return std::atoi(UrRet);
530+
}();
531+
532+
bool ZesInitNeeded = UrSysmanZesinitEnable && !UrSysManEnvInitEnabled;
533+
// Unless the user has forced the SysMan init, we will check the device
534+
// version to see if the zesInit is needed.
535+
if (UserForcedSysManInit == 0 &&
536+
checkDeviceIntelGPUIpVersionOrNewer(0x05004000) == UR_RESULT_SUCCESS) {
537+
if (UrSysManEnvInitEnabled) {
538+
setEnvVar("ZES_ENABLE_SYSMAN", "0");
539+
}
540+
ZesInitNeeded = true;
541+
}
542+
if (ZesInitNeeded) {
543543
#ifdef UR_STATIC_LEVEL_ZERO
544-
getDeviceByUUIdFunctionPtr = zesDriverGetDeviceByUuidExp;
545-
getSysManDriversFunctionPtr = zesDriverGet;
546-
sysManInitFunctionPtr = zesInit;
544+
getDeviceByUUIdFunctionPtr = zesDriverGetDeviceByUuidExp;
545+
getSysManDriversFunctionPtr = zesDriverGet;
546+
sysManInitFunctionPtr = zesInit;
547547
#else
548-
getDeviceByUUIdFunctionPtr = (zes_pfnDriverGetDeviceByUuidExp_t)
549-
ur_loader::LibLoader::getFunctionPtr(processHandle,
550-
"zesDriverGetDeviceByUuidExp");
551-
getSysManDriversFunctionPtr =
552-
(zes_pfnDriverGet_t)ur_loader::LibLoader::getFunctionPtr(
553-
processHandle, "zesDriverGet");
554-
sysManInitFunctionPtr =
555-
(zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr(processHandle,
556-
"zesInit");
548+
getDeviceByUUIdFunctionPtr =
549+
(zes_pfnDriverGetDeviceByUuidExp_t)ur_loader::LibLoader::getFunctionPtr(
550+
processHandle, "zesDriverGetDeviceByUuidExp");
551+
getSysManDriversFunctionPtr =
552+
(zes_pfnDriverGet_t)ur_loader::LibLoader::getFunctionPtr(
553+
processHandle, "zesDriverGet");
554+
sysManInitFunctionPtr = (zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr(
555+
processHandle, "zesInit");
557556
#endif
558-
}
559-
if (getDeviceByUUIdFunctionPtr && getSysManDriversFunctionPtr &&
560-
sysManInitFunctionPtr) {
561-
ze_init_flags_t L0ZesInitFlags = 0;
562-
UR_LOG(DEBUG, "\nzesInit with flags value of {}\n",
563-
static_cast<int>(L0ZesInitFlags));
564-
ZesResult = ZE_CALL_NOCHECK(sysManInitFunctionPtr, (L0ZesInitFlags));
565-
} else {
566-
ZesResult = ZE_RESULT_ERROR_UNINITIALIZED;
567-
}
557+
}
558+
if (getDeviceByUUIdFunctionPtr && getSysManDriversFunctionPtr &&
559+
sysManInitFunctionPtr) {
560+
ze_init_flags_t L0ZesInitFlags = 0;
561+
UR_LOG(DEBUG, "\nzesInit with flags value of {}\n",
562+
static_cast<int>(L0ZesInitFlags));
563+
ZesResult = ZE_CALL_NOCHECK(sysManInitFunctionPtr, (L0ZesInitFlags));
564+
} else {
565+
ZesResult = ZE_RESULT_ERROR_UNINITIALIZED;
566+
}
568567

569-
ur_result_t err = initPlatforms(this, platforms, ZesResult);
570-
if (err == UR_RESULT_SUCCESS) {
571-
Platforms = std::move(platforms);
572-
} else {
573-
throw err;
574-
}
568+
ur_result_t err = initPlatforms(this, platforms, ZesResult);
569+
if (err == UR_RESULT_SUCCESS) {
570+
Platforms = std::move(platforms);
571+
} else {
572+
throw err;
573+
}
575574
}
576575

577576
void globalAdapterOnDemandCleanup() {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "../ur_interface_loader.hpp"
1515
#include "logger/ur_logger.hpp"
1616
#include "queue_handle.hpp"
17+
#include "ur_api.h"
1718

1819
namespace {
1920

@@ -129,6 +130,12 @@ ur_result_t ur_exp_command_buffer_handle_t_::createCommandHandle(
129130
ur_result_t ur_exp_command_buffer_handle_t_::finalizeCommandBuffer() {
130131
// It is not allowed to append to command list from multiple threads.
131132
auto commandListLocked = commandListManager.lock();
133+
134+
// TODO check for queue
135+
// if (isFinalized) {
136+
// return UR_RESULT_SUCCESS;
137+
// }
138+
132139
UR_ASSERT(!isFinalized, UR_RESULT_ERROR_INVALID_OPERATION);
133140

134141
if (!isInOrder) {
@@ -214,6 +221,13 @@ ur_result_t ur_exp_command_buffer_handle_t_::applyUpdateCommands(
214221
return UR_RESULT_SUCCESS;
215222
}
216223

224+
ur_event_handle_t ur_exp_command_buffer_handle_t_::poolMe() {
225+
auto event = eventPool->allocate();
226+
event->setQueue(nullptr);
227+
228+
return event;
229+
}
230+
217231
ur_event_handle_t ur_exp_command_buffer_handle_t_::createEventIfRequested(
218232
ur_exp_command_buffer_sync_point_t *retSyncPoint) {
219233
if (retSyncPoint == nullptr) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "kernel.hpp"
2020
#include "lockable.hpp"
2121
#include "queue_api.hpp"
22+
#include "ur_api.h"
2223
#include <ze_api.h>
2324

2425
struct kernel_command_handle;
@@ -67,6 +68,9 @@ struct ur_exp_command_buffer_handle_t_ : public ur_object {
6768

6869
ur::RefCount RefCount;
6970

71+
// TODO remove
72+
ur_event_handle_t poolMe();
73+
7074
private:
7175
// Stores all sync points that are created by the command buffer.
7276
std::vector<ur_event_handle_t> syncPoints;

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
@@ -129,6 +129,9 @@ wait_list_view ur_command_list_manager::getWaitListView(
129129
numWaitEvents + (additionalWaitEvent != nullptr ? 1 : 0);
130130
waitList.resize(totalNumWaitEvents);
131131
for (uint32_t i = 0; i < numWaitEvents; i++) {
132+
// TODO is it a good place for it? mixing function purposes, but might miss
133+
// preprocessing elsewhere
134+
phWaitEvents[i]->runBatch();
132135
waitList[i] = phWaitEvents[i]->getZeEvent();
133136
}
134137
if (additionalWaitEvent != nullptr) {
@@ -499,6 +502,14 @@ ur_result_t ur_command_list_manager::appendTimestampRecordingExp(
499502
return UR_RESULT_SUCCESS;
500503
}
501504

505+
ur_result_t ur_command_list_manager::appendRegular(
506+
ze_command_list_handle_t *phCommandLists) {
507+
ZE2UR_CALL(zeCommandListImmediateAppendCommandListsExp,
508+
(getZeCommandList(), 1, phCommandLists, nullptr, 0, nullptr));
509+
510+
return UR_RESULT_SUCCESS;
511+
}
512+
502513
ur_result_t ur_command_list_manager::appendGenericCommandListsExp(
503514
uint32_t numCommandLists, ze_command_list_handle_t *phCommandLists,
504515
ur_event_handle_t phEvent, uint32_t numEventsInWaitList,

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

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

234+
ur_result_t appendRegular(ze_command_list_handle_t *phCommandLists);
235+
234236
private:
235237
ur_result_t appendGenericCommandListsExp(
236238
uint32_t numCommandLists, ze_command_list_handle_t *phCommandLists,

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <ze_api.h>
1212

13+
#include "adapters/level_zero/v2/usm.hpp"
1314
#include "context.hpp"
1415
#include "event.hpp"
1516
#include "event_pool.hpp"
@@ -123,10 +124,21 @@ void ur_event_handle_t_::setQueue(ur_queue_t_ *hQueue) {
123124
profilingData.reset();
124125
}
125126

127+
void ur_event_handle_t_::setBatch(int64_t batch_generation) {
128+
this->batch_generation = batch_generation;
129+
}
130+
126131
void ur_event_handle_t_::setCommandType(ur_command_t commandType) {
127132
this->commandType = commandType;
128133
}
129134

135+
void ur_event_handle_t_::runBatch() {
136+
if (batch_generation != -1) {
137+
// TODO check generation number
138+
hQueue->runBatchIfCurrentBatch(batch_generation);
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,8 @@ ur_event_handle_t_::getEventEndTimestampAndHandle() {
192204

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

207+
int64_t ur_event_handle_t_::getBatch() const { return batch_generation; }
208+
195209
ur_context_handle_t ur_event_handle_t_::getContext() const { return hContext; }
196210

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

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ struct ur_event_handle_t_ : ur_object {
6868

6969
// Set the queue and command that this event is associated with
7070
void setQueue(ur_queue_t_ *hQueue);
71+
void setBatch(int64_t batch_generation);
7172
void setCommandType(ur_command_t commandType);
73+
void runBatch();
7274

7375
void reset();
7476
ze_event_handle_t getZeEvent() const;
@@ -98,6 +100,8 @@ struct ur_event_handle_t_ : ur_object {
98100
// Get the type of the command that this event is associated with
99101
ur_command_t getCommandType() const;
100102

103+
int64_t getBatch() const;
104+
101105
// Get the device associated with this event
102106
ur_device_handle_t getDevice() const;
103107

@@ -129,6 +133,8 @@ struct ur_event_handle_t_ : ur_object {
129133
// queue and commandType that this event is associated with, set by enqueue
130134
// commands
131135
ur_queue_t_ *hQueue = nullptr;
136+
// default for non-batched queues
137+
int64_t batch_generation = -1;
132138
ur_command_t commandType = UR_COMMAND_FORCE_UINT32;
133139
ur_device_handle_t hDevice = nullptr;
134140

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ void event_pool::free(ur_event_handle_t event) {
4949
std::unique_lock<ur_mutex> lock(mutex);
5050

5151
event->reset();
52+
// TODO is it a good place for it? Am I missing something?
5253
freelist.push_back(event);
54+
event->setBatch(-1);
5355

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

0 commit comments

Comments
 (0)