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 ;
{ 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 ;
]
[ 2nip \ function-launcher suffix a:void function-effect ]
3bi define-declared ;
+
+[ init-cuda ] "cuda-init" add-startup-hook
! 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
: 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