1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef NEURAL_NETWORK_RUNTIME_COMPILER_H
17 #define NEURAL_NETWORK_RUNTIME_COMPILER_H
18 
19 #include <memory>
20 #include <unordered_map>
21 
22 #include "interfaces/kits/c/neural_network_runtime/neural_network_runtime_type.h"
23 #include "cpp_type.h"
24 
25 namespace OHOS {
26 namespace NeuralNetworkRuntime {
27 class Compiler {
28 public:
29     Compiler() = default;
30     virtual ~Compiler() = default;
31 
32     virtual size_t GetBackendID() const = 0;
33 
34     virtual OH_NN_ReturnCode SetCacheDir(const std::string& cacheModelPath, uint32_t version) = 0;
35     virtual OH_NN_ReturnCode SetPerformance(OH_NN_PerformanceMode performance) = 0;
36     virtual OH_NN_ReturnCode SetPriority(OH_NN_Priority priority) = 0;
37     virtual OH_NN_ReturnCode SetEnableFp16(bool isFp16) = 0;
38 
39     virtual bool IsBuild() const = 0;
40     virtual OH_NN_ReturnCode Build() = 0;
41 
42     virtual OH_NN_ReturnCode SaveToCacheFile() const = 0;
43     virtual OH_NN_ReturnCode RestoreFromCacheFile() = 0;
44     virtual OH_NN_ReturnCode SaveToCacheBuffer(const void* buffer, size_t length, size_t* modelSize) const = 0;
45     virtual OH_NN_ReturnCode RestoreFromCacheBuffer(const void* buffer, size_t length) = 0;
46 
47     virtual OH_NN_ReturnCode SetExtensionConfig(const std::unordered_map<std::string, std::vector<char>>& configs) = 0;
48     virtual OH_NN_ReturnCode SetOptions(const std::vector<std::shared_ptr<void>>& options) = 0;
49     virtual OH_NN_ReturnCode GetModelName(std::string& modelName) = 0;
50 };
51 } // namespace NeuralNetworkRuntime
52 } // namespace OHOS
53 
54 #endif // NEURAL_NETWORK_RUNTIME_COMPILER_H