1 /** 2 * Copyright 2022 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_CONFIG_INFOS_H_ 18 #define MINDSPORE_LITE_SRC_COMMON_CONFIG_INFOS_H_ 19 20 #include <string> 21 #include <map> 22 #include <vector> 23 #include "include/api/visible.h" 24 #include "mindapi/base/shape_vector.h" 25 26 namespace mindspore { 27 using ConfigInfos = std::map<std::string, std::map<std::string, std::string>>; 28 29 struct ProfileInputInfo { 30 std::string name; 31 bool is_dynamic_shape = false; 32 ShapeVector input_shape; 33 }; 34 35 struct ProfileInputRange { 36 ShapeVector min_dims; 37 ShapeVector opt_dims; 38 ShapeVector max_dims; 39 }; 40 41 struct ProfileItem { 42 std::vector<ProfileInputRange> inputs; 43 }; 44 45 struct ProfileConfigs { 46 std::vector<ProfileInputInfo> input_infos; 47 std::vector<ProfileItem> profiles; 48 }; 49 50 class MS_API ProfileParser { 51 public: 52 static bool Parse(const std::map<std::string, std::string> &context, bool require_opt_when_dym, 53 ProfileConfigs *profile_configs); 54 55 static bool ReorderByInputNames(const std::vector<std::string> &input_names, ProfileConfigs *profile_configs); 56 57 static std::string GetOption(const std::map<std::string, std::string> &context, const std::string &option, 58 const std::string &default_val = ""); 59 static bool ParseRangeStr(const std::string &range_str, int64_t *min_ptr, int64_t *max_ptr); 60 61 private: 62 static bool ParseOptDims(const std::string &opt_dims_str, ProfileConfigs *profile_configs); 63 static bool ParseDynamicDims(const std::string &dynamic_dims_str, ProfileConfigs *profile_configs); 64 static bool ParseInputShape(const std::string &input_shapes_str, ProfileConfigs *profile_configs); 65 66 static bool ParseOptDimStr(const std::string &opt_dim_str, int64_t *opt_ptr); 67 }; 68 } // namespace mindspore 69 70 #endif // MINDSPORE_LITE_SRC_COMMON_CONFIG_INFOS_H_ 71