Skip to content

Instantly share code, notes, and snippets.

@jackalcooper
Last active July 3, 2022 01:25
Show Gist options
  • Select an option

  • Save jackalcooper/17b28acf15c2cedfa0bb3fd905e954d0 to your computer and use it in GitHub Desktop.

Select an option

Save jackalcooper/17b28acf15c2cedfa0bb3fd905e954d0 to your computer and use it in GitHub Desktop.

Revisions

  1. jackalcooper revised this gist Jul 3, 2022. No changes.
  2. jackalcooper revised this gist Jul 3, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions pattern-gen.ex
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,7 @@ pattern replace_multi_add_op(
    # 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]
    }
  3. jackalcooper revised this gist Jul 3, 2022. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions pattern-gen.ex
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # I’m working on compiling Elixir pattern to MLIR (the PDL dialect).
    # So that it could be used to manipulate another piece of IR.
    # 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())
    @@ -14,7 +14,8 @@ pattern replace_multi_add_op(
    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?
    # 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
    ],
  4. jackalcooper revised this gist Jul 3, 2022. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions pattern-gen.ex
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,20 @@
    # I’m working on compiling Elixir pattern to MLIR (the PDL dialect) so that it could be used to manipulate another piece of IR.
    # 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())
    # will be rewrite to
    # 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, but I am wondering how to not use the :bound here?
    # 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
    ],
  5. jackalcooper revised this gist Jul 3, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions pattern-gen.ex
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    # I’m working on compiling Elixir pattern to MLIR (the PDL dialect) so that it could be used to manipulate another piece of IR.
    res = TOSA.add(a, b) >>> Type.ranked_tensor([2, 3], Type.f32())
    res1 = TOSA.add(res, b) >>> Type.ranked_tensor([2, 3], Type.f32())
    # will be rewrite to
  6. jackalcooper revised this gist Jul 3, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pattern-gen.ex
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ pattern replace_multi_add_op(
    operands: [
    {:bound, res},
    {:bound, b}
    # the code is working now, but I am wondering how to not using the :bound here?
    # the code is working now, 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
    ],
  7. jackalcooper created this gist Jul 3, 2022.
    20 changes: 20 additions & 0 deletions pattern-gen.ex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    res = TOSA.add(a, b) >>> Type.ranked_tensor([2, 3], Type.f32())
    res1 = TOSA.add(res, b) >>> Type.ranked_tensor([2, 3], Type.f32())
    # will be rewrite to
    res1 = TOSA.sub(res, b) >>> Type.ranked_tensor([2, 3], Type.f32())

    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, but I am wondering how to not using 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
    ],
    results: [res1]
    }
    ) do
    %TOSA.Sub{operands: [a, b]}
    end