---
title: AddTensor接口
description: "添加Tensor。"
url: https://www.hiascend.com/document/detail/zh/mindie/latest/mindiellm/llmdev/mindie_llm0065.html
sourcePath: /source/zh/mindie/310/mindiellm/llmdev/mindie_llm0065.html
indexId: e5e11484fac3b8229dc350e3f9c2d6f39c7cae281e8a3703b241edd002cecc6658
---
# AddTensor接口

#### 接口功能

添加Tensor。


#### 接口格式

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


#### 接口参数

| 参数 | 是否必选 | 说明 | 取值要求 |
| --- | --- | --- | --- |
| tensorName | 是 | Tensor名称。 | 合法的string类型。 |
| tensor | 是 | Tensor数据。 | 合法的InferTensor类型，请参考InferTensor。 |


#### 使用样例

构造一个请求对象，给请求添加一个Tensor名称为"INPUT_IDS"，类型为TYPE_INT64，Shape为{1，2}的Tensor。

```
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);
```


#### 返回值

Status对象。
