GetTensorByName

Function

Obtains a tensor based on the name.

Format

Status GetTensorByName(const std::string& tensorName, TensorPtr &tensor)

Parameters

Parameter

Mandatory/Optional

Description

Value

tensorName

Mandatory

Tensor name.

Valid string type

tensor

Mandatory

Tensor data.

Valid InferTensor class. For details, see InferTensor.

Usage Example

Construct a request object and obtain the tensor object named INPUT_IDS from the request.

1
2
3
4
5
6
7
8
9
mindie_llm::InferRequestId runtimeReqId(0);
std::shared_ptr<mindie_llm::InferRequest> runtimeRequest(runtimeReqId);
std::string name = "INPUT_IDS";
mindie_llm::InferDataType dataType = mindie_llm::InferDataType::TYPE_INT64;
std::vector<int64_t> dataShape = {1, 2};
auto inputsTensor = std::make_shared<mindie_llm::InferTensor>(name, dataType, dataShape);
runtimeRequest->AddTensor(name, inputsTensor);
TensorPtr tensor = std::make_shared<mindie_llm::InferTensor>();
Status ret = runtimeRequest->GetTensorByName("INPUT_IDS", tensor);

Return Value

Status object.