Skip to content

Commit e0f22b5

Browse files
authored
Merge pull request #2351 from nrspruit/mcl_1_1
[L0] Add support for the MCL 1.1 apis thru the spec extensions
2 parents ab3cc0b + 6ba6540 commit e0f22b5

File tree

4 files changed

+86
-42
lines changed

4 files changed

+86
-42
lines changed

source/adapters/level_zero/adapter.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,14 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
407407

408408
return;
409409
}
410+
// Dynamically load the new L0 SysMan separate init and new EXP apis
411+
// separately. This must be done to avoid attempting to use symbols that do
412+
// not exist in older loader runtimes.
413+
#ifdef _WIN32
414+
GlobalAdapter->processHandle = GetModuleHandle(NULL);
415+
#else
416+
GlobalAdapter->processHandle = nullptr;
417+
#endif
410418

411419
// Check if the user has enabled the default L0 SysMan initialization.
412420
const int UrSysmanZesinitEnable = [] {
@@ -422,13 +430,13 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
422430
GlobalAdapter->getDeviceByUUIdFunctionPtr =
423431
(zes_pfnDriverGetDeviceByUuidExp_t)
424432
ur_loader::LibLoader::getFunctionPtr(
425-
processHandle, "zesDriverGetDeviceByUuidExp");
433+
GlobalAdapter->processHandle, "zesDriverGetDeviceByUuidExp");
426434
GlobalAdapter->getSysManDriversFunctionPtr =
427435
(zes_pfnDriverGet_t)ur_loader::LibLoader::getFunctionPtr(
428-
processHandle, "zesDriverGet");
436+
GlobalAdapter->processHandle, "zesDriverGet");
429437
GlobalAdapter->sysManInitFunctionPtr =
430-
(zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr(processHandle,
431-
"zesInit");
438+
(zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr(
439+
GlobalAdapter->processHandle, "zesInit");
432440
}
433441
if (GlobalAdapter->getDeviceByUUIdFunctionPtr &&
434442
GlobalAdapter->getSysManDriversFunctionPtr &&

source/adapters/level_zero/adapter.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct ur_adapter_handle_t_ {
4545
std::optional<ze_result_t> ZesResult;
4646
ZeCache<Result<PlatformVec>> PlatformCache;
4747
logger::Logger &logger;
48+
HMODULE processHandle = nullptr;
4849
};
4950

5051
extern ur_adapter_handle_t_ *GlobalAdapter;

source/adapters/level_zero/platform.cpp

Lines changed: 72 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ ur_result_t ur_platform_handle_t_::initialize() {
220220
ZE2UR_CALL(zeDriverGetExtensionProperties,
221221
(ZeDriver, &Count, ZeExtensions.data()));
222222

223+
bool MutableCommandListSpecExtensionSupported = false;
223224
for (auto &extension : ZeExtensions) {
224225
// Check if global offset extension is available
225226
if (strncmp(extension.name, ZE_GLOBAL_OFFSET_EXP_NAME,
@@ -244,13 +245,11 @@ ur_result_t ur_platform_handle_t_::initialize() {
244245
ZeDriverEventPoolCountingEventsExtensionFound = true;
245246
}
246247
}
247-
248-
// Check if the ImmediateAppendCommandLists extension is available.
249-
if (strncmp(extension.name, ZE_IMMEDIATE_COMMAND_LIST_APPEND_EXP_NAME,
250-
strlen(ZE_IMMEDIATE_COMMAND_LIST_APPEND_EXP_NAME) + 1) == 0) {
251-
if (extension.version ==
252-
ZE_IMMEDIATE_COMMAND_LIST_APPEND_EXP_VERSION_CURRENT) {
253-
zeDriverImmediateCommandListAppendFound = true;
248+
// Check if extension is available for Mutable Command List v1.1.
249+
if (strncmp(extension.name, ZE_MUTABLE_COMMAND_LIST_EXP_NAME,
250+
strlen(ZE_MUTABLE_COMMAND_LIST_EXP_NAME) + 1) == 0) {
251+
if (extension.version == ZE_MUTABLE_COMMAND_LIST_EXP_VERSION_1_1) {
252+
MutableCommandListSpecExtensionSupported = true;
254253
}
255254
}
256255
zeDriverExtensionMap[extension.name] = extension.version;
@@ -289,37 +288,72 @@ ur_result_t ur_platform_handle_t_::initialize() {
289288

290289
// Check if mutable command list extension is supported and initialize
291290
// function pointers.
292-
ZeMutableCmdListExt.Supported |=
293-
(ZE_CALL_NOCHECK(
294-
zeDriverGetExtensionFunctionAddress,
295-
(ZeDriver, "zeCommandListGetNextCommandIdExp",
296-
reinterpret_cast<void **>(
297-
&ZeMutableCmdListExt.zexCommandListGetNextCommandIdExp))) == 0);
298-
299-
ZeMutableCmdListExt.Supported &=
300-
(ZE_CALL_NOCHECK(zeDriverGetExtensionFunctionAddress,
301-
(ZeDriver, "zeCommandListUpdateMutableCommandsExp",
302-
reinterpret_cast<void **>(
303-
&ZeMutableCmdListExt
304-
.zexCommandListUpdateMutableCommandsExp))) ==
305-
0);
306-
307-
ZeMutableCmdListExt.Supported &=
308-
(ZE_CALL_NOCHECK(
309-
zeDriverGetExtensionFunctionAddress,
310-
(ZeDriver, "zeCommandListUpdateMutableCommandSignalEventExp",
311-
reinterpret_cast<void **>(
312-
&ZeMutableCmdListExt
313-
.zexCommandListUpdateMutableCommandSignalEventExp))) == 0);
314-
315-
ZeMutableCmdListExt.Supported &=
316-
(ZE_CALL_NOCHECK(
317-
zeDriverGetExtensionFunctionAddress,
318-
(ZeDriver, "zeCommandListUpdateMutableCommandWaitEventsExp",
319-
reinterpret_cast<void **>(
320-
&ZeMutableCmdListExt
321-
.zexCommandListUpdateMutableCommandWaitEventsExp))) == 0);
322-
291+
if (MutableCommandListSpecExtensionSupported) {
292+
ZeMutableCmdListExt.zexCommandListGetNextCommandIdExp =
293+
(ze_pfnCommandListGetNextCommandIdExp_t)
294+
ur_loader::LibLoader::getFunctionPtr(
295+
GlobalAdapter->processHandle,
296+
"zeCommandListGetNextCommandIdExp");
297+
ZeMutableCmdListExt.Supported |=
298+
ZeMutableCmdListExt.zexCommandListGetNextCommandIdExp != nullptr;
299+
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandsExp =
300+
(ze_pfnCommandListUpdateMutableCommandsExp_t)
301+
ur_loader::LibLoader::getFunctionPtr(
302+
GlobalAdapter->processHandle,
303+
"zeCommandListUpdateMutableCommandsExp");
304+
ZeMutableCmdListExt.Supported |=
305+
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandsExp != nullptr;
306+
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandSignalEventExp =
307+
(ze_pfnCommandListUpdateMutableCommandSignalEventExp_t)
308+
ur_loader::LibLoader::getFunctionPtr(
309+
GlobalAdapter->processHandle,
310+
"zeCommandListUpdateMutableCommandSignalEventExp");
311+
ZeMutableCmdListExt.Supported |=
312+
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandSignalEventExp !=
313+
nullptr;
314+
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandWaitEventsExp =
315+
(ze_pfnCommandListUpdateMutableCommandWaitEventsExp_t)
316+
ur_loader::LibLoader::getFunctionPtr(
317+
GlobalAdapter->processHandle,
318+
"zeCommandListUpdateMutableCommandWaitEventsExp");
319+
ZeMutableCmdListExt.Supported |=
320+
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandWaitEventsExp !=
321+
nullptr;
322+
} else {
323+
ZeMutableCmdListExt.Supported |=
324+
(ZE_CALL_NOCHECK(
325+
zeDriverGetExtensionFunctionAddress,
326+
(ZeDriver, "zeCommandListGetNextCommandIdExp",
327+
reinterpret_cast<void **>(
328+
&ZeMutableCmdListExt.zexCommandListGetNextCommandIdExp))) ==
329+
0);
330+
331+
ZeMutableCmdListExt.Supported &=
332+
(ZE_CALL_NOCHECK(zeDriverGetExtensionFunctionAddress,
333+
(ZeDriver, "zeCommandListUpdateMutableCommandsExp",
334+
reinterpret_cast<void **>(
335+
&ZeMutableCmdListExt
336+
.zexCommandListUpdateMutableCommandsExp))) ==
337+
0);
338+
339+
ZeMutableCmdListExt.Supported &=
340+
(ZE_CALL_NOCHECK(
341+
zeDriverGetExtensionFunctionAddress,
342+
(ZeDriver, "zeCommandListUpdateMutableCommandSignalEventExp",
343+
reinterpret_cast<void **>(
344+
&ZeMutableCmdListExt
345+
.zexCommandListUpdateMutableCommandSignalEventExp))) ==
346+
0);
347+
348+
ZeMutableCmdListExt.Supported &=
349+
(ZE_CALL_NOCHECK(
350+
zeDriverGetExtensionFunctionAddress,
351+
(ZeDriver, "zeCommandListUpdateMutableCommandWaitEventsExp",
352+
reinterpret_cast<void **>(
353+
&ZeMutableCmdListExt
354+
.zexCommandListUpdateMutableCommandWaitEventsExp))) ==
355+
0);
356+
}
323357
return UR_RESULT_SUCCESS;
324358
}
325359

source/adapters/level_zero/platform.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "common.hpp"
1313
#include "ur_api.h"
1414
#include "ze_api.h"
15+
#include "ze_ddi.h"
1516
#include "zes_api.h"
1617

1718
struct ur_device_handle_t_;

0 commit comments

Comments
 (0)