Skip to content

Commit

Permalink
[ONNX] Add ONNX specific FrontEnd classes (openvinotoolkit#6615)
Browse files Browse the repository at this point in the history
This change implements a subset of FrontEnd API for ONNX:

Changes:
- move onnx_common, onnx_editor and onnx_import to ngraph/frontend/onnx
- introduce new target 'onnx_frontend_ngraph' located in ngraph/frontend/onnx/frontend
- new target implements subset of FrontEnd, InputModel and Place interfaces
  • Loading branch information
mateusztabaka authored and akuporos committed Sep 29, 2021
1 parent 3593fd8 commit 711af8c
Show file tree
Hide file tree
Showing 39 changed files with 852 additions and 318 deletions.
1 change: 1 addition & 0 deletions .ci/azure/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ jobs:
-DENABLE_WHEEL=ON
-DENABLE_TESTS=ON
-DNGRAPH_ONNX_IMPORT_ENABLE=ON
-DNGRAPH_ONNX_FRONTEND_ENABLE=ON
-DENABLE_FASTER_BUILD=ON
-DENABLE_STRICT_DEPENDENCIES=OFF
-DIE_EXTRA_MODULES=$(OPENVINO_CONTRIB_REPO_DIR)/modules
Expand Down
1 change: 1 addition & 0 deletions .ci/azure/linux_onnxruntime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ jobs:
-DENABLE_SAMPLES=OFF
-DENABLE_SPEECH_DEMO=OFF
-DNGRAPH_ONNX_IMPORT_ENABLE=ON
-DNGRAPH_ONNX_FRONTEND_ENABLE=ON
-DNGRAPH_DEBUG_ENABLE=OFF
$(REPO_DIR)
workingDirectory: $(BUILD_DIR)
Expand Down
1 change: 1 addition & 0 deletions .ci/openvino-onnx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ RUN cmake .. \
-DENABLE_PYTHON=ON \
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
-DNGRAPH_ONNX_IMPORT_ENABLE=ON \
-DNGRAPH_ONNX_FRONTEND_ENABLE=ON \
-DNGRAPH_DEBUG_ENABLE=OFF \
-DCMAKE_INSTALL_PREFIX=/openvino/dist \
-DNGRAPH_USE_PROTOBUF_LITE=${PROTOBUF_LITE}
Expand Down
12 changes: 9 additions & 3 deletions cmake/coverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,15 @@ ie_coverage_genhtml(INFO_FILE "ngraph"

if(NGRAPH_ONNX_IMPORT_ENABLE)
ie_coverage_extract(INPUT "openvino" OUTPUT "onnx_importer"
PATTERNS "${OV_COVERAGE_BASE_DIRECTORY}/ngraph/frontend/onnx_common*"
"${OV_COVERAGE_BASE_DIRECTORY}/ngraph/frontend/onnx_editor*"
"${OV_COVERAGE_BASE_DIRECTORY}/ngraph/frontend/onnx_import*")
PATTERNS "${OV_COVERAGE_BASE_DIRECTORY}/ngraph/frontend/onnx/onnx_common*"
"${OV_COVERAGE_BASE_DIRECTORY}/ngraph/frontend/onnx/onnx_import*")
ie_coverage_genhtml(INFO_FILE "onnx_importer"
PREFIX "${OV_COVERAGE_BASE_DIRECTORY}")
endif()

if(NGRAPH_ONNX_FRONTEND_ENABLE)
ie_coverage_extract(INPUT "openvino" OUTPUT "onnx_ngraph_frontend"
PATTERNS "${OV_COVERAGE_BASE_DIRECTORY}/ngraph/frontend/onnx/frontend*")
ie_coverage_genhtml(INFO_FILE "onnx_ngraph_frontend"
PREFIX "${OV_COVERAGE_BASE_DIRECTORY}")
endif()
1 change: 1 addition & 0 deletions cmake/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ else()
endif()

ie_dependent_option(NGRAPH_ONNX_IMPORT_ENABLE "Enable ONNX importer" ON "protoc_available" OFF)
ie_dependent_option(NGRAPH_ONNX_FRONTEND_ENABLE "Enable ONNX FrontEnd" OFF "NGRAPH_ONNX_IMPORT_ENABLE" OFF)
ie_dependent_option(NGRAPH_PDPD_FRONTEND_ENABLE "Enable PaddlePaddle FrontEnd" ON "protoc_available" OFF)
ie_dependent_option(NGRAPH_USE_PROTOBUF_LITE "Compiles and links with protobuf-lite" OFF
"NGRAPH_ONNX_IMPORT_ENABLE OR NGRAPH_PDPD_FRONTEND_ENABLE" OFF)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace ngraph
/// \param partiallyConverted partially converted nGraph function
/// \return fully converted nGraph function
virtual std::shared_ptr<ngraph::Function>
convert(std::shared_ptr<ngraph::Function> partiallyConverted) const;
convert(std::shared_ptr<ngraph::Function> partially_converted) const;

/// \brief Convert only those parts of the model that can be converted leaving others
/// as-is. Converted parts are not normalized by additional transformations; normalize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,47 +68,47 @@ namespace ngraph

/// \brief Returns a tensor place by a tensor name following framework conventions, or
/// nullptr if a tensor with this name doesn't exist.
/// \param tensorName Name of tensor
/// \param tensor_name Name of tensor
/// \return Tensor place corresponding to specifed tensor name
virtual Place::Ptr get_place_by_tensor_name(const std::string& tensorName) const;
virtual Place::Ptr get_place_by_tensor_name(const std::string& tensor_name) const;

/// \brief Returns an operation place by an operation name following framework
/// conventions, or nullptr if an operation with this name doesn't exist. \param
/// operationName Name of operation \return Place representing operation
virtual Place::Ptr get_place_by_operation_name(const std::string& operationName);
/// operation_name Name of operation \return Place representing operation
virtual Place::Ptr get_place_by_operation_name(const std::string& operation_name);

/// \brief Returns an input port place by operation name and appropriate port index
/// \param operationName Name of operation
/// \param outputPortIndex Index of input port for this operation
/// \param operation_name Name of operation
/// \param output_port_index Index of input port for this operation
/// \return Place representing input port of operation
virtual Place::Ptr
get_place_by_operation_name_and_input_port(const std::string& operationName,
int inputPortIndex);
get_place_by_operation_name_and_input_port(const std::string& operation_name,
int input_port_index);

/// \brief Returns an output port place by operation name and appropriate port index
/// \param operationNameNname of operation
/// \param outputPortIndex Index of output port for this operation
/// \param operation_name Name of operation
/// \param output_port_index Index of output port for this operation
/// \return Place representing output port of operation
virtual Place::Ptr
get_place_by_operation_name_and_output_port(const std::string& operationName,
int outputPortIndex);
get_place_by_operation_name_and_output_port(const std::string& operation_name,
int output_port_index);

///// Naming and annotation /////

/// \brief Sets name for tensor. Overwrites existing names of this place
/// \param operation Tensor place
/// \param newName New name for this tensor
virtual void set_name_for_tensor(Place::Ptr tensor, const std::string& newName);
/// \param new_name New name for this tensor
virtual void set_name_for_tensor(Place::Ptr tensor, const std::string& new_name);

/// \brief Adds new name for tensor
/// \param operation Tensor place
/// \param newName New name to be added to this place
virtual void add_name_for_tensor(Place::Ptr tensor, const std::string& newName);
/// \param new_name New name to be added to this place
virtual void add_name_for_tensor(Place::Ptr tensor, const std::string& new_name);

/// \brief Sets name for operation. Overwrites existing names of this place
/// \param operation Operation place
/// \param newName New name for this operation
virtual void set_name_for_operation(Place::Ptr operation, const std::string& newName);
/// \param new_name New name for this operation
virtual void set_name_for_operation(Place::Ptr operation, const std::string& new_name);

/// \brief Unassign specified name from tensor place(s)
/// \param name Name of tensor
Expand All @@ -120,27 +120,27 @@ namespace ngraph

/// \brief Set name for a particular dimension of a place (e.g. batch dimension)
/// \param place Model's place
/// \param shapeDimIndex Dimension index
/// \param dimName Name to assign on this dimension
/// \param shape_dim_index Dimension index
/// \param dim_name Name to assign on this dimension
virtual void set_name_for_dimension(Place::Ptr place,
size_t shapeDimIndex,
const std::string& dimName);
size_t shape_dim_index,
const std::string& dim_name);

