Class CpuKernel

Description

Defines the base class of the operator kernel. The custom operator class is a derived class of the base class CpuKernel, and the Compute function of the custom operator class needs to be rewritten.

Prototype

class AICPU_VISIBILITY CpuKernel {
public:
    // Pure virtual function, which is the entry of the operator kernel.
    virtual uint32_t Compute(CpuKernelContext &ctx) = 0;
    virtual ~CpuKernel() {}
};

Parameters

ctx: context of operator kernel execution

Example

// CpuKernel base class and registration macro definition
#include "cpu_kernel.h" 
// Define the aicpu namespace.
namespace aicpu {
// The operator class inherits the CpuKernel base class.
class ReshapeCpuKernel : public CpuKernel {  
public:
~ReshapeCpuKernel() = default;
// Declare the Compute function, which needs to be rewritten.
uint32_t Compute(CpuKernelContext &ctx) override;    
};
REGISTER_CPU_KERNEL(RESHAPE, ReshapeCpuKernel);
} // namespace aicpu