Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "aicpu_engine.h"
12 : #include "ae_def.hpp"
13 : #include "ae_kernel_lib_manager.hpp"
14 : #include "aicpu_event_struct.h"
15 : #include "aicpu_context.h"
16 :
17 : /**
18 : * @ingroup aicpu engine
19 : * @brief aeCallInterface: a interface to call a function in a op kernfel lib
20 : * @param [in] addr: void *, should be HwtsTsKernel * format
21 : * @return int32_t
22 : */
23 126 : __attribute__((visibility("default"))) int32_t aeCallInterface(const void* const addr)
24 : {
25 126 : if (addr == nullptr) {
26 1 : AE_ERR_LOG(AE_MODULE_ID, "Input param addr is NULL");
27 1 : return AE_STATUS_BAD_PARAM;
28 : }
29 125 : const auto strKernel = static_cast<const aicpu::HwtsTsKernel*>(addr);
30 125 : AE_INFO_LOG(AE_MODULE_ID, "Begin to CallKernelApi, kernelType=%u.", strKernel->kernelType);
31 : FUNC_PROFILE_START
32 : // step1. Get the Ai Kernel Lib
33 124 : const aicpu::KernelType kernelType = static_cast<const aicpu::KernelType>(strKernel->kernelType);
34 124 : cce::AIKernelsLibBase* targetKernelLib = nullptr;
35 124 : int32_t ret = cce::AIKernelsLibManger::GetKernelLib(kernelType, targetKernelLib);
36 125 : if ((ret == AE_STATUS_SUCCESS) && (targetKernelLib != nullptr)) {
37 : // step2. Call the Ai Kernel Lib unify abstract interface
38 124 : ret = targetKernelLib->CallKernelApi(kernelType, static_cast<const void*>(&strKernel->kernelBase));
39 : }
40 : FUNC_PROFILE_END
41 123 : return ret;
42 : }
43 :
44 : /**
45 : * @ingroup aicpu engine
46 : * @brief aeClear: a interface to clear all ai kernel lib
47 : * @return aeStatus_t
48 : */
49 2 : __attribute__((visibility("default"))) void aeClear()
50 : {
51 26 : for (int32_t kernelType = aicpu::KERNEL_TYPE_CCE; kernelType <= aicpu::KERNEL_TYPE_RESERVED; kernelType++) {
52 24 : cce::AIKernelsLibManger::ClearKernelLib(static_cast<aicpu::KernelType>(kernelType));
53 : }
54 2 : }
55 :
56 : /**
57 : * @ingroup aicpu engine
58 : * @brief aeBatchLoadKernelSo: a interface to load kernel so
59 : * @param [in] kernelType: uint32_t, kernel type
60 : * @param [in] loadSoNum: uint32_t, so number
61 : * @param [in] soNames: const char_t*[], so name
62 : * @return aeStatus_t
63 : */
64 6 : __attribute__((visibility("default"))) aeStatus_t aeBatchLoadKernelSo(
65 : const uint32_t kernelType, const uint32_t loadSoNum, const char_t* const* const soNames)
66 : {
67 6 : return cce::AIKernelsLibManger::BatchLoadKernelSo(static_cast<aicpu::KernelType>(kernelType), loadSoNum, soNames);
68 : }
69 :
70 : /**
71 : * @ingroup aicpu engine
72 : * @brief aeClear: a interface to close a so
73 : * @param [in]soName: so name
74 : * @return aeStatus_t
75 : */
76 3 : __attribute__((visibility("default"))) aeStatus_t aeCloseSo(const uint32_t kernelType, const char_t* const soName)
77 : {
78 3 : cce::AIKernelsLibBase* targetKernelLib = nullptr;
79 : const aeStatus_t ret =
80 3 : cce::AIKernelsLibManger::GetKernelLib(static_cast<const aicpu::KernelType>(kernelType), targetKernelLib);
81 3 : if ((ret != AE_STATUS_SUCCESS)) {
82 1 : AE_ERR_LOG(AE_MODULE_ID, "aeCloseSo get kernel lib failed, kernelType[%u], ret[%u].", kernelType, ret);
83 1 : return ret;
84 : }
85 2 : return targetKernelLib->CloseSo(soName);
86 : }
87 :
88 2 : __attribute__((visibility("default"))) aeStatus_t AeAddSoInWhiteList(const char_t* const soName)
89 : {
90 2 : if (soName == nullptr) {
91 1 : AE_ERR_LOG(AE_MODULE_ID, "Input param addr is NULL");
92 1 : return AE_STATUS_BAD_PARAM;
93 : }
94 1 : return cce::AIKernelsLibManger::AddSoInWhiteList(soName);
95 : }
96 :
97 2 : __attribute__((visibility("default"))) void AeDeleteSoInWhiteList(const char_t* const soName)
98 : {
99 2 : if (soName == nullptr) {
100 1 : AE_ERR_LOG(AE_MODULE_ID, "Input param addr is NULL");
101 1 : return;
102 : }
103 1 : cce::AIKernelsLibManger::DelteSoInWhiteList(soName);
104 : }
|