Skip to content

Instantly share code, notes, and snippets.

@jackalcooper
Last active July 3, 2022 01:25
Show Gist options
  • Save jackalcooper/17b28acf15c2cedfa0bb3fd905e954d0 to your computer and use it in GitHub Desktop.
Save jackalcooper/17b28acf15c2cedfa0bb3fd905e954d0 to your computer and use it in GitHub Desktop.
Question regarding compiling Elixir pattern to MLIR (PDL dialect)
# 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