GetContext
Function Usage
Obtains the context pointer of a specified type.
Prototype
1 2 | template<typename ContextTypeT> ContextTypeT *GetContext() |
Parameters
ContextTypeT is a generic type, including the following types of contexts:
- InferDataTypeContext;
- InferShapeContext;
- InferShapeRangeContext;
- KernelContext;
- TilingContext;
- TilingParseContext.
Returns
A pointer to the context is returned. The following table describes the relationship between ContextBuilder, ContextHolder, and Context.
ContextBuilder |
Holder |
Context |
|---|---|---|
OpInferDataTypeContextBuilder |
ContextHolder<InferDataTypeContext> |
InferDataTypeContext |
OpInferShapeContextBuilder |
ContextHolder<InferShapeContext> |
InferShapeContext |
OpInferShapeRangeContextBuilder |
ContextHolder<InferShapeRangeContext> |
InferShapeRangeContext |
OpKernelContextBuilder |
ContextHolder<KernelContext> |
KernelContext |
OpTilingContextBuilder |
ContextHolder<TilingContext> |
TilingContext |
OpTilingParseContextBuilder |
ContextHolder<TilingParseContext> |
TilingParseContext |
Constraints
None
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | OpInferDataTypeContextBuilder ctx_builder; ge::DataType dtype0 = ge::DT_FLOAT; ge::DataType dtype1 = ge::DT_FLOAT16; ge::DataType dtype2 = ge::DT_FLOAT; ge::DataType dtype3 = ge::DT_FLOAT16; ge::DataType dtype4 = ge::DT_FLOAT16; std::vector<ge::DataType> input_dtype_ref = {dtype0, dtype1, dtype2, dtype3}; std::vector<ge::DataType *> output_dtype_ref = {&dtype4}; auto holder = ctx_builder.OpType("Concat") .OpName("concat_1") .IOInstanceNum({4}, {1}) .InputTensorDesc(0, dtype0, ge::FORMAT_ND, ge::FORMAT_ND) .InputTensorDesc(1, dtype1, ge::FORMAT_ND, ge::FORMAT_ND) .InputTensorDesc(2, dtype2, ge::FORMAT_ND, ge::FORMAT_ND) .InputTensorDesc(3, dtype3, ge::FORMAT_ND, ge::FORMAT_ND) .OutputTensorDesc(0, ge::FORMAT_ND, ge::FORMAT_ND) .Build(); auto ctx = holder.GetContext(); EXPECT_NE(ctx, nullptr); |
Parent topic: ContextHolder