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 May 1, 2024
1 parent ac27cd6 commit c904368
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 50 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 @@ -160,7 +160,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
10 changes: 5 additions & 5 deletions src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ constexpr std::size_t BATCH_AXIS = 0;
* @param zeDescriptor The Level Zero specific structure used for comparison.
* @param name Tensor identifier used for error logging.
*/
void checkLevelZeroAttributesMatch(const IONodeDescriptor& nodeDescriptor,
void checkLevelZeroAttributesMatch(const IODescriptor& nodeDescriptor,
const ZeroExecutor::ArgumentDescriptor& zeDescriptor,
const std::string& name) {
const ov::element::Type_t ovPrecision = nodeDescriptor.precision;
Expand Down Expand Up @@ -197,7 +197,7 @@ ZeroInferRequest::ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>&
}

for (const std::string& inputName : _metadata.inputNames) {
IONodeDescriptor& parameterDescriptor = _metadata.parameters.at(inputName);
IODescriptor& parameterDescriptor = _metadata.parameters.at(inputName);
checkLevelZeroAttributesMatch(parameterDescriptor, executorInputDescriptors.at(inputName), inputName);

ov::Allocator inputAllocator;
Expand All @@ -218,7 +218,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);

checkLevelZeroAttributesMatch(shapeDescriptor,
executorInputDescriptors.at(shapeBufferName),
Expand All @@ -244,7 +244,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);

checkLevelZeroAttributesMatch(shapeDescriptor,
executorOutputDescriptors.at(shapeBufferName),
Expand All @@ -266,7 +266,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);
checkLevelZeroAttributesMatch(stateDescriptor,
executorInputDescriptors.at(stateInputBufferName),
stateInputBufferName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ class LevelZeroCompilerInDriver final : public IExternalCompiler {
* be 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 @@ -117,9 +117,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;

template <typename T = TableExtension, typename std::enable_if_t<!NotSupportOriginalShape(T), bool> = true>
void getMetadata(TableExtension* graphDdiTableExt,
Expand All @@ -128,9 +128,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
22 changes: 11 additions & 11 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 @@ -841,9 +841,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 @@ -885,7 +885,7 @@ void LevelZeroCompilerInDriver<TableExtension>::getLayoutOrStateDescriptor(IONod
* @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_properties_3_t& arg) {
ov::element::Type_t precision = toOVElementType(arg.devicePrecision);
Expand All @@ -907,7 +907,7 @@ static void getNodeDescriptor(IONodeDescriptorMap& nodeDescriptors,
{legacyName, arg.debug_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,
ze_graph_argument_metadata_t& metadata) {
Expand Down Expand Up @@ -942,9 +942,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 Expand Up @@ -977,9 +977,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 @@ -39,16 +39,16 @@ const char* NPU_PLUGIN_LIB_NAME = "openvino_intel_npu_plugin";
* @param outputNames The names of the outputs registered in the order given by the model.
* @param isBatchingSupported Newer driver versions support batching mode on the plugin.
*/
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,
bool isBatchingSupported) {
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 = [&] {
if (isBatchingSupported) {
Expand All @@ -70,7 +70,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 c904368

Please sign in to comment.