calyxir / calyx

Intermediate Language (IL) for Hardware Accelerator Generators
https://calyxir.org
MIT License
469 stars 46 forks source link

MrXL: allow different commands on the same memory to have different banking factors #1472

Open anshumanmohan opened 1 year ago

anshumanmohan commented 1 year ago

This probably would have been picked up along the way to #1414 anyway, but I'd like it sooner for tutorial purposes (#1457).

I currently cannot compile the following sum of squares program:

input avec: int[4]
output sos: int[4]
squares := map 2 (a <- avec) { a * a }
sos := reduce 1 (acc, i <- squares) 0 { acc + i }

It interprets fine, but mrxl test/sos.mrxl gives

...
Exception: Previous use of `squares` had banking factor 2 but current use has banking factor 1

Increasing the parallelism factor of reduce is not an option, since that is not implemented. This means I'm left with

input avec: int[4]
output sos: int[4]
squares := map 1 (a <- avec) { a * a }
sos := reduce 1 (acc, i <- squares) 0 { acc + i }

which is a much weaker program to work with pedagogically.

anshumanmohan commented 1 year ago

I gave it some more thought. I think an array needs to be banked per the _LCM of the various parallelism factors that ever parallelize the array_. For example,

input avec: int[24]
squares := map 4 (a <- avec) { a * a }
add5 := map 3 (a <- avec) { a + 5 }
...

I've laid out the general case, but in practice array-lengths and parallelism factors will probably all be powers of 2, so this will be easier: just bank per the finest parallelism factor, and then re-group as necessary.

anshumanmohan commented 1 year ago

After the meeting we just had, it appears I have arrived at the need for arbitration logic. Rachit thinks that this is going to be hard, harder possibly than going the whole hog and implementing reduction trees (#1414).

Resolutions:

  1. Tweak the tutorial so that it starts with the less-good (because fully-sequential) example:

    input avec: int[4]
    output sos: int[4]
    squares := map 1 (a <- avec) { a * a }
    sos := reduce 1 (acc, i <- squares) 0 { acc + i }
  2. Later in the tutorial, introduce a new example that does map without reduce. Use this to show how banking works. Not as nice as having one running example, but ah well.
  3. Meanwhile, try out a small arbitration logic using ref cells. #1474
anshumanmohan commented 1 year ago

Done with 1 and 2 above. PR https://github.com/cucapra/calyx/pull/1473 is once again ready for review.

anshumanmohan commented 1 year ago

I'm taking this off the tutorial milestone; the new in-milestone target is #1474. I will incorporate some of the discussion above into my educational slide/handout so that they can see how the sample code created by #1474 will lead them to the solution to this issue.

anshumanmohan commented 1 year ago

@rachitnigam should we just close this as a wontfix? Or maybe convert it into a discussion or somesuch?

rachitnigam commented 1 year ago

Maybe the "Low Priority" tag is in order? The task does seem pretty actionable but probably not critical for anyone's use. However, I think in the past @sampsyo has voted in favor keeping issues like this open as a way to onboard new people.

sampsyo commented 1 year ago

A "low priority" label sounds about right to me!

anshumanmohan commented 1 year ago

Done deal!