昇腾社区首页
中文
注册

GetInputTensor

函数功能

获取算子IR原型定义中类型为“INPUT”的输入Tensor的指针。

函数原型

const Tensor *GetInputTensor(const size_t index) const

参数说明

参数

输入/输出

说明

index

输入

算子IR原型定义中的输入索引,从0开始计数。

返回值说明

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

关于Tensor类型的定义,请参见Tensor类

调用示例

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;
  }
  // ...
}