SetGlobalBuffer

Product Support

Product

Supported

Atlas A3 training products/Atlas A3 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas 200I/500 A2 inference products

Atlas inference product's AI Core

Atlas inference product's Vector Core

Atlas training products

Function

Passes the address of the global data to initialize the GlobalTensor.

Prototype

  • Passes the global data pointer and sets the storage size (expressed by the number of elements).
    1
    __aicore__ inline void SetGlobalBuffer(__gm__ PrimType* buffer, uint64_t bufferSize)
    
  • Passes only the global data pointer. In this case, the number of elements obtained through GetSize is 0.
    1
    __aicore__ inline void SetGlobalBuffer(__gm__ PrimType* buffer)
    

Parameters

Table 1 Parameters

Parameter

Input/Output

Description

buffer

Input

Global data pointer passed from the host, which is of the PrimType type.

PrimType is defined as follows:

1
2
// PrimT is used to extract the basic data type from T. If T is of the basic data type, the data type is directly returned. If T is of the TensorTrait type, the LiteType basic data type in TensorTrait is extracted.
using PrimType = PrimT<T>;

bufferSize

Input

Number of data records of the PrimType type contained in the GlobalTensor. Ensure that the value does not exceed the actual data length. For example, if the pointed external storage contains 256 consecutive int32_t data elements, bufferSize is 256.

Returns

None

Restrictions

None

Example

 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; // Set the size of input_global to 256.

    AscendC::GlobalTensor<int32_t> inputGlobal; // The type is int32_t.
    inputGlobal.SetGlobalBuffer(reinterpret_cast<__gm__ int32_t *>(src_gm), dataSize); // Set the start address of the source operand in the global memory to src_gm and the size of the external storage occupied by the source operand to 256 int32_t data elements.

    AscendC::LocalTensor<int32_t> inputLocal = inQueueX.AllocTensor<int32_t>();    
    AscendC::DataCopy(inputLocal, inputGlobal, dataSize); // Copy inputGlobal from the global memory to inputLocal of the local memory.
    ...
}