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 19F56BBAF for ; Tue, 15 Dec 2009 18:46:46 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As4BACdaJ0vRVdrkkGdsb2JhbACQJYF1ghWGUT8BAQEBCQkMBxMDrHeBMYVviGMBAgMFhCYE X-IronPort-AV: E=Sophos;i="4.47,400,1257116400"; d="scan'208";a="52163816" Received: from mail-bw0-f228.google.com ([209.85.218.228]) by mail4-smtp-sop.national.inria.fr with ESMTP; 15 Dec 2009 18:46:45 +0100 Received: by bwz28 with SMTP id 28so135945bwz.17 for ; Tue, 15 Dec 2009 09:46:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=xu4LwMKrPza9KQZs9hjkeak0ps1q0a/AtQHUqbb9ANo=; b=Zxy+RK/JIMhYQ3XZ7IUc0oryWTYwodMtwLFxTQ6cscFRYuZN+PGJKEdVgLAOuEtXjJ Q2ntD9JLym26WjPBYTLlD8bvxImznRcrdeil0qjxIjeYfocNCiE5owrO+U6A52kn7wpW 38Br5AGqgt3JggAmm21R0YbCSfXMIiFNdmiGI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=jAbp9Nf7ta8y55U+or1TK5WW57f5LTNux6V03KkzWJVWYVp3V0iuTiHGnoLB/pTJa0 avFqTSKc+F9kLrQUGDIspuQ4ChS0TAYoJpsYYVtLVkJk4jBnzcQicAFUMbNImJsf4JQs k7apGsL47P8rvMkTDajsyPUGHh6LLBBTNg8es= MIME-Version: 1.0 Received: by 10.204.15.132 with SMTP id k4mr51761bka.139.1260899205083; Tue, 15 Dec 2009 09:46:45 -0800 (PST) In-Reply-To: <4B27B981.80700@starynkevitch.net> References: <320e992a0912150737t483a5946x9cad351fc344691f@mail.gmail.com> <4B27B442.9030300@starynkevitch.net> <320e992a0912150820l4d36e4e0s24dc7cc084c9fc29@mail.gmail.com> <4B27B981.80700@starynkevitch.net> Date: Tue, 15 Dec 2009 19:46:45 +0200 Message-ID: <320e992a0912150946m11ed652dif902c43945a2d675@mail.gmail.com> Subject: Re: [Caml-list] How to write a CUDA kernel in ocaml? From: Eray Ozkural To: Basile STARYNKEVITCH Cc: caml-list@inria.fr, Emmanuel Chailloux Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; ocaml:01 eray:01 ozkural:01 basile:01 basile:01 eray:01 ozkural:01 bindings:01 ocaml:01 compiler:01 compiler:01 recursive:01 ocaml's:01 runtime:01 bytecode:01 On Tue, Dec 15, 2009 at 6:29 PM, Basile STARYNKEVITCH 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