nv-legate / cunumeric

An Aspiring Drop-In Replacement for NumPy at Scale
https://docs.nvidia.com/cunumeric/24.06/
Apache License 2.0
615 stars 69 forks source link

Force computation completion #1

Open alexnick83 opened 3 years ago

alexnick83 commented 3 years ago

Is there a way to programmatically force Legate to wait for the completion of all pending operations? In the examples, the way to go is to read the output basically, i.e., assert not math.isnan(np.sum(output)). Is there a different way that doesn't incur the penalty of accessing all output elements?

lightsighter commented 3 years ago

We'll work to add a more ergonomic way to do this in the future. In the meantime, you can use the timing submodule from the legate core to get the "current time":

https://github.com/nv-legate/legate.core/blob/master/legate/timing/timing.py#L143

If you then print out the time value you receive back (or just assert that is not zero or anything that will force it to be evaluated), that will actually wait for all computations outstanding to finish before performing the timing measurement (you can see the execution fence here that enforces that here: https://github.com/nv-legate/legate.core/blob/master/legate/timing/timing.py#L146). It should be a very low overhead way of forcing all prior computations to complete. It's worth noting that Legate is not doing lazy evaluation, we're actually kicking off computations as you ask for them. We're just doing it asynchronously.

alexnick83 commented 3 years ago

This works great, thanks a lot!