Group Intel NPU LevelZero interoperability#

group Intel NPU LevelZero interoperability

Set of C++ classes and properties to work with Remote API for Intel NPU LevelZero plugin.

Enums

enum class MemType#

Enum to define the type of the shared memory buffer.

Values:

enumerator L0_INTERNAL_BUF#

Internal Level Zero buffer type allocated by plugin.

enumerator SHARED_BUF#

Shared buffer.

enumerator MMAPED_FILE#

Memory-mapped file buffer.

enumerator CPU_VA#

CPU Virtual Address buffer.

enum class TensorType#

Enum to define the type of the tensor.

Values:

enumerator INPUT#

Tensor is only used as input.

enumerator OUTPUT#

Tensor is only used as output.

enumerator BINDED#

Tensor could be used as input and output.

Variables

static constexpr Property<MemType> mem_type = {"MEM_TYPE"}#

This key identifies type of internal shared memory in a shared memory tensor parameter map.

static constexpr Property<npu_handle_param> mem_handle = {"MEM_HANDLE"}#

This key identifies memory handle in a shared memory tensor parameter map.

static constexpr Property<npu_handle_param> l0_context = {"L0_CONTEXT"}#

This key identifies LevelZero context handle in a shared context parameter map.

static constexpr Property<FileDescriptor> file_descriptor = {"FILE_DESCRIPTOR"}#

This key identifies file descriptor in a shared memory mapped tensor parameter map.

static constexpr Property<TensorType> tensor_type = {"TENSOR_TYPE"}#

This key sets the type of the internal Level Zero buffer allocated by the plugin in a shared memory tensor parameter map.

static constexpr Property<std::size_t> import_size = {"IMPORT_SIZE"}#

This key sets the size, in bytes, of the memory to import in a shared memory tensor parameter map. It allows importing more memory than the tensor itself needs.

  • If not set, the size is computed from the tensor element type and shape.

  • If set, it must not be smaller than the size computed from the tensor element type and shape.

  • For MemType::CPU_VA the imported size must be a multiple of the standard page size (4096 bytes). If the tensor size computed from the shape is not, set this property to that size rounded up to the next multiple of the page size (or to a bigger multiple, to import more memory). The imported allocation must be at least that big.

  • It can be set only when mem_type is MemType::SHARED_BUF or MemType::CPU_VA. Setting it for any other memory type, including MemType::MMAPED_FILE, or without mem_type, results in an error.

  • It can be set only per tensor, when creating a remote tensor. Setting it when creating the context results in an error.

The tensor shape and strides are not affected: only the size of the imported memory changes.

class ZeroBufferTensor : public ov::RemoteTensor#
#include <level_zero.hpp>

This class represents an abstraction for NPU plugin remote tensor which can be shared with user-supplied LevelZero buffer. The plugin object derived from this class can be obtained with ZeroContext::create_tensor() call.

Note

User can obtain Level Zero buffer handle from this class.

Public Functions

inline void *get()#

Returns the underlying LevelZero memory object handle.

Returns:

underlying void* memory object handle

Public Static Functions

static inline void type_check(const Tensor &tensor)#

Checks that type defined runtime parameters are presented in remote object.

Parameters:

tensor – a tensor to check

class ZeroContext : public ov::RemoteContext#
#include <level_zero.hpp>

This class represents an abstraction for NPU plugin remote context which is shared with LevelZero context object. The plugin object derived from this class can be obtained either with CompiledModel::get_context() or Core::create_context() calls.

Public Functions

inline ZeroContext(Core &core)#

Constructs context object from user-supplied LevelZero context handle.

Parameters:

core – A reference to OpenVINO Runtime Core object

inline void *get()#

Returns the underlying LevelZero context handle.

Returns:

void*

inline ZeroBufferTensor create_tensor(const element::Type type, const Shape &shape, void *buffer, const MemType memory_type = MemType::SHARED_BUF, const TensorType tensor_type = TensorType::BINDED)#

This function is used to obtain remote tensor object from user-supplied NT handle object or raw pointer.

Parameters:
  • type – Tensor element type

  • shape – Tensor shape

  • buffer – A void* object that should be wrapped by a remote tensor

  • memory_type – Memory type to use (default: SHARED_BUF)

  • tensor_type – Type of the tensor to be shared, input, output or binded (default: BINDED)

Returns:

A remote tensor instance

inline ZeroBufferTensor create_tensor(const element::Type type, const Shape &shape, int fd, const MemType memory_type = MemType::SHARED_BUF, const TensorType tensor_type = TensorType::BINDED)#

This function is used to obtain remote tensor object from user-supplied DMA-BUF file descriptor object.

Parameters:
  • type – Tensor element type

  • shape – Tensor shape

  • fd – A int object that should be wrapped by a remote tensor

  • memory_type – Memory type to use (default: SHARED_BUF)

  • tensor_type – Type of the tensor to be shared, input, output or binded (default: BINDED)

Returns:

A remote tensor instance

inline ZeroBufferTensor create_tensor(const element::Type type, const Shape &shape, const FileDescriptor &file_descriptor, const TensorType tensor_type = TensorType::INPUT)#

This function is used to obtain remote tensor object from a file.

Parameters:
  • type – Tensor element type

  • shape – Tensor shape

  • file_name – A string object that should be wrapped by a remote tensor

  • offset_in_bytes – Offset in bytes from the beginning of the file

  • tensor_type – Type of the tensor to be shared, input, output or binded

Returns:

A remote tensor instance

inline ZeroBufferTensor create_l0_host_tensor(const element::Type type, const Shape &shape, const TensorType tensor_type = TensorType::BINDED)#

This function is used to obtain remote tensor object.

Parameters:
  • type – Tensor element type

  • shape – Tensor shape

  • tensor_type – Type of the tensor to be shared, input, output or binded

Returns:

A remote tensor instance

RemoteTensor create_tensor(const element::Type &type, const Shape &shape, const AnyMap &params = {})#

Allocates memory tensor in device memory or wraps user-supplied memory handle using the specified tensor description and low-level device-specific parameters. Returns a pointer to the object that implements the RemoteTensor interface.

Parameters:
  • type – Defines the element type of the tensor.

  • shape – Defines the shape of the tensor.

  • params – Map of the low-level tensor object parameters.

Returns:

Pointer to a plugin object that implements the RemoteTensor interface.

struct FileDescriptor#
#include <remote_properties.hpp>

Struct to define file descriptor.

Public Members

std::filesystem::path _file_path#

File path.

std::size_t _offset_in_bytes = 0#

Offset in bytes to read from the file.