GetOptionalInputTensor
Function Usage
Obtains the pointer to an optional input tensor based on the input index in the operator prototype definition.
Prototype
const Tensor *GetOptionalInputTensor(const size_t ir_index) const
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
ir_index |
Input |
Index of the optional input in the operator IR prototype definition, starting from 0. |
Returns
Pointer to the input tensor of a specified ir_index. If the input ir_index is invalid or the input is not instantiated, a null pointer is returned.
For details about the definitions of tensor types (Tensor), see Tensor.
Constraints
The tensor data address can be obtained only when the input is set as a data dependency. If the input is not set as a data dependency, calling this API to get the tensor will only return metadata such as the correct shape, format, and data type, but the actual tensor data address cannot be obtained (the returned address is nullptr). For details about how to set data dependency, see the Ascend C Operator Development
Examples
ge::graphStatus Tiling4ReduceCommon(TilingContext* context) {
auto in_shape = context->GetInputShape(0);
GE_ASSERT_NOTNULL(in_shape);
auto axes_tensor = context->GetOptionalInputTensor(1);
...
}