-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transforms (test-add-mcycle-around-launch) init pass
- Loading branch information
1 parent
7cc59b1
commit f1669ed
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from xdsl.context import MLContext | ||
from xdsl.dialects import builtin | ||
from xdsl.passes import ModulePass | ||
from xdsl.pattern_rewriter import ( | ||
PatternRewriter, | ||
PatternRewriteWalker, | ||
RewritePattern, | ||
op_type_rewrite_pattern, | ||
) | ||
from xdsl.rewriter import InsertPoint | ||
|
||
from compiler.dialects import accfg, snax | ||
|
||
|
||
class InsertBeforeLaunch(RewritePattern): | ||
@op_type_rewrite_pattern | ||
def match_and_rewrite(self, op: accfg.LaunchOp, rewriter: PatternRewriter, /): | ||
rewriter.insert_op(snax.MCycleOp(), InsertPoint.before(op)) | ||
|
||
|
||
class InsertAfterAwait(RewritePattern): | ||
@op_type_rewrite_pattern | ||
def match_and_rewrite(self, op: accfg.AwaitOp, rewriter: PatternRewriter, /): | ||
rewriter.insert_op(snax.MCycleOp(), InsertPoint.after(op)) | ||
|
||
|
||
class AddMcycleAroundLaunch(ModulePass): | ||
""" | ||
Pass to insert an mcycle op before all accfg.launches and after all accfg.awaits | ||
""" | ||
|
||
name = "test-add-mcycle-around-launch" | ||
|
||
def apply(self, ctx: MLContext, op: builtin.ModuleOp) -> None: | ||
PatternRewriteWalker( | ||
InsertBeforeLaunch(), apply_recursively=False | ||
).rewrite_module(op) | ||
PatternRewriteWalker( | ||
InsertAfterAwait(), apply_recursively=False | ||
).rewrite_module(op) |
33 changes: 33 additions & 0 deletions
33
tests/filecheck/transforms/test/test-add-mcycle-around-launch.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// RUN: snax-opt --split-input-file -p test-add-mcycle-around-launch %s | filecheck %s | ||
|
||
"accfg.accelerator"() <{ | ||
name = @acc1, | ||
fields = {A=0x3c0, B=0x3c1}, | ||
launch_fields = {launch=0x3cf}, | ||
barrier = 0x7c3 | ||
}> : () -> () | ||
|
||
func.func @test() { | ||
%one, %two = "test.op"() : () -> (i32, i32) | ||
%zero = arith.constant 0 : i32 | ||
%state = "accfg.setup"(%one, %two) <{ | ||
param_names = ["A", "B"], | ||
accelerator = "acc1", | ||
operandSegmentSizes = array<i32: 2, 0> | ||
}> {"test_attr" = 100 : i64} : (i32, i32) -> !accfg.state<"acc1"> | ||
|
||
%token = "accfg.launch"(%zero, %state) <{ | ||
param_names = ["launch"], | ||
accelerator = "acc1" | ||
}>: (i32, !accfg.state<"acc1">) -> !accfg.token<"acc1"> | ||
|
||
"accfg.await"(%token) : (!accfg.token<"acc1">) -> () | ||
|
||
func.return | ||
} | ||
|
||
|
||
// CHECK: snax.mcycle | ||
// CHECK-NEXT: accfg.launch | ||
// CHECK-NEXT: accfg.await | ||
// CHECK-NEXT: snax.mcycle |