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 #include <string>
17 #include "transform/symbol/symbol_utils.h"
18 #include "transform/symbol/acl_base_symbol.h"
19
20 namespace mindspore {
21 namespace transform {
22 aclCreateDataBufferFunObj aclCreateDataBuffer_ = nullptr;
23 aclCreateTensorDescFunObj aclCreateTensorDesc_ = nullptr;
24 aclDataTypeSizeFunObj aclDataTypeSize_ = nullptr;
25 aclDestroyDataBufferFunObj aclDestroyDataBuffer_ = nullptr;
26 aclDestroyTensorDescFunObj aclDestroyTensorDesc_ = nullptr;
27 aclGetTensorDescDimV2FunObj aclGetTensorDescDimV2_ = nullptr;
28 aclGetTensorDescNumDimsFunObj aclGetTensorDescNumDims_ = nullptr;
29 aclSetTensorConstFunObj aclSetTensorConst_ = nullptr;
30 aclSetTensorDescNameFunObj aclSetTensorDescName_ = nullptr;
31 aclSetTensorFormatFunObj aclSetTensorFormat_ = nullptr;
32 aclSetTensorPlaceMentFunObj aclSetTensorPlaceMent_ = nullptr;
33 aclSetTensorShapeFunObj aclSetTensorShape_ = nullptr;
34 aclrtGetSocNameFunObj aclrtGetSocName_ = nullptr;
35
LoadAclBaseApiSymbol(const std::string & ascend_path)36 void LoadAclBaseApiSymbol(const std::string &ascend_path) {
37 std::string aclbase_plugin_path = "lib64/libascendcl.so";
38 auto base_handler = GetLibHandler(ascend_path + aclbase_plugin_path);
39 if (base_handler == nullptr) {
40 MS_LOG(WARNING) << "Dlopen " << aclbase_plugin_path << " failed!" << dlerror();
41 return;
42 }
43 aclCreateDataBuffer_ = DlsymAscendFuncObj(aclCreateDataBuffer, base_handler);
44 aclCreateTensorDesc_ = DlsymAscendFuncObj(aclCreateTensorDesc, base_handler);
45 aclDataTypeSize_ = DlsymAscendFuncObj(aclDataTypeSize, base_handler);
46 aclDestroyDataBuffer_ = DlsymAscendFuncObj(aclDestroyDataBuffer, base_handler);
47 aclDestroyTensorDesc_ = DlsymAscendFuncObj(aclDestroyTensorDesc, base_handler);
48 aclGetTensorDescDimV2_ = DlsymAscendFuncObj(aclGetTensorDescDimV2, base_handler);
49 aclGetTensorDescNumDims_ = DlsymAscendFuncObj(aclGetTensorDescNumDims, base_handler);
50 aclSetTensorConst_ = DlsymAscendFuncObj(aclSetTensorConst, base_handler);
51 aclSetTensorDescName_ = DlsymAscendFuncObj(aclSetTensorDescName, base_handler);
52 aclSetTensorFormat_ = DlsymAscendFuncObj(aclSetTensorFormat, base_handler);
53 aclSetTensorPlaceMent_ = DlsymAscendFuncObj(aclSetTensorPlaceMent, base_handler);
54 aclSetTensorShape_ = DlsymAscendFuncObj(aclSetTensorShape, base_handler);
55 aclrtGetSocName_ = DlsymAscendFuncObj(aclrtGetSocName, base_handler);
56 MS_LOG(INFO) << "Load acl base api success!";
57 }
58
59 } // namespace transform
60 } // namespace mindspore
61