From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id E80C3BBAF for ; Tue, 15 Dec 2009 17:29:52 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlEDAJxIJ0s+BBFmeWdsb2JhbACBS5l0AQELCwgHFAS8foQrBA X-IronPort-AV: E=Sophos;i="4.47,400,1257116400"; d="scan'208";a="52158486" Received: from smtp-102-tuesday.noc.nerim.net (HELO mallaury.nerim.net) ([62.4.17.102]) by mail4-smtp-sop.national.inria.fr with ESMTP; 15 Dec 2009 17:29:52 +0100 Received: from hector.lesours (ours.starynkevitch.net [213.41.244.95]) by mallaury.nerim.net (Postfix) with ESMTP id 234D0A1083; Tue, 15 Dec 2009 17:29:51 +0100 (CET) Received: from glinka.lesours ([192.168.0.1]) by hector.lesours with esmtp (Exim 4.69) (envelope-from ) id 1NKaHa-0005q8-SC; Tue, 15 Dec 2009 17:29:54 +0100 Message-ID: <4B27B981.80700@starynkevitch.net> Date: Tue, 15 Dec 2009 17:29:53 +0100 From: Basile STARYNKEVITCH User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20091109) MIME-Version: 1.0 To: Eray Ozkural Cc: caml-list@inria.fr, Emmanuel Chailloux Subject: Re: [Caml-list] How to write a CUDA kernel in ocaml? References: <320e992a0912150737t483a5946x9cad351fc344691f@mail.gmail.com> <4B27B442.9030300@starynkevitch.net> <320e992a0912150820l4d36e4e0s24dc7cc084c9fc29@mail.gmail.com> In-Reply-To: <320e992a0912150820l4d36e4e0s24dc7cc084c9fc29@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; basile:01 basile:01 ocaml:01 eray:01 ozkural:01 bindings:01 ocaml:01 compiler:01 compiler:01 recursive:01 ocaml's:01 runtime:01 bytecode:01 gcc:01 trivial:01 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: basilestarynkevitchnet mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} ***