Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit a74c757

Browse files
Sven Verdoolaegeftynse
authored andcommitted
PolyhedralMapperTest: use scheduler to join bands for matmul
The original code relies on the init and the update statements being fused by tc2halide, but this is a temporary hack that will be removed in the next commit. Simply schedule the tree to ensure the bands are joined. Note that the result is slightly different, since the scheduler will also fuse in the third loop level.
1 parent 33a3bb6 commit a74c757

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

test/test_cuda_mapper.cc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ struct PolyhedralMapperTest : public ::testing::Test {
6161
joinBandsIterative(scop->scheduleRoot()->child({0}), true);
6262
return scop;
6363
}
64+
std::unique_ptr<Scop> PrepareAndJoinBandsMatMul() {
65+
auto scop = Prepare(makeMatmulTc());
66+
scop = Scop::makeScheduled(*scop, SchedulerOptions().view);
67+
auto root = scop->scheduleRoot();
68+
bandSplit(root, root->child({0}), 2);
69+
return scop;
70+
}
6471

6572
std::unique_ptr<MappedScop> makeUnmapped(std::string tc) {
6673
return MappedScop::makeOneBlockOneThread(Prepare(tc));
@@ -511,7 +518,7 @@ constexpr auto kExpectedMatmul_64_64_64 =
511518
)CUDA";
512519

513520
TEST_F(PolyhedralMapperTest, MergedContexts) {
514-
auto scop = PrepareAndJoinBands(makeMatmulTc());
521+
auto scop = PrepareAndJoinBandsMatMul();
515522

516523
// Unit test claims to use scop->globalParameterContext properly
517524
auto context = scop->makeContext<int>({{"M", 64}, {"N", 64}, {"K", 64}});
@@ -526,16 +533,16 @@ TEST_F(PolyhedralMapperTest, MergedContexts) {
526533
}
527534

528535
TEST_F(PolyhedralMapperTest, Match1) {
529-
auto scop = PrepareAndJoinBands(makeMatmulTc());
536+
auto scop = PrepareAndJoinBandsMatMul();
530537
auto schedule = scop->scheduleRoot();
531538

532539
auto mscop = TileAndMapThreads(std::move(scop), {16, 16}, {32ul, 8ul});
533540
auto f = match(
534-
sequence(
541+
band(sequence(
535542
filter([](isl::union_set f) {
536543
return f.get_space().dim(isl::dim_type::param) == 3;
537544
}),
538-
filter(band())),
545+
filter())),
539546
schedule);
540547
EXPECT_EQ(1u, f.size());
541548
}
@@ -553,37 +560,31 @@ def fun(float(M, N) I) -> (O) {
553560
}
554561

555562
TEST_F(PolyhedralMapperTest, MatmulTC) {
556-
string tc = R"TC(
557-
def fun(float(M, K) A, float(K, N) B) -> (C) {
558-
C(m, n) +=! A(m, r_k) * B(r_k, n)
559-
}
560-
)TC";
561-
562-
auto scop = PrepareAndJoinBands(tc);
563+
auto scop = PrepareAndJoinBandsMatMul();
563564
auto tileOptions = TileOptions::ShiftPointLoops | TileOptions::ScaleTileLoops;
564565
TileAndCheckStructuralEquality(*scop, tileOptions, {3ul, 4ul});
565566
}
566567

567568
TEST_F(PolyhedralMapperTest, MatmulShiftScale) {
568-
auto scop = PrepareAndJoinBands(makeMatmulTc());
569+
auto scop = PrepareAndJoinBandsMatMul();
569570
auto tileOptions = TileOptions::ShiftPointLoops | TileOptions::ScaleTileLoops;
570571
TileAndCheckStructuralEquality(*scop, tileOptions, {3ul, 4ul});
571572
}
572573

573574
TEST_F(PolyhedralMapperTest, MatmulShift) {
574-
auto scop = PrepareAndJoinBands(makeMatmulTc());
575+
auto scop = PrepareAndJoinBandsMatMul();
575576
auto tileOptions = TileOptions::ShiftPointLoops;
576577
TileAndCheckStructuralEquality(*scop, tileOptions, {3ul, 4ul});
577578
}
578579

579580
TEST_F(PolyhedralMapperTest, MatmulScale) {
580-
auto scop = PrepareAndJoinBands(makeMatmulTc());
581+
auto scop = PrepareAndJoinBandsMatMul();
581582
auto tileOptions = TileOptions::ScaleTileLoops;
582583
TileAndCheckStructuralEquality(*scop, tileOptions, {3ul, 4ul});
583584
}
584585

585586
TEST_F(PolyhedralMapperTest, MatmulNoshiftNoscale) {
586-
auto scop = PrepareAndJoinBands(makeMatmulTc());
587+
auto scop = PrepareAndJoinBandsMatMul();
587588
auto tileOptions = TileOptions();
588589
TileAndCheckStructuralEquality(*scop, tileOptions, {3ul, 4ul});
589590
}

0 commit comments

Comments
 (0)