Overview

OpInferShapeContextBuilder is used to construct InferShapeContext. The constructed Context serves as an input parameter during operator shape inference for retrieving required input and output data of the operator. After the inference completes, the results are written back into the context.

The following figure shows the inheritance relationship of OpInferShapeContextBuilder.

The procedure is as follows:

  1. 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.

  2. Obtain InferShapeContext.

    Call the GetContext API through ContextHolder to obtain InferShapeContext.

  3. 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.
  4. Use the GetOutputShape API of InferShapeContext to obtain the output shape of the inference.
  5. 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()