Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:03:56

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 // IR version 10 introduces overloaded function names. The following APIs to specify
0018 // functions to be inlined currently allow only specifying (domain, name). Thus,
0019 // either all overloads of a function are inlined or none.
0020 // The older-style ids are used below for backward compatibility.
0021 
0022 // A FunctionId is a pair of strings (domain, function name).
0023 using FunctionId = std::pair<std::string, std::string>;
0024 
0025 // A vector of FunctionIds.
0026 using FunctionIdVector = std::vector<FunctionId>;
0027 
0028 // Interface used to represent a set of function ids for the inliner.
0029 class FunctionIdSet {
0030  public:
0031   virtual bool Contains(const std::string& function_domain, const std::string& function_name) const = 0;
0032   virtual ~FunctionIdSet() = default;
0033 
0034   // Factory methods for creating FunctionIdSet instances.
0035 
0036   // Creates a set representing the elements in the given vector, if invert is false.
0037   // Otherwise, creates a set representing elements not in the given vector.
0038   static std::unique_ptr<FunctionIdSet> Create(FunctionIdVector&& function_ids, bool invert = false);
0039 };
0040 
0041 // Inlines the model-local functions in the given model that are in the given set.
0042 // The inlined functions are removed from the model's list of functions as well.
0043 
0044 void InlineSelectedFunctions(ModelProto& model, const FunctionIdSet& to_inline);
0045 
0046 // Inlines all model-local functions in the given model. This supports version
0047 // conversion, an advanced feature that is not enabled by default. When enabled,
0048 // the inliner will attempt to convert the version of the inlined function to
0049 // match the version of the model. If not enabled, the inliner will only inline
0050 // functions that use opset versions that are compatible with the model.
0051 void InlineLocalFunctions(ModelProto& model, bool convert_version = false);
0052 
0053 } // namespace inliner
0054 } // namespace ONNX_NAMESPACE