SetBuffer

Function

Sets data, data size, and whether to release memory for the input tensor object.

Format

void SetBuffer(const void *buffer, size_t tensorbyteSize, bool tensorNeedRelease)

Parameters

Parameter

Mandatory/Optional

Description

Value

buffer

Mandatory

Pointer to the tensor data address

Valid address pointer, which needs to point to the memory address dynamically allocated by the malloc, calloc, and realloc functions.

tensorbyteSize

Mandatory

Tensor memory size

Valid tensor memory size, which is of the size_t type.

tensorNeedRelease

Mandatory

Flag indicating whether to release the memory

Valid bool type

Usage Example

Construct a tensor object whose name is INPUT_IDS, data type is INT64, and data shape is {1, 2}, and then set the data, data size, and whether to release the memory for the input tensor object.

1
2
3
4
5
6
7
8
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);
uint64_t bufferSize = dataSize * sizeof(int64_t);
void *data = (void *)malloc(bufferSize);
inputsTensor->SetBuffer(data, bufferSize, false);

Return Value

None