66 */
77// clang-format on
88
9- #include < fstream>
10-
119#include < gmock/gmock-matchers.h>
1210#include < gtest/gtest.h>
1311
1715#include " id_model/loop_promotion.h"
1816#include " id_model/schedule.h"
1917#include " id_model/to_string.h"
20- #include " ir/graphviz.h"
2118#include " ops/all_ops.h"
2219#include " scheduler/tools/inlining.h"
2320#include " scheduler/tools/resize_utils.h"
@@ -235,8 +232,7 @@ void validateIELResolution(
235232 auto promotion_id = iel_promotion_map_it->second ;
236233 ASSERT_TRUE (
237234 exact_graph.disjointValSets ().strictAreMapped (promotion_id, ref_id))
238- << " Unexpected promotion. "
239- << " Expected: " << ref_id->toString ()
235+ << " Unexpected promotion. Expected: " << ref_id->toString ()
240236 << " . Actual: " << promotion_id->toString ();
241237 ASSERT_TRUE (loop_graph.disjointValSets ().strictAreMapped (id, promotion_id))
242238 << " Promotion of " << id->toString ()
@@ -376,9 +372,9 @@ void checkStep4Results(
376372 const auto & iel_promotion_map = tester.s4_iel_promotion_map ;
377373
378374 EXPECT_EQ (iel_promotion_map.size (), ref_promotion_map.size ())
379- << " Mismatched Step-4 result map. "
380- << " Expected to have " << ref_promotion_map.size ()
381- << " mappings but found " << iel_promotion_map.size ();
375+ << " Mismatched Step-4 result map. Expected to have "
376+ << ref_promotion_map.size () << " mappings but found "
377+ << iel_promotion_map.size ();
382378
383379 for (const auto & ref_promotion_pair : ref_promotion_map) {
384380 const auto & ref_promotion_group = ref_promotion_pair.first ;
@@ -2937,9 +2933,8 @@ TEST_F(IdModelTest, LoopPromotionCyclicGraphWar) {
29372933// Test to verify the split-aware covered group analysis. See
29382934// also https://github.com/NVIDIA/Fuser/pull/3877.
29392935TEST_F (IdModelTest, CoveredGroups) {
2940- auto fusion_ptr = std::make_unique<Fusion>();
2941- auto & fusion = *fusion_ptr;
2942- FusionGuard fg (fusion_ptr.get ());
2936+ Fusion fusion;
2937+ FusionGuard fg (&fusion);
29432938
29442939 auto tv0 = makeContigConcreteTensor ({-1 , 1 });
29452940 fusion.addInput (tv0);
@@ -3000,7 +2995,7 @@ TEST_F(IdModelTest, CoveredGroups) {
30002995TEST_F (IdModelTest, InvalidLoopPromotion) {
30012996 auto fusion_ptr = std::make_unique<Fusion>();
30022997 auto & fusion = *fusion_ptr;
3003- FusionGuard fg (fusion_ptr. get () );
2998+ FusionGuard fg (&fusion );
30042999
30053000 auto T0 = makeContigConcreteTensor ({1 , 32 , 6 });
30063001 fusion.addInput (T0);
@@ -3086,9 +3081,8 @@ TEST_F(IdModelTest, InvalidLoopPromotion) {
30863081// When a loop group only includes broadcast IDs, the group should not
30873082// need to be promoted
30883083TEST_F (IdModelTest, BroadcastOnlyNoLoopPromotion) {
3089- auto fusion_ptr = std::make_unique<Fusion>();
3090- auto & fusion = *fusion_ptr;
3091- FusionGuard fg (fusion_ptr.get ());
3084+ Fusion fusion;
3085+ FusionGuard fg (&fusion);
30923086
30933087 auto tv0 = makeContigConcreteTensor ({-1 , 1 });
30943088 fusion.addInput (tv0);
@@ -3130,9 +3124,8 @@ TEST_F(IdModelTest, BroadcastOnlyNoLoopPromotion) {
31303124
31313125// Scatter output uses unique mapping schemes
31323126TEST_F (IdModelTest, ScatterLoopMapping) {
3133- auto fusion_ptr = std::make_unique<Fusion>();
3134- auto & fusion = *fusion_ptr;
3135- FusionGuard fg (fusion_ptr.get ());
3127+ Fusion fusion;
3128+ FusionGuard fg (&fusion);
31363129
31373130 auto tv0 = makeContigTensor (1 );
31383131 fusion.addInput (tv0);
@@ -3185,8 +3178,7 @@ TEST_F(IdModelTest, ScatterLoopMapping) {
31853178// required but is a WAR for special ops like
31863179// PreprocessGroupedMatmulInputSf. See also issue #5391.
31873180TEST_F (IdModelTest, LoopPromotionIncludeOnlyLoopIds) {
3188- auto fusion_ptr = std::make_unique<Fusion>();
3189- Fusion& fusion = *fusion_ptr.get ();
3181+ Fusion fusion;
31903182 FusionGuard fg (&fusion);
31913183
31923184 auto tv0 = makeSymbolicTensor (2 );
@@ -3219,8 +3211,7 @@ TEST_F(IdModelTest, LoopPromotionIncludeOnlyLoopIds) {
32193211}
32203212
32213213TEST_F (IdModelTest, PermissiveResizeGraph) {
3222- auto fusion_ptr = std::make_unique<Fusion>();
3223- Fusion& fusion = *fusion_ptr.get ();
3214+ Fusion fusion;
32243215 FusionGuard fg (&fusion);
32253216
32263217 auto tv0 = makeConcreteTensor ({36 });
@@ -3270,8 +3261,7 @@ TEST_F(IdModelTest, PermissiveResizeGraph) {
32703261// This is the failing segment of the reproducer of
32713262// https://github.com/NVIDIA/Fuser/issues/5803.
32723263TEST_F (IdModelTest, ReproIssue5803) {
3273- auto fusion_ptr = std::make_unique<Fusion>();
3274- Fusion& fusion = *fusion_ptr.get ();
3264+ Fusion fusion;
32753265 FusionGuard fg (&fusion);
32763266
32773267 auto tv2 = makeContigConcreteTensor ({4 }, DataType::Int);
@@ -3312,8 +3302,7 @@ TEST_F(IdModelTest, ReproIssue5803) {
33123302// This is a minimal fusion pattern to trigger the loop promotion
33133303// issue as reported in https://github.com/NVIDIA/Fuser/issues/5803
33143304TEST_F (IdModelTest, ReproIssue5803Minimal) {
3315- auto fusion_ptr = std::make_unique<Fusion>();
3316- Fusion& fusion = *fusion_ptr.get ();
3305+ Fusion fusion;
33173306 FusionGuard fg (&fusion);
33183307
33193308 auto tv0 = makeConcreteTensor ({4 , 8 });
@@ -3337,4 +3326,63 @@ TEST_F(IdModelTest, ReproIssue5803Minimal) {
33373326 IdModel id_model (&fusion, true );
33383327}
33393328
3329+ TEST_F (IdModelTest, SplittingReshape_Mapped) {
3330+ Fusion fusion;
3331+ FusionGuard fg (&fusion);
3332+
3333+ TensorView* in = makeContigConcreteTensor ({2 * 2 * 2 });
3334+ fusion.addInput (in);
3335+ TensorView* out = reshape (in, {2 * 2 * 2 }, {2 * 2 , 2 });
3336+ fusion.addOutput (out);
3337+
3338+ in->outer_split (0 , 2 );
3339+ out->outer_split (0 , 2 );
3340+
3341+ IdModel id_model (&fusion);
3342+ const ValGraph& almost_exact_graph = id_model.buildAlmostExactGraph ();
3343+ EXPECT_TRUE (almost_exact_graph.disjointValSets ().strictAreMapped (
3344+ in->axis (0 ), out->axis (0 )));
3345+ EXPECT_FALSE (almost_exact_graph.disjointValSets ().strictAreMapped (
3346+ in->axis (0 ), out->axis (1 )));
3347+ EXPECT_FALSE (almost_exact_graph.disjointValSets ().strictAreMapped (
3348+ in->axis (1 ), out->axis (2 )));
3349+ }
3350+
3351+ TEST_F (IdModelTest, SplitingReshape_DifferentExtents_NotMapped) {
3352+ Fusion fusion;
3353+ FusionGuard fg (&fusion);
3354+
3355+ TensorView* in = makeContigConcreteTensor ({12 });
3356+ fusion.addInput (in);
3357+ TensorView* out = reshape (in, {12 }, {6 , 2 });
3358+ fusion.addOutput (out);
3359+
3360+ in->outer_split (0 , 2 );
3361+ out->outer_split (0 , 3 );
3362+
3363+ IdModel id_model (&fusion);
3364+ const ValGraph& almost_exact_graph = id_model.buildAlmostExactGraph ();
3365+ EXPECT_FALSE (almost_exact_graph.disjointValSets ().strictAreMapped (
3366+ in->axis (0 ), out->axis (0 )));
3367+ }
3368+
3369+ TEST_F (IdModelTest, NonDivisibleSplits_NotMapped) {
3370+ Fusion fusion;
3371+ FusionGuard fg (&fusion);
3372+
3373+ TensorView* in = makeContigConcreteTensor ({6 });
3374+ fusion.addInput (in);
3375+ TensorView* out = set (in);
3376+ fusion.addOutput (out);
3377+
3378+ in->outer_split (0 , 2 );
3379+ out->inner_split (0 , 4 );
3380+ out->outer_split (0 , 2 );
3381+
3382+ IdModel id_model (&fusion);
3383+ const ValGraph& almost_exact_graph = id_model.buildAlmostExactGraph ();
3384+ EXPECT_FALSE (almost_exact_graph.disjointValSets ().strictAreMapped (
3385+ in->axis (0 ), out->axis (0 )));
3386+ }
3387+
33403388} // namespace nvfuser
0 commit comments