Skip to content

Commit

Permalink
Refactoring code
Browse files Browse the repository at this point in the history
  • Loading branch information
pereanub committed Oct 16, 2024
1 parent 3721f61 commit 50af560
Show file tree
Hide file tree
Showing 39 changed files with 1,759 additions and 1,823 deletions.
6 changes: 6 additions & 0 deletions src/plugins/intel_npu/src/al/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ target_link_libraries(${TARGET_NAME}
openvino::runtime::dev
)

target_include_directories(${TARGET_NAME}
PUBLIC
$<TARGET_PROPERTY:LevelZero::LevelZero,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:LevelZero::NPUExt,INTERFACE_INCLUDE_DIRECTORIES>
)

set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})

Expand Down
26 changes: 0 additions & 26 deletions src/plugins/intel_npu/src/al/include/icompiler_adapter.hpp

This file was deleted.

57 changes: 47 additions & 10 deletions src/plugins/intel_npu/src/al/include/igraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,80 @@
// SPDX-License-Identifier: Apache-2.0
//

// Compiler Interface

#pragma once

#include <ze_graph_ext.h>

#include <memory>
#include <vector>

#include "intel_npu/al/config/common.hpp"
#include "intel_npu/al/icompiler.hpp"

namespace intel_npu {

class IGraph {
class IExecutor {
public:
IGraph(void* handle, NetworkMetadata metadata) : _handle(handle), _metadata(std::move(metadata)) {}
virtual ~IExecutor() = default;

virtual void setWorkloadType(const ov::WorkloadType workloadType) const = 0;
};

class IGraph : public std::enable_shared_from_this<IGraph> {
public:
IGraph(ze_graph_handle_t handle, NetworkMetadata metadata) : _handle(handle), _metadata(std::move(metadata)) {}

virtual CompiledNetwork export_blob() const = 0;

virtual std::vector<ov::ProfilingInfo> process_profiling_output() const = 0;
virtual std::vector<ov::ProfilingInfo> process_profiling_output(const std::vector<uint8_t>& profData) const = 0;

virtual void set_argument_value(uint32_t argi, const void* argv) const = 0;

virtual void initialize() const = 0;
virtual void initialize() = 0;

virtual ~IGraph() = default;

NetworkMetadata get_metadata() const {
struct ArgumentDescriptor {
ze_graph_argument_properties_3_t info;
uint32_t idx;
};

void setWorkloadType(const ov::WorkloadType workloadType) const {
if (_executor != nullptr) {
_executor->setWorkloadType(workloadType);
}
}

const std::shared_ptr<IExecutor>& get_executor() const {
return _executor;
}

const NetworkMetadata& get_metadata() const {
return _metadata;
}

void* get_handle() const {
ze_graph_handle_t get_handle() const {
return _handle;
}

void update_network_name(std::string_view name) {
_metadata.name = name;
}

inline const std::vector<ArgumentDescriptor>& get_input_descriptors() const {
return _input_descriptors;
}
inline const std::vector<ArgumentDescriptor>& get_output_descriptors() const {
return _output_descriptors;
}

protected:
void* _handle = nullptr;
ze_graph_handle_t _handle = nullptr;
NetworkMetadata _metadata;

std::shared_ptr<IExecutor> _executor;

std::vector<ArgumentDescriptor> _input_descriptors;
std::vector<ArgumentDescriptor> _output_descriptors;
};

} // namespace intel_npu
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <memory>
#include <vector>

#include "igraph.hpp"
#include "intel_npu/al/config/common.hpp"
#include "intel_npu/al/icompiler.hpp"
#include "openvino/runtime/icompiled_model.hpp"
Expand All @@ -18,13 +17,9 @@ class ICompiledModel : public ov::ICompiledModel {
public:
using ov::ICompiledModel::ICompiledModel;

virtual const std::shared_ptr<IGraph>& get_graph() const = 0;

virtual const Config& get_config() const = 0;

const NetworkMetadata get_network_metadata() const {
return get_graph()->get_metadata();
}
virtual const NetworkMetadata& get_network_metadata() const = 0;

protected:
std::shared_ptr<const ICompiledModel> shared_from_this() const {
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/intel_npu/src/al/include/npu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <cstdint>

#include "IGraph.hpp"
#include "igraph.hpp"
#include "intel_npu/al/config/config.hpp"
#include "intel_npu/al/icompiled_model.hpp"
#include "intel_npu/al/icompiler.hpp"
Expand Down Expand Up @@ -53,11 +53,14 @@ class IEngineBackend : public std::enable_shared_from_this<IEngineBackend> {

//------------------------------------------------------------------------------

class IExecutor {
class ICompilerAdapter {
public:
virtual ~IExecutor() = default;
virtual std::shared_ptr<IGraph> compile(const std::shared_ptr<const ov::Model>& model,
const Config& config) const = 0;
virtual std::shared_ptr<IGraph> parse(const std::vector<uint8_t>& network, const Config& config) const = 0;
virtual ov::SupportedOpsMap query(const std::shared_ptr<const ov::Model>& model, const Config& config) const = 0;

virtual void setWorkloadType(const ov::WorkloadType workloadType) const = 0;
virtual ~ICompilerAdapter() = default;
};

//------------------------------------------------------------------------------
Expand All @@ -66,8 +69,6 @@ class IDevice : public std::enable_shared_from_this<IDevice> {
public:
using Uuid = ov::device::UUID;

virtual std::shared_ptr<IExecutor> createExecutor(const std::shared_ptr<IGraph>& graph, const Config& config) = 0;

virtual std::string getName() const = 0;
virtual std::string getFullDeviceName() const = 0;
virtual Uuid getUuid() const;
Expand All @@ -82,7 +83,6 @@ class IDevice : public std::enable_shared_from_this<IDevice> {
virtual std::shared_ptr<SyncInferRequest> createInferRequest(
const std::shared_ptr<const ICompiledModel>& compiledModel,
const std::shared_ptr<IGraph>& graph,
const std::shared_ptr<IExecutor>& executor,
const Config& config) = 0;

virtual void updateInfo(const Config& config) = 0;
Expand Down
34 changes: 15 additions & 19 deletions src/plugins/intel_npu/src/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,21 @@ target_link_libraries(${TARGET_NAME}
ov_install_static_lib(${TARGET_NAME} ${NPU_INTERNAL_COMPONENT})

if(TARGET ze_loader)
if(NOT BUILD_SHARED_LIBS)
# Support link of static runtime in case system does not have ze_loader
install(TARGETS ze_loader EXPORT OpenVINOTargets
RUNTIME DESTINATION ${OV_CPACK_RUNTIMEDIR} COMPONENT ${NPU_PLUGIN_COMPONENT}
ARCHIVE DESTINATION ${OV_CPACK_ARCHIVEDIR} COMPONENT ${NPU_PLUGIN_COMPONENT}
LIBRARY DESTINATION ${OV_CPACK_LIBRARYDIR} COMPONENT ${NPU_PLUGIN_COMPONENT})

install(TARGETS utils EXPORT OpenVINOTargets
RUNTIME DESTINATION ${OV_CPACK_RUNTIMEDIR} COMPONENT ${NPU_PLUGIN_COMPONENT}
ARCHIVE DESTINATION ${OV_CPACK_ARCHIVEDIR} COMPONENT ${NPU_PLUGIN_COMPONENT}
LIBRARY DESTINATION ${OV_CPACK_LIBRARYDIR} COMPONENT ${NPU_PLUGIN_COMPONENT})

# export to local tree to build against static build tree
export(TARGETS ze_loader NAMESPACE openvino::
APPEND FILE "${CMAKE_BINARY_DIR}/OpenVINOTargets.cmake")

export(TARGETS utils NAMESPACE openvino::
APPEND FILE "${CMAKE_BINARY_DIR}/OpenVINOTargets.cmake")
endif()
install(TARGETS ze_loader EXPORT OpenVINOTargets
RUNTIME DESTINATION ${OV_CPACK_RUNTIMEDIR} COMPONENT ${NPU_PLUGIN_COMPONENT}
ARCHIVE DESTINATION ${OV_CPACK_ARCHIVEDIR} COMPONENT ${NPU_PLUGIN_COMPONENT}
LIBRARY DESTINATION ${OV_CPACK_LIBRARYDIR} COMPONENT ${NPU_PLUGIN_COMPONENT})

install(TARGETS utils EXPORT OpenVINOTargets
RUNTIME DESTINATION ${OV_CPACK_RUNTIMEDIR} COMPONENT ${NPU_PLUGIN_COMPONENT}
ARCHIVE DESTINATION ${OV_CPACK_ARCHIVEDIR} COMPONENT ${NPU_PLUGIN_COMPONENT}
LIBRARY DESTINATION ${OV_CPACK_LIBRARYDIR} COMPONENT ${NPU_PLUGIN_COMPONENT})

export(TARGETS ze_loader NAMESPACE openvino::
APPEND FILE "${CMAKE_BINARY_DIR}/OpenVINOTargets.cmake")

export(TARGETS utils NAMESPACE openvino::
APPEND FILE "${CMAKE_BINARY_DIR}/OpenVINOTargets.cmake")

# Support tests to run with ze_loader
install(TARGETS ze_loader
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/intel_npu/src/backend/include/zero_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class ZeroDevice : public IDevice {
public:
ZeroDevice(const std::shared_ptr<ZeroInitStructsHolder>& initStructs);

std::shared_ptr<IExecutor> createExecutor(const std::shared_ptr<IGraph>& graph, const Config& config) override;

std::string getName() const override;
std::string getFullDeviceName() const override;
Uuid getUuid() const override;
Expand All @@ -36,7 +34,6 @@ class ZeroDevice : public IDevice {

std::shared_ptr<SyncInferRequest> createInferRequest(const std::shared_ptr<const ICompiledModel>& compiledModel,
const std::shared_ptr<IGraph>& graph,
const std::shared_ptr<IExecutor>& executor,
const Config& config) override;
void updateInfo(const Config& config) override {
log.setLevel(config.get<LOG_LEVEL>());
Expand Down
15 changes: 7 additions & 8 deletions src/plugins/intel_npu/src/backend/include/zero_executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <mutex>

#include "igraph.hpp"
#include "intel_npu/utils/logger/logger.hpp"
#include "npu.hpp"
#include "openvino/runtime/properties.hpp"
Expand All @@ -20,15 +19,18 @@ namespace intel_npu {

class ZeroExecutor final : public IExecutor {
public:
ZeroExecutor(const std::shared_ptr<const ZeroInitStructsHolder>& initStructs,
const std::shared_ptr<IGraph>& graph,
ZeroExecutor(ze_graph_handle_t graphHandle,
ze_device_handle_t deviceHandle,
ze_context_handle_t contextHandle,
ze_graph_dditable_ext_curr_t& graphDdiTableExt,
ze_command_queue_npu_dditable_ext_curr_t& commandQueueDdiTable,
const Config& config,
uint32_t group_ordinal);
uint32_t groupOrdinal);

ZeroExecutor(const ZeroExecutor&) = delete;
ZeroExecutor& operator=(const ZeroExecutor&) = delete;

~ZeroExecutor() override;
~ZeroExecutor() override{};

struct ArgumentDescriptor {
ze_graph_argument_properties_3_t info;
Expand All @@ -53,9 +55,6 @@ class ZeroExecutor final : public IExecutor {
const Config _config;
Logger _logger;

const std::shared_ptr<const ZeroInitStructsHolder> _initStructs;
std::shared_ptr<IGraph> _graph;

std::vector<ArgumentDescriptor> _input_descriptors;
std::vector<ArgumentDescriptor> _output_descriptors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class ZeroInferRequest final : public SyncInferRequest {
explicit ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>& initStructs,
const std::shared_ptr<const ICompiledModel>& compiledModel,
const std::shared_ptr<IGraph>& graph,
const std::shared_ptr<const IExecutor>& executor,
const Config& config,
uint32_t group_ordinal);

Expand Down Expand Up @@ -87,7 +86,6 @@ class ZeroInferRequest final : public SyncInferRequest {

const std::shared_ptr<ZeroInitStructsHolder> _initStructs;
const std::shared_ptr<IGraph> _graph;
const std::shared_ptr<const IExecutor> _executorPtr;
const ZeroExecutor* _executor;
const uint32_t _group_ordinal;
const Config _config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ struct Pipeline {
Pipeline(const Config& config,
const std::shared_ptr<ZeroInitStructsHolder>& initStructs,
const std::shared_ptr<IGraph>& graph,
const std::shared_ptr<const IExecutor>& executorPtr,
zeroProfiling::ProfilingPool& profiling_pool,
zeroProfiling::ProfilingQuery& profiling_query,
std::shared_ptr<zeroProfiling::NpuInferProfiling> npu_profiling,
Expand Down
8 changes: 0 additions & 8 deletions src/plugins/intel_npu/src/backend/include/zero_wrappers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ namespace intel_npu {
class CommandList;
class CommandQueue;

enum stage {
UPLOAD,
EXECUTE,
READBACK,

COUNT
};

class EventPool {
public:
EventPool() = delete;
Expand Down
8 changes: 1 addition & 7 deletions src/plugins/intel_npu/src/backend/src/zero_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ ZeroDevice::ZeroDevice(const std::shared_ptr<ZeroInitStructsHolder>& initStructs
log.debug("ZeroDevice::ZeroDevice - init completed");
}

std::shared_ptr<IExecutor> ZeroDevice::createExecutor(const std::shared_ptr<IGraph>& graph, const Config& config) {
OV_ITT_SCOPED_TASK(itt::domains::LevelZeroBackend, "Device::createExecutor");
return std::make_shared<ZeroExecutor>(_initStructs, graph, config, _group_ordinal);
}

std::string ZeroDevice::getName() const {
// KMD is setting usDeviceID from VpuFamilyID.h
#define NPU_3720_P_DEVICE_ID 0x7D1D
Expand Down Expand Up @@ -172,9 +167,8 @@ uint32_t ZeroDevice::getGroupOrdinal() const {
std::shared_ptr<SyncInferRequest> ZeroDevice::createInferRequest(
const std::shared_ptr<const ICompiledModel>& compiledModel,
const std::shared_ptr<IGraph>& graph,
const std::shared_ptr<IExecutor>& executor,
const Config& config) {
return std::make_shared<ZeroInferRequest>(_initStructs, compiledModel, graph, executor, config, _group_ordinal);
return std::make_shared<ZeroInferRequest>(_initStructs, compiledModel, graph, config, _group_ordinal);
}

ov::SoPtr<ov::IRemoteTensor> ZeroDevice::createRemoteTensor(std::shared_ptr<ov::IRemoteContext> context,
Expand Down
Loading

0 comments on commit 50af560

Please sign in to comment.