Imported Upstream version 1.12.0
[platform/core/ml/nnfw.git] / runtime / onert / frontend / nnapi / wrapper / OperationFactory.h
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __OPERATION_FACTORY_H__
18 #define __OPERATION_FACTORY_H__
19
20 #include <unordered_map>
21
22 #include "ir/Operands.h"
23 #include "ir/Operation.h"
24 #include "NeuralNetworks.h"
25 #include "NeuralNetworksEx.h"
26
27 /**
28  * @brief A class to create a onert operation object from NN API input parameters
29  */
30 class OperationFactory
31 {
32 public:
33   struct Param
34   {
35     uint32_t input_count;
36     const uint32_t *inputs;
37     uint32_t output_count;
38     const uint32_t *outputs;
39   };
40
41 public:
42   using Generator =
43     std::function<onert::ir::Operation *(const OperationFactory::Param &, onert::ir::Operands &)>;
44
45 public:
46   static OperationFactory &get();
47
48 private:
49   OperationFactory();
50
51 public:
52   onert::ir::Operation *create(ANeuralNetworksOperationType, const OperationFactory::Param &param,
53                                onert::ir::Operands &operands);
54   // TODO add "register" method for separating registration, possibly supporting custom-ops
55
56 private:
57   std::unordered_map<ANeuralNetworksOperationType, Generator> _map;
58 };
59
60 #endif // __OPERATION_FACTORY_H__