xref: /aosp_15_r20/external/armnn/include/armnnOnnxParser/IOnnxParser.hpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1*89c4ff92SAndroid Build Coastguard Worker //
2*89c4ff92SAndroid Build Coastguard Worker // Copyright © 2017,2022 Arm Ltd. All rights reserved.
3*89c4ff92SAndroid Build Coastguard Worker // SPDX-License-Identifier: MIT
4*89c4ff92SAndroid Build Coastguard Worker //
5*89c4ff92SAndroid Build Coastguard Worker #pragma once
6*89c4ff92SAndroid Build Coastguard Worker 
7*89c4ff92SAndroid Build Coastguard Worker #include <armnn/INetwork.hpp>
8*89c4ff92SAndroid Build Coastguard Worker #include <armnn/Tensor.hpp>
9*89c4ff92SAndroid Build Coastguard Worker 
10*89c4ff92SAndroid Build Coastguard Worker #include <memory>
11*89c4ff92SAndroid Build Coastguard Worker #include <vector>
12*89c4ff92SAndroid Build Coastguard Worker #include <map>
13*89c4ff92SAndroid Build Coastguard Worker 
14*89c4ff92SAndroid Build Coastguard Worker namespace armnnOnnxParser
15*89c4ff92SAndroid Build Coastguard Worker {
16*89c4ff92SAndroid Build Coastguard Worker 
17*89c4ff92SAndroid Build Coastguard Worker using BindingPointInfo = armnn::BindingPointInfo;
18*89c4ff92SAndroid Build Coastguard Worker 
19*89c4ff92SAndroid Build Coastguard Worker class OnnxParserImpl;
20*89c4ff92SAndroid Build Coastguard Worker class IOnnxParser;
21*89c4ff92SAndroid Build Coastguard Worker using IOnnxParserPtr = std::unique_ptr<IOnnxParser, void(*)(IOnnxParser* parser)>;
22*89c4ff92SAndroid Build Coastguard Worker 
23*89c4ff92SAndroid Build Coastguard Worker class IOnnxParser
24*89c4ff92SAndroid Build Coastguard Worker {
25*89c4ff92SAndroid Build Coastguard Worker public:
26*89c4ff92SAndroid Build Coastguard Worker     static IOnnxParser* CreateRaw();
27*89c4ff92SAndroid Build Coastguard Worker     static IOnnxParserPtr Create();
28*89c4ff92SAndroid Build Coastguard Worker     static void Destroy(IOnnxParser* parser);
29*89c4ff92SAndroid Build Coastguard Worker 
30*89c4ff92SAndroid Build Coastguard Worker     /// Create the network from a protobuf binary vector
31*89c4ff92SAndroid Build Coastguard Worker     armnn::INetworkPtr CreateNetworkFromBinary(const std::vector<uint8_t>& binaryContent);
32*89c4ff92SAndroid Build Coastguard Worker 
33*89c4ff92SAndroid Build Coastguard Worker     /// Create the network from a protobuf binary vector, with inputShapes specified
34*89c4ff92SAndroid Build Coastguard Worker     armnn::INetworkPtr CreateNetworkFromBinary(const std::vector<uint8_t>& binaryContent,
35*89c4ff92SAndroid Build Coastguard Worker                                                const std::map<std::string, armnn::TensorShape>& inputShapes);
36*89c4ff92SAndroid Build Coastguard Worker 
37*89c4ff92SAndroid Build Coastguard Worker     /// Create the network from a protobuf binary file on disk
38*89c4ff92SAndroid Build Coastguard Worker     armnn::INetworkPtr CreateNetworkFromBinaryFile(const char* graphFile);
39*89c4ff92SAndroid Build Coastguard Worker 
40*89c4ff92SAndroid Build Coastguard Worker     /// Create the network from a protobuf text file on disk
41*89c4ff92SAndroid Build Coastguard Worker     armnn::INetworkPtr CreateNetworkFromTextFile(const char* graphFile);
42*89c4ff92SAndroid Build Coastguard Worker 
43*89c4ff92SAndroid Build Coastguard Worker     /// Create the network directly from protobuf text in a string. Useful for debugging/testing
44*89c4ff92SAndroid Build Coastguard Worker     armnn::INetworkPtr CreateNetworkFromString(const std::string& protoText);
45*89c4ff92SAndroid Build Coastguard Worker 
46*89c4ff92SAndroid Build Coastguard Worker     /// Create the network from a protobuf binary file on disk, with inputShapes specified
47*89c4ff92SAndroid Build Coastguard Worker     armnn::INetworkPtr CreateNetworkFromBinaryFile(const char* graphFile,
48*89c4ff92SAndroid Build Coastguard Worker                                                    const std::map<std::string, armnn::TensorShape>& inputShapes);
49*89c4ff92SAndroid Build Coastguard Worker 
50*89c4ff92SAndroid Build Coastguard Worker     /// Create the network from a protobuf text file on disk, with inputShapes specified
51*89c4ff92SAndroid Build Coastguard Worker     armnn::INetworkPtr CreateNetworkFromTextFile(const char* graphFile,
52*89c4ff92SAndroid Build Coastguard Worker                                                  const std::map<std::string, armnn::TensorShape>& inputShapes);
53*89c4ff92SAndroid Build Coastguard Worker 
54*89c4ff92SAndroid Build Coastguard Worker      /// Create the network directly from protobuf text in a string, with inputShapes specified.
55*89c4ff92SAndroid Build Coastguard Worker      /// Useful for debugging/testing
56*89c4ff92SAndroid Build Coastguard Worker     armnn::INetworkPtr CreateNetworkFromString(const std::string& protoText,
57*89c4ff92SAndroid Build Coastguard Worker                                                const std::map<std::string, armnn::TensorShape>& inputShapes);
58*89c4ff92SAndroid Build Coastguard Worker 
59*89c4ff92SAndroid Build Coastguard Worker     /// Retrieve binding info (layer id and tensor info) for the network input identified by the given layer name
60*89c4ff92SAndroid Build Coastguard Worker     BindingPointInfo GetNetworkInputBindingInfo(const std::string& name) const;
61*89c4ff92SAndroid Build Coastguard Worker 
62*89c4ff92SAndroid Build Coastguard Worker     /// Retrieve binding info (layer id and tensor info) for the network output identified by the given layer name
63*89c4ff92SAndroid Build Coastguard Worker     BindingPointInfo GetNetworkOutputBindingInfo(const std::string& name) const;
64*89c4ff92SAndroid Build Coastguard Worker 
65*89c4ff92SAndroid Build Coastguard Worker private:
66*89c4ff92SAndroid Build Coastguard Worker     IOnnxParser();
67*89c4ff92SAndroid Build Coastguard Worker     ~IOnnxParser();
68*89c4ff92SAndroid Build Coastguard Worker 
69*89c4ff92SAndroid Build Coastguard Worker     std::unique_ptr<OnnxParserImpl> pOnnxParserImpl;
70*89c4ff92SAndroid Build Coastguard Worker   };
71*89c4ff92SAndroid Build Coastguard Worker 
72*89c4ff92SAndroid Build Coastguard Worker   }
73