]> gitweb.factorcode.org Git - factor.git/commitdiff
Run hello-world on each CUDA device. fix a bug with returning the hello world string...
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 23 Apr 2010 19:27:19 +0000 (14:27 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 23 Apr 2010 19:29:24 +0000 (14:29 -0500)
extra/cuda/cuda.factor
extra/cuda/demos/hello-world/hello-world.factor
extra/cuda/utils/utils.factor

index 94e10a96dd86e7ecacb8e78df2b2c224f8a4545e..b2687d1cb6fc79a967dc0c4b6c4c0885dc384078 100644 (file)
@@ -3,7 +3,7 @@
 USING: accessors alien alien.data alien.parser alien.strings
 alien.syntax arrays assocs byte-arrays classes.struct
 combinators continuations cuda.ffi cuda.memory cuda.utils
-destructors fry io io.backend io.encodings.string
+destructors fry init io io.backend io.encodings.string
 io.encodings.utf8 kernel lexer locals macros math math.parser
 namespaces nested-comments opengl.gl.extensions parser
 prettyprint quotations sequences words ;
@@ -14,6 +14,10 @@ TUPLE: launcher
 { device integer initial: 0 }
 { device-flags initial: 0 } ;
 
+: <launcher> ( device-id -- launcher )
+    launcher new
+        swap >>device ; inline
+
 TUPLE: function-launcher
 dim-block dim-grid shared-size stream ;
 
@@ -81,3 +85,5 @@ MACRO: cuda-arguments ( c-types -- quot: ( args... function -- ) )
     ]
     [ 2nip \ function-launcher suffix a:void function-effect ]
     3bi define-declared ;
+
+[ init-cuda ] "cuda-init" add-startup-hook
index 19951c709c23d5b71d04703c0cc88dff5e29f3f2..789948be681b5ca5ffbe548011257ed65b9dfd90 100644 (file)
@@ -1,20 +1,23 @@
 ! Copyright (C) 2010 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types alien.strings cuda cuda.memory cuda.syntax
-destructors io io.encodings.utf8 kernel locals math sequences ;
+USING: accessors alien.c-types alien.strings cuda cuda.devices
+cuda.memory cuda.syntax cuda.utils destructors io
+io.encodings.string io.encodings.utf8 kernel locals math
+math.parser namespaces sequences ;
 IN: cuda.demos.hello-world
 
 CUDA-LIBRARY: hello vocab:cuda/demos/hello-world/hello.ptx
 
 CUDA-FUNCTION: helloWorld ( char* string-ptr ) ;
 
-:: cuda-hello-world ( -- )
-    T{ launcher { device 0 } } [
-        "Hello World!" [ - ] map-index host>device &dispose :> str
+: cuda-hello-world ( -- )
+    [
+        cuda-launcher get device>> number>string
+        "CUDA device " ": " surround write
+        "Hello World!" [ - ] map-index host>device
 
-        str { 6 1 1 } { 2 1 } 2<<< helloWorld
-
-        str device>host utf8 alien>string print
-    ] with-cuda ;
+        [ { 6 1 1 } { 2 1 } 2<<< helloWorld ]
+        [ device>host utf8 decode print ] bi
+    ] with-each-cuda-device ;
 
 MAIN: cuda-hello-world
index 912b9e2e9253575311dd6dd780f5cce9558ce91b..32e8bf2facf9e519d33e29ea299568caaaef2786 100644 (file)
@@ -141,3 +141,6 @@ ERROR: no-cuda-library name ;
 : function-shared-size ( n -- )
     [ cuda-function get ] dip
     cuFuncSetSharedSize cuda-error ;
+
+: with-each-cuda-device ( quot -- )
+    [ enumerate-cuda-devices ] dip '[ <launcher> _ with-cuda ] each ; inline