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 : #ifndef __AE_KERNEL_LIB_AICPU_H_
12 : #define __AE_KERNEL_LIB_AICPU_H_
13 :
14 : #include <string>
15 : #include <mutex>
16 : #include <vector>
17 : #include "aicpu_context.h"
18 : #include "aicpu_engine.h"
19 : #include "ae_def.hpp"
20 : #include "ae_kernel_lib_base.hpp"
21 : #include "ae_so_manager.hpp"
22 :
23 : namespace cce {
24 : class AIKernelsLibAiCpu : public cce::AIKernelsLibBase {
25 : public:
26 12 : ~AIKernelsLibAiCpu() override = default;
27 : /**
28 : * SINGLETON object get interface
29 : */
30 : static AIKernelsLibAiCpu* GetInstance();
31 :
32 : /**
33 : * SINGLETON object destroy interface
34 : */
35 : static void DestroyInstance();
36 :
37 : /**
38 : * Implement get kernelName and kernelSoName
39 : */
40 : aeStatus_t GetKernelNameAndKernelSoName(
41 : char_t* kernelName, char_t* kernelSoName, const char_t* paramKernelSo,
42 : const aicpu::HwtsCceKernel* cceKernelBase) const;
43 :
44 : /**
45 : * Implement call a aicpu op kernel interface
46 : */
47 : int32_t CallKernelApi(const aicpu::KernelType kernelType, const void* const kernelBase) override;
48 :
49 : /**
50 : * Batch load kernel so
51 : */
52 : aeStatus_t BatchLoadKernelSo(const aicpu::KernelType kernelType, std::vector<std::string>& soVec) override;
53 :
54 : /**
55 : * Close so
56 : */
57 : aeStatus_t CloseSo(const char_t* const soName) override;
58 :
59 : void DeleteSoInWhiteList(const std::string& soName);
60 :
61 : aeStatus_t AddSoInWhiteList(const std::string& soName);
62 :
63 : private:
64 7 : AIKernelsLibAiCpu() = default;
65 :
66 : /**
67 : * Transform kernel error code
68 : */
69 : aeStatus_t TransformKernelErrorCode(
70 : const uint32_t errCode, const char_t* const kernelName, const char_t* const soName) const;
71 :
72 : /**
73 : * Run aicpu profiling
74 : */
75 : uint32_t RunAicpuFunc(const void* const kernelBase, void* const funcAddr, const char_t* const funcName) const;
76 :
77 : private:
78 : static AIKernelsLibAiCpu* instance_; // SINGLETON object
79 : static std::mutex mtx_; // Mutex lock to protect SINGLETON object create or destroy
80 : std::mutex soWhiteListMtx_;
81 : std::map<std::string, std::string> soWhiteList_;
82 : };
83 : } // namespace cce
84 : #endif
|