---
title: 算子类声明
description: "用户需要在算子工程的“cpukernel/impl/xx.h”文件中进行算子类的声明，如下所示："
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/others/tbeaicpudevg/atlasopdev_10_0073.html
sourcePath: /source/zh/canncommercial/900/others/tbeaicpudevg/atlasopdev_10_0073.html
indexId: 8fab3e355c55d390b4417190a53d413020d5104dc9798fcbe7c807411191b20773
---
# 算子类声明

用户需要在算子工程的“cpukernel/impl/xx.h”文件中进行算子类的声明，如下所示：

```
// CpuKernel基类以及注册宏定义
#include "cpu_kernel.h"
// 定义命名空间
aicpu
namespace aicpu {
// 算子类继承CpuKernel基类
class
SampleCpuKernel
: public CpuKernel {
public:
~
SampleCpuKernel() = default;
// 声明函数Compute，且Compute函数需要重写
uint32_t Compute(CpuKernelContext &ctx) override;
};
} // namespace aicpu
```

- 引入头文件“cpu_kernel.h”。
  头文件“cpu_kernel.h”中包含了AI CPU算子基类CpuKernel的定义。

  此头文件会自动引入如下头文件：
  - cpu_tensor.h，包含了AI CPU的Tensor类的定义及相关方法。
  - cpu_tensor_shape.h，包含了AI CPU的TensorShape类及相关方法。
  - cpu_types.h，包含了AI CPU的数据类型以及格式等定义。
  - cpu_attr_value.h，包含了AttrValue类的属性定义以及方法。


- 进行算子类的声明，此类为CpuKernel类的派生类，并需要声明重载函数Compute，Compute函数需要在算子实现文件中进行实现，详细请参见  计算逻辑实现
。算子类的声明需要在命名空间“aicpu”中，命名空间的名字“aicpu”为固定值，不允许修改。
