1 /** 2 * Copyright 2020 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_CCSRC_CXXAPI_SESSION_ACL_OPTION_PARSER_H 18 #define MINDSPORE_CCSRC_CXXAPI_SESSION_ACL_OPTION_PARSER_H 19 #include <vector> 20 #include <string> 21 #include <map> 22 #include <tuple> 23 #include <memory> 24 #include <optional> 25 #include "include/api/types.h" 26 #include "include/api/status.h" 27 #include "include/api/context.h" 28 29 namespace mindspore { 30 class MS_API AclModelOptions { 31 public: 32 explicit AclModelOptions(const std::shared_ptr<Context> &context); 33 ~AclModelOptions() = default; 34 std::string GenAclOptionsKey() const; GetDeviceID()35 uint32_t GetDeviceID() const { return device_id_; } 36 void RenameInput(const std::vector<std::string> &input_names); 37 38 // return tuple<init_options, build_options> 39 std::tuple<std::map<std::string, std::string>, std::map<std::string, std::string>> GenAclOptions() const; 40 std::string GenAoeOptions(std::vector<std::string> *aoe_modes); SetFirstGraph(bool is_first_graph)41 void SetFirstGraph(bool is_first_graph) noexcept { first_graph_flag_ = is_first_graph; } SetOmFilePath(const std::string & file_path)42 void SetOmFilePath(const std::string &file_path) noexcept { om_file_path_ = file_path; } GetOmFilePath()43 std::string GetOmFilePath() const { return om_file_path_; } SetAoeMode(const std::string & aoe_mode)44 void SetAoeMode(const std::string &aoe_mode) noexcept { aoe_mode_ = aoe_mode; } GetAoeMode()45 std::string GetAoeMode() const { return aoe_mode_; } GetSocVersion()46 std::string GetSocVersion() const { return soc_version_; } SetDumpModelName(const std::string & name)47 void SetDumpModelName(const std::string &name) noexcept { dump_model_name_ = name; } GetDumpModelName()48 std::string GetDumpModelName() const { return dump_model_name_; } GetInputShape()49 std::string GetInputShape() const { return input_shape_; } SetInitOptionsMap(std::map<std::string,std::string> init_options)50 void SetInitOptionsMap(std::map<std::string, std::string> init_options) { init_options_map_ = init_options; } SetBuildOptionsMap(std::map<std::string,std::string> build_options)51 void SetBuildOptionsMap(std::map<std::string, std::string> build_options) { build_options_map_ = build_options; } SetAoeGlobalOptionsMap(const std::map<std::string,std::string> & global_options)52 void SetAoeGlobalOptionsMap(const std::map<std::string, std::string> &global_options) { 53 aoe_global_options_map_ = global_options; 54 } SetAoeTuningOptionsMap(const std::map<std::string,std::string> & tuning_options)55 void SetAoeTuningOptionsMap(const std::map<std::string, std::string> &tuning_options) { 56 aoe_tuning_options_map_ = tuning_options; 57 } GetAoeGlobalOptionsMap()58 std::map<std::string, std::string> GetAoeGlobalOptionsMap() const { return aoe_global_options_map_; } 59 60 static std::string GetSocName(); 61 62 private: 63 std::string output_node_; // todo: at convert.cc::BuildGraph(), no atc options 64 // build options 65 std::string insert_op_cfg_path_; 66 std::string input_format_; 67 std::string input_shape_; 68 std::string output_type_; 69 std::string precision_mode_; 70 std::string op_select_impl_mode_; 71 std::string fusion_switch_cfg_path_; 72 std::string soc_version_ = "Ascend310"; 73 std::string dynamic_batch_size_; 74 std::string dynamic_image_size_; 75 std::string buffer_optimize_mode_; 76 std::map<int, std::vector<int>> input_shape_map_; 77 std::map<std::string, std::string> init_options_map_; 78 std::map<std::string, std::string> build_options_map_; 79 std::map<std::string, std::string> aoe_global_options_map_; 80 std::map<std::string, std::string> aoe_tuning_options_map_; 81 // other options 82 uint32_t device_id_{0}; 83 std::optional<bool> first_graph_flag_{false}; 84 std::string om_file_path_; 85 std::string aoe_mode_; 86 std::string dump_model_name_; 87 }; 88 } // namespace mindspore 89 90 #endif // MINDSPORE_CCSRC_CXXAPI_SESSION_ACL_OPTION_PARSER_H 91