CpuKernel类
功能说明
CpuKernel类是算子kernel的基类。自定义算子类为基类CpuKernel的派生类,需要重写其Compute函数。
原型定义
class AICPU_VISIBILITY CpuKernel {
public:
// 纯虚函数,算子kernel的入口
virtual uint32_t Compute(CpuKernelContext &ctx) = 0;
virtual ~CpuKernel() {}
};
参数说明
ctx:算子kernel执行上下文
调用示例
// CpuKernel基类以及注册宏定义
#include "cpu_kernel.h"
// 定义命名空间aicpu
namespace aicpu {
// 算子类继承CpuKernel基类
class ReshapeCpuKernel : public CpuKernel {
public:
~ReshapeCpuKernel() = default;
// 声明函数Compute,且Compute函数需要重写
uint32_t Compute(CpuKernelContext &ctx) override;
};
REGISTER_CPU_KERNEL(RESHAPE, ReshapeCpuKernel);
} // namespace aicpu
父主题: CpuKernel注册