///// Topology Editing /////

/// \brief Cut immediately before this place and assign this place as new input; prune
/// all nodes that don't contribute to any output.
/// \param place New place to be assigned as input
/// \param newNameOptional Optional new name assigned to this input place
/// \param new_name_optional Optional new name assigned to this input place
virtual void cut_and_add_new_input(Place::Ptr place,
const std::string& newNameOptional = "");
const std::string& new_name_optional = "");

/// \brief Cut immediately after this place and assign this place as new output; prune
/// all nodes that don't contribute to any output.
/// \param place New place to be assigned as output
/// \param newNameOptional Optional new name assigned to this output place
/// \param new_name_optional Optional new name assigned to this output place
virtual void cut_and_add_new_output(Place::Ptr place,
const std::string& newNameOptional = "");
const std::string& new_name_optional = "");

/// \brief Assign this place as new output or add necessary nodes to represent a new
/// output.
Expand Down Expand Up @@ -200,13 +200,13 @@ namespace ngraph
virtual void set_tensor_value(Place::Ptr place, const void* value);

/// \brief Defines partial value (lower bound and upper bound) for a tensor place
/// TODO: more details for minValue and maxValue format; who defines shape?
/// TODO: more details for min_value and max_value format; who defines shape?
/// \param place Tensor place
/// \param minValue Lower bound of partial value for tensor place
/// \param maxValue Upper bound of partial value for tensor place
/// \param min_value Lower bound of partial value for tensor place
/// \param max_value Upper bound of partial value for tensor place
virtual void set_tensor_partial_value(Place::Ptr place,
const void* minValue,
const void* maxValue);
const void* min_value,
const void* max_value);
};

} // namespace frontend
Expand Down
47 changes: 24 additions & 23 deletions ngraph/frontend/frontend_manager/include/frontend_manager/place.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ namespace ngraph
/// \note It can be called for any kind of graph place searching for the first consuming
/// operations.
///
/// \param outputPortIndex If place is an operational node it specifies which output
/// \param output_port_index If place is an operational node it specifies which output
/// port should be considered.
///
/// \return A vector with all operation node references that consumes data from this
/// place
virtual std::vector<Ptr> get_consuming_operations(int outputPortIndex) const;
virtual std::vector<Ptr> get_consuming_operations(int output_port_index) const;

