• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 Huawei Technologies Co., Ltd
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 #ifndef MINDSPORE_LITE_SRC_CXX_API_CONVERTERS_H_
17 #define MINDSPORE_LITE_SRC_CXX_API_CONVERTERS_H_
18 
19 #include <vector>
20 #include <string>
21 #include <memory>
22 #include "include/api/context.h"
23 #include "include/api/status.h"
24 #include "include/api/cfg.h"
25 #include "include/train/train_cfg.h"
26 #include "src/inner_context.h"
27 #include "src/c_api/context_c.h"
28 
29 namespace mindspore {
30 class ContextUtils {
31  public:
32   static lite::InnerContext *Convert(Context *context);
33   static lite::InnerContext *Convert(const ContextC *context_c);
34 
35  private:
36   static void SetContextAttr(int32_t thread_num, bool enable_parallel, const std::vector<int32_t> &affinity_core_list,
37                              const std::shared_ptr<Delegate> &delegate, lite::InnerContext *inner_context);
38   static Status AddCpuDevice(const std::shared_ptr<Allocator> &allocator, int affinity_mode, bool enable_fp16,
39                              const std::string &provider, const std::string &provider_device,
40                              lite::InnerContext *inner_context);
41   static Status AddGpuDevice(bool enable_fp16, uint32_t device_id, const std::string &provider,
42                              const std::string &provider_device, const std::shared_ptr<Allocator> &allocator,
43                              lite::InnerContext *inner_context);
44   static Status AddNpuDevice(int frequency, lite::InnerContext *inner_context);
45   static Status AddAscend310Device(lite::InnerContext *inner_context, DeviceInfoContext *device);
46   static Status AddNNRtDevice(lite::InnerContext *inner_context);
IsAffinityModeValid(int affinity_mode)47   static bool IsAffinityModeValid(int affinity_mode) {
48     return affinity_mode >= lite::NO_BIND && affinity_mode <= lite::MID_CPU;
49   }
50 };
51 
A2L_ConvertQT(mindspore::QuantizationType qt)52 inline lite::QuantizationType A2L_ConvertQT(mindspore::QuantizationType qt) {
53   if (qt == kNoQuant) {
54     return lite::QT_NONE;
55   }
56   if (qt == kWeightQuant) {
57     return lite::QT_WEIGHT;
58   }
59   return lite::QT_DEFAULT;
60 }
61 
62 Status A2L_ConvertConfig(const TrainCfg *a_train_cfg, lite::TrainCfg *l_train_cfg);
63 }  // namespace mindspore
64 
65 #endif  // MINDSPORE_LITE_SRC_CXX_API_CONVERTERS_H_
66