Overview
OpInferDataTypeContextBuilder is used to construct InferDataTypeContext. The constructed Context serves as an input parameter during operator data type 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 OpInferDataTypeContextBuilder.
The procedure is as follows:
- Construct ContextHolder.
Call the API of the OpInferDataTypeContextBuilder class, transfer the input information like TensorDesc, and call the Build() API to construct a ContextHolder<InferDataTypeContext> object.
- Obtain InferDataTypeContext.
Use the GetContext API of ContextHolder to obtain InferDataTypeContext.
- Call the operator data type inference function InferDataTypeKernelFunc, use InferDataTypeContext as the input parameter of the function, complete data type inference, and write the inference result to the output.
- Use the GetOutputDataType API of InferDataTypeContext to obtain the output data type of the inference.
- Release ContextHolder as required. After the release is complete, the data pointers in InferDataTypeContext 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_datatype_context_builder.h" |
Public Member Functions
OpInferDataTypeContextBuilder()
~OpInferDataTypeContextBuilder() override
OpInferDataTypeContextBuilder &InputTensorDesc(size_t index, ge::DataType dtype, ge::Format origin_format,
ge::Format storage_format,
const gert::ExpandDimsType &expand_dims_type = {})
OpInferDataTypeContextBuilder &OutputTensorDesc(size_t index, ge::Format origin_format, ge::Format storage_format,
const gert::ExpandDimsType &expand_dims_type = {})
ContextHolder<InferDataTypeContext> Build()