/// \brief Returns a tensor place that gets data from this place; applicable for
/// operations, output ports and output edges which have only one output port
Expand All @@ -103,11 +103,11 @@ namespace ngraph
/// \brief Returns a tensor place that gets data from this place; applicable for
/// operations, output ports and output edges
///
/// \param outputPortIndex Output port index if the current place is an operation node
/// \param output_port_index Output port index if the current place is an operation node
/// and has multiple output ports
///
/// \return A tensor place which hold the resulting value for this place
virtual Ptr get_target_tensor(int outputPortIndex) const;
virtual Ptr get_target_tensor(int output_port_index) const;

/// \brief Returns a tensor place that supplies data for this place; applicable for
/// operations, input ports and input edges which have only one input port
Expand All @@ -118,10 +118,10 @@ namespace ngraph
/// \brief Returns a tensor place that supplies data for this place; applicable for
/// operations, input ports and input edges
///
/// \param inputPortIndex Input port index for operational nodes.
/// \param input_port_index Input port index for operational nodes.
///
/// \return A tensor place which supplies data for this place
virtual Ptr get_source_tensor(int inputPortIndex) const;
virtual Ptr get_source_tensor(int input_port_index) const;

/// \brief Get an operation node place that immediately produces data for this place;
/// applicable if place has only one input port
Expand All @@ -131,11 +131,11 @@ namespace ngraph

/// \brief Get an operation node place that immediately produces data for this place
///
/// \param inputPortIndex If a given place is itself an operation node, this specifies a
/// port index
/// \param input_port_index If a given place is itself an operation node, this specifies
/// a port index
///
/// \return An operation place that produces data for this place
virtual Ptr get_producing_operation(int inputPortIndex) const;
virtual Ptr get_producing_operation(int input_port_index) const;

/// Returns a port that produces data for this place
virtual Ptr get_producing_port() const;
Expand All @@ -148,28 +148,28 @@ namespace ngraph

/// \brief For operation node returns reference to an input port with specified index
///
/// \param inputPortIndex Input port index
/// \param input_port_index Input port index
///
/// \return Appropriate input port place
virtual Ptr get_input_port(int inputPortIndex) const;
virtual Ptr get_input_port(int input_port_index) const;

/// \brief For operation node returns reference to an input port with specified name;
/// applicable if port group has only one input port
///
/// \param inputName Name of port group
/// \param input_name Name of port group
///
/// \return Appropriate input port place
virtual Ptr get_input_port(const std::string& inputName) const;
virtual Ptr get_input_port(const std::string& input_name) const;

/// \brief For operation node returns reference to an input port with specified name and
/// index
///
/// \param inputName Name of port group, each group can have multiple ports
/// \param input_name Name of port group, each group can have multiple ports
///
/// \param inputPortIndex Input port index in a group
/// \param input_port_index Input port index in a group
///
/// \return Appropriate input port place
virtual Ptr get_input_port(const std::string& inputName, int inputPortIndex) const;
virtual Ptr get_input_port(const std::string& input_name, int input_port_index) const;

/// \brief For operation node returns reference to an output port; applicable for
/// operations with only one output port
Expand All @@ -179,28 +179,29 @@ namespace ngraph

/// \brief For operation node returns reference to an output port with specified index
///
/// \param outputPortIndex Output port index
/// \param output_port_index Output port index
///
/// \return Appropriate output port place
virtual Ptr get_output_port(int outputPortIndex) const;
virtual Ptr get_output_port(int output_port_index) const;

/// \brief For operation node returns reference to an output port with specified name;
/// applicable if port group has only one output port
///
/// \param outputName Name of output port group
/// \param output_name Name of output port group
///
/// \return Appropriate output port place
virtual Ptr get_output_port(const std::string& outputName) const;
virtual Ptr get_output_port(const std::string& output_name) const;

/// \brief For operation node returns reference to an output port with specified name
/// and index
///
/// \param outputName Name of output port group, each group can have multiple ports
/// \param output_name Name of output port group, each group can have multiple ports
///
/// \param outputPortIndex Output port index
/// \param output_port_index Output port index
///
/// \return Appropriate output port place
virtual Ptr get_output_port(const std::string& outputName, int outputPortIndex) const;
virtual Ptr get_output_port(const std::string& output_name,
int output_port_index) const;

/// \brief Returns all input ports that consume data flows through this place
virtual std::vector<Place::Ptr> get_consuming_ports() const;
Expand Down
Loading

0 comments on commit 711af8c

Please sign in to comment.