LCOV - code coverage report
Current view: top level - aicpu_schedule/core/operator_kernel - operator_kernel.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 4 4
Test Date: 2026-07-28 10:54:05 Functions: 97.2 % 36 35

            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_H
      12              : #define OPERATOR_KERNEL_H
      13              : 
      14              : #include <memory>
      15              : #include <string>
      16              : #include <functional>
      17              : #include "operator_kernel_context.h"
      18              : 
      19              : namespace AicpuSchedule {
      20              : class AICPU_VISIBILITY OperatorKernel {
      21              : public:
      22              :     virtual int32_t Compute(const AicpuTaskInfo &kernelTaskInfo, const RunContext &taskContext) = 0;
      23          503 :     virtual ~OperatorKernel() {}
      24              : };
      25              : 
      26              : using KernelCreatorFunc = std::function<std::shared_ptr<OperatorKernel>(void)>;
      27              : 
      28              : AICPU_VISIBILITY bool RegistOperatorKernel(const std::string &type, const KernelCreatorFunc &fun);
      29              : 
      30              : template <typename T, typename... Args>
      31          105 : static inline std::shared_ptr<T> MakeShared(Args &&...args)
      32              : {
      33              :     using T_NC = typename std::remove_const<T>::type;
      34          105 :     std::shared_ptr<T> ret(new (std::nothrow) T_NC(std::forward<Args>(args)...));
      35          105 :     return ret;
      36              : }
      37              : 
      38              : #define REGISTER_OPERATOR_KERNEL(type, clazz)                 \
      39              :     std::shared_ptr<OperatorKernel> Creator_##type##_Kernel() \
      40              :     {                                                         \
      41              :         std::shared_ptr<clazz> ptr = nullptr;                 \
      42              :         ptr = MakeShared<clazz>();                            \
      43              :         return ptr;                                           \
      44              :     }                                                         \
      45              :     bool g_##type##_Kernel_Creator __attribute__((unused)) = RegistOperatorKernel(type, Creator_##type##_Kernel)
      46              : 
      47              : }  // namespace AicpuSchedule
      48              : 
      49              : #endif  // OPERATOR_KERNEL_H
        

Generated by: LCOV version 2.0-1