产品 |
是否支持 |
|---|---|
Ascend 950PR/Ascend 950DT |
√ |
√ |
|
√ |
|
x |
|
√ |
|
x |
|
x |
将Global Memory上的数据初始化为指定值。该接口可用于对workspace地址或输出数据进行清零。
1 2 | template <typename T> __aicore__ inline void Fill(GlobalTensor<T>& gmWorkspaceAddr, const uint64_t size, const T value) |
参数名 |
含义 |
|---|---|
T |
操作数的数据类型。不同型号支持的数据类型请参考支持的数据类型。 |
参数名 |
输入/输出 |
含义 |
|---|---|---|
gmWorkspaceAddr |
输入 |
gmWorkspaceAddr为用户定义的全局Global空间,是需要被初始化的空间,类型为GlobalTensor。GlobalTensor数据结构的定义请参考GlobalTensor。 |
size |
输入 |
需要初始化的空间大小,单位为元素个数。 |
value |
输入 |
初始化的值,数据类型与gmWorkspaceAddr保持一致。 |
无
Ascend 950PR/Ascend 950DT,支持的数据类型为:uint8_t、int8_t、uint16_t、int16_t、bfloat16_t、half、uint32_t、int32_t、float、uint64_t、int64_t。
1 2 3 4 5 6 7 | // 带初始化的元素个数 constexpr int32_t INIT_SIZE = 65536; // 设置源操作数在Global Memory上的起始地址为z+INIT_SIZE*blockIdx,所占外部存储的大小为INIT_SIZE个float zGm.SetGlobalBuffer((__gm__ float*)z + INIT_SIZE * AscendC::GetBlockIdx(), INIT_SIZE); // 将起始地址为z+INIT_SIZE*blockIdx和大小为INIT_SIZE个float源操作数zGm的值,初始化为每个核用当前blockIdx AscendC::Fill(zGm, INIT_SIZE, (float)(AscendC::GetBlockIdx())); |
结果示例如下:
1 2 3 4 5 6 7 8 | 初始化后zGm数据: [0. 0. 0. ... 0. 0. 0. 1. 1. 1. ... 1. 1. 1. 2. 2. 2. ... 2. 2. 2. ... 5. 5. 5. ... 5. 5. 5. 6. 6. 6. ... 6. 6. 6. 7. 7. 7. ... 7. 7. 7.] |