AccelerateHS/accelerate-cuda — pull request #3 by robeverest (2013-02-15 05:50:35+00:00)
Title: An FFI for the CUDA backend.

Foreign functions for the CUDA backend are just IO functions accepting an array (or a tuple of arrays) as an argument. In CUDA.Foreign there is a collection of functions so that these foreign function can perform things device side. See [this](https://gist.github.com/robeverest/4957566) for a simple example of how it is used.

A few things to note are,

* In order to create a friendly version of devicePtrsOfArray, it was necessary to once again introduce a bunch of nested tuple conversion stuff. There is probably nothing that can be done about this but it does feel a little ugly.

* To test whether a given foreign function is intended for the CUDA backend I had to use Data.Dynamic. I tried a number of ways of doing this but they all fell down because they ultimately involved trying to reify an open typeclass. If there is a better way of doing this I'd love to hear it.

* The IO functions in CUDA.Foreign are mostly wrappers for CIO functions. However simply calling evalCUDA on the original versions results in the CUDA context being pushed when it is already at the top of the stack. To get around this I added evalCUDA', which assumes that the correct CUDA context has already been loaded. This is still not ideal as it involves setting up a bunch of execution state which is already present, but unreachable. The alternatives to this would be having CUDA foreign functions execute in CIO, or perhaps having all the execution state stuff stored in IVars?