Build
Function Usage
Constructs InferDataTypeContext based on the previous settings and returns a ContextHolder<InferDataTypeContext> object.
Prototype
1 | ContextHolder<InferDataTypeContext> Build() |
Parameters
None
Returns
A ContextHolder<InferDataTypeContext> object. You can obtain the InferDataTypeContext pointer by calling the GetContext() method.
Constraints
- The caller owns the memory of all parameters passed to OpInferDataTypeContextBuilder through pointers. The caller must ensure that these pointers are valid throughout the lifecycle of the ContextHolder object.
- When the ContextHolder is destructed, the internal context resources are automatically released. Do not manually release the pointer returned by GetContext().
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include "base/context_builder/op_infer_datatype_context_builder.h" 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); auto ctx_compute_node_info = ctx->GetComputeNodeInfo(); EXPECT_NE(ctx_compute_node_info, nullptr); EXPECT_EQ(std::string(ctx_compute_node_info->GetNodeType()), std::string("Concat")); EXPECT_EQ(std::string(ctx_compute_node_info->GetNodeName()), std::string("concat_1")); EXPECT_EQ(ctx_compute_node_info->GetIrInputsNum(), 1); EXPECT_EQ(ctx_compute_node_info->GetIrOutputsNum(), 1); EXPECT_EQ(ctx_compute_node_info->GetInputsNum(), 4); EXPECT_EQ(ctx_compute_node_info->GetOutputsNum(), 1); const CompileTimeTensorDesc *info_input_0 = ctx_compute_node_info->GetInputTdInfo(0); EXPECT_NE(info_input_0, nullptr); EXPECT_EQ(info_input_0->GetStorageFormat(), ge::FORMAT_ND); EXPECT_EQ(info_input_0->GetOriginFormat(), ge::FORMAT_ND); ge::DataType expected_datatype_0 = ge::DT_FLOAT; ge::DataType expected_datatype_1 = ge::DT_FLOAT16; EXPECT_EQ(ctx->GetInputDataType(0), expected_datatype_0); EXPECT_EQ(ctx->GetInputDataType(1), expected_datatype_1); EXPECT_EQ(ctx->GetInputDataType(2), expected_datatype_0); EXPECT_EQ(ctx->GetInputDataType(3), expected_datatype_1); EXPECT_EQ(ctx->GetOutputDataType(0), ge::DT_MAX); |
Parent topic: OpInferDataTypeContextBuilder