/* * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * Description: api of cpu kernel */ #ifndef CPU_KERNEL_H #define CPU_KERNEL_H #include #include "cpu_context.h" namespace aicpu { class AICPU_VISIBILITY CpuKernel { public: virtual uint32_t Compute(CpuKernelContext &ctx) = 0; virtual ~CpuKernel() {} }; using KERNEL_CREATOR_FUN = std::function(void)>; AICPU_VISIBILITY bool RegistCpuKernel(const std::string &type, const KERNEL_CREATOR_FUN &fun); template static inline std::shared_ptr MakeShared(Args &&... args) { using T_NC = typename std::remove_const::type; std::shared_ptr ret(new (std::nothrow) T_NC(std::forward(args)...)); return ret; } #define REGISTER_CPU_KERNEL(type, clazz) std::shared_ptr Creator_##type##_Kernel() \ { \ std::shared_ptr ptr = nullptr; \ ptr = MakeShared(); \ return ptr; \ } \ bool g_##type##_Kernel_Creator __attribute__((unused)) = RegistCpuKernel(type, Creator_##type##_Kernel) } #endif // CPU_KERNEL_H