Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:42:46

0001 // Copyright (c) ONNX Project Contributors
0002 
0003 /*
0004  * SPDX-License-Identifier: Apache-2.0
0005  */
0006 
0007 #include <memory>
0008 #include <string>
0009 #include <utility>
0010 #include <vector>
0011 
0012 #include "onnx/onnx_pb.h"
0013 
0014 namespace ONNX_NAMESPACE {
0015 namespace inliner {
0016 
0017 // A FunctionId is a pair of strings (domain, function name).
0018 using FunctionId = std::pair<std::string, std::string>;
0019 
0020 // A vector of FunctionIds.
0021 using FunctionIdVector = std::vector<FunctionId>;
0022 
0023 // Interface used to represent a set of function ids for the inliner.
0024 class FunctionIdSet {
0025  public:
0026   virtual bool Contains(const std::string& function_domain, const std::string& function_name) const = 0;
0027   virtual ~FunctionIdSet() = default;
0028 
0029   // Factory methods for creating FunctionIdSet instances.
0030 
0031   // Creates a set representing the elements in the given vector, if invert is false.
0032   // Otherwise, creates a set representing elements not in the given vector.
0033   static std::unique_ptr<FunctionIdSet> Create(FunctionIdVector&& function_ids, bool invert = false);
0034 };
0035 
0036 // Inlines the model-local functions in the given model that are in the given set.
0037 // The inlined functions are removed from the model's list of functions as well.
0038 
0039 void InlineSelectedFunctions(ModelProto& model, const FunctionIdSet& to_inline);
0040 
0041 // Inlines all model-local functions in the given model. This supports version
0042 // conversion, an advanced feature that is not enabled by default. When enabled,
0043 // the inliner will attempt to convert the version of the inlined function to
0044 // match the version of the model. If not enabled, the inliner will only inline
0045 // functions that use opset versions that are compatible with the model.
0046 void InlineLocalFunctions(ModelProto& model, bool convert_version = false);
0047 
0048 } // namespace inliner
0049 } // namespace ONNX_NAMESPACE