GetDataPtr
Supported Products
Product |
Supported |
|---|---|
√ |
|
√ |
|
x |
|
√ |
|
√ |
|
x |
Function
Obtains the address for storing tensor data.
Prototype
T* GetDataPtr()
Parameters
None
Returns
Returns the address for storing tensor data. T data type.
Restrictions
None
Example
The following figure shows the memory layout of srcGm to be parsed.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | AscendC::ListTensorDesc listTensorDesc(reinterpret_cast<__gm__ void *>(srcGm)); // srcGm indicates the GM address to be parsed. uint32_t size = listTensorDesc.GetSize(); // size = 2 auto dataPtr0 = listTensorDesc.GetDataPtr<int32_t>(0); // Obtains ptr0. auto dataPtr1 = listTensorDesc.GetDataPtr<int32_t>(1); // Obtains ptr1. uint64_t buf[100] = {0}; // In the example, dim of the tensor is 3, and the value 100 indicates that sufficient space is reserved. AscendC::TensorDesc<int32_t> desc; desc.SetShapeAddr(buf); // Specifies the address for storing shape information for desc. listTensorDesc.GetDesc(desc, 0); // Obtains the shape information of index 0. uint64_t dim = desc.GetDim(); // dim = 3 uint64_t idx = desc.GetIndex(); // idx = 0 uint64_t shape[3] = {0}; for (uint32_t i = 0; i < desc.GetDim(); i++) { shape[i] = desc.GetShape(i); // GetShape(0) = 1, GetShape(1) = 2, GetShape(2) = 3 } auto ptr = desc.GetDataPtr(); |
Parent topic: TensorDesc