Brcb
产品支持情况
功能说明
给定一个输入张量,每一次取输入张量中的8个数填充到结果张量的8个datablock(32Bytes)中去,每个数对应一个datablock。
函数原型
template <typename T>
__aicore__ inline void Brcb(const LocalTensor<T>& dst, const LocalTensor<T>& src0, const uint8_t repeatTime, const BrcbRepeatParams& repeatParams)
参数说明
表 1 模板参数说明
表 2 参数说明
|
类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 |
||
|
类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 |
||
|
类型为BrcbRepeatParams,具体定义可参考${INSTALL_DIR}/include/ascendc/basic_api/interface/kernel_struct_brcb.h。${INSTALL_DIR}请替换为CANN软件安装后文件存储路径。 其中dstBlkStride、dstRepStride支持用户配置,参数说明参考表3。 |
表 3 BrcbRepeatParams结构体参数说明
返回值说明
无
约束说明
-
操作数地址对齐要求请参见通用地址对齐约束。
-
不支持src0与dst为同一块内存地址。
调用示例
uint16_t数据类型brcb示例
#include "kernel_operator.h"
class VbrcbCase {
public:
__aicore__ inline VbrcbCase()
{}
__aicore__ inline void Init(__gm__ uint8_t *x, __gm__ uint8_t *y)
{
x_gm.SetGlobalBuffer(reinterpret_cast<__gm__ uint16_t *>(x));
y_gm.SetGlobalBuffer(reinterpret_cast<__gm__ uint16_t *>(y));
tpipe.InitBuffer(vecIn, 1, 16 * sizeof(uint16_t));
tpipe.InitBuffer(vecOut, 1, 256 * sizeof(uint16_t));
}
__aicore__ inline void Process()
{
CopyIn();
Compute();
CopyOut();
}
__aicore__ inline void CopyIn()
{
auto x_buf = vecIn.AllocTensor<uint16_t>();
AscendC::DataCopy(x_buf, x_gm, 16);
vecIn.EnQue(x_buf);
}
__aicore__ inline void Compute()
{
auto x_buf = vecIn.DeQue<uint16_t>();
auto y_buf = vecOut.AllocTensor<uint16_t>();
AscendC::Brcb(y_buf, x_buf, 2, {1,8});
vecOut.EnQue(y_buf);
vecIn.FreeTensor(x_buf);
}
__aicore__ inline void CopyOut()
{
auto y_buf = vecOut.DeQue<uint16_t>();
AscendC::DataCopy(y_gm, y_buf, 256);
vecOut.FreeTensor(y_buf);
}
private:
AscendC::GlobalTensor<uint16_t> x_gm;
AscendC::GlobalTensor<uint16_t> y_gm;
AscendC::TPipe tpipe;
AscendC::TQue<AscendC::TPosition::VECIN, 1> vecIn;
AscendC::TQue<AscendC::TPosition::VECOUT, 1> vecOut;
};
extern "C" __global__ __aicore__ void vbrcb_uint16_t_16(__gm__ uint8_t *x, __gm__ uint8_t *y)
{
VbrcbCase op;
op.Init(x, y);
op.Process();
}
结果示例:
输入数据x_gm:[1 2 3 ... 16]
输出数据y_gm:[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16]