Overview
OpInferShapeContextBuilder is used to construct InferShapeContext. The constructed Context serves as an input parameter during operator Shape inference to obtain necessary operator input and output data. After the inference is complete, the result is written back to the context.
The following figure shows the inheritance relationship of OpInferShapeContextBuilder.
The procedure is as follows:
- Construct ContextHolder.
Call the OpInferShapeContextBuilder API, transfer information like the operator input Tensor and output TensorDesc, and finally call the Build() API to construct a ContextHolder<InferShapeContext> object.
- Obtain InferShapeContext.
Call the GetContext API through ContextHolder to obtain InferShapeContext.
- Call the operator shape inference function InferShapeKernelFunc, uses InferShapeContext as the function input parameter, complete shape inference, and write the inference result to the output.
- Use the GetOutputShape API of InferShapeContext to obtain the output shape of the inference.
- Release ContextHolder as required. After the release is complete, the data pointers in InferShapeContext constructed using Build are invalid.
This class is inherited from the OpContextBuilderBase class. Before the ContextHolder object construction, it is necessary to call OpType, OpName, and IONum (or IOInstanceNum) of OpContextBuilderBase to respectively set the operator type, name, and numbers of inputs and outputs, and to call the AppendAttr API to set operator attributes.
Header Files to Be Included
1 | #include "base/context_builder/op_infer_shape_context_builder.h" |
Public Member Functions
OpInferShapeContextBuilder()
~OpInferShapeContextBuilder() override
OpInferShapeContextBuilder &OutputTensorDesc(size_t index, ge::DataType dtype, ge::Format origin_format, ge::Format storage_format, const gert::ExpandDimsType &expand_dims_type = {})
OpInferShapeContextBuilder &InputTensors(const std::vector<gert::Tensor *> &inputs)
ContextHolder<InferShapeContext> Build()