Allocate
Function
Allocates memory space for the input tensor object to receive input data.
Format
bool Allocate(size_t size)
Parameters
Parameter |
Mandatory/Optional |
Description |
Value |
|---|---|---|---|
size |
Mandatory |
Valid memory size |
The value is of the size_t type. |
Usage Example
Construct a tensor object whose name is INPUT_IDS, data type is INT64, and data shape is {1, 2}, and allocate memory space for the object.
1 2 3 4 5 6 7 | std::string name = "INPUT_IDS"; mindie_llm::InferDataType dataType= mindie_llm::InferDataType::TYPE_INT64; int64_t dataSize = 2; std::vector<int64_t> dataShape = {1, dataSize}; auto inputsTensor = std::make_shared<mindie_llm::InferTensor>(name, dataType, dataShape); size_t bufferSize = dataSize * sizeof(int64_t); inputsTensor->Allocate(bufferSize); |
Return Value
A Boolean value specifying whether the memory space of the tensor object is successfully allocated.
Parent topic: InferTensor