• 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 
17 #ifndef MINDSPORE_CCSRC_CXX_API_ACL_UTILS_H
18 #define MINDSPORE_CCSRC_CXX_API_ACL_UTILS_H
19 
20 #include <string>
21 #include <unordered_map>
22 #include "transform/symbol/acl_base_symbol.h"
23 #include "transform/symbol/symbol_utils.h"
24 
25 namespace mindspore {
IsAscend910Soc()26 static inline bool IsAscend910Soc() {
27   const char *soc_name_c = CALL_ASCEND_API(aclrtGetSocName);
28   if (soc_name_c == nullptr) {
29     return false;
30   }
31   std::string soc_name(soc_name_c);
32   if (soc_name.find("910") == std::string::npos) {
33     return false;
34   }
35   return true;
36 }
37 
IsAscendNo910Soc()38 static inline bool IsAscendNo910Soc() {
39   const char *soc_name_c = CALL_ASCEND_API(aclrtGetSocName);
40   if (soc_name_c == nullptr) {
41     return false;
42   }
43   std::string soc_name(soc_name_c);
44   if (soc_name.find("910") != std::string::npos) {
45     return false;
46   }
47   return true;
48 }
49 
TransforPrecisionToAcl(const std::string & precision_mode)50 static inline std::string TransforPrecisionToAcl(const std::string &precision_mode) {
51   static const std::unordered_map<std::string, std::string> precision_map = {
52     {"enforce_fp32", "force_fp32"},
53     {"preferred_fp32", "allow_fp32_to_fp16"},
54     {"enforce_fp16", "force_fp16"},
55     {"enforce_origin", "must_keep_origin_dtype"},
56     {"preferred_optimal", "allow_mix_precision"}};
57   return precision_map.find(precision_mode) != precision_map.end() ? precision_map.at(precision_mode) : precision_mode;
58 }
59 }  // namespace mindspore
60 
61 #endif  // MINDSPORE_CCSRC_CXX_API_ACL_UTILS_H
62