---
title: SetGlobalBuffer
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/ascendcopapi/atlasascendc_api_07_00024.html
sourcePath: /source/zh/canncommercial/900/API/ascendcopapi/atlasascendc_api_07_00024.html
indexId: e12ba64ad73f5e708667835c2b733a8b50d179beaee20300b11e581c893b3c8277
---
# SetGlobalBuffer

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| Atlas 350 加速卡 | √ |
| Atlas A3 训练系列产品 / Atlas A3 推理系列产品 | √ |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | √ |
| Atlas 200I/500 A2 推理产品 | √ |
| Atlas 推理系列产品 AI Core | √ |
| Atlas 推理系列产品 Vector Core | √ |
| Atlas 训练系列产品 | √ |


#### 功能说明

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


#### 函数原型

- 传入全局数据的指针，并设置存储大小（通过元素个数表达）。
  1 __aicore__ inline void SetGlobalBuffer(__gm__ PrimType* buffer, uint64_t bufferSize)


- 仅传入全局数据的指针，此时通过  GetSize
获取到的元素个数为0。
  1 __aicore__ inline void SetGlobalBuffer(__gm__ PrimType* buffer)


#### 参数说明


**表1 参数说明**

| 参数名 | 输入/输出 | 描述 |  |  |
| --- | --- | --- | --- | --- |
| buffer | 输入 | Host侧传入的全局数据指针。PrimType类型。 PrimType定义如下： 1 2 // PrimT用于从T中提取基础数据类型：T传入基础数据类型，直接返回数据类型；T传入为TensorTrait类型时萃取TensorTrait中的LiteType基础数据类型 using PrimType = PrimT<T>; | 1 2 | // PrimT用于从T中提取基础数据类型：T传入基础数据类型，直接返回数据类型；T传入为TensorTrait类型时萃取TensorTrait中的LiteType基础数据类型 using PrimType = PrimT<T>; |
| 1 2 | // PrimT用于从T中提取基础数据类型：T传入基础数据类型，直接返回数据类型；T传入为TensorTrait类型时萃取TensorTrait中的LiteType基础数据类型 using PrimType = PrimT<T>; |  |  |  |
| bufferSize | 输入 | GlobalTensor所包含的类型为PrimType的数据个数，需自行保证不会超出实际数据的长度。如指向的外部存储有连续256个int32\_t，则其bufferSize为256。 |  |  |


#### 返回值说明

无。


#### 约束说明

无。


#### 调用示例

```
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上
```
