SetGlobalBuffer

功能说明

传入全局数据地址,初始化GlobalTensor。

函数原型

参数说明

表1 参数说明

参数名

输入/输出

描述

buffer

输入

Host侧传入的全局数据指针。

bufferSize

输入

GlobalTensor所包含的类型为PrimType的数据个数,需自行保证不会超出实际数据的长度。如指向的外部存储有连续256个int32_t,则其bufferSize为256。

返回值

无。

支持的型号

Atlas 训练系列产品

Atlas 推理系列产品AI Core

Atlas 推理系列产品Vector Core

Atlas A2 训练系列产品/Atlas 800I A2 推理产品/A200I A2 Box 异构组件

Atlas 200I/500 A2 推理产品

约束说明

无。

调用示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
void Init(__gm__ uint8_t *src_gm, __gm__ uint8_t *dst_gm)
{
    uint64_t dataSize = 256; //设置input_global的大小为256

    AscendC::GlobalTensor<int32_t> inputGlobal; // 类型为int32_t
    inputGlobal.SetGlobalBuffer(reinterpret_cast<__gm__ int32_t *>(src_gm), dataSize); // 设置源操作数在Global Memory上的起始地址为src_gm,所占外部存储的大小为256个int32_t

    AscendC::LocalTensor<int32_t> inputLocal = inQueueX.AllocTensor<int32_t>();    
    AscendC::DataCopy(inputLocal, inputGlobal, dataSize); // 将Global Memory上的inputGlobal拷贝到Local Memory的inputLocal上
    ...
}