From 9de0818a0ed6b71e48d99b2e1110ec22b678cbd5 Mon Sep 17 00:00:00 2001 From: Krzysztof Filipek Date: Tue, 2 Dec 2025 14:59:08 +0100 Subject: [PATCH 1/7] [UR][L0v2] Add initial record & replay implementation --- .../source/adapters/level_zero/CMakeLists.txt | 2 +- .../source/adapters/level_zero/platform.cpp | 36 +++++ .../source/adapters/level_zero/platform.hpp | 31 +++++ .../level_zero/v2/command_list_manager.cpp | 76 ++++++++++ .../level_zero/v2/command_list_manager.hpp | 30 ++++ .../source/adapters/level_zero/v2/graph.cpp | 131 ++++++++++++++++++ .../source/adapters/level_zero/v2/graph.hpp | 48 +++++++ .../v2/queue_immediate_in_order.hpp | 33 +++-- 8 files changed, 372 insertions(+), 15 deletions(-) create mode 100644 unified-runtime/source/adapters/level_zero/v2/graph.cpp create mode 100644 unified-runtime/source/adapters/level_zero/v2/graph.hpp diff --git a/unified-runtime/source/adapters/level_zero/CMakeLists.txt b/unified-runtime/source/adapters/level_zero/CMakeLists.txt index c7e9724b21d99..0b39576ff01bd 100644 --- a/unified-runtime/source/adapters/level_zero/CMakeLists.txt +++ b/unified-runtime/source/adapters/level_zero/CMakeLists.txt @@ -149,7 +149,6 @@ if(UR_BUILD_ADAPTER_L0_V2) ${CMAKE_CURRENT_SOURCE_DIR}/physical_mem.cpp ${CMAKE_CURRENT_SOURCE_DIR}/program.cpp ${CMAKE_CURRENT_SOURCE_DIR}/helpers/kernel_helpers.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/graph.cpp ${CMAKE_CURRENT_SOURCE_DIR}/helpers/memory_helpers.cpp ${CMAKE_CURRENT_SOURCE_DIR}/helpers/mutable_helpers.cpp ${CMAKE_CURRENT_SOURCE_DIR}/usm_p2p.cpp @@ -169,6 +168,7 @@ if(UR_BUILD_ADAPTER_L0_V2) ${CMAKE_CURRENT_SOURCE_DIR}/v2/event_provider_normal.hpp ${CMAKE_CURRENT_SOURCE_DIR}/v2/event_provider.hpp ${CMAKE_CURRENT_SOURCE_DIR}/v2/event.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/v2/graph.cpp ${CMAKE_CURRENT_SOURCE_DIR}/v2/kernel.hpp ${CMAKE_CURRENT_SOURCE_DIR}/v2/memory.hpp ${CMAKE_CURRENT_SOURCE_DIR}/v2/lockable.hpp diff --git a/unified-runtime/source/adapters/level_zero/platform.cpp b/unified-runtime/source/adapters/level_zero/platform.cpp index 4fd04c5962843..310b4b79be43e 100644 --- a/unified-runtime/source/adapters/level_zero/platform.cpp +++ b/unified-runtime/source/adapters/level_zero/platform.cpp @@ -526,6 +526,42 @@ ur_result_t ur_platform_handle_t_::initialize() { ZeMemGetPitchFor2dImageExt.Supported = ZeMemGetPitchFor2dImageExt.zeMemGetPitchFor2dImage != nullptr; + // Populate Graph Extension structure. + std::unordered_map ZeGraphFuncNameToAddrMap = { + {"zeGraphCreateExp", + reinterpret_cast(&ZeGraphExt.zeGraphCreateExp)}, + {"zeCommandListBeginGraphCaptureExp", + reinterpret_cast( + &ZeGraphExt.zeCommandListBeginGraphCaptureExp)}, + {"zeCommandListBeginCaptureIntoGraphExp", + reinterpret_cast( + &ZeGraphExt.zeCommandListBeginCaptureIntoGraphExp)}, + {"zeCommandListEndGraphCaptureExp", + reinterpret_cast(&ZeGraphExt.zeCommandListEndGraphCaptureExp)}, + {"zeCommandListInstantiateGraphExp", + reinterpret_cast(&ZeGraphExt.zeCommandListInstantiateGraphExp)}, + {"zeCommandListAppendGraphExp", + reinterpret_cast(&ZeGraphExt.zeCommandListAppendGraphExp)}, + {"zeGraphDestroyExp", + reinterpret_cast(&ZeGraphExt.zeGraphDestroyExp)}, + {"zeExecutableGraphDestroyExp", + reinterpret_cast(&ZeGraphExt.zeExecutableGraphDestroyExp)}, + {"zeCommandListIsGraphCaptureEnabledExp", + reinterpret_cast( + &ZeGraphExt.zeCommandListIsGraphCaptureEnabledExp)}, + {"zeGraphIsEmptyExp", + reinterpret_cast(&ZeGraphExt.zeGraphIsEmptyExp)}, + {"zeGraphDumpContentsExp", + reinterpret_cast(&ZeGraphExt.zeGraphDumpContentsExp)}, + }; + + ZeGraphExt.Supported = true; + for (auto &[funcName, funcAddr] : ZeGraphFuncNameToAddrMap) { + ZE_CALL_NOCHECK(zeDriverGetExtensionFunctionAddress, + (ZeDriver, funcName.c_str(), funcAddr)); + ZeGraphExt.Supported &= (*funcAddr != nullptr); + } + if (this->isDriverVersionNewerOrSimilar(1, 14, 36035)) { ZeCommandListAppendLaunchKernelWithArgumentsExt.Supported = true; } else { diff --git a/unified-runtime/source/adapters/level_zero/platform.hpp b/unified-runtime/source/adapters/level_zero/platform.hpp index fb9b9024abb8a..e605af42505b7 100644 --- a/unified-runtime/source/adapters/level_zero/platform.hpp +++ b/unified-runtime/source/adapters/level_zero/platform.hpp @@ -10,6 +10,7 @@ #pragma once #include "common.hpp" +#include "level_zero/driver_experimental/zex_api.h" #include "ur_api.h" #include "ze_api.h" #include "ze_ddi.h" @@ -168,4 +169,34 @@ struct ur_platform_handle_t_ : ur::handle_base, bool DriverSupportsCooperativeKernelLaunchWithArgs = false; bool DisableZeLaunchKernelWithArgs = false; } ZeCommandListAppendLaunchKernelWithArgumentsExt; + + struct ZeGraphExtension { + bool Supported = false; + ze_result_t (*zeGraphCreateExp)(ze_context_handle_t hContext, + ze_graph_handle_t *phGraph, void *pNext); + ze_result_t (*zeCommandListBeginGraphCaptureExp)( + ze_command_list_handle_t hCommandList, void *pNext); + ze_result_t (*zeCommandListBeginCaptureIntoGraphExp)( + ze_command_list_handle_t hCommandList, ze_graph_handle_t hGraph, + void *pNext); + ze_result_t (*zeCommandListEndGraphCaptureExp)( + ze_command_list_handle_t hCommandList, ze_graph_handle_t *phGraph, + void *pNext); + ze_result_t (*zeCommandListInstantiateGraphExp)( + ze_graph_handle_t hGraph, + ze_executable_graph_handle_t *phExecutableGraph, void *pNext); + ze_result_t (*zeCommandListAppendGraphExp)( + ze_command_list_handle_t hCommandList, + ze_executable_graph_handle_t hGraph, void *pNext, + ze_event_handle_t hSignalEvent, uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents); + ze_result_t (*zeGraphDestroyExp)(ze_graph_handle_t hGraph); + ze_result_t (*zeExecutableGraphDestroyExp)( + ze_executable_graph_handle_t hGraph); + ze_result_t (*zeCommandListIsGraphCaptureEnabledExp)( + ze_command_list_handle_t hCommandList); + ze_result_t (*zeGraphIsEmptyExp)(ze_graph_handle_t hGraph); + ze_result_t (*zeGraphDumpContentsExp)(ze_graph_handle_t hGraph, + const char *filePath, void *pNext); + } ZeGraphExt; }; diff --git a/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp b/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp index 94161a46edce8..9d463f870e895 100644 --- a/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp +++ b/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp @@ -16,6 +16,7 @@ #include "command_buffer.hpp" #include "common.hpp" #include "context.hpp" +#include "graph.hpp" #include "kernel.hpp" #include "memory.hpp" @@ -1302,3 +1303,78 @@ ur_result_t ur_command_list_manager::appendKernelLaunchWithArgsExp( return UR_RESULT_SUCCESS; } + +ur_result_t ur_command_list_manager::beginGraphCapture() { + if (!checkGraphExtensionSupport(hContext.get())) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + ZE2UR_CALL(hContext.get() + ->getPlatform() + ->ZeGraphExt.zeCommandListBeginGraphCaptureExp, + (getZeCommandList(), nullptr)); + graphCapture.enableCapture(); + + return UR_RESULT_SUCCESS; +} + +ur_result_t +ur_command_list_manager::beginCaptureIntoGraph(ur_exp_graph_handle_t hGraph) { + if (!checkGraphExtensionSupport(hContext.get())) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + ZE2UR_CALL(hContext.get() + ->getPlatform() + ->ZeGraphExt.zeCommandListBeginCaptureIntoGraphExp, + (getZeCommandList(), hGraph->getZeHandle(), nullptr)); + graphCapture.enableCapture(hGraph); + + return UR_RESULT_SUCCESS; +} + +ur_result_t +ur_command_list_manager::endGraphCapture(ur_exp_graph_handle_t *phGraph) { + if (!checkGraphExtensionSupport(hContext.get())) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + ze_graph_handle_t zeGraph = nullptr; + ZE2UR_CALL( + hContext.get()->getPlatform()->ZeGraphExt.zeCommandListEndGraphCaptureExp, + (getZeCommandList(), &zeGraph, nullptr)); + auto graph = graphCapture.getGraph(); + graphCapture.disableCapture(); + + *phGraph = + graph ? graph : new ur_exp_graph_handle_t_(hContext.get(), zeGraph); + + return UR_RESULT_SUCCESS; +} + +ur_result_t +ur_command_list_manager::appendGraph(ur_exp_executable_graph_handle_t hGraph, + wait_list_view &waitListView, + ur_event_handle_t hEvent) { + if (!checkGraphExtensionSupport(hContext.get())) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + auto zeSignalEvent = getSignalEvent(hEvent, UR_COMMAND_ENQUEUE_GRAPH_EXP); + ZE2UR_CALL( + hContext.get()->getPlatform()->ZeGraphExt.zeCommandListAppendGraphExp, + (getZeCommandList(), hGraph->getZeHandle(), nullptr, zeSignalEvent, + waitListView.num, waitListView.handles)); + + return UR_RESULT_SUCCESS; +} + +ur_result_t ur_command_list_manager::isGraphCaptureActive(bool *pResult) { + if (!checkGraphExtensionSupport(hContext.get())) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + *pResult = graphCapture.isActive(); + + return UR_RESULT_SUCCESS; +} diff --git a/unified-runtime/source/adapters/level_zero/v2/command_list_manager.hpp b/unified-runtime/source/adapters/level_zero/v2/command_list_manager.hpp index e9fa6ac978ef5..b36dc5aea8446 100644 --- a/unified-runtime/source/adapters/level_zero/v2/command_list_manager.hpp +++ b/unified-runtime/source/adapters/level_zero/v2/command_list_manager.hpp @@ -45,6 +45,25 @@ struct wait_list_view { } }; +struct graph_capture_tracking_data_t { + void enableCapture(ur_exp_graph_handle_t graph) { + capturedGraph = graph; + enableCapture(); + } + void enableCapture() { active = true; } + void disableCapture() { + active = false; + capturedGraph = nullptr; + } + + ur_exp_graph_handle_t getGraph() const { return capturedGraph; } + bool isActive() const { return active; } + +private: + bool active = false; + ur_exp_graph_handle_t capturedGraph = nullptr; +}; + struct ur_command_list_manager { ur_command_list_manager(ur_context_handle_t context, ur_device_handle_t device, @@ -227,6 +246,15 @@ struct ur_command_list_manager { const ur_kernel_launch_ext_properties_t *launchPropList, wait_list_view &waitListView, ur_event_handle_t phEvent); + /************ Graph methods *************/ + ur_result_t appendGraph(ur_exp_executable_graph_handle_t hGraph, + wait_list_view &waitListView, + ur_event_handle_t hEvent); + ur_result_t beginGraphCapture(); + ur_result_t beginCaptureIntoGraph(ur_exp_graph_handle_t hGraph); + ur_result_t endGraphCapture(ur_exp_graph_handle_t *phGraph); + ur_result_t isGraphCaptureActive(bool *pResult); + v2::raii::command_list_unique_handle &&releaseCommandList(); void replaceCommandList(v2::raii::command_list_unique_handle &&cmdlist); @@ -301,4 +329,6 @@ struct ur_command_list_manager { std::vector submittedKernels; v2::raii::command_list_unique_handle zeCommandList; std::vector waitList; + + graph_capture_tracking_data_t graphCapture; }; diff --git a/unified-runtime/source/adapters/level_zero/v2/graph.cpp b/unified-runtime/source/adapters/level_zero/v2/graph.cpp new file mode 100644 index 0000000000000..326771a5d25d7 --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/v2/graph.cpp @@ -0,0 +1,131 @@ +//===--------- graph.cpp - Level Zero Adapter -----------------------------===// +// +// Copyright (C) 2025 Intel Corporation +// +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM +// Exceptions. See LICENSE.TXT +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "graph.hpp" +#include "../ur_interface_loader.hpp" +#include "common.hpp" +#include "context.hpp" +#include "level_zero/driver_experimental/zex_api.h" + +ur_exp_graph_handle_t_::ur_exp_graph_handle_t_(ur_context_handle_t hContext) + : hContext(hContext) { + ZE2UR_CALL_THROWS(hContext->getPlatform()->ZeGraphExt.zeGraphCreateExp, + (hContext->getZeHandle(), &zeGraph, nullptr)); +} + +ur_exp_graph_handle_t_::ur_exp_graph_handle_t_(ur_context_handle_t hContext, + ze_graph_handle_t zeGraph) + : hContext(hContext), zeGraph(zeGraph) {} + +ur_exp_graph_handle_t_::~ur_exp_graph_handle_t_() { + if (zeGraph) { + ze_result_t ZeResult = ZE_CALL_NOCHECK( + hContext->getPlatform()->ZeGraphExt.zeGraphDestroyExp, (zeGraph)); + if (ZeResult != ZE_RESULT_SUCCESS) { + UR_LOG(WARN, "Failed to destroy graph handle: {}", ZeResult); + } + } +} + +ur_exp_executable_graph_handle_t_::ur_exp_executable_graph_handle_t_( + ur_context_handle_t hContext, ur_exp_graph_handle_t hGraph) + : hContext(hContext) { + ZE2UR_CALL_THROWS( + hContext->getPlatform()->ZeGraphExt.zeCommandListInstantiateGraphExp, + (hGraph->getZeHandle(), &zeExGraph, nullptr)); +} + +ur_exp_executable_graph_handle_t_::~ur_exp_executable_graph_handle_t_() { + if (zeExGraph) { + ze_result_t ZeResult = ZE_CALL_NOCHECK( + hContext->getPlatform()->ZeGraphExt.zeExecutableGraphDestroyExp, + (zeExGraph)); + if (ZeResult != ZE_RESULT_SUCCESS) { + UR_LOG(WARN, "Failed to destroy executable graph handle: {}", ZeResult); + } + } +} + +namespace ur::level_zero { + +ur_result_t urGraphCreateExp(ur_context_handle_t hContext, + ur_exp_graph_handle_t *phGraph) try { + if (!checkGraphExtensionSupport(hContext)) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + *phGraph = new ur_exp_graph_handle_t_(hContext); + return UR_RESULT_SUCCESS; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +ur_result_t urGraphDestroyExp(ur_exp_graph_handle_t hGraph) try { + ur_context_handle_t hContext = hGraph->getContext(); + if (!checkGraphExtensionSupport(hContext)) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + delete hGraph; + return UR_RESULT_SUCCESS; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +ur_result_t urGraphInstantiateGraphExp( + ur_exp_graph_handle_t hGraph, + ur_exp_executable_graph_handle_t *phExecutableGraph) try { + ur_context_handle_t hContext = hGraph->getContext(); + if (!checkGraphExtensionSupport(hContext)) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + *phExecutableGraph = new ur_exp_executable_graph_handle_t_(hContext, hGraph); + return UR_RESULT_SUCCESS; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +ur_result_t urGraphExecutableGraphDestroyExp( + ur_exp_executable_graph_handle_t hExecutableGraph) try { + ur_context_handle_t hContext = hExecutableGraph->getContext(); + if (!checkGraphExtensionSupport(hContext)) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + delete hExecutableGraph; + return UR_RESULT_SUCCESS; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +ur_result_t urGraphIsEmptyExp(ur_exp_graph_handle_t hGraph, bool *pIsEmpty) { + ur_context_handle_t hContext = hGraph->getContext(); + if (!checkGraphExtensionSupport(hContext)) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + ze_result_t zeResult = + ZE_CALL_NOCHECK(hContext->getPlatform()->ZeGraphExt.zeGraphIsEmptyExp, + (hGraph->getZeHandle())); + if (zeResult == ZE_RESULT_ERROR_INVALID_GRAPH) { + return UR_RESULT_ERROR_INVALID_GRAPH; + } + + *pIsEmpty = (zeResult == ZE_RESULT_QUERY_TRUE); + return UR_RESULT_SUCCESS; +} + +ur_result_t urGraphDumpContentsExp(ur_exp_graph_handle_t, const char *) { + UR_LOG(ERR, "{} function not implemented!", __FUNCTION__); + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +} // namespace ur::level_zero diff --git a/unified-runtime/source/adapters/level_zero/v2/graph.hpp b/unified-runtime/source/adapters/level_zero/v2/graph.hpp new file mode 100644 index 0000000000000..6cd68f8bd15f9 --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/v2/graph.hpp @@ -0,0 +1,48 @@ +//===--------- graph.hpp - Level Zero Adapter -----------------------------===// +// +// Copyright (C) 2025 Intel Corporation +// +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM +// Exceptions. See LICENSE.TXT +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#pragma once + +#include "common.hpp" +#include "context.hpp" +#include "level_zero/driver_experimental/zex_api.h" +#include "ur_api.h" + +struct ur_exp_graph_handle_t_ : ur_object { +public: + ur_exp_graph_handle_t_(ur_context_handle_t hContext); + ur_exp_graph_handle_t_(ur_context_handle_t hContext, + ze_graph_handle_t zeGraph); + ~ur_exp_graph_handle_t_(); + + ze_graph_handle_t getZeHandle() { return zeGraph; } + ur_context_handle_t getContext() { return hContext; } + +private: + ur_context_handle_t hContext = nullptr; + ze_graph_handle_t zeGraph = nullptr; +}; + +struct ur_exp_executable_graph_handle_t_ : ur_object { +public: + ur_exp_executable_graph_handle_t_(ur_context_handle_t hContext, + ur_exp_graph_handle_t hGraph); + ~ur_exp_executable_graph_handle_t_(); + + ze_executable_graph_handle_t &getZeHandle() { return zeExGraph; } + ur_context_handle_t getContext() const { return hContext; } + +private: + ur_context_handle_t hContext = nullptr; + ze_executable_graph_handle_t zeExGraph = nullptr; +}; + +inline bool checkGraphExtensionSupport(ur_context_handle_t hContext) { + return hContext->getPlatform()->ZeGraphExt.Supported; +} diff --git a/unified-runtime/source/adapters/level_zero/v2/queue_immediate_in_order.hpp b/unified-runtime/source/adapters/level_zero/v2/queue_immediate_in_order.hpp index 6db4993e98b36..5d69ebf9be943 100644 --- a/unified-runtime/source/adapters/level_zero/v2/queue_immediate_in_order.hpp +++ b/unified-runtime/source/adapters/level_zero/v2/queue_immediate_in_order.hpp @@ -16,6 +16,7 @@ #include "context.hpp" #include "event.hpp" #include "event_pool_cache.hpp" +#include "graph.hpp" #include "memory.hpp" #include "queue_api.hpp" @@ -548,29 +549,33 @@ struct ur_queue_immediate_in_order_t : ur_object, ur_queue_t_ { createEventIfRequested(eventPool.get(), phEvent, this)); } - ur_result_t queueBeginGraphCapteExp() override { - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + ur_result_t enqueueGraphExp(ur_exp_executable_graph_handle_t hGraph, + uint32_t numEventsInWaitList, + const ur_event_handle_t *phEventWaitList, + ur_event_handle_t *phEvent) override { + wait_list_view waitListView = + wait_list_view(phEventWaitList, numEventsInWaitList); + + return commandListManager.lock()->appendGraph( + hGraph, waitListView, + createEventIfRequested(eventPool.get(), phEvent, this)); } - ur_result_t - queueBeginCapteIntoGraphExp(ur_exp_graph_handle_t /* hGraph */) override { - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + ur_result_t queueBeginGraphCapteExp() override { + return commandListManager.lock()->beginGraphCapture(); } ur_result_t - queueEndGraphCapteExp(ur_exp_graph_handle_t * /* phGraph */) override { - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + queueBeginCapteIntoGraphExp(ur_exp_graph_handle_t hGraph) override { + return commandListManager.lock()->beginCaptureIntoGraph(hGraph); } - ur_result_t enqueueGraphExp(ur_exp_executable_graph_handle_t /* hGraph */, - uint32_t /* numEventsInWaitList */, - const ur_event_handle_t * /* phEventWaitList */, - ur_event_handle_t * /* phEvent */) override { - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + ur_result_t queueEndGraphCapteExp(ur_exp_graph_handle_t *phGraph) override { + return commandListManager.lock()->endGraphCapture(phGraph); } - ur_result_t queueIsGraphCapteEnabledExp(bool * /* pResult */) override { - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + ur_result_t queueIsGraphCapteEnabledExp(bool *pResult) override { + return commandListManager.lock()->isGraphCaptureActive(pResult); } ur::RefCount RefCount; From 6ad86b7e9f5c5996af9b67182e6e7bf56b4d1ae8 Mon Sep 17 00:00:00 2001 From: Krzysztof Swiecicki Date: Mon, 8 Dec 2025 15:53:35 +0000 Subject: [PATCH 2/7] [UR] Fix record & replay tests --- .../test/conformance/exp_graph/fixtures.h | 23 ++++++------------- .../exp_graph/urEnqueueGraphExp.cpp | 6 ++--- .../exp_graph/urGraphInstantiateGraphExp.cpp | 4 ++-- .../exp_graph/urGraphIsEmptyExp.cpp | 8 +++---- .../urQueueBeginCaptureIntoGraphExp.cpp | 10 ++++++++ .../exp_graph/urQueueEndGraphCaptureExp.cpp | 3 ++- .../urQueueIsGraphCaptureEnabledExp.cpp | 2 +- 7 files changed, 29 insertions(+), 27 deletions(-) diff --git a/unified-runtime/test/conformance/exp_graph/fixtures.h b/unified-runtime/test/conformance/exp_graph/fixtures.h index fbe1805a5288f..b24b8b1418aa4 100644 --- a/unified-runtime/test/conformance/exp_graph/fixtures.h +++ b/unified-runtime/test/conformance/exp_graph/fixtures.h @@ -18,7 +18,8 @@ struct urGraphSupportedExpTest : uur::urQueueTest { UUR_RETURN_ON_FATAL_FAILURE(urQueueTest::SetUp()); UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{}, uur::NativeCPU{}, - uur::OpenCL{}, uur::LevelZero{}, uur::LevelZeroV2{}); + uur::OpenCL{}, uur::LevelZero{}, + /* uur::LevelZeroV2{} */); } }; @@ -58,14 +59,11 @@ struct urGraphPopulatedExpTest : urGraphExpTest { ASSERT_SUCCESS(urEnqueueUSMFill(queue, deviceMem, patternSize, pattern.data(), allocationSize, 0, nullptr, - fillEvent.ptr())); - ASSERT_SUCCESS(urQueueFinish(queue)); + nullptr)); ur_exp_graph_handle_t sameGraph = nullptr; ASSERT_SUCCESS(urQueueEndGraphCaptureExp(queue, &sameGraph)); ASSERT_EQ(graph, sameGraph); - - ASSERT_NO_FATAL_FAILURE(verifyData(false)); } void TearDown() override { @@ -73,6 +71,8 @@ struct urGraphPopulatedExpTest : urGraphExpTest { ASSERT_SUCCESS(urUSMFree(context, deviceMem)); } + resetData(); + UUR_RETURN_ON_FATAL_FAILURE(urGraphExpTest::TearDown()); } @@ -80,16 +80,8 @@ struct urGraphPopulatedExpTest : urGraphExpTest { ASSERT_SUCCESS(urEnqueueUSMMemcpy(queue, true, hostMem.data(), deviceMem, allocationSize, 0, nullptr, nullptr)); - size_t patternIdx = 0; - for (size_t i = 0; i < allocationSize; ++i) { - uint8_t *hostPtr = hostMem.data(); - ASSERT_EQ((*(hostPtr + i) == pattern[patternIdx]), shouldMatch); - - ++patternIdx; - if (patternIdx % pattern.size() == 0) { - patternIdx = 0; - } - } + int cmpResult = memcmp(hostMem.data(), pattern.data(), pattern.size()); + ASSERT_EQ(cmpResult == 0, shouldMatch); } void resetData() { @@ -104,7 +96,6 @@ struct urGraphPopulatedExpTest : urGraphExpTest { std::vector hostMem = std::vector(allocationSize); const size_t patternSize = 64; std::vector pattern = std::vector(patternSize); - uur::raii::Event fillEvent = nullptr; }; struct urGraphExecutableExpTest : urGraphPopulatedExpTest { diff --git a/unified-runtime/test/conformance/exp_graph/urEnqueueGraphExp.cpp b/unified-runtime/test/conformance/exp_graph/urEnqueueGraphExp.cpp index 3187c0b179c7a..e7da20ad42a4f 100644 --- a/unified-runtime/test/conformance/exp_graph/urEnqueueGraphExp.cpp +++ b/unified-runtime/test/conformance/exp_graph/urEnqueueGraphExp.cpp @@ -14,7 +14,7 @@ using urEnqueueGraphExpTest = uur::urGraphExecutableExpTest; UUR_INSTANTIATE_DEVICE_TEST_SUITE(urEnqueueGraphExpTest); TEST_P(urEnqueueGraphExpTest, Success) { - verifyData(false); + ASSERT_NO_FATAL_FAILURE(verifyData(false)); ASSERT_SUCCESS(urEnqueueGraphExp(queue, exGraph, 0, nullptr, nullptr)); ASSERT_SUCCESS(urQueueFinish(queue)); @@ -41,12 +41,12 @@ TEST_P(urEnqueueGraphExpTest, InvalidNullHandleExGraph) { TEST_P(urEnqueueGraphExpTest, InvalidEventWaitListArray) { ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST, - urEnqueueGraphExp(queue, nullptr, 1, nullptr, nullptr)); + urEnqueueGraphExp(queue, exGraph, 1, nullptr, nullptr)); } TEST_P(urEnqueueGraphExpTest, InvalidEventWaitListSize) { ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST, - urEnqueueGraphExp(queue, nullptr, 0, + urEnqueueGraphExp(queue, exGraph, 0, (ur_event_handle_t *)0xC0FFEE, nullptr)); } diff --git a/unified-runtime/test/conformance/exp_graph/urGraphInstantiateGraphExp.cpp b/unified-runtime/test/conformance/exp_graph/urGraphInstantiateGraphExp.cpp index 749e7637d0df4..8e73647e770cf 100644 --- a/unified-runtime/test/conformance/exp_graph/urGraphInstantiateGraphExp.cpp +++ b/unified-runtime/test/conformance/exp_graph/urGraphInstantiateGraphExp.cpp @@ -12,8 +12,8 @@ UUR_INSTANTIATE_DEVICE_TEST_SUITE(urGraphInstantiateGraphExpTest); TEST_P(urGraphInstantiateGraphExpTest, InvalidEmptyGraph) { ur_exp_executable_graph_handle_t exGraph = nullptr; - ASSERT_SUCCESS(urGraphInstantiateGraphExp(graph, &exGraph)); - ASSERT_SUCCESS(urGraphExecutableGraphDestroyExp(exGraph)); + ASSERT_EQ(urGraphInstantiateGraphExp(graph, &exGraph), + UR_RESULT_ERROR_INVALID_ARGUMENT); } TEST_P(urGraphInstantiateGraphExpTest, InvalidNullHandleGraph) { diff --git a/unified-runtime/test/conformance/exp_graph/urGraphIsEmptyExp.cpp b/unified-runtime/test/conformance/exp_graph/urGraphIsEmptyExp.cpp index 1b9b737d6cd1b..7fe9971d1fac4 100644 --- a/unified-runtime/test/conformance/exp_graph/urGraphIsEmptyExp.cpp +++ b/unified-runtime/test/conformance/exp_graph/urGraphIsEmptyExp.cpp @@ -10,20 +10,20 @@ using urGraphNonEmptyExpTest = uur::urGraphPopulatedExpTest; UUR_INSTANTIATE_DEVICE_TEST_SUITE(urGraphNonEmptyExpTest); -TEST_P(urGraphNonEmptyExpTest, SuccessFalse) { +TEST_P(urGraphNonEmptyExpTest, Success) { bool isEmpty = false; ASSERT_SUCCESS(urGraphIsEmptyExp(graph, &isEmpty)); - ASSERT_TRUE(isEmpty); + ASSERT_FALSE(isEmpty); } using urGraphEmptyExpTest = uur::urGraphExpTest; UUR_INSTANTIATE_DEVICE_TEST_SUITE(urGraphEmptyExpTest); -TEST_P(urGraphEmptyExpTest, SuccessTrue) { +TEST_P(urGraphEmptyExpTest, Success) { bool isEmpty = false; ASSERT_SUCCESS(urGraphIsEmptyExp(graph, &isEmpty)); - ASSERT_FALSE(isEmpty); + ASSERT_TRUE(isEmpty); } TEST_P(urGraphEmptyExpTest, InvalidNullHandleQueue) { diff --git a/unified-runtime/test/conformance/exp_graph/urQueueBeginCaptureIntoGraphExp.cpp b/unified-runtime/test/conformance/exp_graph/urQueueBeginCaptureIntoGraphExp.cpp index 05445c8d55425..3ef87b0afcbe3 100644 --- a/unified-runtime/test/conformance/exp_graph/urQueueBeginCaptureIntoGraphExp.cpp +++ b/unified-runtime/test/conformance/exp_graph/urQueueBeginCaptureIntoGraphExp.cpp @@ -23,3 +23,13 @@ TEST_P(urQueueBeginCaptureIntoGraphExpTest, InvalidNullHandleGraph) { ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE, urQueueBeginCaptureIntoGraphExp(queue, nullptr)); } + +using urQueueBeginCaptureIntoPupulatedGraphExpTest = + uur::urGraphPopulatedExpTest; + +UUR_INSTANTIATE_DEVICE_TEST_SUITE(urQueueBeginCaptureIntoPupulatedGraphExpTest); + +TEST_P(urQueueBeginCaptureIntoPupulatedGraphExpTest, InvalidNonEmptyGraph) { + ASSERT_EQ(urQueueBeginCaptureIntoGraphExp(queue, graph), + UR_RESULT_ERROR_INVALID_ARGUMENT); +} diff --git a/unified-runtime/test/conformance/exp_graph/urQueueEndGraphCaptureExp.cpp b/unified-runtime/test/conformance/exp_graph/urQueueEndGraphCaptureExp.cpp index e1e92b7b77bd2..9cc05d05c5988 100644 --- a/unified-runtime/test/conformance/exp_graph/urQueueEndGraphCaptureExp.cpp +++ b/unified-runtime/test/conformance/exp_graph/urQueueEndGraphCaptureExp.cpp @@ -6,11 +6,12 @@ #include "fixtures.h" -using urQueueEndGraphCaptureExpTest = uur::urGraphPopulatedExpTest; +using urQueueEndGraphCaptureExpTest = uur::urGraphExpTest; UUR_INSTANTIATE_DEVICE_TEST_SUITE(urQueueEndGraphCaptureExpTest); TEST_P(urQueueEndGraphCaptureExpTest, SuccessSameGraph) { + ASSERT_SUCCESS(urQueueBeginCaptureIntoGraphExp(queue, graph)); ur_exp_graph_handle_t sameGraph = nullptr; ASSERT_SUCCESS(urQueueEndGraphCaptureExp(queue, &sameGraph)); ASSERT_EQ(graph, sameGraph); diff --git a/unified-runtime/test/conformance/exp_graph/urQueueIsGraphCaptureEnabledExp.cpp b/unified-runtime/test/conformance/exp_graph/urQueueIsGraphCaptureEnabledExp.cpp index 2416780205781..6404ba8c627de 100644 --- a/unified-runtime/test/conformance/exp_graph/urQueueIsGraphCaptureEnabledExp.cpp +++ b/unified-runtime/test/conformance/exp_graph/urQueueIsGraphCaptureEnabledExp.cpp @@ -23,7 +23,7 @@ struct urQueueIsGraphCaptureEnabledExpTest : uur::urGraphSupportedExpTest { } void endGraphCapture() { - if (graph) { + if (!graph) { ASSERT_SUCCESS(urQueueEndGraphCaptureExp(queue, &graph)); } } From dd2fec7ce0568a832a05a1058b7c5e40ebe33ad8 Mon Sep 17 00:00:00 2001 From: Krzysztof Swiecicki Date: Tue, 9 Dec 2025 14:21:07 +0000 Subject: [PATCH 3/7] [UR][L0] Remove UR_DFAILURE from ZE2UR_CALL_THROWS UR_DFAILURE aborts program before throwing an exception making it impossible to handle it using try catch. --- unified-runtime/source/adapters/level_zero/common.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/unified-runtime/source/adapters/level_zero/common.hpp b/unified-runtime/source/adapters/level_zero/common.hpp index 15c4afe82047d..112f289e0a56b 100644 --- a/unified-runtime/source/adapters/level_zero/common.hpp +++ b/unified-runtime/source/adapters/level_zero/common.hpp @@ -219,8 +219,6 @@ void zeParseError(ze_result_t ZeError, const char *&ErrorString); { \ ze_result_t ZeResult = ZeName ZeArgs; \ if (auto Result = ZeCall().doCall(ZeResult, #ZeName, #ZeArgs, true)) { \ - UR_DFAILURE("failed ZE call " #ZeName " with " #ZeArgs ", with result:" \ - << Result); \ throw ze2urResult(Result); \ } \ } From 3dd399bcc42bfc8141460b375e43a77bdd6b0b6f Mon Sep 17 00:00:00 2001 From: Krzysztof Swiecicki Date: Wed, 10 Dec 2025 09:02:00 +0000 Subject: [PATCH 4/7] Remove trailing comma from known failures --- unified-runtime/test/conformance/exp_graph/fixtures.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/unified-runtime/test/conformance/exp_graph/fixtures.h b/unified-runtime/test/conformance/exp_graph/fixtures.h index b24b8b1418aa4..01df21379c61c 100644 --- a/unified-runtime/test/conformance/exp_graph/fixtures.h +++ b/unified-runtime/test/conformance/exp_graph/fixtures.h @@ -18,8 +18,7 @@ struct urGraphSupportedExpTest : uur::urQueueTest { UUR_RETURN_ON_FATAL_FAILURE(urQueueTest::SetUp()); UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{}, uur::NativeCPU{}, - uur::OpenCL{}, uur::LevelZero{}, - /* uur::LevelZeroV2{} */); + uur::OpenCL{}, uur::LevelZero{}); } }; From f692870cf36d3700e07c404d71965d61a7ce9cfc Mon Sep 17 00:00:00 2001 From: Krzysztof Swiecicki Date: Wed, 10 Dec 2025 09:13:07 +0000 Subject: [PATCH 5/7] Copy and use compute-runtime experimental headers --- unified-runtime/CMakeLists.txt | 1 + .../adapters/level_zero/external/README.md | 3 + .../mcl_ext/ze_mutable_command_list_exp.h | 39 +++ .../zex_mutable_cmdlist_control_flow_ext.h | 161 +++++++++ .../zex_mutable_cmdlist_dispatch_ext.h | 45 +++ .../mcl_ext/zex_mutable_cmdlist_ext.h | 16 + .../zex_mutable_cmdlist_serialization_ext.h | 47 +++ .../zex_mutable_cmdlist_temp_mem_ext.h | 77 +++++ .../zex_mutable_cmdlist_variable_ext.h | 308 ++++++++++++++++++ .../zex_mutable_cmdlist_variable_info_ext.h | 124 +++++++ .../ze_bindless_image_exp.h | 73 +++++ .../external/driver_experimental/zex_api.h | 29 ++ .../driver_experimental/zex_cmdlist.h | 43 +++ .../external/driver_experimental/zex_common.h | 297 +++++++++++++++++ .../driver_experimental/zex_context.h | 35 ++ .../external/driver_experimental/zex_driver.h | 43 +++ .../external/driver_experimental/zex_event.h | 59 ++++ .../external/driver_experimental/zex_graph.h | 115 +++++++ .../external/driver_experimental/zex_memory.h | 103 ++++++ .../external/driver_experimental/zex_module.h | 59 ++++ .../source/adapters/level_zero/platform.hpp | 2 +- .../source/adapters/level_zero/v2/graph.cpp | 2 +- .../source/adapters/level_zero/v2/graph.hpp | 2 +- 23 files changed, 1680 insertions(+), 3 deletions(-) create mode 100644 unified-runtime/source/adapters/level_zero/external/README.md create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/ze_mutable_command_list_exp.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_control_flow_ext.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_dispatch_ext.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_ext.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_serialization_ext.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_temp_mem_ext.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_variable_ext.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_variable_info_ext.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/ze_bindless_image_exp.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_api.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_cmdlist.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_common.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_context.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_driver.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_event.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_graph.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_memory.h create mode 100644 unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_module.h diff --git a/unified-runtime/CMakeLists.txt b/unified-runtime/CMakeLists.txt index 7f4dc3185f3c6..2248cfcb3db28 100644 --- a/unified-runtime/CMakeLists.txt +++ b/unified-runtime/CMakeLists.txt @@ -324,6 +324,7 @@ file(GLOB_RECURSE license_src ${license_glob}) # Add license check target list(FILTER license_src EXCLUDE REGEX "registry.yml") +list(FILTER format_src EXCLUDE REGEX "source/adapters/level_zero/external") add_custom_target(verify-licenses COMMAND ${Python3_EXECUTABLE} "${PROJECT_SOURCE_DIR}/scripts/verify_license.py" diff --git a/unified-runtime/source/adapters/level_zero/external/README.md b/unified-runtime/source/adapters/level_zero/external/README.md new file mode 100644 index 0000000000000..5e6b88d30cec8 --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/README.md @@ -0,0 +1,3 @@ +This subdirectory contains a copy of Level Zero experimental headers. +Repo: https://github.com/intel/compute-runtime +Tag: 25.44.36015.5 diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/ze_mutable_command_list_exp.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/ze_mutable_command_list_exp.h new file mode 100644 index 0000000000000..f3edef70c0907 --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/ze_mutable_command_list_exp.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include + +typedef ze_result_t(ZE_APICALL *ze_pfnCommandListGetNextCommandIdExpCb_t)( + ze_command_list_handle_t hCommandList, + const ze_mutable_command_id_exp_desc_t *desc, uint64_t *pCommandId); + +typedef ze_result_t(ZE_APICALL *ze_pfnCommandListUpdateMutableCommandsExpCb_t)( + ze_command_list_handle_t hCommandList, + const ze_mutable_commands_exp_desc_t *desc); + +typedef ze_result_t( + ZE_APICALL *ze_pfnCommandListUpdateMutableCommandSignalEventExpCb_t)( + ze_command_list_handle_t hCommandList, uint64_t commandId, + ze_event_handle_t hSignalEvent); + +typedef ze_result_t( + ZE_APICALL *ze_pfnCommandListUpdateMutableCommandWaitEventsExpCb_t)( + ze_command_list_handle_t hCommandList, uint64_t commandId, + uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents); + +typedef ze_result_t( + ZE_APICALL *ze_pfnCommandListGetNextCommandIdWithKernelsExpCb_t)( + ze_command_list_handle_t hCommandList, + const ze_mutable_command_id_exp_desc_t *desc, uint32_t numKernels, + ze_kernel_handle_t *phKernels, uint64_t *pCommandId); + +typedef ze_result_t( + ZE_APICALL *ze_pfnCommandListUpdateMutableCommandKernelsExpCb_t)( + ze_command_list_handle_t hCommandList, uint32_t numKernels, + uint64_t *pCommandId, ze_kernel_handle_t *phKernels); diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_control_flow_ext.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_control_flow_ext.h new file mode 100644 index 0000000000000..e5f8fac7408ce --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_control_flow_ext.h @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "level_zero/ze_stypes.h" +#include + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Label handle. +typedef struct _zex_label_handle_t *zex_label_handle_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Label descriptor. +typedef struct _zex_label_desc_t { + ze_structure_type_ext_t stype = + ZEX_STRUCTURE_TYPE_LABEL_DESCRIPTOR; ///< [in] type of this structure + const void *pNext = + nullptr; ///< [in][optional] pointer to extension-specific structure + + const char *name; ///< [in][optional] null-terminated name of the label + uint32_t alignment; ///< [in][optional] minimum alignment of the label +} zex_label_desc_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Operand flags +typedef uint32_t zex_operand_flags_t; +typedef enum _zex_operand_flag_t { + ZEX_OPERAND_FLAG_USES_VARIABLE = + ZE_BIT(0), // variable is being used - passed via memory + ZEX_OPERAND_FLAG_JUMP_ON_CLEAR = + ZE_BIT(1) // jump on '0', instead of default '1' +} zex_operand_flag_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Operand descriptor. +typedef struct _zex_operand_desc_t { + ze_structure_type_ext_t stype = + ZEX_STRUCTURE_TYPE_OPERAND_DESCRIPTOR; ///< [in] type of this structure + const void *pNext = + nullptr; ///< [in][optional] pointer to extension-specific structure + + void *memory; // if memory is NULL then offset is interpreted as MMIO + // if flag ZEX_OPERAND_FLAG_USES_VARIABLE is set memory is + // interpreted as variable + size_t offset; // offset within memory or register MMIO + uint32_t size; // operand size - dword + zex_operand_flags_t flags; // flags +} zex_operand_desc_t; + +#if defined(__cplusplus) +extern "C" { +#endif +/////////////////////////////////////////////////////////////////////////////// +/// @brief Creates/returns label based on name provided in +/// label descriptor. +/// +/// @details +/// - When label with the name provided in label descriptor does not +/// exist new label is created. +/// - If label with provided name exists it's returned. +/// - Label at creation is undefined (points to nothing). +/// +/// @returns +/// - ZE_RESULT_SUCCESS +/// - ZE_RESULT_ERROR_INVALID_ARGUMENT +/// + nullptr == hCommandList +/// + nullptr == pLabelDesc +/// + nullptr == phLabel +/// + pLabelDesc->alignment & (pLabelDesc->alignment - 1) != 0 +/// - ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY +/// + bad_alloc +ze_result_t ZE_APICALL zexCommandListGetLabel( + ze_command_list_handle_t hCommandList, ///< [in] handle of command list + const zex_label_desc_t *pLabelDesc, ///< [in] pointer to label descriptor + zex_label_handle_t *phLabel ///< [out] pointer to handle of label +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Sets label to point to current location in command list. +/// +/// @details +/// - Sets label address to current location. +/// - All previous jumps to this label are patched with label's address. +/// - Future jumps to this label will be patched with label's address. +/// - Label can be set only once. +/// - Label must be located in the same command list, as it was created +/// +/// @returns +/// - ZE_RESULT_SUCCESS +/// - ZE_RESULT_ERROR_INVALID_ARGUMENT +/// + nullptr == hCommandList +/// + nullptr == hLabel +/// - ZE_RESULT_ERROR_UNSUPPORTED_FEATURE +/// + variable already set +/// - ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT +/// + label's address is not aligned to it's alignment +ze_result_t ZE_APICALL zexCommandListSetLabel( + ze_command_list_handle_t hCommandList, ///< [in] handle of command list + zex_label_handle_t hLabel ///< [in] handle of label +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Appends jump to label predicated by condition. +/// +/// @details +/// If condition is present: +/// If condition->memory is present: +/// If ZEX_OPERAND_FLAG_USES_VARIABLE flag is set: +/// - Append MI_LOAD_REGISTER_MEM +/// reg = PREDICATE_RESULT_2 +/// memAddr = gpu address of buffer variable +/// Else: +/// - Append MI_LOAD_REGISTER_MEM +/// reg = PREDICATE_RESULT_2 +/// memAddr = pCondition->memory + pCondition->offset +/// Else: +/// - Append MI_LOAD_REGISTER_REG +/// regDst = PREDICATE_RESULT_2 +/// regSrc = pCondition->offset (need to pass MMIO) +/// +/// If ZEX_OPERAND_FLAG_JUMP_ON_CLEAR flag is set: // jumps when '0' +/// - Append MI_SET_PREDICATE(ENABLE_ON_SET) +/// Else: // jumps when '1' +/// - Append MI_SET_PREDICATE(ENABLE_ON_CLEAR) +/// +/// - Append MI_BATCH_BUFFER_START +/// predicationEnabled = condition is present +/// jumpAddress = label's address +/// - Append MI_SET_PREDICATE(DISABLE) - after BB_START +/// - Append MI_SET_PREDICATE(DISABLE) - at label's address +/// +/// @returns +/// - ZE_RESULT_SUCCESS +/// - ZE_RESULT_ERROR_INVALID_ARGUMENT +/// + nullptr == hCommandList +/// + nullptr == hLabel +ze_result_t ZE_APICALL zexCommandListAppendJump( + ze_command_list_handle_t hCommandList, ///< [in] handle of command list + zex_label_handle_t hLabel, ///< [in] handle of label + zex_operand_desc_t *pCondition ///< [in][opt] pointer to operand +); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListGetLabelCb_t)( + ze_command_list_handle_t hCommandList, const zex_label_desc_t *pLabelDesc, + zex_label_handle_t *phLabel); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListSetLabelCb_t)( + ze_command_list_handle_t hCommandList, zex_label_handle_t hLabel); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListAppendJumpCb_t)( + ze_command_list_handle_t hCommandList, zex_label_handle_t hLabel, + zex_operand_desc_t *pCondition); + +#if defined(__cplusplus) +} // extern "C" +#endif diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_dispatch_ext.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_dispatch_ext.h new file mode 100644 index 0000000000000..6c804a5a93f2f --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_dispatch_ext.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "level_zero/driver_experimental/mcl_ext/zex_mutable_cmdlist_variable_ext.h" +#include + +#if defined(__cplusplus) +extern "C" { +#endif +/////////////////////////////////////////////////////////////////////////////// +/// @brief Sets kernel group size to provided variable. +ze_result_t ZE_APICALL zexKernelSetVariableGroupSize( + ze_kernel_handle_t hKernel, ///< [in] handle of kernel + zex_variable_handle_t hGroupSizeVariable ///< [in] handle of variable +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Appends kernel launch to command list with variable group size. +ze_result_t ZE_APICALL zexCommandListAppendVariableLaunchKernel( + ze_command_list_handle_t + hCommandList, ///< [in] hnadle of mutable command list + ze_kernel_handle_t hKernel, ///< [in] handle of kernel + zex_variable_handle_t hGroupCountVariable, ///< [in] handle of variable + ze_event_handle_t hSignalEvent, ///< [in] handle to signal event + uint32_t numWaitEvents, ///< [in] num events to wait for + ze_event_handle_t *phWaitEvents); ///< [in] array of events to wait for + +typedef ze_result_t(ZE_APICALL *zex_pfnKernelSetVariableGroupSizeCb_t)( + ze_kernel_handle_t hKernel, zex_variable_handle_t hGroupSizeVariable); + +typedef ze_result_t( + ZE_APICALL *zex_pfnCommandListAppendVariableLaunchKernelCb_t)( + ze_command_list_handle_t hCommandList, ze_kernel_handle_t hKernel, + zex_variable_handle_t hGroupCountVariable, ze_event_handle_t hSignalEvent, + uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents); + +#if defined(__cplusplus) +} // extern "C" +#endif diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_ext.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_ext.h new file mode 100644 index 0000000000000..4392452ef3752 --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_ext.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "level_zero/driver_experimental/mcl_ext/ze_mutable_command_list_exp.h" +#include "level_zero/driver_experimental/mcl_ext/zex_mutable_cmdlist_control_flow_ext.h" +#include "level_zero/driver_experimental/mcl_ext/zex_mutable_cmdlist_dispatch_ext.h" +#include "level_zero/driver_experimental/mcl_ext/zex_mutable_cmdlist_serialization_ext.h" +#include "level_zero/driver_experimental/mcl_ext/zex_mutable_cmdlist_temp_mem_ext.h" +#include "level_zero/driver_experimental/mcl_ext/zex_mutable_cmdlist_variable_ext.h" +#include "level_zero/driver_experimental/mcl_ext/zex_mutable_cmdlist_variable_info_ext.h" diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_serialization_ext.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_serialization_ext.h new file mode 100644 index 0000000000000..f188fc25bff18 --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_serialization_ext.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include + +#if defined(__cplusplus) +extern "C" { +#endif +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieve native MCL binary from cmdlist. +ze_result_t ZE_APICALL zexCommandListGetNativeBinary( + ze_command_list_handle_t + hCommandList, ///< [in] handle of mutable command list + void *pBinary, ///< [in,out][optional] byte pointer to native MCL binary + size_t *pBinarySize, ///< [in,out] size of native MCL binary in bytes + const void *pModule, ///< [in] byte pointer to module containing kernels' + ///< used in cmdlist + size_t moduleSize ///< [in] size in bytes of module containing kernels's + ///< used in cmdlist +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Load command list from native MCL binary. +ze_result_t ZE_APICALL zexCommandListLoadNativeBinary( + ze_command_list_handle_t + hCommandList, ///< [in] handle of mutable command list + const void *pBinary, ///< [in] byte pointer to native MCL binary + size_t binarySize ///< [in] size of native MCL binary in bytes +); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListGetNativeBinaryCb_t)( + ze_command_list_handle_t hCommandList, void *pBinary, size_t *pBinarySize, + const void *pModule, size_t moduleSize); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListLoadNativeBinaryCb_t)( + ze_command_list_handle_t hCommandList, const void *pBinary, + size_t binarySize); + +#if defined(__cplusplus) +} // extern "C" +#endif diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_temp_mem_ext.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_temp_mem_ext.h new file mode 100644 index 0000000000000..6ce206ec110db --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_temp_mem_ext.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "level_zero/driver_experimental/mcl_ext/zex_mutable_cmdlist_variable_ext.h" +#include "level_zero/ze_stypes.h" + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Temporary variable flags +typedef uint32_t zex_temp_variable_flags_t; +typedef enum _zex_temp_variable_flag_t { + ZEX_TEMP_VARIABLE_FLAGS_IS_CONST_SIZE = + ZE_BIT(0), ///< temp variable has constant size + ZEX_TEMP_VARIABLE_FLAGS_IS_SCALABLE = + ZE_BIT(1) ///< temp variable scales with num elements +} zex_temp_variable_flag_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Temporary variable type +typedef enum _zex_temp_variable_type_t { + ZEX_TEMP_VARIABLE_TYPE_CONST_SIZE = 0, ///< temp variable has constant size + ZEX_TEMP_VARIABLE_TYPE_SCALABLE = + 1 ///< temp variable scales with num elements +} zex_temp_variable_type_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Temporary variable descriptor +typedef struct _zex_temp_variable_desc_t { + ze_structure_type_ext_t stype = ZEX_STRUCTURE_TYPE_TEMP_VARIABLE_DESCRIPTOR; + const void *pNext = nullptr; + + zex_temp_variable_flags_t flags; + size_t size; +} zex_temp_variable_desc_t; + +#if defined(__cplusplus) +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Sets number of elements used by scalable temporary variables. +ze_result_t ZE_APICALL zexCommandListTempMemSetEleCount( + ze_command_list_handle_t + hCommandList, ///< [in] handle of mutable command list + size_t eleCount); ///< [in] number of elements + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Returns size of the buffer required for all temporary variables. +ze_result_t ZE_APICALL zexCommandListTempMemGetSize( + ze_command_list_handle_t + hCommandList, ///< [in] handle of mutable command list + size_t *pTempMemSize); ///< [in,out] size of temporary memory buffer + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Sets buffer used by temporary variables. +ze_result_t ZE_APICALL zexCommandListTempMemSet( + ze_command_list_handle_t + hCommandList, ///< [in] handle of mutable command list + const void *pTempMem); ///< [in] ptr to temporary memory buffer + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListTempMemSetEleCountCb_t)( + ze_command_list_handle_t hCommandList, size_t eleCount); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListTempMemGetSizeCb_t)( + ze_command_list_handle_t hCommandList, size_t *pTempMemSize); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListTempMemSetCb_t)( + ze_command_list_handle_t hCommandList, const void *pTempMem); + +#if defined(__cplusplus) +} // extern "C" +#endif diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_variable_ext.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_variable_ext.h new file mode 100644 index 0000000000000..c2f30dbf8ec47 --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_variable_ext.h @@ -0,0 +1,308 @@ +/* + * Copyright (C) 2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "level_zero/ze_stypes.h" +#include + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Variable handle +typedef struct _zex_variable_handle_t *zex_variable_handle_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Variable descriptor +typedef struct _zex_variable_desc_t { + ze_structure_type_ext_t stype = + ZEX_STRUCTURE_TYPE_VARIABLE_DESCRIPTOR; ///< [in] type of this structure + const void *pNext = + nullptr; ///< [in][optional] pointer to extension-specific structure + + const char *name = + nullptr; ///< [in][optional] null-terminated name of the variable +} zex_variable_desc_t; + +#if defined(__cplusplus) +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Creates/returns variable based on name provided in +/// variable descriptor. +/// +/// @details +/// - When variable with the name provided in variable descriptor does not +/// exist new variable is created. +/// - Variable at creation has no type attached to it (can be set to buffer, +/// image, etc). +/// - If variable with provided name exists it's returned. +/// +/// @returns +/// - ZE_RESULT_SUCCESS +/// - ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY +/// + bad_alloc +/// - ZE_RESULT_ERROR_INVALID_ARGUMENT +/// + nullptr == hCmdList +/// + nullptr == pVariableDescriptor +/// + nullptr == phVariable +ze_result_t ZE_APICALL zexCommandListGetVariable( + ze_command_list_handle_t hCmdList, ///< [in] handle of mutable command list + const zex_variable_desc_t + *pVariableDescriptor, ///< [in] pointer to variable descriptor + zex_variable_handle_t + *phVariable ///< [in,out] pointer to handle of variable +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Sets kernel argument to be a variable. +/// +/// @details +/// - Variable will be used as kernel argument at argIndex. +/// - If variable is used for first time sets it's type accordingly, +/// else checks if type is right. +/// - On zeCommandListAppendLaunchKernel, variable will be notified of it's +/// usage in kernel. +/// - On zexVariableSetValue all usages will be patched - kernel argument +/// will be set. +/// - If kernel has not yet been appended using +/// zeCommandListAppendLaunchKernel +/// it can be overridden with zeKernelSetArgumentValue(). Argument stops +/// being a variable. +/// +/// @returns +/// - ZE_RESULT_SUCCESS +/// - ZE_RESULT_ERROR_INVALID_ARGUMENT +/// + nullptr == hKernel +/// + nullptr == hVariable +/// + kernelArgType != variable->type +ze_result_t ZE_APICALL zexKernelSetArgumentVariable( + ze_kernel_handle_t hKernel, ///< [in] handle of kernel + uint32_t argIndex, ///< [in] argument index in kernel + zex_variable_handle_t hVariable ///< [in] handle of variable +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Sets variable's value. +/// +/// @details +/// - Sets variable's value based on variable's type. +/// - Patches all variable's usages with it's value. +/// - Can be called multiple times to override previous value. +/// - If variable is a buffer: +/// - Adds buffer to residency container +/// - If variable already set remove buffer form residency container +/// +/// @returns +/// - ZE_RESULT_SUCCESS +/// - ZE_RESULT_ERROR_INVALID_ARGUMENT +/// + nullptr == hVariable +/// + nullptr == pValue +/// + variable->size != valueSize +/// - ZE_RESULT_UNSUPPORTED_FEATURE +/// + variable->type != Type::Buffer ;for now only works with buffers +ze_result_t ZE_APICALL zexVariableSetValue( + zex_variable_handle_t hVariable, ///< [in] handle of variable + uint32_t flags, ///< [in] flags + size_t valueSize, ///< [in] size of value + const void *pValue ///< [in] pointer to value +); + +typedef enum _zex_mcl_alu_reg_t { + ZE_MCL_ALU_REG_GPR0 = 0, + ZE_MCL_ALU_REG_GPR0_1 = 1, + ZE_MCL_ALU_REG_GPR1 = 2, + ZE_MCL_ALU_REG_GPR1_1 = 3, + ZE_MCL_ALU_REG_GPR2 = 4, + ZE_MCL_ALU_REG_GPR2_1 = 5, + ZE_MCL_ALU_REG_GPR3 = 6, + ZE_MCL_ALU_REG_GPR3_1 = 7, + ZE_MCL_ALU_REG_GPR4 = 8, + ZE_MCL_ALU_REG_GPR4_1 = 9, + ZE_MCL_ALU_REG_GPR5 = 10, + ZE_MCL_ALU_REG_GPR5_1 = 11, + ZE_MCL_ALU_REG_GPR6 = 12, + ZE_MCL_ALU_REG_GPR6_1 = 13, + ZE_MCL_ALU_REG_GPR7 = 14, + ZE_MCL_ALU_REG_GPR7_1 = 15, + ZE_MCL_ALU_REG_GPR8 = 16, + ZE_MCL_ALU_REG_GPR8_1 = 17, + ZE_MCL_ALU_REG_GPR9 = 18, + ZE_MCL_ALU_REG_GPR9_1 = 19, + ZE_MCL_ALU_REG_GPR10 = 20, + ZE_MCL_ALU_REG_GPR10_1 = 21, + ZE_MCL_ALU_REG_GPR11 = 22, + ZE_MCL_ALU_REG_GPR11_1 = 23, + ZE_MCL_ALU_REG_GPR12 = 24, + ZE_MCL_ALU_REG_GPR12_1 = 25, + ZE_MCL_ALU_REG_GPR13 = 26, + ZE_MCL_ALU_REG_GPR13_1 = 27, + ZE_MCL_ALU_REG_GPR14 = 28, + ZE_MCL_ALU_REG_GPR14_1 = 29, + ZE_MCL_ALU_REG_GPR15 = 30, + ZE_MCL_ALU_REG_GPR15_1 = 31, + ZE_MCL_ALU_REG_GPR_MAX = 32, + ZE_MCL_ALU_REG_PREDICATE1 = 33, + ZE_MCL_ALU_REG_REG_MAX = 36, + ZE_MCL_ALU_REG_CONST0 = 37, + ZE_MCL_ALU_REG_CONST1 = 38, + ZE_MCL_ALU_REG_NONE = 39, + ZE_MCL_ALU_REG_PREDICATE2 = 40, + ZE_MCL_ALU_REG_PREDICATE_RESULT = 41, + ZE_MCL_ALU_REG_MAX = 42 +} zex_mcl_alu_reg_t; + +typedef enum _zex_mcl_alu_op_type_t { + ZE_MCL_ALU_OP_ADD = 0x100, + ZE_MCL_ALU_OP_SUB = 0x101, + ZE_MCL_ALU_OP_AND = 0x102, + ZE_MCL_ALU_OP_OR = 0x103, + ZE_MCL_ALU_OP_XOR = 0x104, + ZE_MCL_ALU_OP_STORE = 0x180, + ZE_MCL_ALU_OP_STOREINV = 0x580, + ZE_MCL_ALU_OP_LOAD = 0x080, + ZE_MCL_ALU_OP_LOAD0 = 0x081, + ZE_MCL_ALU_OP_LOAD1 = 0x481, + ZE_MCL_ALU_OP_LOADINV = 0x480, + ZE_MCL_ALU_OP_NOOP = 0x0, + ZE_MCL_ALU_OP_MAX +} zex_mcl_alu_op_type_t; + +typedef enum _zex_mcl_alu_flag_t { + ZE_MCL_ALU_FLAG_ACC = 0x31, + ZE_MCL_ALU_FLAG_ZF = 0x32, + ZE_MCL_ALU_FLAG_CF = 0x33, + ZE_MCL_ALU_FLAG_NACC = ZE_MCL_ALU_FLAG_ACC + 0x100, + ZE_MCL_ALU_FLAG_NZF = ZE_MCL_ALU_FLAG_ZF + 0x100, + ZE_MCL_ALU_FLAG_NCF = ZE_MCL_ALU_FLAG_CF + 0x100, + ZE_MCL_ALU_FLAG_MAX +} zex_mcl_alu_flag_t; + +typedef struct _zex_mcl_alu_operation_t { + zex_mcl_alu_op_type_t opType; + zex_mcl_alu_reg_t regDest; + zex_mcl_alu_reg_t regSource1; + zex_mcl_alu_reg_t regSource2; + zex_mcl_alu_flag_t flag; +} zex_mcl_alu_operation_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Appends command loading value (DWORD) to GPR register from +/// variable's buffer. +ze_result_t ZE_APICALL zexCommandListAppendLoadRegVariable( + ze_command_list_handle_t + hCommandList, ///< [in] handle of mutable command list + zex_mcl_alu_reg_t reg, ///< [in] GPR register destination + zex_variable_handle_t hVariable); ///< [in] handle of variable + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Appends command storing value (DWORD) from GPR register to +/// variable's buffer. +ze_result_t ZE_APICALL zexCommandListAppendStoreRegVariable( + ze_command_list_handle_t + hCommandList, ///< [in] handle of mutable command list + zex_mcl_alu_reg_t reg, ///< [in] GPR register source + zex_variable_handle_t hVariable); ///< [in] handle of variable + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Appends command to load a value from source register to destination +/// register. +/// +/// @details +/// - Performs a register-to-register copy operation. +ze_result_t ZE_APICALL zexCommandListAppendMILoadRegReg( + ze_command_list_handle_t + hCommandList, ///< [in] handle of mutable command list + zex_mcl_alu_reg_t destination, ///< [in] destination register + zex_mcl_alu_reg_t source); ///< [in] source register + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Appends command to load a value from memory address to register. +/// +/// @details +/// - Loads a DWORD from the specified memory address into the register. +ze_result_t ZE_APICALL zexCommandListAppendMILoadRegMem( + ze_command_list_handle_t + hCommandList, ///< [in] handle of mutable command list + zex_mcl_alu_reg_t reg, ///< [in] destination register + uint64_t address); ///< [in] source memory address + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Appends command to load an immediate value into a register. +/// +/// @details +/// - Loads the provided immediate 32-bit value into the destination +/// register. +ze_result_t ZE_APICALL zexCommandListAppendMILoadRegImm( + ze_command_list_handle_t + hCommandList, ///< [in] handle of mutable command list + zex_mcl_alu_reg_t destination, ///< [in] destination register + uint32_t val); ///< [in] immediate value to load + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Appends command to store a value from register to memory. +/// +/// @details +/// - Stores a DWORD from the register to the specified memory address. +ze_result_t ZE_APICALL zexCommandListAppendMIStoreRegMem( + ze_command_list_handle_t + hCommandList, ///< [in] handle of mutable command list + zex_mcl_alu_reg_t reg, ///< [in] source register + uint64_t address); ///< [in] destination memory address + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Appends commands to perform ALU operations. +/// +/// @details +/// - Executes an array of ALU operations in sequence. +/// - Operations can include arithmetic, logical, and register transfer +/// commands. +ze_result_t ZE_APICALL zexCommandListAppendMIMath( + ze_command_list_handle_t + hCommandList, ///< [in] handle of mutable command list + zex_mcl_alu_operation_t + *opArray, ///< [in] array of ALU operations to perform + size_t noOperations); ///< [in] number of operations in the array + +typedef ze_result_t(ZE_APICALL *zex_pfnKernelSetArgumentVariableCb_t)( + ze_kernel_handle_t hKernel, uint32_t argIndex, + zex_variable_handle_t hVariable); + +typedef ze_result_t(ZE_APICALL *zex_pfnVariableSetValueCb_t)( + zex_variable_handle_t hVariable, uint32_t flags, size_t valueSize, + const void *pValue); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListAppendLoadRegVariableCb_t)( + ze_command_list_handle_t hCommandList, zex_mcl_alu_reg_t reg, + zex_variable_handle_t hVariable); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListAppendStoreRegVariableCb_t)( + ze_command_list_handle_t hCommandList, zex_mcl_alu_reg_t reg, + zex_variable_handle_t hVariable); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListAppendMILoadRegRegCb_t)( + ze_command_list_handle_t hCommandList, zex_mcl_alu_reg_t destination, + zex_mcl_alu_reg_t source); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListAppendMILoadRegMemCb_t)( + ze_command_list_handle_t hCommandList, zex_mcl_alu_reg_t reg, + uint64_t address); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListAppendMILoadRegImmCb_t)( + ze_command_list_handle_t hCommandList, zex_mcl_alu_reg_t destination, + uint32_t val); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListAppendMIStoreRegMemCb_t)( + ze_command_list_handle_t hCommandList, zex_mcl_alu_reg_t reg, + uint64_t address); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListAppendMIMathCb_t)( + ze_command_list_handle_t hCommandList, zex_mcl_alu_operation_t *opArray, + size_t noOperations); + +#if defined(__cplusplus) +} // extern "C" +#endif diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_variable_info_ext.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_variable_info_ext.h new file mode 100644 index 0000000000000..393f110cbe2eb --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/mcl_ext/zex_mutable_cmdlist_variable_info_ext.h @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "level_zero/ze_stypes.h" +#include + +/////////////////////////////////////////////////////////////////////////////// +/// @brief State of the variable object +typedef enum _zex_variable_state_t { + ZEX_VARIABLE_STATE_DECLARED, ///< not associated to any operation + ZEX_VARIABLE_STATE_DEFINED, ///< associated to an operation, but value not set + ZEX_VARIABLE_STATE_INITIALIZED ///< value is set +} zex_variable_state_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Variable object flags +typedef uint32_t zex_variable_flags_t; +typedef enum _zex_variable_flag_t { + ZEX_VARIABLE_FLAGS_NONE = 0, + ZEX_VARIABLE_FLAGS_INPUT = ZE_BIT(0), ///< used as input + ZEX_VARIABLE_FLAGS_OUTPUT = ZE_BIT(1), ///< used as output + ZEX_VARIABLE_FLAGS_TEMPORARY = + ZE_BIT(2), ///< used as temporary (not visible to host) object + ZEX_VARIABLE_FLAGS_SCALABLE = ZE_BIT(3), ///< variable is scalable +} zex_variable_flag_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Variable object value type +typedef enum _zex_variable_type_t { + ZEX_VARIABLE_TYPE_NONE, ///< ZEX_VARIABLE_STATE_DECLARED + ZEX_VARIABLE_TYPE_IMAGE, ///< variable represents an image + ZEX_VARIABLE_TYPE_VALUE, ///< variable represents a value + ZEX_VARIABLE_TYPE_BUFFER, ///< variable represents a buffer + ZEX_VARIABLE_TYPE_SAMPLER, ///< variable represents a sampler + ZEX_VARIABLE_TYPE_EVENT, ///< variable represents an event + ZEX_VARIABLE_TYPE_PARAM, ///< variable represents host param + ZEX_VARIABLE_TYPE_GROUP_SIZE, ///< variable represents group size + ZEX_VARIABLE_TYPE_GROUP_COUNT, ///< variable represents group count + ZEX_VARIABLE_TYPE_GLOBAL_OFFSET, ///< variable represents global offset + ZEX_VARIABLE_TYPE_SIGNAL_EVENT, ///< variable represents signal event + ZEX_VARIABLE_TYPE_WAIT_EVENT, ///< variable represents wait events + ZEX_VARIABLE_TYPE_SLM_BUFFER, ///< variable represents slm buffer +} zex_variable_type_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Variable information +typedef struct _zex_variable_info_t { + ze_structure_type_ext_t stype = + ZEX_STRUCTURE_TYPE_VARIABLE_INFO; ///< type of this structure + const void *pNext = + nullptr; ///< [optional] pointer to extension-specific structure + + zex_variable_handle_t handle = nullptr; ///< handle to the variable + const char *name = nullptr; ///< name of the variable + size_t size = 0U; ///< size of the variable + zex_variable_state_t state = + ZEX_VARIABLE_STATE_DECLARED; ///< current state of the variable + zex_variable_flags_t flags = + ZEX_VARIABLE_FLAGS_NONE; ///< flags providing additional metadata about + ///< the variable + zex_variable_type_t type = + ZEX_VARIABLE_TYPE_NONE; ///< type of value represented by this variable +} zex_variable_info_t; + +#if defined(__cplusplus) +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Variable information +/// +/// @details +/// - Variable information represents set of metadata describing a variable +/// - Retrieved zex_variable_info_t lifetime is bound to lifetime of the +/// commandlist (zex_variable_info_t is not being copied into caller memory) +ze_result_t ZE_APICALL zexVariableGetInfo( + zex_variable_handle_t hVariable, // [in] handle to the variable + const zex_variable_info_t * + *pTypeInfo // [in] pointer where pointer to requested variable info + // should be copied to +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieve list of all variables tied to a command list +/// +/// @details +/// - pVariables should be big enough to hold pointers to variables +/// information representing all variables in the command list +/// - it's expected that user first calls zexCommandListGetVariablesList +/// with pVariables==nullptr to query total number of variables in the +/// command list. +/// Next, user should allocate big enough array and use it with second +/// call to zexCommandListGetVariablesList +/// - lifetime of zex_variable_info_t pointed to by pointers in pVariables +/// is tied to lifetime of the command list (similarly to +/// zexVariableGetInfo) +ze_result_t ZE_APICALL zexCommandListGetVariablesList( + ze_command_list_handle_t + hCommandList, // [in] handle to the command list object + uint32_t *pVariablesCount, // [in,out] number of variables defined in the + // command list + const zex_variable_info_t * + *pVariablesInfos // [in,out][optional] array to which pointers to + // variables information should be copied to +); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListGetVariableCb_t)( + ze_command_list_handle_t hCmdList, + const zex_variable_desc_t *pVariableDescriptor, + zex_variable_handle_t *phVariable); + +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListGetVariablesListCb_t)( + ze_command_list_handle_t hCommandList, uint32_t *pVariablesCount, + const zex_variable_info_t **pVariablesInfos); + +#if defined(__cplusplus) +} // extern "C" +#endif diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/ze_bindless_image_exp.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/ze_bindless_image_exp.h new file mode 100644 index 0000000000000..20a4f74ab6d51 --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/ze_bindless_image_exp.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#ifndef _ZE_BINDLESS_IMAGE_EXP_H +#define _ZE_BINDLESS_IMAGE_EXP_H +#if defined(__cplusplus) +#pragma once +#endif + +#include "level_zero/ze_stypes.h" +#include + +#ifndef ZE_BINDLESS_IMAGE_EXP_NAME +#define ZE_BINDLESS_IMAGE_EXP_NAME "ZE_experimental_bindless_image" + +typedef enum _ze_bindless_image_exp_version_t { + ZE_BINDLESS_IMAGE_EXP_VERSION_1_0 = 0, + ZE_BINDLESS_IMAGE_EXP_VERSION_CURRENT = 1, + ZE_BINDLESS_IMAGE_EXP_VERSION_FORCE_UINT32 = 0x7fffffff +} ze_bindless_image_exp_version_t; + +typedef enum _ze_image_bindless_exp_flags_t { + ZE_IMAGE_BINDLESS_EXP_FLAG_BINDLESS = ZE_BIT(0), + ZE_IMAGE_BINDLESS_EXP_FLAG_SAMPLED_IMAGE = ZE_BIT(1), + ZE_IMAGE_BINDLESS_EXP_FLAG_FORCE_UINT32 = 0x7fffffff +} ze_image_bindless_exp_flags_t; + +typedef struct _ze_image_bindless_exp_desc_t { + ze_structure_type_t stype; ///< [in] type of this structure + const void + *pNext; ///< [in][optional] must be null or a pointer to an + ///< extension-specific structure (i.e. contains stype and pNext). + ze_image_bindless_exp_flags_t + flags; ///< [in] image flags. + ///< must be 0 (default) or a valid combination of + ///< ::ze_image_bindless_exp_flag_t; default behavior bindless + ///< images are not used when creating handles via zeImageCreate. +} ze_image_bindless_exp_desc_t; + +typedef struct _ze_image_pitched_exp_desc_t { + ze_structure_type_t stype; ///< [in] type of this structure + const void + *pNext; ///< [in][optional] must be null or a pointer to an + ///< extension-specific structure (i.e. contains stype and pNext). + void *ptr; ///< [in] pointer to pitched device allocation allocated using + ///< zeMemAllocDevice. +} ze_image_pitched_exp_desc_t; + +typedef struct _ze_device_pitched_alloc_exp_properties_t { + ze_structure_type_t stype; ///< [in] type of this structure + void + *pNext; ///< [in,out][optional] must be null or a pointer to an + ///< extension-specific structure (i.e. contains stype and pNext). + size_t maxImageLinearWidth; ///< [out] Maximum image linear width. + size_t maxImageLinearHeight; ///< [out] Maximum image linear height. +} ze_device_pitched_alloc_exp_properties_t; + +ZE_APIEXPORT ze_result_t ZE_APICALL zeMemGetPitchFor2dImage( + ze_context_handle_t hContext, ze_device_handle_t hDevice, size_t imageWidth, + size_t imageHeight, unsigned int elementSizeInBytes, size_t *rowPitch); + +ZE_APIEXPORT ze_result_t ZE_APICALL +zeImageGetDeviceOffsetExp(ze_image_handle_t hImage, uint64_t *pDeviceOffset); + +#endif // ZE_BINDLESS_IMAGE_EXP_NAME + +#define ZE_IMAGE_BINDLESS_EXP_FLAG_SAMPLED_IMAGE 2 + +#endif diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_api.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_api.h new file mode 100644 index 0000000000000..7ce1b0c545781 --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_api.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2022-2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#ifndef _ZEX_API_H +#define _ZEX_API_H +#if defined(__cplusplus) +#pragma once +#endif + +// 'core' API headers +#include "level_zero/ze_stypes.h" +#include +// 'sysman' API headers +#include + +// driver experimental API headers +#include "zex_cmdlist.h" +#include "zex_context.h" +#include "zex_driver.h" +#include "zex_event.h" +#include "zex_graph.h" +#include "zex_memory.h" +#include "zex_module.h" + +#endif // _ZEX_API_H diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_cmdlist.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_cmdlist.h new file mode 100644 index 0000000000000..250d53e82dcf1 --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_cmdlist.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2022-2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#ifndef _ZEX_CMDLIST_H +#define _ZEX_CMDLIST_H +#if defined(__cplusplus) +#pragma once +#endif + +#include + +#include "zex_common.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +ZE_APIEXPORT ze_result_t ZE_APICALL zexCommandListAppendWaitOnMemory( + zex_command_list_handle_t hCommandList, zex_wait_on_mem_desc_t *desc, + void *ptr, uint32_t data, zex_event_handle_t hSignalEvent); + +ZE_APIEXPORT ze_result_t ZE_APICALL zexCommandListAppendWaitOnMemory64( + zex_command_list_handle_t hCommandList, zex_wait_on_mem_desc_t *desc, + void *ptr, uint64_t data, zex_event_handle_t hSignalEvent); + +ZE_APIEXPORT ze_result_t ZE_APICALL zexCommandListAppendWriteToMemory( + zex_command_list_handle_t hCommandList, zex_write_to_mem_desc_t *desc, + void *ptr, uint64_t data); + +ZE_APIEXPORT ze_result_t ZE_APICALL zexCommandListAppendHostFunction( + ze_command_list_handle_t hCommandList, void *pHostFunction, void *pUserData, + void *pNext, ze_event_handle_t hSignalEvent, uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // _ZEX_CMDLIST_H diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_common.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_common.h new file mode 100644 index 0000000000000..a5e5f1b3fa9ad --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_common.h @@ -0,0 +1,297 @@ +/* + * Copyright (C) 2022-2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#ifndef _ZEX_COMMON_H +#define _ZEX_COMMON_H +#if defined(__cplusplus) +#pragma once +#endif +#include "level_zero/ze_stypes.h" +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Handle of command list object +typedef ze_command_list_handle_t zex_command_list_handle_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Handle of event object +typedef ze_event_handle_t zex_event_handle_t; + +#define ZEX_BIT(_i) (1 << _i) + +typedef uint32_t zex_mem_action_scope_flags_t; +typedef enum _zex_mem_action_scope_flag_t { + ZEX_MEM_ACTION_SCOPE_FLAG_SUBDEVICE = ZEX_BIT(0), + ZEX_MEM_ACTION_SCOPE_FLAG_DEVICE = ZEX_BIT(1), + ZEX_MEM_ACTION_SCOPE_FLAG_HOST = ZEX_BIT(2), + ZEX_MEM_ACTION_SCOPE_FLAG_FORCE_UINT32 = 0x7fffffff +} zex_mem_action_scope_flag_t; + +typedef uint32_t zex_wait_on_mem_action_flags_t; +typedef enum _zex_wait_on_mem_action_flag_t { + ZEX_WAIT_ON_MEMORY_FLAG_EQUAL = ZEX_BIT(0), + ZEX_WAIT_ON_MEMORY_FLAG_NOT_EQUAL = ZEX_BIT(1), + ZEX_WAIT_ON_MEMORY_FLAG_GREATER_THAN = ZEX_BIT(2), + ZEX_WAIT_ON_MEMORY_FLAG_GREATER_THAN_EQUAL = ZEX_BIT(3), + ZEX_WAIT_ON_MEMORY_FLAG_LESSER_THAN = ZEX_BIT(4), + ZEX_WAIT_ON_MEMORY_FLAG_LESSER_THAN_EQUAL = ZEX_BIT(5), + ZEX_WAIT_ON_MEMORY_FLAG_FORCE_UINT32 = 0x7fffffff +} zex_wait_on_mem_action_flag_t; + +typedef struct _zex_wait_on_mem_desc_t { + zex_wait_on_mem_action_flags_t actionFlag; + zex_mem_action_scope_flags_t waitScope; +} zex_wait_on_mem_desc_t; + +typedef struct _zex_write_to_mem_desc_t { + zex_mem_action_scope_flags_t writeScope; +} zex_write_to_mem_desc_t; + +/////////////////////////////////////////////////////////////////////////////// +#ifndef ZE_SYNCHRONIZED_DISPATCH_EXP_NAME +/// @brief Synchronized Dispatch extension name +#define ZE_SYNCHRONIZED_DISPATCH_EXP_NAME \ + "ZE_experimental_synchronized_dispatch" +#endif // ZE_SYNCHRONIZED_DISPATCH_EXP_NAME + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Synchronized Dispatch extension version(s) +typedef enum _ze_synchronized_dispatch_exp_version_t { + ZE_SYNCHRONIZED_DISPATCH_EXP_VERSION_1_0 = + ZE_MAKE_VERSION(1, 0), ///< version 1.0 + ZE_SYNCHRONIZED_DISPATCH_EXP_VERSION_CURRENT = + ZE_MAKE_VERSION(1, 0), ///< latest known version + ZE_SYNCHRONIZED_DISPATCH_EXP_VERSION_FORCE_UINT32 = 0x7fffffff + +} ze_synchronized_dispatch_exp_version_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Supported synchronized dispatch flags +typedef uint32_t ze_synchronized_dispatch_exp_flags_t; +typedef enum _ze_synchronized_dispatch_exp_flag_t { + ZE_SYNCHRONIZED_DISPATCH_DISABLED_EXP_FLAG = + ZE_BIT(0), ///< Non-synchronized dispatch. Must synchronize only with + ///< other synchronized dispatches + ZE_SYNCHRONIZED_DISPATCH_ENABLED_EXP_FLAG = + ZE_BIT(1), ///< Synchronized dispatch. Must synchronize with all + ///< synchronized and non-synchronized dispatches + ZE_SYNCHRONIZED_DISPATCH_EXP_FLAG_FORCE_UINT32 = 0x7fffffff + +} ze_synchronized_dispatch_exp_flag_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Forward-declare ze_synchronized_dispatch_exp_desc_t +typedef struct _ze_synchronized_dispatch_exp_desc_t + ze_synchronized_dispatch_exp_desc_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Command queue or command list descriptor for synchronized dispatch. +/// This structure may be +/// passed as pNext member of ::ze_command_queue_desc_t. or +/// ::ze_command_list_desc_t. +typedef struct _ze_synchronized_dispatch_exp_desc_t { + ze_structure_type_ext_t stype; ///< [in] type of this structure + const void + *pNext; ///< [in][optional] must be null or a pointer to an + ///< extension-specific structure (i.e. contains stype and pNext). + ze_synchronized_dispatch_exp_flags_t + flags; ///< [in] mode flags. + ///< must be valid value of ::ze_synchronized_dispatch_exp_flag_t + +} ze_synchronized_dispatch_exp_desc_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Forward-declare ze_intel_media_communication_desc_t +typedef struct _ze_intel_media_communication_desc_t + ze_intel_media_communication_desc_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief ze_intel_media_communication_desc_t +typedef struct _ze_intel_media_communication_desc_t { + ze_structure_type_ext_t stype; ///< [in] type of this structure + void * + pNext; ///< [in][optional] must be null or a pointer to an + ///< extension-specific, this will be used to extend this in future + void *controlSharedMemoryBuffer; ///< [in] control shared memory buffer + ///< pointer, must be USM address + uint32_t + controlSharedMemoryBufferSize; ///< [in] control shared memory buffer size + void *controlBatchBuffer; ///< [in] control batch buffer pointer, must be USM + ///< address + uint32_t controlBatchBufferSize; ///< [in] control batch buffer size +} ze_intel_media_communication_desc_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Forward-declare ze_intel_media_doorbell_handle_desc_t +typedef struct _ze_intel_media_doorbell_handle_desc_t + ze_intel_media_doorbell_handle_desc_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief ze_intel_media_doorbell_handle_desc_t +/// @details Handle of the doorbell. This structure is passed as argument of +/// zeIntelMediaCommunicationCreate and zeIntelMediaCommunicationDestroy +typedef struct _ze_intel_media_doorbell_handle_desc_t { + ze_structure_type_ext_t stype; ///< [in] type of this structure + void * + pNext; ///< [in][optional] must be null or a pointer to an + ///< extension-specific, this will be used to extend this in future + void *doorbell; ///< [in,out] handle of the doorbell +} ze_intel_media_doorbell_handle_desc_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Supported device media flags +typedef uint32_t ze_intel_device_media_exp_flags_t; +typedef enum _ze_intel_device_media_exp_flag_t { + ZE_INTEL_DEVICE_MEDIA_SUPPORTS_ENCODING_EXP_FLAG = + ZE_BIT(0), ///< Supports encoding + ZE_INTEL_DEVICE_MEDIA_SUPPORTS_DECODING_EXP_FLAG = + ZE_BIT(1), ///< Supports decoding + ZE_INTEL_DEVICE_MEDIA_EXP_FLAG_FORCE_UINT32 = 0x7fffffff +} ze_intel_device_media_exp_flag_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Forward-declare ze_intel_device_media_exp_properties_t +typedef struct _ze_intel_device_media_exp_properties_t + ze_intel_device_media_exp_properties_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief May be passed to ze_device_properties_t through pNext. +typedef struct _ze_intel_device_media_exp_properties_t { + ze_structure_type_ext_t stype; ///< [in] type of this structure + const void *pNext; ///< [in][optional] must be null or a pointer to an + ///< extension-specific + ze_intel_device_media_exp_flags_t flags; ///< [out] device media flags + uint32_t numEncoderCores; ///< [out] number of encoder cores + uint32_t numDecoderCores; ///< [out] number of decoder cores +} ze_intel_device_media_exp_properties_t; + +#ifndef ZEX_COUNTER_BASED_EVENT_EXT_NAME +/// @brief Counter Based Event Extension Name +#define ZEX_COUNTER_BASED_EVENT_EXT_NAME "ZEX_counter_based_event" +#endif // ZEX_COUNTER_BASED_EVENT_EXT_NAME + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Counter Based Event Extension Version(s) +typedef enum _zex_counter_based_event_version_t { + ZEX_COUNTER_BASED_EVENT_VERSION_1_0 = ZE_MAKE_VERSION(1, 0), ///< version 1.0 + ZEX_COUNTER_BASED_EVENT_VERSION_CURRENT = + ZE_MAKE_VERSION(1, 0), ///< latest known version + ZEX_COUNTER_BASED_EVENT_VERSION_FORCE_UINT32 = 0x7fffffff + +} zex_counter_based_event_version_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief IPC handle to counter based event +typedef struct _zex_ipc_counter_based_event_handle_t { + char data[ZE_MAX_IPC_HANDLE_SIZE]; ///< [out] Opaque data representing an IPC + ///< handle +} zex_ipc_counter_based_event_handle_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Supported event flags for defining counter-based event +typedef uint32_t zex_counter_based_event_exp_flags_t; +typedef enum _zex_counter_based_event_exp_flag_t { + ZEX_COUNTER_BASED_EVENT_FLAG_IMMEDIATE = ZE_BIT( + 0), ///< Counter-based event is used for immediate command lists (default) + ZEX_COUNTER_BASED_EVENT_FLAG_NON_IMMEDIATE = ZE_BIT( + 1), ///< Counter-based event is used for non-immediate command lists + ZEX_COUNTER_BASED_EVENT_FLAG_HOST_VISIBLE = + ZE_BIT(2), ///< Signals and waits are also visible to host + ZEX_COUNTER_BASED_EVENT_FLAG_IPC = + ZE_BIT(3), ///< Event can be shared across processes for waiting + ZEX_COUNTER_BASED_EVENT_FLAG_KERNEL_TIMESTAMP = + ZE_BIT(4), ///< Event contains kernel timestamps + ZEX_COUNTER_BASED_EVENT_FLAG_KERNEL_MAPPED_TIMESTAMP = + ZE_BIT(5), ///< Event contains kernel timestamps synchronized to host time + ///< domain. Cannot be combined + ///< with::ZEX_COUNTER_BASED_EVENT_FLAG_KERNEL_TIMESTAMP + ZEX_COUNTER_BASED_EVENT_FLAG_GRAPH_EXTERNAL_EVENT = + ZE_BIT(6), ///< Event when is used in graph record & replay, can be used + ///< outside recorded graph for synchronization (using as wait + ///< event or for host synchronization) + ZEX_COUNTER_BASED_EVENT_FLAG_FORCE_UINT32 = 0x7fffffff + +} zex_counter_based_event_exp_flag_t; + +typedef struct _zex_counter_based_event_desc_t { + ze_structure_type_ext_t stype; ///< [in] type of this structure + const void *pNext; ///< [in][optional] must be null or a pointer to an + ///< extension-specific + zex_counter_based_event_exp_flags_t + flags; ///< [in] counter based event flags. + ///< Must be 0 (default) or a valid combination of + ///< ::zex_counter_based_event_exp_flag_t + ze_event_scope_flags_t + signalScope; ///< [in] defines the scope of relevant cache hierarchies to + ///< flush on a signal action before the event is triggered. + ///< must be 0 (default) or a valid combination of + ///< ::ze_event_scope_flag_t; default behavior is + ///< synchronization within the command list only, no + ///< additional cache hierarchies are flushed. + ze_event_scope_flags_t + waitScope; ///< [in] defines the scope of relevant cache hierarchies to + ///< invalidate on a wait action after the event is complete. + ///< must be 0 (default) or a valid combination of + ///< ::ze_event_scope_flag_t; default behavior is + ///< synchronization within the command list only, no + ///< additional cache hierarchies are invalidated. +} zex_counter_based_event_desc_t; + +static const zex_counter_based_event_desc_t defaultIntelCounterBasedEventDesc = + { + ZEX_STRUCTURE_COUNTER_BASED_EVENT_DESC, // stype + nullptr, // pNext + ZEX_COUNTER_BASED_EVENT_FLAG_IMMEDIATE | + ZEX_COUNTER_BASED_EVENT_FLAG_NON_IMMEDIATE | + ZEX_COUNTER_BASED_EVENT_FLAG_HOST_VISIBLE, // flags + ZE_EVENT_SCOPE_FLAG_HOST, // signalScope + ZE_EVENT_SCOPE_FLAG_DEVICE // waitScope +}; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Initial Counter Based Event synchronization parameters. This +/// structure may be +/// passed as pNext member of ::zex_counter_based_event_desc_t. +typedef struct _zex_counter_based_event_external_sync_alloc_properties_t { + ze_structure_type_ext_t stype; ///< [in] type of this structure + const void *pNext; ///< [in][optional] must be null or a pointer to an + ///< extension-specific + uint64_t *deviceAddress; ///< [in] device address for external synchronization + ///< allocation + uint64_t *hostAddress; ///< [in] host address for external synchronization + ///< allocation + uint64_t completionValue; ///< [in] completion value for external + ///< synchronization allocation +} zex_counter_based_event_external_sync_alloc_properties_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Initial Counter Based Event synchronization parameters. This +/// structure may be +/// passed as pNext member of ::zex_counter_based_event_desc_t. +typedef struct _zex_counter_based_event_external_storage_properties_t { + ze_structure_type_ext_t stype; ///< [in] type of this structure + const void *pNext; ///< [in][optional] must be null or a pointer to an + ///< extension-specific + uint64_t *deviceAddress; ///< [in] device address that would be updated with + ///< atomic_add upon signaling of this event, must be + ///< device USM memory + uint64_t incrementValue; ///< [in] value which would by atomically added upon + ///< each completion + uint64_t completionValue; ///< [in] final completion value, when value under + ///< deviceAddress is equal or greater then this + ///< value then event is considered as completed +} zex_counter_based_event_external_storage_properties_t; + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // _ZEX_COMMON_EXTENDED_H diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_context.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_context.h new file mode 100644 index 0000000000000..03d215589f73e --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_context.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2024-2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#ifndef _ZEX_CONTEXT_H +#define _ZEX_CONTEXT_H +#if defined(__cplusplus) +#pragma once +#endif + +#include "level_zero/ze_intel_gpu.h" +#include + +#include "zex_common.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +ZE_APIEXPORT ze_result_t ZE_APICALL zeIntelMediaCommunicationCreate( + ze_context_handle_t hContext, ze_device_handle_t hDevice, + ze_intel_media_communication_desc_t *desc, + ze_intel_media_doorbell_handle_desc_t *phDoorbell); +ZE_APIEXPORT ze_result_t ZE_APICALL zeIntelMediaCommunicationDestroy( + ze_context_handle_t hContext, ze_device_handle_t hDevice, + ze_intel_media_doorbell_handle_desc_t *phDoorbell); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // _ZEX_CONTEXT_H diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_driver.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_driver.h new file mode 100644 index 0000000000000..77d82431b8a32 --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_driver.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2020-2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#ifndef _ZEX_DRIVER_H +#define _ZEX_DRIVER_H + +#if defined(__cplusplus) +#pragma once +#endif + +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +ZE_APIEXPORT ze_result_t ZE_APICALL zexDriverImportExternalPointer( + ze_driver_handle_t hDriver, ///< [in] handle of the driver + void *ptr, ///< [in] pointer to be imported to the driver + size_t size ///< [in] size to be imported +); + +ZE_APIEXPORT ze_result_t ZE_APICALL zexDriverReleaseImportedPointer( + ze_driver_handle_t hDriver, ///< [in] handle of the driver + void *ptr ///< [in] pointer to be released from the driver +); + +ZE_APIEXPORT ze_result_t ZE_APICALL zexDriverGetHostPointerBaseAddress( + ze_driver_handle_t hDriver, ///< [in] handle of the driver + void *ptr, ///< [in] pointer to be checked if imported to the driver + void **baseAddress ///< [out] if not null, returns address of the base + ///< pointer of the imported pointer +); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // _ZEX_DRIVER_H diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_event.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_event.h new file mode 100644 index 0000000000000..a88b0f3fba158 --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_event.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2023-2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#ifndef _ZEX_EVENT_H +#define _ZEX_EVENT_H +#if defined(__cplusplus) +#pragma once +#endif + +#include + +#include "zex_common.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +ZE_APIEXPORT ze_result_t ZE_APICALL zexEventGetDeviceAddress( + ze_event_handle_t event, uint64_t *completionValue, uint64_t *address); + +// deprecated +ZE_APIEXPORT ze_result_t ZE_APICALL zexCounterBasedEventCreate( + ze_context_handle_t hContext, ze_device_handle_t hDevice, + uint64_t *deviceAddress, uint64_t *hostAddress, uint64_t completionValue, + const ze_event_desc_t *desc, ze_event_handle_t *phEvent); + +ZE_APIEXPORT ze_result_t ZE_APICALL zexIntelAllocateNetworkInterrupt( + ze_context_handle_t hContext, uint32_t &networkInterruptId); + +ZE_APIEXPORT ze_result_t ZE_APICALL zexIntelReleaseNetworkInterrupt( + ze_context_handle_t hContext, uint32_t networkInterruptId); + +ZE_APIEXPORT ze_result_t ZE_APICALL zexCounterBasedEventCreate2( + ze_context_handle_t hContext, ze_device_handle_t hDevice, + const zex_counter_based_event_desc_t *desc, ze_event_handle_t *phEvent); + +ZE_APIEXPORT ze_result_t ZE_APICALL zexCounterBasedEventGetIpcHandle( + ze_event_handle_t hEvent, zex_ipc_counter_based_event_handle_t *phIpc); + +ZE_APIEXPORT ze_result_t ZE_APICALL zexCounterBasedEventOpenIpcHandle( + ze_context_handle_t hContext, zex_ipc_counter_based_event_handle_t hIpc, + ze_event_handle_t *phEvent); + +ZE_APIEXPORT ze_result_t ZE_APICALL +zexCounterBasedEventCloseIpcHandle(ze_event_handle_t hEvent); + +ZE_APIEXPORT ze_result_t ZE_APICALL +zexDeviceGetAggregatedCopyOffloadIncrementValue(ze_device_handle_t hDevice, + uint32_t *incrementValue); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // _ZEX_EVENT_H diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_graph.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_graph.h new file mode 100644 index 0000000000000..8ccc837a70542 --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_graph.h @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#ifndef _ZEX_GRAPH_H +#define _ZEX_GRAPH_H +#if defined(__cplusplus) +#pragma once +#endif + +#include + +#include "zex_common.h" + +#if defined(__cplusplus) +#define EXTENDED_ENUM(ENUM_T, VALUE) \ + static_cast( \ + VALUE) // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) +#else +#define EXTENDED_ENUM(ENUM_T, VALUE) ((ENUM_T)VALUE) +#endif + +#ifndef ZE_RECORD_REPLAY_GRAPH_EXP_NAME +/// @brief Record and Replay Graph Extension Name +#define ZE_RECORD_REPLAY_GRAPH_EXP_NAME "ZE_experimental_record_replay_graph" + +typedef enum _ze_record_replay_graph_exp_version_t { + ZE_RECORD_REPLAY_GRAPH_EXP_VERSION_1_0 = + ZE_MAKE_VERSION(1, 0), ///< version 1.0 + ZE_RECORD_REPLAY_GRAPH_EXP_VERSION_CURRENT = + ZE_MAKE_VERSION(1, 0), ///< latest known version + ZE_RECORD_REPLAY_GRAPH_EXP_VERSION_FORCE_UINT32 = + 0x7fffffff, ///< Value marking end of ZE_RECORD_REPLAY_GRAPH_EXP_VERSION_* + ///< ENUMs +} ze_record_replay_graph_exp_version_t; + +typedef uint32_t ze_record_replay_graph_exp_flags_t; +typedef enum _ze_record_replay_graph_exp_flag_t { + ZE_RECORD_REPLAY_GRAPH_EXP_FLAG_IMMUTABLE_GRAPH = ZE_BIT(0), ///< immutable + ZE_RECORD_REPLAY_GRAPH_EXP_FLAG_MUTABLE_GRAPH = ZE_BIT(1), ///< mutable + ZE_RECORD_REPLAY_GRAPH_EXP_FLAG_FORCE_UINT32 = + 0x7fffffff, ///< Value marking end of ZE_RECORD_REPLAY_EXP_FLAG_* ENUMs +} ze_record_replay_graph_exp_flag_t; + +typedef struct _ze_record_replay_graph_exp_properties_t { + ze_structure_type_ext_t stype; ///< [in] type of this structure + void *pNext; ///< [in,out][optional] must be null or a pointer to an + ///< extension-specific + ///< structure (i.e. contains stype and pNext). + ze_record_replay_graph_exp_flags_t graphFlags; ///< [out] record replay flags +} ze_record_replay_graph_exp_properties_t; + +typedef struct _ze_graph_handle_t *ze_graph_handle_t; +typedef struct _ze_executable_graph_handle_t *ze_executable_graph_handle_t; + +typedef enum _ze_record_replay_graph_exp_dump_mode_t { + ZE_RECORD_REPLAY_GRAPH_EXP_DUMP_MODE_DETAILED = + 0x0, ///< detailed mode (default) + ZE_RECORD_REPLAY_GRAPH_EXP_DUMP_MODE_SIMPLE = 0x1, ///< simple mode + ZE_RECORD_REPLAY_GRAPH_EXP_DUMP_MODE_FORCE_UINT32 = + 0x7fffffff, ///< Value marking end of + ///< ZE_RECORD_REPLAY_GRAPH_EXP_DUMP_MODE_* ENUMs +} ze_record_replay_graph_exp_dump_mode_t; + +typedef struct _ze_record_replay_graph_exp_dump_desc_t { + ze_structure_type_ext_t stype; ///< [in] type of this structure + const void + *pNext; ///< [in][optional] must be null or a pointer to an + ///< extension-specific structure (i.e. contains stype and pNext). + ze_record_replay_graph_exp_dump_mode_t mode; ///< [in] graph dump mode +} ze_record_replay_graph_exp_dump_desc_t; + +#define ZE_RESULT_QUERY_TRUE EXTENDED_ENUM(ze_result_t, 0x7fff0000) +#define ZE_RESULT_QUERY_FALSE EXTENDED_ENUM(ze_result_t, 0x7fff0001) +#define ZE_RESULT_ERROR_INVALID_GRAPH EXTENDED_ENUM(ze_result_t, 0x7fff0002) + +#if defined(__cplusplus) +extern "C" { +#endif + +ZE_APIEXPORT ze_result_t ZE_APICALL zeGraphCreateExp( + ze_context_handle_t hContext, ze_graph_handle_t *phGraph, void *pNext); +ZE_APIEXPORT ze_result_t ZE_APICALL zeCommandListBeginGraphCaptureExp( + ze_command_list_handle_t hCommandList, void *pNext); +ZE_APIEXPORT ze_result_t ZE_APICALL +zeCommandListBeginCaptureIntoGraphExp(ze_command_list_handle_t hCommandList, + ze_graph_handle_t hGraph, void *pNext); +ZE_APIEXPORT ze_result_t ZE_APICALL +zeCommandListEndGraphCaptureExp(ze_command_list_handle_t hCommandList, + ze_graph_handle_t *phGraph, void *pNext); +ZE_APIEXPORT ze_result_t ZE_APICALL zeCommandListInstantiateGraphExp( + ze_graph_handle_t hGraph, ze_executable_graph_handle_t *phExecutableGraph, + void *pNext); +ZE_APIEXPORT ze_result_t ZE_APICALL zeCommandListAppendGraphExp( + ze_command_list_handle_t hCommandList, ze_executable_graph_handle_t hGraph, + void *pNext, ze_event_handle_t hSignalEvent, uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents); +ZE_APIEXPORT ze_result_t ZE_APICALL zeGraphDestroyExp(ze_graph_handle_t hGraph); +ZE_APIEXPORT ze_result_t ZE_APICALL +zeExecutableGraphDestroyExp(ze_executable_graph_handle_t hGraph); +ZE_APIEXPORT ze_result_t ZE_APICALL +zeCommandListIsGraphCaptureEnabledExp(ze_command_list_handle_t hCommandList); +ZE_APIEXPORT ze_result_t ZE_APICALL zeGraphIsEmptyExp(ze_graph_handle_t hGraph); +ZE_APIEXPORT ze_result_t ZE_APICALL zeGraphDumpContentsExp( + ze_graph_handle_t hGraph, const char *filePath, void *pNext); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // ZE_RECORD_REPLAY_GRAPH_EXP_NAME +#endif // _ZEX_GRAPH_H diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_memory.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_memory.h new file mode 100644 index 0000000000000..2897e5a299999 --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_memory.h @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2020-2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#ifndef _ZEX_MEMORY_H +#define _ZEX_MEMORY_H +#if defined(__cplusplus) +#pragma once +#endif + +#include + +/////////////////////////////////////////////////////////////////////////////// +// It indicates that the application wants the L0 driver implementation to use +// memory referenced by **ptr passed in `zeMemAllocHost` or `zeMemAllocShared`. +// Can be set in `ze_host_mem_alloc_flags_t`. +constexpr uint32_t ZEX_HOST_MEM_ALLOC_FLAG_USE_HOST_PTR = ZE_BIT(30); + +/////////////////////////////////////////////////////////////////////////////// +#ifndef ZEX_MEM_IPC_HANDLES_NAME +/// @brief Multiple IPC handles driver extension name +#define ZEX_MEM_IPC_HANDLES_NAME "ZEX_mem_ipc_handles" +#endif // ZEX_MEM_IPC_HANDLES_NAME + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Multiple IPC handles driver extension Version(s) +typedef enum _zex_mem_ipc_handles_version_t { + ZEX_MEM_IPC_HANDLES_VERSION_1_0 = ZE_MAKE_VERSION(1, 0), ///< version 1.0 + ZEX_MEM_IPC_HANDLES_VERSION_CURRENT = + ZE_MAKE_VERSION(1, 0), ///< latest known version + ZEX_MEM_IPC_HANDLES_VERSION_FORCE_UINT32 = 0x7fffffff + +} zex_mem_ipc_handles_version_t; + +#if defined(__cplusplus) +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Returns an array IPC memory handles for the specified allocation +/// +/// @details +/// - Takes a pointer to a device memory allocation and returns an array of +// IPC memory handle for exporting it for use in another process. +/// - The application may call this function from simultaneous threads. +/// - The implementation of this function must be thread-safe. +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_ARGUMENT +/// + `ptr` not known +ZE_APIEXPORT ze_result_t ZE_APICALL zexMemGetIpcHandles( + ze_context_handle_t hContext, ///< [in] handle of the context object + const void *ptr, ///< [in] pointer to the device memory allocation + uint32_t + *numIpcHandles, ///< [in,out] number of IPC handles associated with the + ///< allocation if numIpcHandles is zero, then the + ///< driver shall update the value with the total number + ///< of IPC handles associated with the allocation. + ze_ipc_mem_handle_t + *pIpcHandles ///< [in,out][optional][range(0, *numIpcHandles)] returned + ///< array of IPC memory handles +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Creates an allocation associated with an array of IPC memory handles +/// imported from another process. +/// +/// @details +/// - Takes an array of IPC memory handles from a remote process and +/// associates it +/// with a device pointer usable in this process. +/// - The device pointer in this process should not be freed with +/// ::zeMemFree, but rather with ::zeMemCloseIpcHandle. +/// - The application may call this function from simultaneous threads. +/// - The implementation of this function must be thread-safe. +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_INVALID_ARGUMENT +/// + handles not known +ZE_APIEXPORT ze_result_t ZE_APICALL zexMemOpenIpcHandles( + ze_context_handle_t hContext, ///< [in] handle of the context object + ze_device_handle_t hDevice, ///< [in] handle of the device to associate with + ///< the IPC memory handle + uint32_t numIpcHandles, ///< [in] number of IPC handles associated with the + ///< allocation + ze_ipc_mem_handle_t *pIpcHandles, ///< [in][range(0, *numIpcHandles)] array + ///< of IPC memory handles + ze_ipc_memory_flags_t flags, ///< [in] flags controlling the operation. + ///< must be 0 (default) or a valid combination + ///< of ::ze_ipc_memory_flag_t. + void **pptr ///< [out] pointer to device allocation in this process +); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // _ZEX_MEMORY_H diff --git a/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_module.h b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_module.h new file mode 100644 index 0000000000000..0dbe75b740372 --- /dev/null +++ b/unified-runtime/source/adapters/level_zero/external/driver_experimental/zex_module.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2020-2025 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#ifndef _ZEX_MODULE_H +#define _ZEX_MODULE_H +#if defined(__cplusplus) +#pragma once +#endif + +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +ZE_APIEXPORT ze_result_t ZE_APICALL +zexKernelGetBaseAddress(ze_kernel_handle_t hKernel, uint64_t *baseAddress); + +ZE_APIEXPORT ze_result_t ZE_APICALL zexKernelGetArgumentSize( + ze_kernel_handle_t hKernel, uint32_t argIndex, uint32_t *pArgSize); + +ZE_APIEXPORT ze_result_t ZE_APICALL +zexKernelGetArgumentType(ze_kernel_handle_t hKernel, uint32_t argIndex, + uint32_t *pSize, char *pString); + +#if defined(__cplusplus) +} // extern "C" +#endif + +/////////////////////////////////////////////////////////////////////////////// +/// @brief General Register File descriptor. +/// Must be passed to zeDeviceGetModuleProperties via pNext member of +/// ze_device_module_properties_t. +typedef struct _zex_device_module_register_file_exp_t { + ze_structure_type_ext_t stype; ///< [in] type of this structure + const void + *pNext; ///< [in, out][optional] pointer to extension-specific structure + uint32_t + registerFileSizesCount; ///< [out] Size of array of supported GRF sizes + uint32_t + *registerFileSizes; ///< [in, out][optional] Array of supported GRF sizes +} zex_device_module_register_file_exp_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Kernel register file size information +/// Must be passed to zeKernelGetProperties via pNext member of +/// ze_kernel_properties_t +typedef struct _zex_kernel_register_file_size_exp_t { + ze_structure_type_ext_t stype; ///< [in] type of this structure + const void + *pNext; ///< [in, out][optional] pointer to extension-specific structure + uint32_t registerFileSize; ///< [out] Register file size used in kernel +} zex_kernel_register_file_size_exp_t; + +#endif // _ZEX_MODULE_H diff --git a/unified-runtime/source/adapters/level_zero/platform.hpp b/unified-runtime/source/adapters/level_zero/platform.hpp index e605af42505b7..d58481ae9749d 100644 --- a/unified-runtime/source/adapters/level_zero/platform.hpp +++ b/unified-runtime/source/adapters/level_zero/platform.hpp @@ -10,7 +10,7 @@ #pragma once #include "common.hpp" -#include "level_zero/driver_experimental/zex_api.h" +#include "external/driver_experimental/zex_graph.h" #include "ur_api.h" #include "ze_api.h" #include "ze_ddi.h" diff --git a/unified-runtime/source/adapters/level_zero/v2/graph.cpp b/unified-runtime/source/adapters/level_zero/v2/graph.cpp index 326771a5d25d7..3023570966bd6 100644 --- a/unified-runtime/source/adapters/level_zero/v2/graph.cpp +++ b/unified-runtime/source/adapters/level_zero/v2/graph.cpp @@ -9,10 +9,10 @@ //===----------------------------------------------------------------------===// #include "graph.hpp" +#include "../external/driver_experimental/zex_graph.h" #include "../ur_interface_loader.hpp" #include "common.hpp" #include "context.hpp" -#include "level_zero/driver_experimental/zex_api.h" ur_exp_graph_handle_t_::ur_exp_graph_handle_t_(ur_context_handle_t hContext) : hContext(hContext) { diff --git a/unified-runtime/source/adapters/level_zero/v2/graph.hpp b/unified-runtime/source/adapters/level_zero/v2/graph.hpp index 6cd68f8bd15f9..178c206719833 100644 --- a/unified-runtime/source/adapters/level_zero/v2/graph.hpp +++ b/unified-runtime/source/adapters/level_zero/v2/graph.hpp @@ -9,9 +9,9 @@ //===----------------------------------------------------------------------===// #pragma once +#include "../external/driver_experimental/zex_graph.h" #include "common.hpp" #include "context.hpp" -#include "level_zero/driver_experimental/zex_api.h" #include "ur_api.h" struct ur_exp_graph_handle_t_ : ur_object { From e09f7c87768cc2993463eeeb3e5605231ca15001 Mon Sep 17 00:00:00 2001 From: Krzysztof Swiecicki Date: Wed, 10 Dec 2025 11:25:08 +0000 Subject: [PATCH 6/7] Fix exp_graph fixtures teardown --- unified-runtime/test/conformance/exp_graph/fixtures.h | 3 +-- .../exp_graph/urQueueIsGraphCaptureEnabledExp.cpp | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/unified-runtime/test/conformance/exp_graph/fixtures.h b/unified-runtime/test/conformance/exp_graph/fixtures.h index 01df21379c61c..cfe59da8764ec 100644 --- a/unified-runtime/test/conformance/exp_graph/fixtures.h +++ b/unified-runtime/test/conformance/exp_graph/fixtures.h @@ -68,10 +68,9 @@ struct urGraphPopulatedExpTest : urGraphExpTest { void TearDown() override { if (deviceMem) { ASSERT_SUCCESS(urUSMFree(context, deviceMem)); + resetData(); } - resetData(); - UUR_RETURN_ON_FATAL_FAILURE(urGraphExpTest::TearDown()); } diff --git a/unified-runtime/test/conformance/exp_graph/urQueueIsGraphCaptureEnabledExp.cpp b/unified-runtime/test/conformance/exp_graph/urQueueIsGraphCaptureEnabledExp.cpp index 6404ba8c627de..3f1f441a7cb48 100644 --- a/unified-runtime/test/conformance/exp_graph/urQueueIsGraphCaptureEnabledExp.cpp +++ b/unified-runtime/test/conformance/exp_graph/urQueueIsGraphCaptureEnabledExp.cpp @@ -11,6 +11,7 @@ struct urQueueIsGraphCaptureEnabledExpTest : uur::urGraphSupportedExpTest { UUR_RETURN_ON_FATAL_FAILURE(urGraphSupportedExpTest::SetUp()); ASSERT_SUCCESS(urQueueBeginGraphCaptureExp(queue)); + isCapturing = true; } void TearDown() override { @@ -23,11 +24,13 @@ struct urQueueIsGraphCaptureEnabledExpTest : uur::urGraphSupportedExpTest { } void endGraphCapture() { - if (!graph) { + if (isCapturing) { ASSERT_SUCCESS(urQueueEndGraphCaptureExp(queue, &graph)); + isCapturing = false; } } + bool isCapturing = false; ur_exp_graph_handle_t graph = nullptr; }; From 4b1d1ce9ce4977989694db57afdddce646cf86e1 Mon Sep 17 00:00:00 2001 From: Krzysztof Swiecicki Date: Fri, 12 Dec 2025 08:35:28 +0000 Subject: [PATCH 7/7] Turn off urEnqueueGraph tests See: https://github.com/intel/llvm/issues/20884. --- .../test/conformance/exp_graph/urEnqueueGraphExp.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/unified-runtime/test/conformance/exp_graph/urEnqueueGraphExp.cpp b/unified-runtime/test/conformance/exp_graph/urEnqueueGraphExp.cpp index e7da20ad42a4f..e333faa98c670 100644 --- a/unified-runtime/test/conformance/exp_graph/urEnqueueGraphExp.cpp +++ b/unified-runtime/test/conformance/exp_graph/urEnqueueGraphExp.cpp @@ -9,7 +9,15 @@ #include -using urEnqueueGraphExpTest = uur::urGraphExecutableExpTest; +struct urEnqueueGraphExpTest : uur::urGraphExecutableExpTest { + void SetUp() override { + UUR_RETURN_ON_FATAL_FAILURE(uur::urGraphExecutableExpTest::SetUp()); + + // TODO: Re-enable urEnqueueGraph tests on L0V2. + // See: https://github.com/intel/llvm/issues/20884. + UUR_KNOWN_FAILURE_ON(uur::LevelZeroV2{}); + } +}; UUR_INSTANTIATE_DEVICE_TEST_SUITE(urEnqueueGraphExpTest);