Version française
Home     About     Download     Resources     Contact us    
Browse thread
How to write a CUDA kernel in ocaml?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Eray Ozkural <examachine@g...>
Subject: Re: [Caml-list] How to write a CUDA kernel in ocaml?
On Tue, Dec 15, 2009 at 6:29 PM, Basile STARYNKEVITCH
<basile@starynkevitch.net> wrote:
> Eray Ozkural wrote:
>>>>
>>>> I've looked at the CUDA bindings for ocaml, but it seems the kernels
>>>> were in C, am I right? How can I write the kernel in ocaml?
>
>> At any rate, the obvious question from a compiler standpoint is,
>> cannot we compile ocaml to C, is there a way to translate to C first
>> and then to whatever works for kernel? I know little about the ocaml
>> compiler so please forgive my naive questions.
>
> Compiling Ocaml to efficient C is not easy and probably impossible (or
> extremely difficult) in the general case. In particular, tail recursive
> calls are essential in Ocaml, and are not available in C in most compilers.
> Some C compilers are able to generate (in the machine) a teil call for a
> limited kind of C functions, which are not compatible with Ocaml's runtime
> system (& garbage collector).
>
> You could perhaps translate (in a dummy & inefficient way) the full Ocaml
> bytecode of an entire Ocaml application into a C program (for example, as a
> huge monolithic single C function, which would make gcc very unhappy to
> compile it). Of course, you could do much better, but it is not a trivial
> task.
>
> Another issue is that Ocaml might not box (or unbox) your floating point
> values as CUDA (or OpenCL) expects them.
>
> But I am not an expert on these things.


Can any expert please chime in?

The proposed approach of converting from bytecode is sound. In a
hardware compiler project we started from assembly, so I know it can
be done.

One problem I see is, I suppose there would be function pointers, and
they won't work with OpenCL?

I suppose I should investigate a bit more!

Best,

-- 
Eray Ozkural, PhD candidate.  Comp. Sci. Dept., Bilkent University, Ankara
http://groups.yahoo.com/group/ai-philosophy
http://myspace.com/arizanesil http://myspace.com/malfunct