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(char_t *kernelName, char_t *kernelSoName,
41 : 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,
53 : std::vector<std::string> &soVec) override;
54 :
55 : /**
56 : * Close so
57 : */
58 : aeStatus_t CloseSo(const char_t * const soName) override;
59 :
60 : void DeleteSoInWhiteList(const std::string &soName);
61 :
62 : aeStatus_t AddSoInWhiteList(const std::string &soName);
63 :
64 : private:
65 7 : AIKernelsLibAiCpu() = default;
66 :
67 : /**
68 : * Transform kernel error code
69 : */
70 : aeStatus_t TransformKernelErrorCode(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,
76 : void* const funcAddr,
77 : const char_t* const funcName) const;
78 :
79 : private:
80 : static AIKernelsLibAiCpu *instance_; // SINGLETON object
81 : static std::mutex mtx_; // Mutex lock to protect SINGLETON object create or destroy
82 : std::mutex soWhiteListMtx_;
83 : std::map<std::string, std::string> soWhiteList_;
84 : };
85 : }
86 : #endif
|