Skip to content

Commit

Permalink
[intel-npu] Adding zero_init functions to check if an extension is su…
Browse files Browse the repository at this point in the history
…pported; adding extension support checks for LUID; unpublish luid property if backend doesn't support it
  • Loading branch information
csoka committed Oct 18, 2024
1 parent 06e2d8f commit de85a87
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/plugins/intel_npu/src/al/include/npu.hpp
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
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
4 changes: 4 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,9 @@ class ZeroInitStructsHolder final {
inline uint32_t getMutableCommandListVersion() const {
return mutable_command_list_version;
}
inline bool isExtensionSupported(std::string ext_name) const {
return driver_extension_properties.count(ext_name) > 0 ? true : false;
}

private:
static const ze_driver_uuid_t uuid;
Expand All @@ -61,6 +64,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
4 changes: 4 additions & 0 deletions src/plugins/intel_npu/src/backend/src/zero_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ bool ZeroEngineBackend::isCommandQueueExtSupported() const {
return _instance->getCommandQueueDdiTable().version() >= ZE_COMMAND_QUEUE_NPU_EXT_VERSION_1_0;
}

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

ZeroEngineBackend::~ZeroEngineBackend() = default;

const std::shared_ptr<IDevice> ZeroEngineBackend::getDevice() const {
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/intel_npu/src/backend/src/zero_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +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;
#if defined(_WIN32) || defined(__CYGWIN__)
// Obtain LUID
// Luid is obtained via zeDeviceGetProperties, but it is windows-only
device_luid.stype = ZE_STRUCTURE_TYPE_DEVICE_LUID_EXT_PROPERTIES;
device_properties.pNext = &device_luid;
#endif

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

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",
zeroUtils::throwOnFail("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
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
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 @@ -175,6 +175,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
2 changes: 1 addition & 1 deletion src/plugins/intel_npu/src/plugin/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ Plugin::Plugin()
return decltype(ov::device::uuid)::value_type{devUuid};
}}},
{ov::device::luid.name(),
{true,
{_backends->isLUIDExtSupported(),
ov::PropertyMutability::RO,
[&](const Config& config) {
const auto specifiedDeviceName = get_specified_device_name(config);
Expand Down

0 comments on commit de85a87

Please sign in to comment.