@@ -660,5 +660,65 @@ TEST(PrintingTest, TflAddOptionsPointer) {
660660 EXPECT_EQ (absl::StrFormat (" %v" , &add_opts), " {fa=RELU6,pot=true}" );
661661}
662662
663+ TEST (PrintingTest, Subgraph) {
664+ LiteRtSubgraphT subgraph;
665+
666+ {
667+ auto & op = subgraph.EmplaceOp ();
668+
669+ op.SetOpCode (kLiteRtOpCodeTflAdd );
670+
671+ ::tflite::AddOptionsT add_opts;
672+ add_opts.fused_activation_function = ::tflite::ActivationFunctionType_RELU;
673+ add_opts.pot_scale_int16 = false ;
674+ TflOptions opts;
675+ opts.type = ::tflite::BuiltinOptions_AddOptions;
676+ opts.Set (std::move (add_opts));
677+ litert::internal::SetTflOptions (op, std::move (opts));
678+
679+ auto & tensor = subgraph.EmplaceTensor ();
680+ tensor.SetType (MakeRankedTensorType (kLiteRtElementTypeInt32 , {2 , 2 , 2 }));
681+ op.Inputs ().push_back (&tensor);
682+
683+ auto & tensor2 = subgraph.EmplaceTensor ();
684+ tensor2.SetType (MakeRankedTensorType (kLiteRtElementTypeInt32 , {2 }));
685+ op.Inputs ().push_back (&tensor2);
686+
687+ auto & tensor3 = subgraph.EmplaceTensor ();
688+ tensor3.SetType (MakeRankedTensorType (kLiteRtElementTypeInt32 , {2 , 2 , 2 }));
689+ op.Outputs ().push_back (&tensor3);
690+ }
691+
692+ {
693+ auto & op = subgraph.EmplaceOp ();
694+
695+ op.SetOpCode (kLiteRtOpCodeTflAdd );
696+
697+ ::tflite::AddOptionsT add_opts;
698+ add_opts.fused_activation_function = ::tflite::ActivationFunctionType_RELU;
699+ add_opts.pot_scale_int16 = false ;
700+ TflOptions opts;
701+ opts.type = ::tflite::BuiltinOptions_AddOptions;
702+ opts.Set (std::move (add_opts));
703+ litert::internal::SetTflOptions (op, std::move (opts));
704+
705+ auto & tensor = subgraph.EmplaceTensor ();
706+ tensor.SetType (MakeRankedTensorType (kLiteRtElementTypeInt32 , {2 , 2 , 2 }));
707+ op.Inputs ().push_back (&tensor);
708+
709+ auto & tensor2 = subgraph.EmplaceTensor ();
710+ tensor2.SetType (MakeRankedTensorType (kLiteRtElementTypeInt32 , {2 }));
711+ op.Inputs ().push_back (&tensor2);
712+
713+ auto & tensor3 = subgraph.EmplaceTensor ();
714+ tensor3.SetType (MakeRankedTensorType (kLiteRtElementTypeInt32 , {2 , 2 , 2 }));
715+ op.Outputs ().push_back (&tensor3);
716+ }
717+
718+ EXPECT_EQ (absl::StrFormat (" %v" , subgraph.Ops ()),
719+ " tfl.add{fa=RELU}(3d_i32<2x2x2>,1d_i32<2>)->(3d_i32<2x2x2>)/"
720+ " tfl.add{fa=RELU}(3d_i32<2x2x2>,1d_i32<2>)->(3d_i32<2x2x2>)" );
721+ }
722+
663723} // namespace
664724} // namespace litert::internal
0 commit comments