onnxruntime/onnxruntime/core/optimizer/shape_input_merge.h
Vincent Wang 0c078dfc8b
Some Shape Related Fusions (#19832)
This PR adds below shape related fusions, which is helpful for some
transformer models:
- ShapeInputMerge is to merge all Shape nodes' input NodeArg to a single
one (the 1st one on topo order) if they have the same shape value. This
helps CSE fusion to merge more nodes.
- CSE fusion to support scalar tensor as attribute value. This is mainly
to support ConstantOfShape node.
2024-03-12 10:29:27 +08:00

23 lines
769 B
C++

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
#include "core/optimizer/graph_transformer.h"
namespace onnxruntime {
/**
@Class ShapeInputMerge
Merge all shape inputs having same shape value to a single shape input.
This change will not affect the performance, but it open chances for CSE fusion to merge nodes.
*/
class ShapeInputMerge : public GraphTransformer {
public:
ShapeInputMerge(const InlinedHashSet<std::string_view>& compatible_execution_providers = {}) noexcept
: GraphTransformer("ShapeInputMerge", compatible_execution_providers) {}
Status ApplyImpl(Graph& graph, bool& modified, int graph_level, const logging::Logger& logger) const override;
};
} // namespace onnxruntime