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 OPERATOR_KERNEL_REGISTER_H
12 : #define OPERATOR_KERNEL_REGISTER_H
13 :
14 : #include <map>
15 : #include <mutex>
16 : #include <functional>
17 : #include "operator_kernel.h"
18 :
19 : namespace AicpuSchedule {
20 : class AICPU_VISIBILITY OperatorKernelRegister {
21 : public:
22 8 : OperatorKernelRegister() : kernelInstMap_(){};
23 8 : ~OperatorKernelRegister() = default;
24 :
25 : static OperatorKernelRegister& Instance();
26 :
27 : int32_t RunOperatorKernel(const AicpuTaskInfo& kernelTaskInfo, const RunContext& taskContext);
28 : int32_t CheckOperatorKernelSupported(const std::string& kernelName);
29 :
30 : class Registerar {
31 : public:
32 : Registerar(const std::string& type, const KernelCreatorFunc& fun);
33 : ~Registerar() = default;
34 :
35 : Registerar(const Registerar&) = delete;
36 : Registerar(Registerar&&) = delete;
37 : Registerar& operator=(const Registerar&) = delete;
38 : Registerar& operator=(Registerar&&) = delete;
39 : };
40 :
41 : private:
42 : OperatorKernelRegister(const OperatorKernelRegister&) = delete;
43 : OperatorKernelRegister(OperatorKernelRegister&&) = delete;
44 : OperatorKernelRegister& operator=(const OperatorKernelRegister&) = delete;
45 : OperatorKernelRegister& operator=(OperatorKernelRegister&&) = delete;
46 :
47 : std::shared_ptr<OperatorKernel> GetOperatorKernel(const std::string& opType);
48 : void Register(const std::string& type, const KernelCreatorFunc& fun);
49 :
50 : std::mutex kernelInstMapMutex_;
51 : // To accelerate, each types of kernel only have one inst
52 : std::map<std::string, std::shared_ptr<OperatorKernel>> kernelInstMap_;
53 : };
54 :
55 : }; // namespace AicpuSchedule
56 :
57 : #endif // OPERATOR_KERNEL_REGISTER_H
|