Skip to content

Commit

Permalink
Renaming the I/O descriptor structure
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanapetroaie committed Apr 26, 2024
1 parent 6f0e530 commit 329edac
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 57 deletions.
30 changes: 11 additions & 19 deletions src/plugins/intel_npu/src/al/include/intel_npu/al/icompiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,29 @@ namespace intel_npu {
* upon applying a transposition corresponding to the legacy layout value. Use the "transposedShape" one if not sure
* which one you need.
*/
struct IONodeDescriptor {
std::string legacyName;
std::string currentNodeName;
struct IODescriptor {
std::string nameFromCompiler;
std::string nodeFriendlyName;
std::unordered_set<std::string> outputTensorNames;
ov::element::Type_t precision;
ov::PartialShape originalShape;
ov::PartialShape transposedShape;
ov::PartialShape shape;
bool isStateInput;
bool isStateOutput;
bool isShapeTensor;
};

/**
* @brief A helper map to represent descriptions for inputs and outputs
* of a network
*/
using IONodeDescriptorMap = std::unordered_map<std::string, IONodeDescriptor>;
using std::vector<IODescriptor> = std::vector<IODescriptor>;

struct NetworkMetadata final {
std::string name;

std::vector<std::string> inputNames;
std::vector<std::string> outputNames;
std::vector<std::string> stateNames;
std::vector<std::string> shapeNames;

IONodeDescriptorMap parameters;
IONodeDescriptorMap results;
IONodeDescriptorMap states;
IONodeDescriptorMap shapes;
IONodeDescriptorMap profilingOutputs;

std::unordered_map<std::string, size_t> inputOrder;
std::unordered_map<std::string, size_t> outputOrder;
std::vector<IODescriptor> inputs;
std::vector<IODescriptor> outputs;
std::vector<IODescriptor> profilingOutputs;

int numStreams = 1;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class SyncInferRequest : public ov::IInferRequest {
* @param allocator If provided, the tensor uses the custom allocator instead of using the default one.
*/
void allocate_tensor(std::string tensorName,
const IONodeDescriptor& descriptor,
const IODescriptor& descriptor,
TensorType tensorType = TensorType::InputOrOutput,
const ov::Allocator& allocator = {});

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_npu/src/al/src/sync_infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void SyncInferRequest::check_tensors() const {
}

void SyncInferRequest::allocate_tensor(std::string tensorName,
const IONodeDescriptor& descriptor,
const IODescriptor& descriptor,
TensorType tensorType,
const ov::Allocator& allocator) {
std::shared_ptr<ov::ITensor> tensor;
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace {
* @param zeDescriptor The Level Zero specific structure used for comparison.
* @param name Tensor identifier used for error logging.
*/
void check_level_zero_attributes_match(const IONodeDescriptor& nodeDescriptor,
void check_level_zero_attributes_match(const IODescriptor& nodeDescriptor,
const ZeroExecutor::ArgumentDescriptor& zeDescriptor,
const std::string& name) {
const ov::element::Type_t ovPrecision = nodeDescriptor.precision;
Expand Down Expand Up @@ -98,7 +98,7 @@ ZeroInferRequest::ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>&
OPENVINO_THROW("Invalid graph input descriptor key: " + inputName);
}

const IONodeDescriptor& parameterDescriptor = _metadata.parameters.at(inputName);
const IODescriptor& parameterDescriptor = _metadata.parameters.at(inputName);
check_level_zero_attributes_match(parameterDescriptor, executorInputDescriptors.at(inputName), inputName);

ov::Allocator inputAllocator;
Expand All @@ -113,7 +113,7 @@ ZeroInferRequest::ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>&

if (contains(_metadata.shapeNames, inputName)) {
const std::string shapeBufferName = SHAPE_TENSOR_PREFIX + inputName;
const IONodeDescriptor& shapeDescriptor = _metadata.shapes.at(inputName);
const IODescriptor& shapeDescriptor = _metadata.shapes.at(inputName);

check_level_zero_attributes_match(shapeDescriptor,
executorInputDescriptors.at(shapeBufferName),
Expand All @@ -128,7 +128,7 @@ ZeroInferRequest::ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>&
OPENVINO_THROW("Invalid graph output descriptor key: " + outputName);
}

const IONodeDescriptor& resultDescriptor = _metadata.results.at(outputName);
const IODescriptor& resultDescriptor = _metadata.results.at(outputName);
check_level_zero_attributes_match(resultDescriptor, executorOutputDescriptors.at(outputName), outputName);

allocate_tensor(outputName, resultDescriptor, TensorType::InputOrOutput, allocator);
Expand All @@ -137,7 +137,7 @@ ZeroInferRequest::ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>&
if (shapeNameMatch != _nodeNameToLegacyName.end()) {
if (contains(_metadata.shapeNames, shapeNameMatch->second)) {
const std::string shapeBufferName = SHAPE_TENSOR_PREFIX + shapeNameMatch->second;
const IONodeDescriptor& shapeDescriptor = _metadata.shapes.at(shapeNameMatch->second);
const IODescriptor& shapeDescriptor = _metadata.shapes.at(shapeNameMatch->second);

check_level_zero_attributes_match(shapeDescriptor,
executorOutputDescriptors.at(shapeBufferName),
Expand All @@ -159,7 +159,7 @@ ZeroInferRequest::ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>&
OPENVINO_THROW("Invalid graph output descriptor key: " + stateOutputBufferName);
}

const IONodeDescriptor& stateDescriptor = _metadata.states.at(stateName);
const IODescriptor& stateDescriptor = _metadata.states.at(stateName);
check_level_zero_attributes_match(stateDescriptor,
executorInputDescriptors.at(stateInputBufferName),
stateInputBufferName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ class LevelZeroCompilerInDriver final : public IExternalCompiler {
* extracted.
*/
template <typename T>
void getLayoutOrStateDescriptor(IONodeDescriptorMap& parameters,
IONodeDescriptorMap& results,
IONodeDescriptorMap& states,
void getLayoutOrStateDescriptor(std::vector<IODescriptor>& parameters,
std::vector<IODescriptor>& results,
std::vector<IODescriptor>& states,
std::vector<std::string>& stateNames,
const T& arg) const;

Expand All @@ -127,9 +127,9 @@ class LevelZeroCompilerInDriver final : public IExternalCompiler {
*/
template <typename T = TableExtension,
std::enable_if_t<std::is_same<T, ze_graph_dditable_ext_t>::value, bool> = true>
void getNodeOrStateDescriptorLegacy(IONodeDescriptorMap& parameters,
IONodeDescriptorMap& results,
IONodeDescriptorMap& states,
void getNodeOrStateDescriptorLegacy(std::vector<IODescriptor>& parameters,
std::vector<IODescriptor>& results,
std::vector<IODescriptor>& states,
std::vector<std::string>& inputNames,
std::vector<std::string>& outputNames,
std::vector<std::string>& stateNames,
Expand All @@ -141,9 +141,9 @@ class LevelZeroCompilerInDriver final : public IExternalCompiler {
std::vector<std::string>& inputNames,
std::vector<std::string>& outputNames,
std::vector<std::string>& stateNames,
IONodeDescriptorMap& parameters,
IONodeDescriptorMap& results,
IONodeDescriptorMap& state) const;
std::vector<IODescriptor>& parameters,
std::vector<IODescriptor>& results,
std::vector<IODescriptor>& state) const;

// ext version >= 1.5, support API (pfnCreate2, pfnQueryNetworkCreate2, pfnQueryContextMemory)
template <typename T = TableExtension, typename std::enable_if_t<SupportAPIGraphQueryNetworkV2(T), bool> = true>
Expand Down
34 changes: 17 additions & 17 deletions src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,9 @@ uint32_t LevelZeroCompilerInDriver<TableExtension>::getSupportedOpset() const {

template <typename TableExtension>
template <typename T>
void LevelZeroCompilerInDriver<TableExtension>::getLayoutOrStateDescriptor(IONodeDescriptorMap& parameters,
IONodeDescriptorMap& results,
IONodeDescriptorMap& states,
void LevelZeroCompilerInDriver<TableExtension>::getLayoutOrStateDescriptor(std::vector<IODescriptor>& parameters,
std::vector<IODescriptor>& results,
std::vector<IODescriptor>& states,
std::vector<std::string>& stateNames,
const T& arg) const {
std::string legacyName = arg.name;
Expand Down Expand Up @@ -913,9 +913,9 @@ void LevelZeroCompilerInDriver<TableExtension>::getLayoutOrStateDescriptor(IONod
template <typename TableExtension>
template <typename T, std::enable_if_t<std::is_same<T, ze_graph_dditable_ext_t>::value, bool>>
void LevelZeroCompilerInDriver<TableExtension>::getNodeOrStateDescriptorLegacy(
IONodeDescriptorMap& parameters,
IONodeDescriptorMap& results,
IONodeDescriptorMap& states,
std::vector<IODescriptor>& parameters,
std::vector<IODescriptor>& results,
std::vector<IODescriptor>& states,
std::vector<std::string>& inputNames,
std::vector<std::string>& outputNames,
std::vector<std::string>& stateNames,
Expand Down Expand Up @@ -961,7 +961,7 @@ void LevelZeroCompilerInDriver<TableExtension>::getNodeOrStateDescriptorLegacy(
* @param names The I/O identifiers shall be stored here in the order found within the compiled model.
* @param metadata The Level Zero structure fomr which the descriptors will be extracted.
*/
static void getNodeDescriptor(IONodeDescriptorMap& nodeDescriptors,
static void getNodeDescriptor(std::vector<IODescriptor>& nodeDescriptors,
std::vector<std::string>& names,
ze_graph_argument_metadata_t& metadata) {
const ov::element::Type_t precision = toOVElementType(metadata.data_type);
Expand All @@ -981,7 +981,7 @@ static void getNodeDescriptor(IONodeDescriptorMap& nodeDescriptors,
{legacyName, metadata.friendly_name, std::move(outputTensorNames), precision, shape, shape};
}

static void getNodeDescriptor(IONodeDescriptorMap& nodeDescriptors,
static void getNodeDescriptor(std::vector<IODescriptor>& nodeDescriptors,
std::vector<std::string>& names,
ze_graph_argument_properties_3_t& arg) {
ov::element::Type_t precision = toOVElementType(arg.devicePrecision);
Expand All @@ -1008,9 +1008,9 @@ void LevelZeroCompilerInDriver<ze_graph_dditable_ext_t>::getMetadata(ze_graph_dd
std::vector<std::string>& inputNames,
std::vector<std::string>& outputNames,
std::vector<std::string>& stateNames,
IONodeDescriptorMap& parameters,
IONodeDescriptorMap& results,
IONodeDescriptorMap& states) const {
std::vector<IODescriptor>& parameters,
std::vector<IODescriptor>& results,
std::vector<IODescriptor>& states) const {
ze_graph_argument_properties_t arg;
auto result = graphDdiTableExt->pfnGetArgumentProperties(graphHandle, index, &arg);
if (ZE_RESULT_SUCCESS != result) {
Expand All @@ -1032,9 +1032,9 @@ void LevelZeroCompilerInDriver<ze_graph_dditable_ext_1_1_t>::getMetadata(ze_grap
std::vector<std::string>& inputNames,
std::vector<std::string>& outputNames,
std::vector<std::string>& stateNames,
IONodeDescriptorMap& parameters,
IONodeDescriptorMap& results,
IONodeDescriptorMap& states) const {
std::vector<IODescriptor>& parameters,
std::vector<IODescriptor>& results,
std::vector<IODescriptor>& states) const {
ze_graph_argument_properties_2_t arg;
auto result = graphDdiTableExt->pfnGetArgumentProperties2(graphHandle, index, &arg);
if (ZE_RESULT_SUCCESS != result) {
Expand Down Expand Up @@ -1078,9 +1078,9 @@ void LevelZeroCompilerInDriver<TableExtension>::getMetadata(TableExtension* grap
std::vector<std::string>& inputNames,
std::vector<std::string>& outputNames,
std::vector<std::string>& stateNames,
IONodeDescriptorMap& parameters,
IONodeDescriptorMap& results,
IONodeDescriptorMap& states) const {
std::vector<IODescriptor>& parameters,
std::vector<IODescriptor>& results,
std::vector<IODescriptor>& states) const {
ze_graph_argument_properties_3_t arg;
auto result = graphDdiTableExt->pfnGetArgumentProperties3(graphHandle, index, &arg);
if (ZE_RESULT_SUCCESS != result) {
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/intel_npu/src/plugin/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ const char* NPU_PLUGIN_LIB_NAME = "openvino_intel_npu_plugin";
* @param inputNames The names of the inputs registered in the order given by the model.
* @param outputNames The names of the outputs registered in the order given by the model.
*/
std::shared_ptr<ov::Model> create_dummy_model(const IONodeDescriptorMap& parameterDescriptors,
const IONodeDescriptorMap& resultDescriptors,
std::shared_ptr<ov::Model> create_dummy_model(const std::vector<IODescriptor>& parameterDescriptors,
const std::vector<IODescriptor>& resultDescriptors,
const std::vector<std::string>& inputNames,
const std::vector<std::string>& outputNames) {
ov::ParameterVector parameters;
ov::NodeVector results;

for (const std::string& inputName : inputNames) {
const IONodeDescriptor& parameterDescriptor = parameterDescriptors.at(inputName);
const IODescriptor& parameterDescriptor = parameterDescriptors.at(inputName);
std::shared_ptr<ov::op::v0::Parameter> parameter =
std::make_shared<ov::op::v0::Parameter>(parameterDescriptor.precision, parameterDescriptor.transposedShape);
parameter->set_friendly_name(parameterDescriptor.currentNodeName);
Expand All @@ -60,7 +60,7 @@ std::shared_ptr<ov::Model> create_dummy_model(const IONodeDescriptorMap& paramet
// constant can't have dynamic shape). The dummy tensor was also brought in order to register the correct,
// potentially dynamic, output shape.
for (const std::string& outputName : outputNames) {
const IONodeDescriptor& resultDescriptor = resultDescriptors.at(outputName);
const IODescriptor& resultDescriptor = resultDescriptors.at(outputName);
std::shared_ptr<ov::Node> constantDummy =
std::make_shared<ov::op::v0::Constant>(resultDescriptor.precision, CONSTANT_NODE_DUMMY_SHAPE);
constantDummy->set_friendly_name(resultDescriptor.legacyName);
Expand Down

0 comments on commit 329edac

Please sign in to comment.