Last active
July 3, 2022 01:25
-
-
Save jackalcooper/17b28acf15c2cedfa0bb3fd905e954d0 to your computer and use it in GitHub Desktop.
Question regarding compiling Elixir pattern to MLIR (PDL dialect)
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
# I’m working on compiling Elixir pattern to MLIR (the PDL dialect), | |
# so that it could be used to manipulate another piece of IR. | |
# If we want to rewrite | |
res = TOSA.add(a, b) >>> Type.ranked_tensor([2, 3], Type.f32()) | |
res1 = TOSA.add(res, b) >>> Type.ranked_tensor([2, 3], Type.f32()) | |
# to | |
res1 = TOSA.sub(res, b) >>> Type.ranked_tensor([2, 3], Type.f32()) | |
# We can declare a pattern like this | |
pattern replace_multi_add_op( | |
%TOSA.Add{operands: [a, b], results: [res]}, | |
_t = %TOSA.Add{ | |
operands: [ | |
{:bound, res}, | |
{:bound, b} | |
# the code is working now (including the codegen and IR manipulation), | |
# but I am wondering how to not use the :bound here? | |
# there should be a more elegant way to prevent generating IR for this unbound variable | |
# I have tried to use ^res but it is not working | |
# Also any advice on the general pattern expression (especially regarding nesting) is appreciated. | |
], | |
results: [res1] | |
} | |
) do | |
%TOSA.Sub{operands: [a, b]} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
diff in the broader context: https://github.com/beaver-project/beaver/compare/add-prototype-dsl?expand=1#diff-cbf34ba9f03a1facb5709bcc0887a1a32984b0ecb40c0215816095de6b6c6a9dR128-R131