• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-2023 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 
17 #ifndef MINDSPORE_LITE_SRC_COMMON_COMMON_H_
18 #define MINDSPORE_LITE_SRC_COMMON_COMMON_H_
19 
20 #include <string>
21 #include "mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/op_base.h"
22 
23 /*
24 Naming a key of path must be consistent with existing naming styles and follow the following rules:
25 (1) If a path points to a file, please name it xxx_file;
26 (2) If a path points to a dir, please name it xxx_dir;
27 (3) If others, please make a technical review.
28 */
29 
30 namespace mindspore {
31 namespace lite {
32 enum NCHW_SHAPE { NCHW_N = 0, NCHW_C = 1, NCHW_H = 2, NCHW_W = 3 };
33 enum NHWC_SHAPE { NHWC_N = 0, NHWC_H = 1, NHWC_W = 2, NHWC_C = 3 };
34 enum HWCK_SHAPE { HWCK_H = 0, HWCK_W = 1, HWCK_C = 2, HWCK_K = 3 };
35 enum HWKC_SHAPE { HWKC_H = 0, HWKC_W = 1, HWKC_K = 2, HWKC_C = 3 };
36 enum KCHW_SHAPE { KCHW_K = 0, KCHW_C = 1, KCHW_H = 2, KCHW_W = 3 };
37 enum CKHW_SHAPE { CKHW_C = 0, CKHW_K = 1, CKHW_H = 2, CKHW_W = 3 };
38 enum CHWK_SHAPE { CHWK_C = 0, CHWK_H = 1, CHWK_W = 2, CHWK_K = 3 };
39 enum KHWC_SHAPE { KHWC_K = 0, KHWC_H = 1, KHWC_W = 2, KHWC_C = 3 };
40 enum CHW_SHAPE { CHW_C = 0, CHW_H = 1, CHW_W = 2 };
41 enum HWC_SHAPE { HWC_H = 0, HWC_W = 1, HWC_C = 2 };
42 static constexpr int kHWDimNumber = 2;
43 static constexpr int kCHWDimNumber = 3;
44 static constexpr int kNCHWDimNumber = 4;
45 static constexpr int kNHWCDimNumber = 4;
46 
47 static constexpr int TENSOR_MAX_REFCOUNT = 999;
48 
49 // quantization relative
50 static const char QUANTIZED_UINT8[] = "QUANTIZED_UINT8";
51 static const char QUANTIZED_INT8[] = "QUANTIZED_INT8";
52 static const char QUANTIZED_INT16[] = "QUANTIZED_INT16";
53 static const char QUANTIZED_UINT16[] = "QUANTIZED_UINT16";
54 static const char QUANTIZED_FLOAT16[] = "FLOAT16";
55 static const char QUANTIZED_FLOAT32[] = "FLOAT32";
56 static const char QUANTIZATION_TYPE_DYNAMIC[] = "DYNAMIC";
57 static const char QUANTIZATION_TYPE_STATIC[] = "STATIC";
58 static const char CALIB_NORM[] = "NORM";
59 
60 // dims
61 static const int32_t DIM_DEFAULT_SIZE = 4;
62 static const char *const kIsOptimized = "isOptimized";
63 static const char *const kInputFormat = "inputFormat";
64 static const char *const kOutputFormat = "outputFormat";
65 static const char *const kIsDynamicShape = "isDynamicShape";
66 // ms cache
67 static const char *const kMSCacheSection = "ms_cache";
68 static const char *const kMSCacheModelPathKey = "cache_model_path";
69 static const char *const kMSCacheVocabSizeKey = "vocab_size";
70 static const char *const kMSCacheDeviceSizeKey = "device_cache_size";
71 static const char *const kMSCacheSerializePathKey = "serialize_path";
72 // mindir weight path
73 static const char *const kConfigModelFileSection = "model_file";
74 static const char *const kConfigMindIRPathKey = "mindir_path";
75 static const char *const kWeightSection = "weight";
76 static const char *const kWeightPathKey = "weight_path";
77 // shared parallel thread pool
78 static const char *const kSharedThreadPoolSection = "shared_thread_pool";
79 static const char *const kEnableSharedThreadPoolKey = "enable_shared_thread_pool";
80 static const char *const kThreadNumLimitPerWorkerKey = "thread_num_limit_per_worker";
81 static const char *const kThreadNumRemainingPerWorkerKey = "thread_num_remaining_per_worker";
82 // model pool inner section and key
83 static const char *const kInnerModelParallelRunnerSection = "inner_model_parallel_runner";
84 static const char *const kInnerSharingWeightCopyBufKey = "sharing_weight_copy_buf";
85 static const char *const kInnerModelIDKey = "inner_model_id";
86 static const char *const kInnerRunnerIDKey = "inner_runner_id";
87 static const char *const kInnerNumaIDKey = "inner_numa_id";
88 static const char *const kInnerWorkerNumKey = "inner_worker_num";
89 
90 // common context
91 static const char *const kCommonContextSection = "common_context";
92 // gpu context
93 static const char *const kGPUContextSection = "gpu_context";
94 static const char *const kInputShapeKey = "input_shape";
95 static const char *const kDynamicDimsKey = "dynamic_dims";
96 static const char *const kOptimizeDimsKey = "opt_dims";
97 static const char *const kPrecisionModeKey = "precision_mode";
98 static const char *const kDumpOpsKey = "dump_ops";
99 static const char *const kDumpDirKey = "dump_dir";
100 // ascend context
101 static const char *const kAscendContextSection = "ascend_context";
102 static const char *const kProfilingPathKey = "profiling_config_file";
103 static const char *const kDumpPathKey = "dump_config_file";
104 static const char *const kDumpModelNameKey = "dump_model_name";
105 static const char *const kGeVariableMemoryMaxSize = "ge_variable_memory_max_size";
106 static const char *const kGeGraphMemoryMaxSize = "ge_graph_memory_max_size";
107 static const char *const kGraphCompilerCacheDirKey = "model_cache_dir";
108 static const char *const kModifyMixList = "mixprecision_list_path";
109 static const char *const kEnableCustomOp = "enable_custom_op";
110 static const char *const kPluginCustomOps = "plugin_custom_ops";
111 static const char *const kOpAttrs = "op_attrs";
112 static const char *const kAoeMode = "aoe_mode";
113 static const char *const kProvider = "provider";
114 static const char *const kAscendProviderGe = "ge";
115 static const char *const kParameterAsRefData = "parameter_as_refdata";
116 static const char *const kModelCacheMode = "model_cache_mode";
117 // ge options
118 static const char *const kGeSessionOptionsSection = "ge_session_options";
119 static const char *const kGeGraphOptionsSection = "ge_graph_options";
120 static const char *const kGeGlobalOptionsSection = "ge_global_options";
121 // distributed infer
122 static const char *const kRankTableFilePathKey = "rank_table_file";
123 // transformer
124 static const char *const kTransformerSection = "transformer_context";
125 static const char *const kEncoderInputKey = "encoder_input";
126 static const char *const kDecoderInputKey = "decoder_input";
127 static const char *const kFfnFp16Key = "ffn_fp16";
128 static const char *const kOptimizeTransformer = "optimize_transformer";
129 // lite inner group
130 static const char *const kLiteInnerGroupSection = "lite_inner_group";
131 static const char *const kLiteInnerGroupId = "group_id";
132 // aoe section
133 static const char *const kAoeGlobalOptionsSection = "aoe_global_options";
134 static const char *const kAoeTuningOptionsSection = "aoe_tuning_options";
135 // acl options
136 static const char *const kAclOptionParam = "acl_option_cfg_param";
137 static const char *const kAclInitOptionParam = "acl_init_options";
138 static const char *const kAclBuildOptionParam = "acl_build_options";
139 
140 static const char *const kNameAttrWeightDir = "weight_dir";
141 
142 static const char *const kOutputShapes = "outputs_shape";
143 static const char *const kNameCustomAscend = "CustomAscend";
144 
145 static const char *const kNameAttrRefDatas = "ref_datas";
146 static const char *const kNameAttrZeroValRefDatas = "zero_val_ref_datas";
147 static const char *const kConverterParams = "converter_params";
148 static const char *const kConverterOutputFile = "output_file";
149 // om converter options
150 static const char *const kOMConverterOptionsSection = "om_converter";
151 
152 static const char *const KModelUserInfo = "user_info";
153 
154 // for [ascend_context] [kvcache_input_layout]
155 static const char *const kKVCacheLayoutBNSD = "BNSD";
156 static const char *const kKVCacheLayoutBSH = "BSH";
157 }  // namespace lite
158 }  // namespace mindspore
159 #endif  // MINDSPORE_LITE_SRC_COMMON_COMMON_H_
160