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: Basile STARYNKEVITCH <basile@s...>
Subject: Re: [Caml-list] How to write a CUDA kernel in ocaml?
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.

Good luck.

Regards.
-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***