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_KFC_H_
12 : #define __AE_KERNEL_LIB_AICPU_KFC_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 : using AicpuKFCOpFuncPtr = uint32_t (*)(void*);
25 : class AIKernelsLibAiCpuKFC : public cce::AIKernelsLibBase {
26 : public:
27 2 : ~AIKernelsLibAiCpuKFC() override = default;
28 : /**
29 : * SINGLETON object get interface
30 : */
31 : static AIKernelsLibAiCpuKFC* GetInstance();
32 : /**
33 : * SINGLETON object destroy interface
34 : */
35 : static void DestroyInstance();
36 : /**
37 : * Implement get kernelName and kernelSoName
38 : */
39 : aeStatus_t GetKernelName(char_t*& kernelName, const aicpu::HwtsCceKernel* cceKernelBase) const;
40 : /**
41 : * Implement call a aicpu op kernel interface
42 : */
43 : int32_t CallKernelApi(const aicpu::KernelType kernelType, const void* const kernelBase) override;
44 : aeStatus_t Init() override;
45 1 : aeStatus_t BatchLoadKernelSo(const aicpu::KernelType kernelType, std::vector<std::string>& soVec) override
46 : {
47 : (void)kernelType;
48 : (void)soVec;
49 1 : return AE_STATUS_SUCCESS;
50 : }
51 1 : aeStatus_t CloseSo(const char_t* const soName) override
52 : {
53 : (void)soName;
54 1 : return AE_STATUS_SUCCESS;
55 : }
56 :
57 : private:
58 1 : AIKernelsLibAiCpuKFC() = default;
59 : /**
60 : * Run aicpu profiling
61 : */
62 : uint32_t RunAicpuFunc(const void* const kernelBase, AicpuKFCOpFuncPtr& opFuncPtr) const;
63 :
64 : int32_t TransformKernelErrorCode(const uint32_t errCode, const char_t* const kernelName) const;
65 :
66 : int32_t GetApiGlobal(AicpuKFCOpFuncPtr& opFuncPtr, const char_t* kernelName) const;
67 :
68 : int32_t GetApiWhenSonameNotEmpty(
69 : const aicpu::KernelType kernelType, const uint32_t soNameLen, const char_t* kernelSoName,
70 : const char_t* kernelName, void*& funcAddr);
71 :
72 : int32_t GetApiBySoname(
73 : const aicpu::KernelType kernelType, const char_t* kernelSoName, AicpuKFCOpFuncPtr& opFuncPtr,
74 : const char_t* kernelName);
75 :
76 : private:
77 : static AIKernelsLibAiCpuKFC* instance_; // SINGLETON object
78 : // api cacher
79 : std::unordered_map<std::string, AicpuKFCOpFuncPtr> apiCacher_;
80 : // A Read Write lock to protect apiCacher_
81 : tAERwLock rwLock_ = PTHREAD_RWLOCK_INITIALIZER;
82 : };
83 : } // namespace cce
84 : #endif
|