pepijndevos / futhark-pycffi

Python library using the Futhark C backend via CFFI
MIT License
23 stars 7 forks source link

Out of bounds error causes a hang #25

Closed mortvest closed 3 years ago

mortvest commented 3 years ago

This program has an out of bounds error. When compiled with the opencl backend, it causes a hang instead of raising an ValueError (works as intended with c backend)

athas commented 3 years ago

Well, the type of the input is wrong here (np.arange produces 64-bit ints), but I don't know if that is the cause.

mortvest commented 3 years ago

Fixed it. Sadly, the problem remains.

athas commented 3 years ago

The problem is due to Futhark's asynchronous error detection (documented here). The entry point will return a succesfull error code, but it will actually fail in its outstanding operations, as can be detected by calling the sync function. Two options are open to us:

  1. Always synchronise after calling an entry point. This will have some overhead for small entry points.
  2. Remember that the objects returned may not be valid yet, and we need to sync (and do error detection) before we touch them.
athas commented 3 years ago

I thought option (2) would be very difficult to implement, but apparently not - at least not with the (slightly naive) solution of just syncing initially in from_futhark.