ListTensorDesc
Supported Products
Product |
Supported |
|---|---|
√ |
|
√ |
|
x |
|
√ |
|
x |
|
x |
Function
Parses the data that meets the following memory layouts and obtains the address and shape information of the corresponding data based on the index on the kernel.

Header File to Be Included
1 | #include "kernel_operator_list_tensor_intf.h" |
Prototype
1 2 3 4 5 6 7 8 | class ListTensorDesc { ListTensorDesc(); ListTensorDesc(__gm__ void* data, uint32_t length = 0xffffffff, uint32_t shapeSize = 0xffffffff); void Init(__gm__ void* data, uint32_t length = 0xffffffff, uint32_t shapeSize = 0xffffffff); template<class T> void GetDesc(TensorDesc<T>& desc, uint32_t index); template<class T> T* GetDataPtr(uint32_t index); uint32_t GetSize(); } |
Function Description
Parameter |
Description |
|---|---|
T |
Data type of an element in a tensor. |
Function Name |
Input Parameter |
Description |
|---|---|---|
ListTensorDesc |
- |
Default constructor, which must be used together with the Init function. |
ListTensorDesc |
data: initial address of the data to be parsed length: length of the memory to be parsed shapeSize: number of data pointers length and shapeSize are used only for verification. If their values are not set, verification is not performed. |
Constructor of the ListTensorDesc class, which is used to parse the corresponding memory layout. |
Init |
data: initial address of the data to be parsed length: length of the memory to be parsed shapeSize: number of data pointers length and shapeSize are used only for verification. If their values are not set, verification is not performed. |
Initialization function, which is used to parse the corresponding memory layout. |
GetDesc |
desc: output parameter, description of the parsed tensor index: index value |
Obtains the corresponding TensorDesc information in the function usage diagram based on index. Before using GetDesc, call TensorDesc.SetShapeAddr to specify the address for storing the shape information for desc. After GetDesc is called, the shape information is written to this address. For the For the For the For the For the |
GetDataPtr |
index: index value |
Obtains the address for storing the corresponding data. |
GetSize |
- |
Obtains the number of data pointers contained in ListTensor. |
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(); |