exo-lang / exo

Exocompilation for productive programming of hardware accelerators
https://exo-lang.dev
MIT License
279 stars 28 forks source link

Externalize builtins and fix bugs #637

Open yamaguchi1024 opened 2 months ago

yamaguchi1024 commented 2 months ago
codecov-commenter commented 2 months ago

Codecov Report

Attention: Patch coverage is 81.02894% with 59 lines in your changes are missing coverage. Please review.

Project coverage is 87.00%. Comparing base (5ca4872) to head (4a523c2).

Files Patch % Lines
src/exo/libs/externs.py 76.97% 32 Missing :warning:
src/exo/extern.py 70.00% 6 Missing :warning:
src/exo/parse_fragment.py 60.00% 4 Missing :warning:
src/exo/pyparser.py 86.36% 3 Missing :warning:
src/exo/API_cursors.py 75.00% 2 Missing :warning:
src/exo/LoopIR_unification.py 33.33% 2 Missing :warning:
src/exo/stdlib/inspection.py 33.33% 2 Missing :warning:
tests/test_externs.py 94.59% 2 Missing :warning:
src/exo/API.py 80.00% 1 Missing :warning:
src/exo/LoopIR_compiler.py 95.65% 1 Missing :warning:
... and 4 more
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #637 +/- ## ======================================== Coverage 86.99% 87.00% ======================================== Files 94 96 +2 Lines 22022 22155 +133 ======================================== + Hits 19159 19276 +117 - Misses 2863 2879 +16 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

SamirDroubi commented 2 months ago

I think a more ergonomic way of implementing this feature would be something like the following:

@extern("{a_data} < {b_data} ? {c_data} : {d_data}")
def select(a: f32, b: f32, c: f32, d: f32) -> f32:
      return c if a < b else d

This would effectively encode all the information you are encoding in the class and it is more akin to how we externalized instructions definitions. There is the issue however of how to make sure these externs' arguments are dynamically typed which was the case before. We might want to allow these externs to be overloaded to avoid having to write on per-type or maybe this is not an issue because it is the same problem for instruction. We might though need to allow them to be rewritten modulo precisions. e.g. swap_builtin(proc, proc.find("select_R(_)"), select_f32) or something like that.

yamaguchi1024 commented 2 months ago

I like this interface!! It's like we're adding Exo type annotation (e.g., f32) to Python function, but the @extern function body is in Python.

yamaguchi1024 commented 2 months ago

@SamirDroubi I think @extern makes sense and we should do it at some point, but I don't have an energy to do it now so I'll just move the typechecking into the compiler and parse the proc's externs instead of using call_depth