Skip to content

Commit

Permalink
Merge pull request #2351 from nrspruit/mcl_1_1
Browse files Browse the repository at this point in the history
[L0] Add support for the MCL 1.1 apis thru the spec extensions
  • Loading branch information
callumfare authored Nov 26, 2024
2 parents ab3cc0b + 6ba6540 commit e0f22b5
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 42 deletions.
16 changes: 12 additions & 4 deletions source/adapters/level_zero/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,14 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()

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

// Check if the user has enabled the default L0 SysMan initialization.
const int UrSysmanZesinitEnable = [] {
Expand All @@ -422,13 +430,13 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
GlobalAdapter->getDeviceByUUIdFunctionPtr =
(zes_pfnDriverGetDeviceByUuidExp_t)
ur_loader::LibLoader::getFunctionPtr(
processHandle, "zesDriverGetDeviceByUuidExp");
GlobalAdapter->processHandle, "zesDriverGetDeviceByUuidExp");
GlobalAdapter->getSysManDriversFunctionPtr =
(zes_pfnDriverGet_t)ur_loader::LibLoader::getFunctionPtr(
processHandle, "zesDriverGet");
GlobalAdapter->processHandle, "zesDriverGet");
GlobalAdapter->sysManInitFunctionPtr =
(zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr(processHandle,
"zesInit");
(zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr(
GlobalAdapter->processHandle, "zesInit");
}
if (GlobalAdapter->getDeviceByUUIdFunctionPtr &&
GlobalAdapter->getSysManDriversFunctionPtr &&
Expand Down
1 change: 1 addition & 0 deletions source/adapters/level_zero/adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct ur_adapter_handle_t_ {
std::optional<ze_result_t> ZesResult;
ZeCache<Result<PlatformVec>> PlatformCache;
logger::Logger &logger;
HMODULE processHandle = nullptr;
};

extern ur_adapter_handle_t_ *GlobalAdapter;
110 changes: 72 additions & 38 deletions source/adapters/level_zero/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ ur_result_t ur_platform_handle_t_::initialize() {
ZE2UR_CALL(zeDriverGetExtensionProperties,
(ZeDriver, &Count, ZeExtensions.data()));

bool MutableCommandListSpecExtensionSupported = false;
for (auto &extension : ZeExtensions) {
// Check if global offset extension is available
if (strncmp(extension.name, ZE_GLOBAL_OFFSET_EXP_NAME,
Expand All @@ -244,13 +245,11 @@ ur_result_t ur_platform_handle_t_::initialize() {
ZeDriverEventPoolCountingEventsExtensionFound = true;
}
}

// Check if the ImmediateAppendCommandLists extension is available.
if (strncmp(extension.name, ZE_IMMEDIATE_COMMAND_LIST_APPEND_EXP_NAME,
strlen(ZE_IMMEDIATE_COMMAND_LIST_APPEND_EXP_NAME) + 1) == 0) {
if (extension.version ==
ZE_IMMEDIATE_COMMAND_LIST_APPEND_EXP_VERSION_CURRENT) {
zeDriverImmediateCommandListAppendFound = true;
// Check if extension is available for Mutable Command List v1.1.
if (strncmp(extension.name, ZE_MUTABLE_COMMAND_LIST_EXP_NAME,
strlen(ZE_MUTABLE_COMMAND_LIST_EXP_NAME) + 1) == 0) {
if (extension.version == ZE_MUTABLE_COMMAND_LIST_EXP_VERSION_1_1) {
MutableCommandListSpecExtensionSupported = true;
}
}
zeDriverExtensionMap[extension.name] = extension.version;
Expand Down Expand Up @@ -289,37 +288,72 @@ ur_result_t ur_platform_handle_t_::initialize() {

// Check if mutable command list extension is supported and initialize
// function pointers.
ZeMutableCmdListExt.Supported |=
(ZE_CALL_NOCHECK(
zeDriverGetExtensionFunctionAddress,
(ZeDriver, "zeCommandListGetNextCommandIdExp",
reinterpret_cast<void **>(
&ZeMutableCmdListExt.zexCommandListGetNextCommandIdExp))) == 0);

ZeMutableCmdListExt.Supported &=
(ZE_CALL_NOCHECK(zeDriverGetExtensionFunctionAddress,
(ZeDriver, "zeCommandListUpdateMutableCommandsExp",
reinterpret_cast<void **>(
&ZeMutableCmdListExt
.zexCommandListUpdateMutableCommandsExp))) ==
0);

ZeMutableCmdListExt.Supported &=
(ZE_CALL_NOCHECK(
zeDriverGetExtensionFunctionAddress,
(ZeDriver, "zeCommandListUpdateMutableCommandSignalEventExp",
reinterpret_cast<void **>(
&ZeMutableCmdListExt
.zexCommandListUpdateMutableCommandSignalEventExp))) == 0);

ZeMutableCmdListExt.Supported &=
(ZE_CALL_NOCHECK(
zeDriverGetExtensionFunctionAddress,
(ZeDriver, "zeCommandListUpdateMutableCommandWaitEventsExp",
reinterpret_cast<void **>(
&ZeMutableCmdListExt
.zexCommandListUpdateMutableCommandWaitEventsExp))) == 0);

if (MutableCommandListSpecExtensionSupported) {
ZeMutableCmdListExt.zexCommandListGetNextCommandIdExp =
(ze_pfnCommandListGetNextCommandIdExp_t)
ur_loader::LibLoader::getFunctionPtr(
GlobalAdapter->processHandle,
"zeCommandListGetNextCommandIdExp");
ZeMutableCmdListExt.Supported |=
ZeMutableCmdListExt.zexCommandListGetNextCommandIdExp != nullptr;
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandsExp =
(ze_pfnCommandListUpdateMutableCommandsExp_t)
ur_loader::LibLoader::getFunctionPtr(
GlobalAdapter->processHandle,
"zeCommandListUpdateMutableCommandsExp");
ZeMutableCmdListExt.Supported |=
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandsExp != nullptr;
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandSignalEventExp =
(ze_pfnCommandListUpdateMutableCommandSignalEventExp_t)
ur_loader::LibLoader::getFunctionPtr(
GlobalAdapter->processHandle,
"zeCommandListUpdateMutableCommandSignalEventExp");
ZeMutableCmdListExt.Supported |=
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandSignalEventExp !=
nullptr;
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandWaitEventsExp =
(ze_pfnCommandListUpdateMutableCommandWaitEventsExp_t)
ur_loader::LibLoader::getFunctionPtr(
GlobalAdapter->processHandle,
"zeCommandListUpdateMutableCommandWaitEventsExp");
ZeMutableCmdListExt.Supported |=
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandWaitEventsExp !=
nullptr;
} else {
ZeMutableCmdListExt.Supported |=
(ZE_CALL_NOCHECK(
zeDriverGetExtensionFunctionAddress,
(ZeDriver, "zeCommandListGetNextCommandIdExp",
reinterpret_cast<void **>(
&ZeMutableCmdListExt.zexCommandListGetNextCommandIdExp))) ==
0);

ZeMutableCmdListExt.Supported &=
(ZE_CALL_NOCHECK(zeDriverGetExtensionFunctionAddress,
(ZeDriver, "zeCommandListUpdateMutableCommandsExp",
reinterpret_cast<void **>(
&ZeMutableCmdListExt
.zexCommandListUpdateMutableCommandsExp))) ==
0);

ZeMutableCmdListExt.Supported &=
(ZE_CALL_NOCHECK(
zeDriverGetExtensionFunctionAddress,
(ZeDriver, "zeCommandListUpdateMutableCommandSignalEventExp",
reinterpret_cast<void **>(
&ZeMutableCmdListExt
.zexCommandListUpdateMutableCommandSignalEventExp))) ==
0);

ZeMutableCmdListExt.Supported &=
(ZE_CALL_NOCHECK(
zeDriverGetExtensionFunctionAddress,
(ZeDriver, "zeCommandListUpdateMutableCommandWaitEventsExp",
reinterpret_cast<void **>(
&ZeMutableCmdListExt
.zexCommandListUpdateMutableCommandWaitEventsExp))) ==
0);
}
return UR_RESULT_SUCCESS;
}

Expand Down
1 change: 1 addition & 0 deletions source/adapters/level_zero/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "common.hpp"
#include "ur_api.h"
#include "ze_api.h"
#include "ze_ddi.h"
#include "zes_api.h"

struct ur_device_handle_t_;
Expand Down

0 comments on commit e0f22b5

Please sign in to comment.