1 /**
2 * Copyright 2024 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_TRANSFORM_SYMBOL_SYMBOL_UTILS_H_
18 #define MINDSPORE_CCSRC_TRANSFORM_SYMBOL_SYMBOL_UTILS_H_
19 #include <string>
20 #include "utils/log_adapter.h"
21
22 template <typename Function, typename... Args>
RunAscendApi(Function f,const char * file,int line,const char * call_f,const char * func_name,Args...args)23 auto RunAscendApi(Function f, const char *file, int line, const char *call_f, const char *func_name, Args... args) {
24 MS_LOG(DEBUG) << "Call ascend api <" << func_name << "> in <" << call_f << "> at " << file << ":" << line;
25 if (f == nullptr) {
26 MS_LOG(EXCEPTION) << func_name << " is null.";
27 }
28 return f(args...);
29 }
30
31 template <typename Function>
RunAscendApi(Function f,const char * file,int line,const char * call_f,const char * func_name)32 auto RunAscendApi(Function f, const char *file, int line, const char *call_f, const char *func_name) {
33 MS_LOG(DEBUG) << "Call ascend api <" << func_name << "> in <" << call_f << "> at " << file << ":" << line;
34 if (f == nullptr) {
35 MS_LOG(EXCEPTION) << func_name << " is null.";
36 }
37 return f();
38 }
39
40 template <typename Function>
HasAscendApi(Function f)41 bool HasAscendApi(Function f) {
42 return f != nullptr;
43 }
44
45 namespace mindspore {
46 namespace transform {
47
48 #define CALL_ASCEND_API(func_name, ...) \
49 RunAscendApi(mindspore::transform::func_name##_, FILE_NAME, __LINE__, __FUNCTION__, #func_name, ##__VA_ARGS__)
50
51 #define HAS_ASCEND_API(func_name) HasAscendApi(mindspore::transform::func_name##_)
52
53 std::string GetAscendPath();
54 void *GetLibHandler(const std::string &lib_path);
55 void LoadAscendApiSymbols();
56 } // namespace transform
57 } // namespace mindspore
58
59 #endif // MINDSPORE_CCSRC_TRANSFORM_SYMBOL_SYMBOL_UTILS_H_
60