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 17 #include "tools/converter/converter_context.h" 18 #include <vector> 19 #include "include/registry/converter_context.h" 20 21 namespace mindspore { 22 namespace converter { 23 constexpr int kMaxInput = 255; 24 SetGraphOutputTensorNames(const std::vector<std::vector<char>> && output_names)25void ConverterContext::SetGraphOutputTensorNames(const std::vector<std::vector<char>> &&output_names) { 26 auto converter_context = lite::ConverterInnerContext::GetInstance(); 27 if (converter_context == nullptr) { 28 MS_LOG(ERROR) << "Set graph output's names failed."; 29 return; 30 } 31 converter_context->SetGraphOutputTensorNames(VectorCharToString(output_names)); 32 } 33 GetGraphOutputTensorNamesInChar()34std::vector<std::vector<char>> ConverterContext::GetGraphOutputTensorNamesInChar() { 35 auto converter_context = lite::ConverterInnerContext::GetInstance(); 36 if (converter_context == nullptr) { 37 MS_LOG(ERROR) << "Get graph output's names failed."; 38 return {}; 39 } 40 return VectorStringToChar(converter_context->GetGraphOutputTensorNames()); 41 } 42 GetConfigInfo(const std::vector<char> && section)43std::map<std::vector<char>, std::vector<char>> ConverterContext::GetConfigInfo(const std::vector<char> &§ion) { 44 if (section.empty()) { 45 MS_LOG(ERROR) << "Get config information parameter is empty."; 46 return {}; 47 } 48 if (section.size() > kMaxInput) { 49 MS_LOG(ERROR) << "Config information parameter is too long"; 50 return {}; 51 } 52 auto converter_context = lite::ConverterInnerContext::GetInstance(); 53 if (converter_context == nullptr) { 54 MS_LOG(ERROR) << "Get config information only used by external extension failed."; 55 return {}; 56 } 57 auto &external_used_config_infos = converter_context->GetExternalUsedConfigInfos(); 58 if (external_used_config_infos.find(CharToString(section)) == external_used_config_infos.end()) { 59 MS_LOG(ERROR) << "This section " << section << " config info is not existed."; 60 return {}; 61 } 62 return MapStringToVectorChar(external_used_config_infos.at(CharToString(section))); 63 } 64 } // namespace converter 65 } // namespace mindspore 66