Operator Class Declaration

Declare the operator class in the cpukernel/impl/xx.h files of the operator project as follows:

// 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 SampleCpuKernel : public CpuKernel {  
public:
~SampleCpuKernel() = default;
// Declare the Compute function, which needs to be rewritten.
uint32_t Compute(CpuKernelContext &ctx) override;    
};
} // namespace aicpu
  • Import the header file cpu_kernel.h.

    The header file cpu_kernel.h contains the definition of the AI CPU operator base class CpuKernel.

    This header file automatically imports the following header files:
    • cpu_tensor.h: defines the AI CPU Tensor class and related methods.
    • cpu_tensor_shape.h: defines the AI CPU TensorShape class and related methods.
    • cpu_types.h: defines the AI CPU data types and formats.
    • cpu_attr_value.h: defines the AttrValue class and related methods.
  • Declare the operator class, which is derived from the CpuKernel class. Declare the overloading function Compute, which needs to be implemented in the operator implementation file. For details, see Compute Logic Implementation. The operator class must be defined within the aicpu namespace. The namespace name is fixed to aicpu and must not be modified.