Skip to content

Commit

Permalink
[intel-npu] Implementing LUID property in npu plugin (openvinotoolkit…
Browse files Browse the repository at this point in the history
…#27091)

### Details:
- Implements ov::device::LUID property in npu_plugin (works on windows
only)

### Tickets:
 - EISW-140889
  • Loading branch information
csoka authored and CuriousPanCake committed Nov 6, 2024
1 parent 9e57819 commit a10e069
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/plugins/intel_npu/src/backend/include/zero_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ZeroEngineBackend final : public IEngineBackend {

bool isBatchingSupported() const override;
bool isCommandQueueExtSupported() const override;
bool isLUIDExtSupported() const override;

void* getContext() const override;
void* getDriverHandle() const;
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/intel_npu/src/backend/include/zero_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ZeroDevice : public IDevice {
std::string getName() const override;
std::string getFullDeviceName() const override;
Uuid getUuid() const override;
ov::device::LUID getLUID() const override;
uint32_t getSubDevId() const override;
uint32_t getMaxNumSlices() const override;
uint64_t getAllocMemSize() const override;
Expand Down Expand Up @@ -67,6 +68,8 @@ class ZeroDevice : public IDevice {

ze_pci_ext_properties_t pci_properties = {};

ze_device_luid_ext_properties_t device_luid = {};

std::map<ov::element::Type, float> device_gops = {{ov::element::f32, 0.f},
{ov::element::f16, 0.f},
{ov::element::bf16, 0.f},
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/intel_npu/src/backend/include/zero_init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ class ZeroInitStructsHolder final {
inline uint32_t getMutableCommandListVersion() const {
return mutable_command_list_version;
}
// Helper function to check if extension with <ext_name> exists and its newer than <version>
inline bool isExtensionSupported(std::string ext_name, uint32_t version) const {
auto iter = driver_extension_properties.find(ext_name);
if (iter == driver_extension_properties.end()) {
return false;
} else if (iter->second >= version) {
return true;
}
return false;
}

private:
static const ze_driver_uuid_t uuid;
Expand All @@ -61,6 +71,7 @@ class ZeroInitStructsHolder final {
ze_driver_handle_t driver_handle = nullptr;
ze_device_handle_t device_handle = nullptr;

std::map<std::string, uint32_t> driver_extension_properties;
std::unique_ptr<ze_graph_dditable_ext_decorator> graph_dditable_ext_decorator;
std::unique_ptr<ze_command_queue_npu_dditable_ext_decorator> command_queue_npu_dditable_ext_decorator;
std::unique_ptr<ze_graph_profiling_ddi_table_ext_decorator> graph_profiling_npu_dditable_ext_decorator;
Expand Down
8 changes: 6 additions & 2 deletions src/plugins/intel_npu/src/backend/src/zero_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ uint32_t ZeroEngineBackend::getGraphExtVersion() const {
}

bool ZeroEngineBackend::isBatchingSupported() const {
return _instance->getGraphDdiTable().version() >= ZE_GRAPH_EXT_VERSION_1_6;
return _instance->isExtensionSupported(std::string(ZE_GRAPH_EXT_NAME_1_6), ZE_MAKE_VERSION(1, 6));
}

bool ZeroEngineBackend::isCommandQueueExtSupported() const {
return _instance->getCommandQueueDdiTable().version() >= ZE_COMMAND_QUEUE_NPU_EXT_VERSION_1_0;
return _instance->isExtensionSupported(std::string(ZE_COMMAND_QUEUE_NPU_EXT_NAME), ZE_MAKE_VERSION(1, 0));
}

bool ZeroEngineBackend::isLUIDExtSupported() const {
return _instance->isExtensionSupported(std::string(ZE_DEVICE_LUID_EXT_NAME), ZE_MAKE_VERSION(1, 0));
}

ZeroEngineBackend::~ZeroEngineBackend() = default;
Expand Down
16 changes: 16 additions & 0 deletions src/plugins/intel_npu/src/backend/src/zero_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ ZeroDevice::ZeroDevice(const std::shared_ptr<ZeroInitStructsHolder>& initStructs
log("ZeroDevice", Logger::global().level()) {
log.debug("ZeroDevice::ZeroDevice init");
device_properties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;

// Get LUID info, if supported
if (_initStructs->isExtensionSupported(std::string(ZE_DEVICE_LUID_EXT_NAME), ZE_MAKE_VERSION(1, 0))) {
device_luid.stype = ZE_STRUCTURE_TYPE_DEVICE_LUID_EXT_PROPERTIES;
device_properties.pNext = &device_luid;
}
THROW_ON_FAIL_FOR_LEVELZERO("zeDeviceGetProperties",
zeDeviceGetProperties(_initStructs->getDevice(), &device_properties));

Expand Down Expand Up @@ -128,6 +134,16 @@ IDevice::Uuid ZeroDevice::getUuid() const {
return uuid;
}

ov::device::LUID ZeroDevice::getLUID() const {
ov::device::LUID luidstruct;
// incompatibility check
static_assert(ZE_MAX_DEVICE_LUID_SIZE_EXT == ov::device::LUID::MAX_LUID_SIZE, "LUID size mismatch");
for (int i = 0; i < ZE_MAX_DEVICE_LUID_SIZE_EXT; i++) {
luidstruct.luid[i] = device_luid.luid.id[i];
}
return luidstruct;
}

uint32_t ZeroDevice::getSubDevId() const {
return device_properties.subdeviceId;
}
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/intel_npu/src/backend/src/zero_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ ZeroInitStructsHolder::ZeroInitStructsHolder() : log("NPUZeroInitStructsHolder",
THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetExtensionProperties",
zeDriverGetExtensionProperties(driver_handle, &count, extProps.data()));

// save the list of extension properties for later searches
for (auto it = extProps.begin(); it != extProps.end(); ++it) {
ze_driver_extension_properties_t p = *it;
driver_extension_properties.emplace(std::string(p.name), p.version);
}

// Query our graph extension version
std::string graph_ext_name;
uint32_t graph_ext_version = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class IEngineBackend : public std::enable_shared_from_this<IEngineBackend> {
virtual bool isBatchingSupported() const = 0;
/** @brief Backend has support for workload type */
virtual bool isCommandQueueExtSupported() const = 0;
/** @brief Backend has support for LUID info */
virtual bool isLUIDExtSupported() const = 0;
/** @brief Register backend-specific options */
virtual void registerOptions(OptionsDesc& options) const;
/** @brief Get Level Zero context*/
Expand Down Expand Up @@ -72,6 +74,7 @@ class IDevice : public std::enable_shared_from_this<IDevice> {
virtual std::string getName() const = 0;
virtual std::string getFullDeviceName() const = 0;
virtual Uuid getUuid() const;
virtual ov::device::LUID getLUID() const;
virtual uint32_t getSubDevId() const;
virtual uint32_t getMaxNumSlices() const;
virtual uint64_t getAllocMemSize() const;
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/intel_npu/src/common/src/npu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ IDevice::Uuid IDevice::getUuid() const {
OPENVINO_THROW("Get UUID not supported");
}

ov::device::LUID IDevice::getLUID() const {
OPENVINO_THROW("Get LUID not supported");
}

uint32_t IDevice::getSubDevId() const {
OPENVINO_THROW("Get SubDevId is not supported");
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/intel_npu/src/plugin/include/backends.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class NPUBackends final {
uint32_t getGraphExtVersion() const;
bool isBatchingSupported() const;
bool isCommandQueueExtSupported() const;
bool isLUIDExtSupported() const;
void registerOptions(OptionsDesc& options) const;
void* getContext() const;
std::string getCompilationPlatform(const std::string_view platform, const std::string& deviceId) const;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/intel_npu/src/plugin/include/metrics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Metrics final {
const std::vector<std::string>& SupportedMetrics() const;
std::string GetFullDeviceName(const std::string& specifiedDeviceName) const;
IDevice::Uuid GetDeviceUuid(const std::string& specifiedDeviceName) const;
ov::device::LUID GetDeviceLUID(const std::string& specifiedDeviceName) const;
const std::vector<std::string>& GetSupportedConfigKeys() const;
const std::vector<std::string> GetOptimizationCapabilities() const;
const std::tuple<uint32_t, uint32_t, uint32_t>& GetRangeForAsyncInferRequest() const;
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/intel_npu/src/plugin/src/backends.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ bool NPUBackends::isCommandQueueExtSupported() const {
return false;
}

bool NPUBackends::isLUIDExtSupported() const {
if (_backend != nullptr) {
return _backend->isLUIDExtSupported();
}

return false;
}

std::shared_ptr<IDevice> NPUBackends::getDevice(const std::string& specificName) const {
_logger.debug("Searching for device %s to use started...", specificName.c_str());
// TODO iterate over all available backends
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/intel_npu/src/plugin/src/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ IDevice::Uuid Metrics::GetDeviceUuid(const std::string& specifiedDeviceName) con
return IDevice::Uuid{};
}

ov::device::LUID Metrics::GetDeviceLUID(const std::string& specifiedDeviceName) const {
const auto devName = getDeviceName(specifiedDeviceName);
auto device = _backends->getDevice(devName);
if (device) {
return device->getLUID();
}
return ov::device::LUID{{
0,
}};
}

std::vector<ov::PropertyName> Metrics::GetCachingProperties() const {
return _cachingProperties;
}
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/intel_npu/src/plugin/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,13 @@ Plugin::Plugin()
auto devUuid = _metrics->GetDeviceUuid(specifiedDeviceName);
return decltype(ov::device::uuid)::value_type{devUuid};
}}},
{ov::device::luid.name(),
{_backends->isLUIDExtSupported(),
ov::PropertyMutability::RO,
[&](const Config& config) {
const auto specifiedDeviceName = get_specified_device_name(config);
return _metrics->GetDeviceLUID(specifiedDeviceName);
}}},
// Add FULL_DEVICE_NAME and DEVICE_ARCHITECTURE in supported
// properties list only in case of non-empty device list (#1424144d)
{ov::device::architecture.name(),
Expand Down

0 comments on commit a10e069

Please sign in to comment.