Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[NPU] Update zero backend code (#29032)

Bogdan Pereanu2c7483514841
diff --git a/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp b/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp
index 6baabc55b43..d23b1fdb3b7 100644
--- a/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp
+++ b/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp
@@ -59,7 +59,7 @@ protected:
std::vector<std::unique_ptr<Fence>> _fences;
std::shared_ptr<EventPool> _event_pool;
std::vector<std::shared_ptr<Event>> _events;
- bool sync_output_with_fences_ = true;
+ bool _sync_output_with_fences = true;
std::shared_ptr<zeroProfiling::NpuInferProfiling> _npu_profiling;
Logger _logger;
};
diff --git a/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp b/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp
index b5829cb0c0a..3bb8f222f6a 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp
@@ -322,7 +322,7 @@ void ZeroInferRequest::set_tensor(const ov::Output<const ov::Node>& port, const
_userOutputTensors.at(foundPort.idx) = tensor;
}
- if (_initStructs->getMutableCommandListVersion()) {
+ if (_initStructs->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0)) {
auto remoteTensor = std::dynamic_pointer_cast<ZeroRemoteTensor>(tensor._ptr);
if (remoteTensor == nullptr) {
@@ -356,7 +356,7 @@ void ZeroInferRequest::set_tensors(const ov::Output<const ov::Node>& port,
void* data = nullptr;
- if (_initStructs->getMutableCommandListVersion()) {
+ if (_initStructs->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0)) {
if (_graph->get_batch_size().has_value()) {
for (size_t i = 0; i < tensors.size(); i++) {
auto remoteTensor = std::dynamic_pointer_cast<ZeroRemoteTensor>(tensors[i]._ptr);
@@ -576,7 +576,7 @@ void ZeroInferRequest::infer_async() {
_pipelineIsCreated = true;
} else {
- if (_initStructs->getMutableCommandListVersion()) {
+ if (_initStructs->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0)) {
update_pipeline_if_memory_changed();
update_states_if_memory_changed();
}
diff --git a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp
index 9f55897193a..36a5592454e 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp
@@ -39,21 +39,36 @@ Pipeline::Pipeline(const Config& config,
OV_ITT_SCOPED_TASK(itt::domains::LevelZeroBackend, "Zero_infer_request::Pipeline::Pipeline");
_logger.debug("Pipeline - initialize started");
+ OPENVINO_ASSERT(_sync_output_with_fences || !_config.get<RUN_INFERENCES_SEQUENTIALLY>(),
+ "In-order execution doesn't work in case synchronization of the inferences is done using events");
+
if (profiling_pool.create()) {
profiling_query.create(profiling_pool._handle);
}
+ if (!_sync_output_with_fences || _config.get<RUN_INFERENCES_SEQUENTIALLY>()) {
+ _event_pool =
+ std::make_shared<EventPool>(init_structs->getDevice(),
+ init_structs->getContext(),
+ _number_of_command_lists ? static_cast<uint32_t>(_number_of_command_lists) : 1);
+
+ _events.reserve(_number_of_command_lists);
+ for (size_t i = 0; i < _number_of_command_lists; i++) {
+ _events.emplace_back(std::make_shared<Event>(_event_pool, static_cast<uint32_t>(i)));
+ }
+ }
+
_command_lists.reserve(_number_of_command_lists);
- _events.reserve(_number_of_command_lists);
- _fences.reserve(_number_of_command_lists);
- _logger.debug("Pipeline - emplace_back _event_pool and _command_queue");
for (size_t i = 0; i < _number_of_command_lists; i++) {
- _command_lists.emplace_back(
- std::make_unique<CommandList>(init_structs,
- group_ordinal,
- init_structs->getMutableCommandListVersion() ? true : false));
- _events.emplace_back(std::make_shared<Event>(_event_pool, static_cast<uint32_t>(i)));
- _fences.emplace_back(std::make_unique<Fence>(*_graph->get_command_queue()));
+ _command_lists.emplace_back(std::make_unique<CommandList>(init_structs, group_ordinal));
+ }
+
+ if (_sync_output_with_fences) {
+ _fences.reserve(_number_of_command_lists);
+
+ for (size_t i = 0; i < _number_of_command_lists; i++) {
+ _fences.emplace_back(std::make_unique<Fence>(_graph->get_command_queue()));
+ }
}
for (size_t i = 0; i < _number_of_command_lists; i++) {
@@ -138,7 +153,7 @@ Pipeline::Pipeline(const Config& config,
}
// appendBarrier used in L0 as well
- if (!sync_output_with_fences_) {
+ if (!_sync_output_with_fences) {
_command_lists.at(i)->appendBarrier();
_events.at(i)->AppendSignalEvent(*_command_lists.at(i));
}
@@ -164,7 +179,7 @@ void Pipeline::push() {
for (size_t i = 0; i < _command_lists.size(); ++i) {
OV_ITT_TASK_CHAIN(ZERO_PIPELINE_IP_PUSH, itt::domains::LevelZeroBackend, "Pipeline", "push");
- if (sync_output_with_fences_) {
+ if (_sync_output_with_fences) {
_graph->get_command_queue()->executeCommandList(*_command_lists.at(i), *_fences.at(i));
} else {
_graph->get_command_queue()->executeCommandList(*_command_lists.at(i));
@@ -179,7 +194,7 @@ void Pipeline::pull() {
OV_ITT_TASK_CHAIN(ZERO_PIPELINE_IP_PULL, itt::domains::LevelZeroBackend, "Pipeline", "pull");
for (size_t i = 0; i < _command_lists.size(); ++i) {
- if (sync_output_with_fences_) {
+ if (_sync_output_with_fences) {
_fences.at(i)->hostSynchronize();
} else {
_events.at(i)->hostSynchronize();
@@ -197,7 +212,7 @@ void Pipeline::reset() const {
_logger.debug("Pipeline - rest() started");
for (size_t i = 0; i < _command_lists.size(); ++i) {
- if (sync_output_with_fences_) {
+ if (_sync_output_with_fences) {
_fences.at(i)->reset();
} else {
_events.at(i)->reset();
diff --git a/src/plugins/intel_npu/src/backend/src/zero_tensor.cpp b/src/plugins/intel_npu/src/backend/src/zero_tensor.cpp
index 6cb2d354dea..58bd86ae951 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_tensor.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_tensor.cpp
@@ -121,7 +121,7 @@ void ZeroTensor::set_shape(ov::Shape new_shape) {
_shape = std::move(new_shape);
if (get_size() > get_capacity()) {
- if (!_init_structs->getMutableCommandListVersion()) {
+ if (_init_structs->getMutableCommandListExtVersion() < ZE_MAKE_VERSION(1, 0)) {
OPENVINO_THROW("Re-shaping the tensor with a larger shape is not available using this driver version. "
"Please update the driver to the latest version.");
}
diff --git a/src/plugins/intel_npu/src/backend/src/zero_variable_state.cpp b/src/plugins/intel_npu/src/backend/src/zero_variable_state.cpp
index 442ae3fe9b2..a3437c64ce9 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_variable_state.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_variable_state.cpp
@@ -28,7 +28,7 @@ void ZeroVariableState::set_state(const ov::SoPtr<ov::ITensor>& new_state) {
m_state = new_state;
_tensor_updated = true;
- if (_init_structs->getMutableCommandListVersion()) {
+ if (_init_structs->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0)) {
if (!is_remote_tensor(new_state._ptr)) {
if (zeroUtils::memory_was_allocated_in_the_same_l0_context(_init_structs->getContext(),
new_state->data())) {
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp
index df538521d85..a9290d29682 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp
@@ -48,7 +48,7 @@ public:
void setGraphArgumentValue(ze_graph_handle_t graphHandle, uint32_t argi_, const void* argv) const;
- void initializeGraph(ze_graph_handle_t graphHandle, const Config& config) const;
+ void initializeGraph(ze_graph_handle_t graphHandle) const;
private:
std::unordered_set<std::string> getQueryResultFromSupportedLayers(
@@ -60,7 +60,7 @@ private:
std::vector<IODescriptor>& inputs,
std::vector<IODescriptor>& outputs) const;
- void initialize_graph_through_command_list(ze_graph_handle_t graphHandle, const Config& config) const;
+ void initialize_graph_through_command_list(ze_graph_handle_t graphHandle) const;
std::shared_ptr<ZeroInitStructsHolder> _zeroInitStruct;
uint32_t _graphExtVersion;
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/driver_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/driver_graph.cpp
index 9610b163377..6ba518764b9 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/driver_graph.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/driver_graph.cpp
@@ -119,7 +119,7 @@ void DriverGraph::initialize(const Config& config) {
set_workload_type(config.get<WORKLOAD_TYPE>());
}
- _zeGraphExt->initializeGraph(_handle, config);
+ _zeGraphExt->initializeGraph(_handle);
_logger.debug("Graph initialize finish");
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_graph.cpp
index 3723de6a2dd..05e56373ba5 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_graph.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_graph.cpp
@@ -119,7 +119,7 @@ void PluginGraph::initialize(const Config& config) {
set_workload_type(config.get<WORKLOAD_TYPE>());
}
- _zeGraphExt->initializeGraph(_handle, config);
+ _zeGraphExt->initializeGraph(_handle);
if (config.get<BATCH_MODE>() != ov::intel_npu::BatchMode::COMPILER) {
_batch_size = get_batch_size(_metadata);
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp
index 45ab0ff57bc..02ba8b4eb26 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp
@@ -162,10 +162,10 @@ void ZeGraphExtWrappers::setGraphArgumentValue(ze_graph_handle_t graphHandle, ui
THROW_ON_FAIL_FOR_LEVELZERO_EXT("zeGraphSetArgumentValue", result, _zeroInitStruct->getGraphDdiTable());
}
-void ZeGraphExtWrappers::initializeGraph(ze_graph_handle_t graphHandle, const Config& config) const {
+void ZeGraphExtWrappers::initializeGraph(ze_graph_handle_t graphHandle) const {
if (_zeroInitStruct->getGraphDdiTable().version() < ZE_GRAPH_EXT_VERSION_1_8) {
_logger.debug("Use initialize_graph_through_command_list for ext version smaller than 1.8");
- initialize_graph_through_command_list(graphHandle, config);
+ initialize_graph_through_command_list(graphHandle);
} else {
_logger.debug("Initialize graph based on graph properties for ext version larger than 1.8");
ze_graph_properties_2_t properties = {};
@@ -179,13 +179,12 @@ void ZeGraphExtWrappers::initializeGraph(ze_graph_handle_t graphHandle, const Co
}
if (properties.initStageRequired & ZE_GRAPH_STAGE_COMMAND_LIST_INITIALIZE) {
- initialize_graph_through_command_list(graphHandle, config);
+ initialize_graph_through_command_list(graphHandle);
}
}
}
-void ZeGraphExtWrappers::initialize_graph_through_command_list(ze_graph_handle_t graphHandle,
- const Config& config) const {
+void ZeGraphExtWrappers::initialize_graph_through_command_list(ze_graph_handle_t graphHandle) const {
ze_device_properties_t deviceProperties = {};
deviceProperties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
THROW_ON_FAIL_FOR_LEVELZERO("zeDeviceGetProperties",
@@ -195,7 +194,8 @@ void ZeGraphExtWrappers::initialize_graph_through_command_list(ze_graph_handle_t
_logger.debug("initialize_graph_through_command_list init start - create graph_command_list");
CommandList graph_command_list(_zeroInitStruct, groupOrdinal);
_logger.debug("initialize_graph_through_command_list - create graph_command_queue");
- CommandQueue graph_command_queue(_zeroInitStruct, ZE_COMMAND_QUEUE_PRIORITY_NORMAL, groupOrdinal, false);
+ std::shared_ptr<CommandQueue> graph_command_queue =
+ std::make_shared<CommandQueue>(_zeroInitStruct, ZE_COMMAND_QUEUE_PRIORITY_NORMAL, groupOrdinal, false);
_logger.debug("initialize_graph_through_command_list - create fence");
Fence fence(graph_command_queue);
@@ -205,7 +205,7 @@ void ZeGraphExtWrappers::initialize_graph_through_command_list(ze_graph_handle_t
graph_command_list.close();
_logger.debug("initialize_graph_through_command_list - performing executeCommandList");
- graph_command_queue.executeCommandList(graph_command_list, fence);
+ graph_command_queue->executeCommandList(graph_command_list, fence);
_logger.debug("initialize_graph_through_command_list - performing hostSynchronize");
fence.hostSynchronize();
_logger.debug("initialize_graph_through_command_list - hostSynchronize completed");
diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_init.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_init.hpp
index 123c0c505b3..79a81e1ef1d 100644
--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_init.hpp
+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_init.hpp
@@ -56,8 +56,8 @@ public:
inline ze_device_graph_properties_t getCompilerProperties() const {
return compiler_properties;
}
- inline uint32_t getMutableCommandListVersion() const {
- return mutable_command_list_version;
+ inline uint32_t getMutableCommandListExtVersion() const {
+ return mutable_command_list_ext_version;
}
inline ze_api_version_t getZeDrvApiVersion() const {
return ze_drv_api_version;
@@ -92,7 +92,7 @@ private:
std::unique_ptr<ze_graph_profiling_ddi_table_ext_decorator> graph_profiling_npu_dditable_ext_decorator;
ze_driver_properties_t driver_properties = {};
- uint32_t mutable_command_list_version = 0;
+ uint32_t mutable_command_list_ext_version = 0;
ze_api_version_t ze_drv_api_version = {};
diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_wrappers.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_wrappers.hpp
index c2041d678b0..0faa5c24a17 100644
--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_wrappers.hpp
+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_wrappers.hpp
@@ -61,9 +61,7 @@ class CommandList {
public:
friend class CommandQueue;
CommandList() = delete;
- CommandList(const std::shared_ptr<ZeroInitStructsHolder>& initStructs,
- const uint32_t& group_ordinal,
- bool mtci_is_supported = false);
+ CommandList(const std::shared_ptr<ZeroInitStructsHolder>& init_structs, const uint32_t& group_ordinal);
CommandList(const CommandList&) = delete;
CommandList(CommandList&&) = delete;
CommandList& operator=(const CommandList&) = delete;
@@ -85,7 +83,7 @@ public:
}
private:
- std::shared_ptr<ZeroInitStructsHolder> _initStructs;
+ std::shared_ptr<ZeroInitStructsHolder> _init_structs;
Logger _log;
@@ -96,7 +94,7 @@ private:
class Fence {
public:
Fence() = delete;
- Fence(const CommandQueue& command_queue);
+ Fence(const std::shared_ptr<CommandQueue>& command_queue);
Fence(const Fence&) = delete;
Fence(Fence&&) = delete;
Fence& operator=(const Fence&) = delete;
@@ -110,6 +108,8 @@ public:
}
private:
+ std::shared_ptr<CommandQueue> _command_queue;
+
ze_fence_handle_t _handle = nullptr;
Logger _log;
@@ -118,7 +118,7 @@ private:
class CommandQueue {
public:
CommandQueue() = delete;
- CommandQueue(const std::shared_ptr<ZeroInitStructsHolder>& initStructs,
+ CommandQueue(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,
const ze_command_queue_priority_t& priority,
const uint32_t& group_ordinal,
bool turbo = false);
@@ -136,7 +136,7 @@ public:
}
private:
- std::shared_ptr<ZeroInitStructsHolder> _initStructs;
+ std::shared_ptr<ZeroInitStructsHolder> _init_structs;
Logger _log;
diff --git a/src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp
index db8884dff80..06500808ff6 100644
--- a/src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp
+++ b/src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp
@@ -280,7 +280,7 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()
if (driver_properties.driverVersion != WIN_DRIVER_NO_MCL_SUPPORT) {
#endif
[[maybe_unused]] std::string mutuable_command_list_ext_name;
- std::tie(mutable_command_list_version, mutuable_command_list_ext_name) =
+ std::tie(mutable_command_list_ext_version, mutuable_command_list_ext_name) =
queryDriverExtensionVersion(ZE_MUTABLE_COMMAND_LIST_EXP_NAME,
ZE_MUTABLE_COMMAND_LIST_EXP_VERSION_CURRENT,
extProps,
@@ -290,8 +290,8 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()
#endif
log.debug("Mutable command list version %d.%d",
- ZE_MAJOR_VERSION(mutable_command_list_version),
- ZE_MINOR_VERSION(mutable_command_list_version));
+ ZE_MAJOR_VERSION(mutable_command_list_ext_version),
+ ZE_MINOR_VERSION(mutable_command_list_ext_version));
// Load our profiling extension
ze_graph_profiling_dditable_ext_t* _graph_profiling_ddi_table_ext = nullptr;
diff --git a/src/plugins/intel_npu/src/utils/src/zero/zero_wrappers.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_wrappers.cpp
index 1d3c0cc23e6..53481316d98 100644
--- a/src/plugins/intel_npu/src/utils/src/zero/zero_wrappers.cpp
+++ b/src/plugins/intel_npu/src/utils/src/zero/zero_wrappers.cpp
@@ -22,6 +22,8 @@ EventPool::~EventPool() {
if (ZE_RESULT_SUCCESS != result) {
_log.error("zeEventPoolDestroy failed %#X", uint64_t(result));
}
+
+ _handle = nullptr;
}
Event::Event(const std::shared_ptr<EventPool>& event_pool, uint32_t event_index)
@@ -53,25 +55,42 @@ Event::~Event() {
if (ZE_RESULT_SUCCESS != result) {
_log.error("zeEventDestroy failed %#X", uint64_t(result));
}
+
+ _handle = nullptr;
}
-CommandList::CommandList(const std::shared_ptr<ZeroInitStructsHolder>& initStructs,
- const uint32_t& group_ordinal,
- bool mtci_is_supported)
- : _initStructs(initStructs),
+CommandList::CommandList(const std::shared_ptr<ZeroInitStructsHolder>& init_structs, const uint32_t& group_ordinal)
+ : _init_structs(init_structs),
_log("CommandList", Logger::global().level()) {
ze_mutable_command_list_exp_desc_t mutable_desc = {ZE_STRUCTURE_TYPE_MUTABLE_COMMAND_LIST_EXP_DESC, nullptr, 0};
ze_command_list_desc_t desc = {ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC, &mutable_desc, group_ordinal, 0};
THROW_ON_FAIL_FOR_LEVELZERO(
"zeCommandListCreate",
- zeCommandListCreate(_initStructs->getContext(), _initStructs->getDevice(), &desc, &_handle));
-
- if (mtci_is_supported) {
- ze_mutable_command_id_exp_desc_t mutableCmdIdDesc = {ZE_STRUCTURE_TYPE_MUTABLE_COMMAND_ID_EXP_DESC,
- nullptr,
- ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENT_DEPRECATED};
- THROW_ON_FAIL_FOR_LEVELZERO("zeCommandListGetNextCommandIdExp",
- zeCommandListGetNextCommandIdExp(_handle, &mutableCmdIdDesc, &_command_id));
+ zeCommandListCreate(_init_structs->getContext(), _init_structs->getDevice(), &desc, &_handle));
+
+ uint32_t mutable_command_list_ext_version = _init_structs->getMutableCommandListExtVersion();
+ if (mutable_command_list_ext_version >= ZE_MAKE_VERSION(1, 0)) {
+ ze_mutable_command_id_exp_desc_t mutable_cmd_id_desc = {};
+
+ mutable_cmd_id_desc.stype = ZE_STRUCTURE_TYPE_MUTABLE_COMMAND_ID_EXP_DESC;
+
+ if (mutable_command_list_ext_version >= ZE_MAKE_VERSION(1, 1)) {
+ mutable_cmd_id_desc.flags = ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENTS;
+ } else {
+ mutable_cmd_id_desc.flags = ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENT_DEPRECATED;
+ };
+
+ auto result = zeCommandListGetNextCommandIdExp(_handle, &mutable_cmd_id_desc, &_command_id);
+ if (result == ZE_RESULT_ERROR_INVALID_ENUMERATION) {
+ // If ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENTS is not supported by the driver, try again with
+ // ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENT_DEPRECATED
+ mutable_cmd_id_desc.flags = ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENT_DEPRECATED;
+
+ THROW_ON_FAIL_FOR_LEVELZERO("zeCommandListGetNextCommandIdExp",
+ zeCommandListGetNextCommandIdExp(_handle, &mutable_cmd_id_desc, &_command_id))
+ } else {
+ THROW_ON_FAIL_FOR_LEVELZERO("zeCommandListGetNextCommandIdExp", result)
+ }
}
}
void CommandList::reset() const {
@@ -83,14 +102,14 @@ void CommandList::appendMemoryCopy(void* dst, const void* src, const std::size_t
}
void CommandList::appendGraphInitialize(const ze_graph_handle_t& graph_handle) const {
ze_result_t result =
- _initStructs->getGraphDdiTable().pfnAppendGraphInitialize(_handle, graph_handle, nullptr, 0, nullptr);
- THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnAppendGraphInitialize", result, _initStructs->getGraphDdiTable());
+ _init_structs->getGraphDdiTable().pfnAppendGraphInitialize(_handle, graph_handle, nullptr, 0, nullptr);
+ THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnAppendGraphInitialize", result, _init_structs->getGraphDdiTable());
}
void CommandList::appendGraphExecute(const ze_graph_handle_t& graph_handle,
const ze_graph_profiling_query_handle_t& profiling_query_handle) const {
- ze_result_t result = _initStructs->getGraphDdiTable()
+ ze_result_t result = _init_structs->getGraphDdiTable()
.pfnAppendGraphExecute(_handle, graph_handle, profiling_query_handle, nullptr, 0, nullptr);
- THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnAppendGraphExecute", result, _initStructs->getGraphDdiTable());
+ THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnAppendGraphExecute", result, _init_structs->getGraphDdiTable());
}
void CommandList::appendNpuTimestamp(uint64_t* timestamp_buff) const {
THROW_ON_FAIL_FOR_LEVELZERO("zeCommandListAppendWriteGlobalTimestamp",
@@ -107,12 +126,12 @@ CommandList::~CommandList() {
if (ZE_RESULT_SUCCESS != result) {
_log.error("zeCommandListDestroy failed %#X", uint64_t(result));
}
+
+ _handle = nullptr;
}
void CommandList::updateMutableCommandList(uint32_t arg_index, const void* arg_value) const {
ze_mutable_graph_argument_exp_desc_t desc = {
- (ZE_MAJOR_VERSION(_initStructs->getZeDrvApiVersion()) > 1 ||
- (ZE_MAJOR_VERSION(_initStructs->getZeDrvApiVersion()) == 1 &&
- ZE_MINOR_VERSION(_initStructs->getZeDrvApiVersion()) >= 11))
+ (_init_structs->getZeDrvApiVersion() >= ZE_MAKE_VERSION(1, 11))
? ZE_STRUCTURE_TYPE_MUTABLE_GRAPH_ARGUMENT_EXP_DESC
: static_cast<ze_structure_type_t>(ZE_STRUCTURE_TYPE_MUTABLE_GRAPH_ARGUMENT_EXP_DESC_DEPRECATED),
nullptr,
@@ -128,17 +147,17 @@ void CommandList::updateMutableCommandList(uint32_t arg_index, const void* arg_v
zeCommandListUpdateMutableCommandsExp(_handle, &mutable_commands_exp_desc_t));
}
-CommandQueue::CommandQueue(const std::shared_ptr<ZeroInitStructsHolder>& initStructs,
+CommandQueue::CommandQueue(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,
const ze_command_queue_priority_t& priority,
const uint32_t& group_ordinal,
bool turbo)
- : _initStructs(initStructs),
+ : _init_structs(init_structs),
_log("CommandQueue", Logger::global().level()) {
ze_command_queue_desc_t queue_desc =
{ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC, nullptr, group_ordinal, 0, 0, ZE_COMMAND_QUEUE_MODE_DEFAULT, priority};
if (turbo) {
- if (_initStructs->getCommandQueueDdiTable().version()) {
+ if (_init_structs->getCommandQueueDdiTable().version() >= ZE_MAKE_VERSION(1, 0)) {
ze_command_queue_desc_npu_ext_t turbo_cfg = {ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC_NPU_EXT, nullptr, turbo};
queue_desc.pNext = &turbo_cfg;
} else {
@@ -148,7 +167,7 @@ CommandQueue::CommandQueue(const std::shared_ptr<ZeroInitStructsHolder>& initStr
THROW_ON_FAIL_FOR_LEVELZERO(
"zeCommandQueueCreate",
- zeCommandQueueCreate(_initStructs->getContext(), _initStructs->getDevice(), &queue_desc, &_handle));
+ zeCommandQueueCreate(_init_structs->getContext(), _init_structs->getDevice(), &queue_desc, &_handle));
}
void CommandQueue::executeCommandList(CommandList& command_list) const {
THROW_ON_FAIL_FOR_LEVELZERO("zeCommandQueueExecuteCommandLists",
@@ -160,9 +179,9 @@ void CommandQueue::executeCommandList(CommandList& command_list, Fence& fence) c
}
void CommandQueue::setWorkloadType(ze_command_queue_workload_type_t workloadType) const {
- if (_initStructs->getCommandQueueDdiTable().version()) {
+ if (_init_structs->getCommandQueueDdiTable().version() >= ZE_MAKE_VERSION(1, 0)) {
THROW_ON_FAIL_FOR_LEVELZERO("zeSetWorkloadType",
- _initStructs->getCommandQueueDdiTable().pfnSetWorkloadType(_handle, workloadType));
+ _init_structs->getCommandQueueDdiTable().pfnSetWorkloadType(_handle, workloadType));
} else {
OPENVINO_THROW("The WorkloadType property is not supported by the current Driver Version!");
}
@@ -173,11 +192,15 @@ CommandQueue::~CommandQueue() {
if (ZE_RESULT_SUCCESS != result) {
_log.error("zeCommandQueueDestroy failed %#X", uint64_t(result));
}
+
+ _handle = nullptr;
}
-Fence::Fence(const CommandQueue& command_queue) : _log("Fence", Logger::global().level()) {
+Fence::Fence(const std::shared_ptr<CommandQueue>& command_queue)
+ : _command_queue(command_queue),
+ _log("Fence", Logger::global().level()) {
ze_fence_desc_t fence_desc = {ZE_STRUCTURE_TYPE_FENCE_DESC, nullptr, 0};
- THROW_ON_FAIL_FOR_LEVELZERO("zeFenceCreate", zeFenceCreate(command_queue.handle(), &fence_desc, &_handle));
+ THROW_ON_FAIL_FOR_LEVELZERO("zeFenceCreate", zeFenceCreate(_command_queue->handle(), &fence_desc, &_handle));
}
void Fence::reset() const {
THROW_ON_FAIL_FOR_LEVELZERO("zeFenceReset", zeFenceReset(_handle));
@@ -190,6 +213,8 @@ Fence::~Fence() {
if (ZE_RESULT_SUCCESS != result) {
_log.error("zeFenceDestroy failed %#X", uint64_t(result));
}
+
+ _handle = nullptr;
}
} // namespace intel_npu