---
title: GetInputTensor
description: "根据算子输入索引获取对应的输入tensor指针。这里的输入索引是指算子实例化后实际的索引，不是原型定义中的索引。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/maintenref/basicdataapi/atlasopapi_07_00096.html
sourcePath: /source/zh/canncommercial/900/maintenref/basicdataapi/atlasopapi_07_00096.html
indexId: 005e7b85041aa51a7588a5790a62ff5fa0d2203dfaf4b361e2fce231d813ead778
---
# GetInputTensor

#### 函数功能

根据算子输入索引获取对应的输入tensor指针。这里的输入索引是指算子实例化后实际的索引，不是原型定义中的索引。


#### 函数原型

```
const Tensor *GetInputTensor(const size_t index) const
```


#### 参数说明

| 参数 | 输入/输出 | 说明 |
| --- | --- | --- |
| index | 输入 | 算子输入索引，从0开始计数。 |


#### 返回值说明

返回指向输入Tensor指针，当输入index非法时，返回空指针。

关于Tensor类型的定义，请参见Tensor。


#### 约束说明

仅在设置数据依赖(https://www.hiascend.comdocument/detail/zh/canncommercial/900/programug/Ascendcopdevg/atlas_ascendc_10_0078.html#ZH-CN_TOPIC_0000002531362232__section0610144611487)时可以获取tensor的数据地址。如果输入没有被设置为数据依赖，调用此接口获取tensor时，只能在tensor中获取到正确的shape、format、datatype信息，无法获取到真实的tensor数据地址（获取到的地址为nullptr）。


#### 调用示例

```
ge::graphStatus InferShapeForReshape(InferShapeContext *context) {
  const gert::Shape *x_shape = context->GetInputShape(0);        // 获取第0个输入的shape
  const gert::Tensor *shape_tensor = context->GetInputTensor(1); // 获取第1个输入的tensor  数据依赖
  gert::Shape *output_shape = context->GetOutputShape(0);
  if (x_shape == nullptr || shape_tensor == nullptr || output_shape == nullptr) {
    // 防御式编程，不应该出现的场景，打印错误并返回失败
    return ge::GRAPH_FAILED;
  }
  // ...
}
```
