Skip to content

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

[NPU] Move remote tensor from backend/device to utils (#30287)

Bogdan Pereanuc6e5fd857eac
diff --git a/src/plugins/intel_npu/src/backend/include/zero_backend.hpp b/src/plugins/intel_npu/src/backend/include/zero_backend.hpp
index d4cb931a293..5efccb84b95 100644
--- a/src/plugins/intel_npu/src/backend/include/zero_backend.hpp
+++ b/src/plugins/intel_npu/src/backend/include/zero_backend.hpp
@@ -25,7 +25,6 @@ public:
uint32_t getDriverVersion() const override;
uint32_t getGraphExtVersion() const override;
- bool isBatchingSupported() const override;
bool isCommandQueueExtSupported() const override;
bool isLUIDExtSupported() const override;
diff --git a/src/plugins/intel_npu/src/backend/include/zero_device.hpp b/src/plugins/intel_npu/src/backend/include/zero_device.hpp
index c11b9fddca2..b3a9ad88e79 100644
--- a/src/plugins/intel_npu/src/backend/include/zero_device.hpp
+++ b/src/plugins/intel_npu/src/backend/include/zero_device.hpp
@@ -38,22 +38,6 @@ public:
log.setLevel(config.get<LOG_LEVEL>());
}
- ov::SoPtr<ov::IRemoteTensor> createRemoteTensor(
- std::shared_ptr<ov::IRemoteContext> context,
- const ov::element::Type& element_type,
- const ov::Shape& shape,
- const Config& config,
- ov::intel_npu::TensorType tensor_type = ov::intel_npu::TensorType::BINDED,
- ov::intel_npu::MemType mem_type = ov::intel_npu::MemType::L0_INTERNAL_BUF,
- void* mem = nullptr) override;
-
- ov::SoPtr<ov::ITensor> createHostTensor(
- std::shared_ptr<ov::IRemoteContext> context,
- const ov::element::Type& element_type,
- const ov::Shape& shape,
- const Config& config,
- ov::intel_npu::TensorType tensor_type = ov::intel_npu::TensorType::BINDED) override;
-
ZeroDevice& operator=(const ZeroDevice&) = delete;
ZeroDevice(const ZeroDevice&) = delete;
diff --git a/src/plugins/intel_npu/src/backend/include/zero_infer_request.hpp b/src/plugins/intel_npu/src/backend/include/zero_infer_request.hpp
index 6c6a2f8c6b5..a5a433224d1 100644
--- a/src/plugins/intel_npu/src/backend/include/zero_infer_request.hpp
+++ b/src/plugins/intel_npu/src/backend/include/zero_infer_request.hpp
@@ -10,10 +10,10 @@
#include "intel_npu/common/npu.hpp"
#include "intel_npu/common/sync_infer_request.hpp"
#include "intel_npu/utils/logger/logger.hpp"
+#include "intel_npu/utils/zero/zero_remote_tensor.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"
#include "intel_npu/utils/zero/zero_wrappers.hpp"
#include "zero_pipeline.hpp"
-#include "zero_remote_tensor.hpp"
#include "zero_tensor.hpp"
namespace intel_npu {
diff --git a/src/plugins/intel_npu/src/backend/include/zero_remote_tensor.hpp b/src/plugins/intel_npu/src/backend/include/zero_remote_tensor.hpp
deleted file mode 100644
index 6ec7294ae71..00000000000
--- a/src/plugins/intel_npu/src/backend/include/zero_remote_tensor.hpp
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (C) 2018-2025 Intel Corporation
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#pragma once
-
-#include <map>
-#include <memory>
-#include <string>
-
-#include "intel_npu/common/remote_tensor.hpp"
-#include "intel_npu/utils/zero/zero_init.hpp"
-#include "openvino/runtime/intel_npu/remote_properties.hpp"
-
-namespace intel_npu {
-
-class ZeroRemoteTensor final : public RemoteTensor {
-public:
- ZeroRemoteTensor(const std::shared_ptr<ov::IRemoteContext>& context,
- const std::shared_ptr<ZeroInitStructsHolder>& init_structs,
- const ze_device_properties_t& device_properties,
- const ov::element::Type& element_type,
- const ov::Shape& shape,
- const Config& config,
- ov::intel_npu::TensorType tensor_type = ov::intel_npu::TensorType::BINDED,
- ov::intel_npu::MemType mem_type = ov::intel_npu::MemType::L0_INTERNAL_BUF,
- void* mem = nullptr);
-
- void* get_original_memory() const;
- ze_context_handle_t get_zero_context_handle() const;
-
- ~ZeroRemoteTensor() override;
-
-private:
- void allocate(const size_t bytes) override;
- bool deallocate() noexcept override;
- bool is_allocated() const noexcept;
- void update_properties();
-
- const Config _config;
- Logger _logger;
-
- std::shared_ptr<ZeroInitStructsHolder> _init_structs;
-
- ze_device_properties_t _device_properties = {};
-
- ov::intel_npu::TensorType _tensor_type;
- ov::intel_npu::MemType _mem_type;
- void* _mem = nullptr;
- void* _data = nullptr;
-
- bool _external_memory_support = false;
-};
-
-inline bool is_remote_tensor(const std::shared_ptr<ov::ITensor>& tensor) {
- return std::dynamic_pointer_cast<ZeroRemoteTensor>(tensor) != nullptr;
-}
-
-} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/backend/src/zero_backend.cpp b/src/plugins/intel_npu/src/backend/src/zero_backend.cpp
index 78170daefdd..0bd02dccb96 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_backend.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_backend.cpp
@@ -29,10 +29,6 @@ uint32_t ZeroEngineBackend::getGraphExtVersion() const {
return _initStruct->getGraphDdiTable().version();
}
-bool ZeroEngineBackend::isBatchingSupported() const {
- OPENVINO_NOT_IMPLEMENTED;
-}
-
bool ZeroEngineBackend::isCommandQueueExtSupported() const {
return _initStruct->isExtensionSupported(std::string(ZE_COMMAND_QUEUE_NPU_EXT_NAME), ZE_MAKE_VERSION(1, 0));
}
diff --git a/src/plugins/intel_npu/src/backend/src/zero_device.cpp b/src/plugins/intel_npu/src/backend/src/zero_device.cpp
index ba48ca49b8d..29ebf4424bb 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_device.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_device.cpp
@@ -7,9 +7,7 @@
#include "intel_npu/common/itt.hpp"
#include "intel_npu/utils/zero/zero_api.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"
-#include "zero_host_tensor.hpp"
#include "zero_infer_request.hpp"
-#include "zero_remote_tensor.hpp"
using namespace intel_npu;
@@ -176,35 +174,3 @@ std::shared_ptr<SyncInferRequest> ZeroDevice::createInferRequest(
const Config& config) {
return std::make_shared<ZeroInferRequest>(_initStructs, compiledModel, config);
}
-
-ov::SoPtr<ov::IRemoteTensor> ZeroDevice::createRemoteTensor(std::shared_ptr<ov::IRemoteContext> context,
- const ov::element::Type& element_type,
- const ov::Shape& shape,
- const Config& config,
- ov::intel_npu::TensorType tensor_type,
- ov::intel_npu::MemType mem_type,
- void* mem) {
- return {std::make_shared<ZeroRemoteTensor>(context,
- _initStructs,
- device_properties,
- element_type,
- shape,
- config,
- tensor_type,
- mem_type,
- mem)};
-};
-
-ov::SoPtr<ov::ITensor> ZeroDevice::createHostTensor(std::shared_ptr<ov::IRemoteContext> context,
- const ov::element::Type& element_type,
- const ov::Shape& shape,
- const Config& config,
- ov::intel_npu::TensorType tensor_type) {
- return {std::make_shared<ZeroHostTensor>(context,
- _initStructs,
- device_properties,
- element_type,
- shape,
- config,
- tensor_type)};
-};
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 cd16bcf466d..5b6dde6a87a 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp
@@ -12,8 +12,8 @@
#include "intel_npu/prefix.hpp"
#include "intel_npu/utils/logger/logger.hpp"
#include "intel_npu/utils/zero/zero_api.hpp"
+#include "intel_npu/utils/zero/zero_remote_tensor.hpp"
#include "intel_npu/utils/zero/zero_types.hpp"
-#include "zero_remote_tensor.hpp"
namespace intel_npu {
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 44f0767c5d5..d4816009010 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
@@ -5,8 +5,8 @@
#include "zero_variable_state.hpp"
#include "intel_npu/config/options.hpp"
+#include "intel_npu/utils/zero/zero_remote_tensor.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"
-#include "zero_remote_tensor.hpp"
namespace intel_npu {
diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/npu.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/npu.hpp
index ebdc0b36a55..f21f909d940 100644
--- a/src/plugins/intel_npu/src/common/include/intel_npu/common/npu.hpp
+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/npu.hpp
@@ -11,8 +11,6 @@
#include "intel_npu/common/sync_infer_request.hpp"
#include "intel_npu/config/config.hpp"
#include "intel_npu/utils/zero/zero_init.hpp"
-#include "openvino/runtime/intel_npu/remote_properties.hpp"
-#include "openvino/runtime/iremote_context.hpp"
#include "openvino/runtime/properties.hpp"
namespace intel_npu {
@@ -36,8 +34,6 @@ public:
virtual uint32_t getGraphExtVersion() const;
/** @brief Get name of backend */
virtual const std::string getName() const = 0;
- /** @brief Backend has support for concurrency batching */
- virtual bool isBatchingSupported() const = 0;
/** @brief Backend has support for workload type */
virtual bool isCommandQueueExtSupported() const = 0;
/** @brief Backend has support for LUID info */
@@ -81,22 +77,6 @@ public:
virtual void updateInfo(const Config& config) = 0;
- virtual ov::SoPtr<ov::IRemoteTensor> createRemoteTensor(
- std::shared_ptr<ov::IRemoteContext> context,
- const ov::element::Type& element_type,
- const ov::Shape& shape,
- const Config& config,
- ov::intel_npu::TensorType tensor_type = ov::intel_npu::TensorType::BINDED,
- ov::intel_npu::MemType mem_type = ov::intel_npu::MemType::L0_INTERNAL_BUF,
- void* mem = nullptr);
-
- virtual ov::SoPtr<ov::ITensor> createHostTensor(
- std::shared_ptr<ov::IRemoteContext> context,
- const ov::element::Type& element_type,
- const ov::Shape& shape,
- const Config& config,
- ov::intel_npu::TensorType tensor_type = ov::intel_npu::TensorType::BINDED);
-
protected:
virtual ~IDevice() = default;
};
diff --git a/src/plugins/intel_npu/src/common/src/npu.cpp b/src/plugins/intel_npu/src/common/src/npu.cpp
index 43978396273..8c433078f01 100644
--- a/src/plugins/intel_npu/src/common/src/npu.cpp
+++ b/src/plugins/intel_npu/src/common/src/npu.cpp
@@ -79,22 +79,4 @@ std::map<ov::element::Type, float> IDevice::getGops() const {
OPENVINO_THROW("Get DEVICE_GOPS is not supported");
}
-ov::SoPtr<ov::IRemoteTensor> IDevice::createRemoteTensor(std::shared_ptr<ov::IRemoteContext>,
- const ov::element::Type&,
- const ov::Shape&,
- const Config&,
- ov::intel_npu::TensorType,
- ov::intel_npu::MemType,
- void*) {
- OPENVINO_THROW("Create Remote Tensor is not supported");
-}
-
-ov::SoPtr<ov::ITensor> IDevice::createHostTensor(std::shared_ptr<ov::IRemoteContext>,
- const ov::element::Type&,
- const ov::Shape&,
- const Config&,
- ov::intel_npu::TensorType) {
- OPENVINO_THROW("Create Host Tensor is not supported");
-}
-
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/common/src/remote_tensor.cpp b/src/plugins/intel_npu/src/common/src/remote_tensor.cpp
deleted file mode 100644
index 2f6134f1a62..00000000000
--- a/src/plugins/intel_npu/src/common/src/remote_tensor.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright (C) 2018-2025 Intel Corporation
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#include "intel_npu/common/remote_tensor.hpp"
-
-#include "intel_npu/config/options.hpp"
-#include "openvino/core/type/element_iterator.hpp"
-#include "openvino/runtime/intel_npu/remote_properties.hpp"
-
-namespace intel_npu {
-
-RemoteTensor::RemoteTensor(const std::shared_ptr<ov::IRemoteContext>& context,
- const ov::element::Type& element_type,
- const ov::Shape& shape)
- : _context(context),
- _element_type(element_type),
- _shape(shape),
- _capacity(shape) {
- OPENVINO_ASSERT(shape_size(_shape) != 0);
- OPENVINO_ASSERT(_element_type.is_static());
-}
-
-RemoteTensor::~RemoteTensor() = default;
-
-const ov::element::Type& RemoteTensor::get_element_type() const {
- return _element_type;
-}
-
-const ov::Shape& RemoteTensor::get_shape() const {
- return _shape;
-}
-
-const ov::Strides& RemoteTensor::get_strides() const {
- return _strides;
-}
-
-const ov::AnyMap& RemoteTensor::get_properties() const {
- return _properties;
-}
-
-void RemoteTensor::set_shape(ov::Shape new_shape) {
- if (_shape == new_shape) {
- return;
- }
-
- _shape = std::move(new_shape);
-
- if (ov::shape_size(_shape) > ov::shape_size(_capacity)) {
- OPENVINO_THROW("Cannot set a new bigger shape to this tensor.");
- }
-
- _strides.clear();
- update_strides();
-}
-
-void RemoteTensor::update_strides() {
- if (_element_type.bitwidth() < 8) {
- return;
- }
-
- auto& shape = get_shape();
- if (_strides.empty() && !shape.empty()) {
- _strides.resize(shape.size());
- _strides.back() = shape.back() == 0 ? 0 : _element_type.size();
- std::transform(shape.crbegin(),
- shape.crend() - 1,
- _strides.rbegin(),
- _strides.rbegin() + 1,
- std::multiplies<size_t>());
- }
-}
-
-const std::string& RemoteTensor::get_device_name() const {
- return _context->get_device_name();
-}
-
-std::shared_ptr<ov::IRemoteContext> RemoteTensor::get_context() const {
- return _context;
-}
-
-} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/plugin/include/remote_context.hpp b/src/plugins/intel_npu/src/plugin/include/remote_context.hpp
index 759e2c76a61..d8838967612 100644
--- a/src/plugins/intel_npu/src/plugin/include/remote_context.hpp
+++ b/src/plugins/intel_npu/src/plugin/include/remote_context.hpp
@@ -9,7 +9,9 @@
#include <string>
#include "intel_npu/common/npu.hpp"
-#include "intel_npu/config/config.hpp"
+#include "intel_npu/utils/zero/zero_host_tensor.hpp"
+#include "intel_npu/utils/zero/zero_init.hpp"
+#include "intel_npu/utils/zero/zero_remote_tensor.hpp"
#include "openvino/runtime/intel_npu/remote_properties.hpp"
#include "openvino/runtime/iremote_context.hpp"
@@ -17,9 +19,7 @@ namespace intel_npu {
class RemoteContextImpl : public ov::IRemoteContext {
public:
- RemoteContextImpl(const ov::SoPtr<IEngineBackend>& engineBackend,
- const Config& config,
- const ov::AnyMap& remote_properties = {});
+ RemoteContextImpl(const ov::SoPtr<IEngineBackend>& engineBackend, const ov::AnyMap& remote_properties = {});
/**
* @brief Returns name of a device on which underlying object is allocated.
@@ -57,8 +57,8 @@ public:
private:
std::shared_ptr<ov::IRemoteContext> get_this_shared_ptr();
- const Config _config;
- std::shared_ptr<intel_npu::IDevice> _device;
+ std::shared_ptr<ZeroInitStructsHolder> _init_structs;
+
ov::AnyMap _properties;
std::string _device_name;
diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
index a25a90ff045..d973079d308 100644
--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
@@ -515,11 +515,11 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
}
ov::SoPtr<ov::IRemoteContext> Plugin::create_context(const ov::AnyMap& remoteProperties) const {
- return std::make_shared<RemoteContextImpl>(_backend, _globalConfig, remoteProperties);
+ return std::make_shared<RemoteContextImpl>(_backend, remoteProperties);
}
ov::SoPtr<ov::IRemoteContext> Plugin::get_default_context(const ov::AnyMap&) const {
- return std::make_shared<RemoteContextImpl>(_backend, _globalConfig);
+ return std::make_shared<RemoteContextImpl>(_backend);
}
std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& stream, const ov::AnyMap& properties) const {
diff --git a/src/plugins/intel_npu/src/plugin/src/remote_context.cpp b/src/plugins/intel_npu/src/plugin/src/remote_context.cpp
index f089f650326..8a4a0160517 100644
--- a/src/plugins/intel_npu/src/plugin/src/remote_context.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/remote_context.cpp
@@ -4,8 +4,6 @@
#include "remote_context.hpp"
-#include "intel_npu/config/options.hpp"
-
using namespace ov::intel_npu;
namespace {
@@ -25,18 +23,13 @@ std::optional<Type> extract_object(const ov::AnyMap& params, const ov::Property<
namespace intel_npu {
RemoteContextImpl::RemoteContextImpl(const ov::SoPtr<IEngineBackend>& engineBackend,
- const Config& config,
const ov::AnyMap& remote_properties)
- : _config(config),
- _device_name("NPU") {
+ : _device_name("NPU") {
if (engineBackend == nullptr || engineBackend->getName() != "LEVEL0") {
OPENVINO_THROW("Level zero backend is not found!");
}
- _device = engineBackend->getDevice(config.get<DEVICE_ID>());
- if (_device == nullptr) {
- OPENVINO_THROW("Device is not available!");
- }
+ _init_structs = engineBackend->getInitStructs();
_properties = {l0_context(engineBackend->getContext())};
@@ -83,7 +76,7 @@ ov::SoPtr<ov::IRemoteTensor> RemoteContextImpl::create_tensor(const ov::element:
}
if (!mem_type_object.has_value()) {
- return _device->createRemoteTensor(get_this_shared_ptr(), type, shape, _config);
+ return {std::make_shared<ZeroRemoteTensor>(get_this_shared_ptr(), _init_structs, type, shape)};
}
// Mem_handle shall be set if mem_type is a shared memory type.
@@ -91,21 +84,21 @@ ov::SoPtr<ov::IRemoteTensor> RemoteContextImpl::create_tensor(const ov::element:
OPENVINO_THROW("No parameter ", mem_handle.name(), " found in parameters map");
}
- return _device->createRemoteTensor(get_this_shared_ptr(),
- type,
- shape,
- _config,
- tensor_type_object.value_or(ov::intel_npu::TensorType::BINDED),
- mem_type_object.value_or(ov::intel_npu::MemType::L0_INTERNAL_BUF),
- mem_handle_object.value_or(nullptr));
+ return {std::make_shared<ZeroRemoteTensor>(get_this_shared_ptr(),
+ _init_structs,
+ type,
+ shape,
+ tensor_type_object.value_or(ov::intel_npu::TensorType::BINDED),
+ mem_type_object.value_or(ov::intel_npu::MemType::L0_INTERNAL_BUF),
+ mem_handle_object.value_or(nullptr))};
}
ov::SoPtr<ov::ITensor> RemoteContextImpl::create_host_tensor(const ov::element::Type type, const ov::Shape& shape) {
- return _device->createHostTensor(get_this_shared_ptr(),
- type,
- shape,
- _config,
- _tensor_type_object.value_or(ov::intel_npu::TensorType::BINDED));
+ return {std::make_shared<ZeroHostTensor>(get_this_shared_ptr(),
+ _init_structs,
+ type,
+ shape,
+ _tensor_type_object.value_or(ov::intel_npu::TensorType::BINDED))};
}
const std::string& RemoteContextImpl::get_device_name() const {
diff --git a/src/plugins/intel_npu/src/backend/include/zero_host_tensor.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_host_tensor.hpp
similarity index 88%
rename from src/plugins/intel_npu/src/backend/include/zero_host_tensor.hpp
rename to src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_host_tensor.hpp
index 2e92c0ca251..27b5b1df376 100644
--- a/src/plugins/intel_npu/src/backend/include/zero_host_tensor.hpp
+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_host_tensor.hpp
@@ -4,7 +4,6 @@
#pragma once
-#include "intel_npu/config/config.hpp"
#include "intel_npu/utils/zero/zero_init.hpp"
#include "openvino/runtime/itensor.hpp"
#include "zero_remote_tensor.hpp"
@@ -15,10 +14,8 @@ class ZeroHostTensor : public ov::ITensor {
public:
ZeroHostTensor(const std::shared_ptr<ov::IRemoteContext>& context,
const std::shared_ptr<ZeroInitStructsHolder>& init_structs,
- const ze_device_properties_t& device_properties,
const ov::element::Type element_type,
const ov::Shape& shape,
- const Config& config,
ov::intel_npu::TensorType tensor_type = ov::intel_npu::TensorType::BINDED);
~ZeroHostTensor() override = default;
diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/remote_tensor.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_remote_tensor.hpp
similarity index 51%
rename from src/plugins/intel_npu/src/common/include/intel_npu/common/remote_tensor.hpp
rename to src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_remote_tensor.hpp
index 51da495ca6b..58da97c7224 100644
--- a/src/plugins/intel_npu/src/common/include/intel_npu/common/remote_tensor.hpp
+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_remote_tensor.hpp
@@ -8,21 +8,23 @@
#include <memory>
#include <string>
-#include "intel_npu/config/config.hpp"
+#include "intel_npu/utils/logger/logger.hpp"
+#include "intel_npu/utils/zero/zero_init.hpp"
+#include "openvino/runtime/intel_npu/remote_properties.hpp"
#include "openvino/runtime/iremote_context.hpp"
#include "openvino/runtime/iremote_tensor.hpp"
namespace intel_npu {
-/**
- * @brief Acts as an interface for the remote tensor structures implemented by all backends.
- * @details The operations common for all backends can be found implemented here
- */
-class RemoteTensor : public ov::IRemoteTensor {
+class ZeroRemoteTensor final : public ov::IRemoteTensor {
public:
- RemoteTensor(const std::shared_ptr<ov::IRemoteContext>& context,
- const ov::element::Type& element_type,
- const ov::Shape& shape);
+ ZeroRemoteTensor(const std::shared_ptr<ov::IRemoteContext>& context,
+ const std::shared_ptr<ZeroInitStructsHolder>& init_structs,
+ const ov::element::Type& element_type,
+ const ov::Shape& shape,
+ ov::intel_npu::TensorType tensor_type = ov::intel_npu::TensorType::BINDED,
+ ov::intel_npu::MemType mem_type = ov::intel_npu::MemType::L0_INTERNAL_BUF,
+ const void* mem = nullptr);
/**
* @brief Returns additional information associated with tensor
@@ -63,20 +65,39 @@ public:
*/
std::shared_ptr<ov::IRemoteContext> get_context() const;
-protected:
- virtual void allocate(const size_t bytes) = 0;
- virtual bool deallocate() noexcept = 0;
- void update_strides();
+ void* get_original_memory() const;
+ ze_context_handle_t get_zero_context_handle() const;
+
+ ~ZeroRemoteTensor() override;
- virtual ~RemoteTensor();
+private:
+ void allocate(const size_t bytes);
+ bool deallocate() noexcept;
+ bool is_allocated() const noexcept;
+ void update_strides();
+ void update_properties();
std::shared_ptr<ov::IRemoteContext> _context;
+ std::shared_ptr<ZeroInitStructsHolder> _init_structs;
ov::element::Type _element_type;
ov::Shape _shape;
ov::Shape _capacity;
ov::Strides _strides{};
ov::AnyMap _properties;
+
+ Logger _logger;
+
+ ov::intel_npu::TensorType _tensor_type;
+ ov::intel_npu::MemType _mem_type;
+ const void* _mem = nullptr;
+ void* _data = nullptr;
+
+ bool _external_memory_support = false;
};
+inline bool is_remote_tensor(const std::shared_ptr<ov::ITensor>& tensor) {
+ return std::dynamic_pointer_cast<ZeroRemoteTensor>(tensor) != nullptr;
+}
+
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/backend/src/zero_host_tensor.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_host_tensor.cpp
similarity index 84%
rename from src/plugins/intel_npu/src/backend/src/zero_host_tensor.cpp
rename to src/plugins/intel_npu/src/utils/src/zero/zero_host_tensor.cpp
index 985d8f5fd6a..de1b5a2b980 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_host_tensor.cpp
+++ b/src/plugins/intel_npu/src/utils/src/zero/zero_host_tensor.cpp
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
-#include "zero_host_tensor.hpp"
+#include "intel_npu/utils/zero/zero_host_tensor.hpp"
#include "openvino/runtime/intel_npu/remote_properties.hpp"
@@ -10,17 +10,13 @@ namespace intel_npu {
ZeroHostTensor::ZeroHostTensor(const std::shared_ptr<ov::IRemoteContext>& context,
const std::shared_ptr<ZeroInitStructsHolder>& init_structs,
- const ze_device_properties_t& device_properties,
const ov::element::Type element_type,
const ov::Shape& shape,
- const Config& config,
ov::intel_npu::TensorType tensor_type)
: _impl(std::make_shared<ZeroRemoteTensor>(context,
init_structs,
- device_properties,
element_type,
shape,
- config,
tensor_type,
ov::intel_npu::MemType::L0_INTERNAL_BUF)) {}
diff --git a/src/plugins/intel_npu/src/backend/src/zero_remote_tensor.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_remote_tensor.cpp
similarity index 77%
rename from src/plugins/intel_npu/src/backend/src/zero_remote_tensor.cpp
rename to src/plugins/intel_npu/src/utils/src/zero/zero_remote_tensor.cpp
index 4fa149d28f6..3641ac4f264 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_remote_tensor.cpp
+++ b/src/plugins/intel_npu/src/utils/src/zero/zero_remote_tensor.cpp
@@ -2,11 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
//
-#include "zero_remote_tensor.hpp"
+#include "intel_npu/utils/zero/zero_remote_tensor.hpp"
#include <ze_api.h>
-#include "intel_npu/config/options.hpp"
#include "intel_npu/utils/zero/zero_api.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"
#include "openvino/core/type/element_iterator.hpp"
@@ -23,21 +22,23 @@ namespace intel_npu {
ZeroRemoteTensor::ZeroRemoteTensor(const std::shared_ptr<ov::IRemoteContext>& context,
const std::shared_ptr<ZeroInitStructsHolder>& init_structs,
- const ze_device_properties_t& device_properties,
const ov::element::Type& element_type,
const ov::Shape& shape,
- const Config& config,
TensorType tensor_type,
MemType mem_type,
- void* mem)
- : RemoteTensor(context, element_type, shape),
- _config(config),
- _logger("ZeroRemoteContext", _config.get<LOG_LEVEL>()),
+ const void* mem)
+ : _context(context),
_init_structs(init_structs),
- _device_properties(device_properties),
+ _element_type(element_type),
+ _shape(shape),
+ _capacity(shape),
+ _logger("ZeroRemoteContext", Logger::global().level()),
_tensor_type(tensor_type),
_mem_type(mem_type),
_mem(mem) {
+ OPENVINO_ASSERT(shape_size(_shape) != 0);
+ OPENVINO_ASSERT(_element_type.is_static());
+
const auto byte_size = ov::element::get_memory_size(_element_type, shape_size(_shape));
ze_device_external_memory_properties_t desc = {};
@@ -58,6 +59,62 @@ ZeroRemoteTensor::ZeroRemoteTensor(const std::shared_ptr<ov::IRemoteContext>& co
allocate(byte_size);
}
+const ov::element::Type& ZeroRemoteTensor::get_element_type() const {
+ return _element_type;
+}
+
+const ov::Shape& ZeroRemoteTensor::get_shape() const {
+ return _shape;
+}
+
+const ov::Strides& ZeroRemoteTensor::get_strides() const {
+ return _strides;
+}
+
+const ov::AnyMap& ZeroRemoteTensor::get_properties() const {
+ return _properties;
+}
+
+void ZeroRemoteTensor::set_shape(ov::Shape new_shape) {
+ if (_shape == new_shape) {
+ return;
+ }
+
+ _shape = std::move(new_shape);
+
+ if (ov::shape_size(_shape) > ov::shape_size(_capacity)) {
+ OPENVINO_THROW("Cannot set a new bigger shape to this tensor.");
+ }
+
+ _strides.clear();
+ update_strides();
+}
+
+void ZeroRemoteTensor::update_strides() {
+ if (_element_type.bitwidth() < 8) {
+ return;
+ }
+
+ auto& shape = get_shape();
+ if (_strides.empty() && !shape.empty()) {
+ _strides.resize(shape.size());
+ _strides.back() = shape.back() == 0 ? 0 : _element_type.size();
+ std::transform(shape.crbegin(),
+ shape.crend() - 1,
+ _strides.rbegin(),
+ _strides.rbegin() + 1,
+ std::multiplies<size_t>());
+ }
+}
+
+const std::string& ZeroRemoteTensor::get_device_name() const {
+ return _context->get_device_name();
+}
+
+std::shared_ptr<ov::IRemoteContext> ZeroRemoteTensor::get_context() const {
+ return _context;
+}
+
ZeroRemoteTensor::~ZeroRemoteTensor() {
auto res = deallocate();
if (!res) {
@@ -97,7 +154,7 @@ void ZeroRemoteTensor::allocate(const size_t bytes) {
size_t size = (bytes + STANDARD_PAGE_SIZE - 1) & ~(STANDARD_PAGE_SIZE - 1);
ze_host_mem_alloc_desc_t desc = {};
- if (_tensor_type == TensorType::INPUT && (_device_properties.flags & ZE_DEVICE_PROPERTY_FLAG_INTEGRATED)) {
+ if (_tensor_type == TensorType::INPUT) {
ze_host_mem_alloc_flag_t flag = ZE_HOST_MEM_ALLOC_FLAG_BIAS_WRITE_COMBINED;
desc = {ZE_STRUCTURE_TYPE_HOST_MEM_ALLOC_DESC, nullptr, static_cast<ze_host_mem_alloc_flags_t>(flag)};
} else {
@@ -120,7 +177,7 @@ void ZeroRemoteTensor::allocate(const size_t bytes) {
ze_external_memory_import_win32_handle_t memory_import = {ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMPORT_WIN32,
nullptr,
ZE_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_WIN32,
- _mem,
+ const_cast<void*>(_mem),
nullptr};
ze_device_mem_alloc_desc_t desc = {ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC, &memory_import, 0, 0};
THROW_ON_FAIL_FOR_LEVELZERO("zeMemAllocDevice",