[Haskell-cafe] Anonymous FFI calls
f at mazzo.li
Wed Feb 11 15:18:43 UTC 2015
Thanks for the reply.
The work on accelerated is indeed relevant: in accelerate-cuda, CUDA
kernels (which are composed of C code) get compiled to a binary file
invoking an external compiler, and then (this is the relevant part)
the compiled binary is executed used the CUDA library.
The problem is that while CUDA kernels are executable through a
libraries, compiled functions using the C calling convention aren't.
So I can't really call compiled C functions like accelerate-cuda
invokes CUDA kernels.
Relatedly, if I have some function pointer known at runtime that
addresses a C function that takes some arguments, I have no way to
invoke it from Haskell, since all FFI imports must be declared at
compile-time, and I don't know the address of the symbol I want to
execute at compile time.
I am exploring the possibility of adding such capabilities to GHC,
since as I mentioned I don't see any particular roadblock.
On 11 February 2015 at 11:40, Simon Peyton Jones <simonpj at microsoft.com> wrote:
> This may be relevant. http://www.cse.unsw.edu.au/~chak/papers/CMCK14.html
> Manuel gave a talk about something like this at the Haskell Symposium.
> | -----Original Message-----
> | From: Haskell-Cafe [mailto:haskell-cafe-bounces at haskell.org] On Behalf
> | Of Francesco Mazzoli
> | Sent: 11 February 2015 10:26
> | To: haskell; ghc-devs at haskell.org
> | Subject: [Haskell-cafe] Anonymous FFI calls
> | Hi,
> | I am in a situation where it would be very useful to call C functions
> | without an explicit FFI import. For example, I'd like to be able to
> | do
> | (foreign import ccall "cadd" :: CInt -> CInt -> CInt) 1 2
> | instead of declaring the foreign import explicitely at the top level.
> | Is there a way to do this or to achieve similar results in some other
> | way?
> | If not, I imagine it would be easy to implement such a facility in
> | GHC, given that the code implementing calling to C functions must
> | already be present to implement "proper" FFI imports. I think such an
> | addition would be useful in many cases.
> | Thanks,
> | Francesco
> | _______________________________________________
> | Haskell-Cafe mailing list
> | Haskell-Cafe at haskell.org
> | http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the ghc-devs