StanfordLegion / regent-lang.org

Regent website
Apache License 2.0
1 stars 3 forks source link

Documentation on partition types (and other complex types that can be passed in Regent programs) #4

Closed LonelyCat124 closed 4 years ago

LonelyCat124 commented 4 years ago

I'm trying to create a task that takes an input of a partition, loops over the partition and launches tasks on the regions each partition element represents:

e.g.

task pairsearch( reg1 : region(ispace(int1d), v), reg2 : region(ispace(int1d), v)) where reads(reg1, reg2) do
 --some code
end

task main()

   var is = ispace(int1d,256)
   var reg = region(is, v)
   var ps = ispace(int3d, {2,2,2})
   var p = partition(equal, reg, ps)

   for part in p.colors do -- Put this code into a task
     for part2 in p.colors do
       if (part ~= part2) then
         pairsearch(p[part], p[part2])
       end
     end

   end

end

but I can't see any documentation on how to declare the type for this function. I tried:

task launch_pairsearch( p : partition(disjoint, region(ispace(int1d), part), ispace(int3d))) where reads(p) do
  for part in p.colors do
    for part2 in p.colors do
      if (part ~= part2) then
        pairsearch(p[part], p[part2])
      end
    end
  end
end

but this fails with /home/aidan/Legion/legion/language/src/regent/std.t:2724: Partition type requires region to be a symbol.

What is the correct way to do this and can documentation on type descriptions (or maybe how to print types of regent objects if possible, terra docs suggest it should be in terra so I assume you can in Regent too?) be added?

elliottslaughter commented 4 years ago

So the way to do this is something like:

task launch_pairsearch(r : region(ispace(int1d), part), p : partition(disjoint, r, ispace(int3d)))

I updated the documentation here. Does that help?

http://regent-lang.org/reference/#passing-a-partition-to-a-task

LonelyCat124 commented 4 years ago

Almost sorted, but I'm getting an error that I don't understand from using that. From the same code as initially, I now have:

task launch_pairsearch( regionspace : region(ispace(int1d, part)), p : partition(disjoint, regionspace, ispace(int3d))) where reads(regionspace) do
  for part in p.colors do
    for part2 in p.colors do
      if (part ~= part2) then
        pairsearch(p[part], p[part2])
      end
    end
  end
end

but when I run this code I get an error

test2.rg:20: type mismatch in argument 1: expected region(ispace(int1d), v()) but got region(ispace(int1d))
        pairsearch(p[part], p[part2])

though from the main function the code is valid on the same partition. Is this a regent bug or is there something different about how I need to access the partition?

elliottslaughter commented 4 years ago

I'm not sure what part is, but ispace (as a type) takes only one argument, while region takes two. Maybe you flipped the parentheses around?

regionspace : region(ispace(int1d), part)

LonelyCat124 commented 4 years ago

Yup, that was basically the issue there, cheers. One other quick question about disjointness. If I require:

task pairsearch( reg1 : region(ispace(int1d), v), reg2 : region(ispace(int1d), v)) where reads(reg1, reg2), reg1 * reg2

Then the disjointness criteria fails, even though the partition is disjoint/equal (and the function knows this), and the call will not happen if reg1 == reg2 (due to the ~= comparison). Does the disjointness criteria instead require totally separate regions (as in cross products of index space and field space)?

elliottslaughter commented 4 years ago

The compiler isn't smart enough to detect this case because it can't analyze the if statement to figure out what the condition is. It would work with simpler cases like p[0] and p[1], but I think here probably the easiest thing to do is to not put an explicit disjointness constraint on the task.

LonelyCat124 commented 4 years ago

Ah ok - the reason I added the disjointness criteria was an issue in the non-dummy case shown here, as it resolved an issue with an assertion failing. I think that might be a bug or something instead so I'll put that in the main repo instead.