| 24 | namespace framework { |
| 25 | |
| 26 | TEST(ProgramDesc, GetInputsOutputsInBlock) { |
| 27 | ProgramDesc program; |
| 28 | auto* global_block = program.MutableBlock(0); |
| 29 | auto* mul_1_x = global_block->Var("Mul_1_X"); |
| 30 | mul_1_x->SetType(proto::VarType::DENSE_TENSOR); |
| 31 | mul_1_x->SetLoDLevel(0); |
| 32 | mul_1_x->SetDataType(proto::VarType::FP32); |
| 33 | mul_1_x->SetShape({1000, 784}); |
| 34 | |
| 35 | auto* mul_1_y = global_block->Var("Mul_1_Y"); |
| 36 | mul_1_y->SetType(proto::VarType::DENSE_TENSOR); |
| 37 | mul_1_y->SetLoDLevel(0); |
| 38 | mul_1_y->SetDataType(proto::VarType::FP32); |
| 39 | mul_1_y->SetShape({784, 100}); |
| 40 | |
| 41 | auto* mul_1_out = global_block->Var("Mul_1_Out"); |
| 42 | mul_1_out->SetType(proto::VarType::DENSE_TENSOR); |
| 43 | auto* mul_op_1 = global_block->AppendOp(); |
| 44 | |
| 45 | mul_op_1->SetType("mul"); |
| 46 | mul_op_1->SetInput("X", {mul_1_x->Name()}); |
| 47 | mul_op_1->SetInput("Y", {mul_1_y->Name()}); |
| 48 | mul_op_1->SetOutput("Y", {mul_1_out->Name()}); |
| 49 | |
| 50 | // building cond op such as less_than |
| 51 | auto* less_than_op_1 = global_block->AppendOp(); |
| 52 | less_than_op_1->SetType("less_than"); |
| 53 | auto* less_than_1_x = global_block->Var("Less_than_1_X"); |
| 54 | less_than_1_x->SetType(proto::VarType::DENSE_TENSOR); |
| 55 | less_than_1_x->SetLoDLevel(0); |
| 56 | less_than_1_x->SetDataType(proto::VarType::FP32); |
| 57 | less_than_1_x->SetShape({1}); |
| 58 | |
| 59 | auto* less_than_1_y = global_block->Var("Less_than_1_Y"); |
| 60 | less_than_1_y->SetType(proto::VarType::DENSE_TENSOR); |
| 61 | less_than_1_y->SetLoDLevel(0); |
| 62 | less_than_1_y->SetDataType(proto::VarType::FP32); |
| 63 | less_than_1_y->SetShape({1}); |
| 64 | |
| 65 | auto* less_than_1_out = global_block->Var("Less_than_1_Out"); |
| 66 | less_than_1_out->SetType(proto::VarType::BOOL); |
| 67 | |
| 68 | less_than_op_1->SetInput("X", {less_than_1_x->Name()}); |
| 69 | less_than_op_1->SetInput("Y", {less_than_1_y->Name()}); |
| 70 | less_than_op_1->SetOutput("Out", {less_than_1_out->Name()}); |
| 71 | |
| 72 | BlockDesc* sub_block = program.AppendBlock(*global_block); |
| 73 | std::vector<BlockDesc*> sub_blocks; |
| 74 | sub_blocks.push_back(sub_block); |
| 75 | |
| 76 | BlockDesc* sub_block2 = |
| 77 | program.AppendBlock(*sub_block); // for testing nested case. |
| 78 | sub_blocks.push_back(sub_block2); |
| 79 | |
| 80 | // building while op in sub_block |
| 81 | auto* while_op = global_block->AppendOp(); |
| 82 | while_op->SetType("while"); |
| 83 | while_op->SetAttr("sub_block", sub_blocks[0]); |
nothing calls this directly
no test coverage detected