StanfordLegion / legion

The Legion Parallel Programming System
https://legion.stanford.edu
Apache License 2.0
674 stars 146 forks source link

Regent: __demand(__index_launch) does not support non-interfering region access #499

Open ellishg opened 5 years ago

ellishg commented 5 years ago

My understanding is that __demand(__parallel) should work for loops over independent tasks, but I've been getting errors when I try to use it with reductions.

import "regent"

task reduce(value : int,
            sums  : region(ispace(int1d), int))
where
  reduces +(sums)
do
  for v = 1, value do
    sums[v % 5] += v
  end
end

task top_level()
  var values = region(ispace(int1d, 5), int)
  var sums = region(ispace(int1d, 5), int)
  fill(values, 8)
  fill(sums, 0)

  __demand(__parallel) -- loop optimization failed: argument 1 is not side-effect free
  for i in values.ispace do
    reduce(values[i], sums)
  end

  __demand(__parallel) -- works
  for i = 5, 10 do
    reduce(i, sums)
  end

  for i = 0, 5 do
    regentlib.c.printf("%d ", sums[i])
  end
  regentlib.c.printf("\n")
end

regentlib.start(top_level)

And the error message

...pos/legion/language/src/regent/optimize_index_launches.t:632: Errors reported during typechecking.
bug.rg:21: loop optimization failed: argument 1 is not side-effect free
    reduce(values[i], sums)
          ^

stack traceback:
    [C]: in function 'error'
    src/terralib.lua:388: in function 'finishandabortiferrors'
    /home/ellis/repos/legion/language/src/common/report.t:56: in function 'report_fail'
    ...pos/legion/language/src/regent/optimize_index_launches.t:632: in function 'optimize_loop_body'
    ...pos/legion/language/src/regent/optimize_index_launches.t:777: in function 'fn'
    src/asdl.lua:16: in function 'map'
    ...pos/legion/language/src/regent/optimize_index_launches.t:847: in function 'block'
    ...pos/legion/language/src/regent/optimize_index_launches.t:857: in function <...pos/legion/language/src/regent/optimize_index_launches.t:853>
    /home/ellis/repos/legion/language/src/regent/passes_hooks.t:41: in function 'optimize'
    /home/ellis/repos/legion/language/src/regent/passes.t:52: in function </home/ellis/repos/legion/language/src/regent/passes.t:48>
    bug.rg:13: in main chunk
elliottslaughter commented 5 years ago

It's complaining because you're accessing the region values inside the loop itself (i.e. values[i]). This is probably something the optimizer could accept because you're only accessing values, not passing it into the task.

In the mean time, you could pass values (or a subregion of values, if you're worried about that getting big) into the task instead of an individual element of the region.

streichler commented 5 years ago

@elliottslaughter what's the plan here?

elliottslaughter commented 3 years ago

I'm actually think it's better to discourage this since even if we support it, it would defeat the constant-time launch optimization which is important for scalability to extreme node counts. Since it hasn't come up recently I'm inclined to close this.