// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once #include "core/optimizer/transpose_optimization/optimizer_api.h" #include "core/optimizer/transpose_optimization/onnx_transpose_optimization.h" namespace onnxruntime { /// /// Get the extended handlers for ORT specific transpose optimization. /// These include handlers for contrib ops, and where we have an NHWC version of a layout sensitive op. /// /// HandlerMap const onnx_transpose_optimization::HandlerMap& OrtExtendedHandlers(); /// /// Cost check function for transpose optimizer that takes into account implementation details of the /// ORT execution provider kernels. /// /// The graph being optimized /// The node we're considering pushing a Transpose through /// The perm value of the Transpose /// The set of outputs that lead to another Transpose in the graph. /// If we can successfully push the Transpose until it meets another Transpose they can either cancel each other out, /// or be merged into a single Transpose. /// /// CostCheckResult indicating the action the transpose optimizer should perform. onnx_transpose_optimization::CostCheckResult OrtEPCostCheck( const onnx_transpose_optimization::api::GraphRef& graph, const onnx_transpose_optimization::api::NodeRef& node, const std::vector& perm, const std::unordered_set& outputs_leading_to_transpose); /// /// Swaps out a node for a new copy of that node with the specified op type and domain. /// Current API does not allow nodes to have their op types or domains changed, so a new node is needed. All /// attributes, inputs, and outputs are moved to the new node. The old node is removed from the graph and should no /// longer be accessed. /// /// Graph containing the node /// Node to copy and remove /// New node op_type /// New node domain. "" for the default domain. /// The newly created node. std::unique_ptr SwapNodeOpTypeAndDomain(onnx_transpose_optimization::api::GraphRef& graph, onnx_transpose_optimization::api::NodeRef& node, std::string_view op_type, std::string_view domain); /// /// Swaps out a node for a new copy of that node with the specified op type, domain, and since version. /// Current API does not allow nodes to have their op types or domains changed, so a new node is needed. All /// attributes, inputs, and outputs are moved to the new node. The old node is removed from the graph and should no /// longer be accessed. /// /// Graph containing the node /// Node to copy and remove /// New node op_type /// New node domain. "" for the default domain. /// New node since version. /// The newly created node. std::unique_ptr SwapNodeOpTypeDomainAndSinceVersion(onnx_transpose_optimization::api::GraphRef& graph, onnx_transpose_optimization::api::NodeRef& node, std::string_view op_type, std::string_view domain, int since_version); } // namespace onnxruntime