Run hello-world on each CUDA device. fix a bug with returning the hello world string. add with-each-cuda-device combinator to run a program on each device. add an init-hook for cuda-init
parent
d6036b6d5b
commit
656f8987a1
|
@ -3,7 +3,7 @@
|
||||||
USING: accessors alien alien.data alien.parser alien.strings
|
USING: accessors alien alien.data alien.parser alien.strings
|
||||||
alien.syntax arrays assocs byte-arrays classes.struct
|
alien.syntax arrays assocs byte-arrays classes.struct
|
||||||
combinators continuations cuda.ffi cuda.memory cuda.utils
|
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
|
io.encodings.utf8 kernel lexer locals macros math math.parser
|
||||||
namespaces nested-comments opengl.gl.extensions parser
|
namespaces nested-comments opengl.gl.extensions parser
|
||||||
prettyprint quotations sequences words ;
|
prettyprint quotations sequences words ;
|
||||||
|
@ -14,6 +14,10 @@ TUPLE: launcher
|
||||||
{ device integer initial: 0 }
|
{ device integer initial: 0 }
|
||||||
{ device-flags initial: 0 } ;
|
{ device-flags initial: 0 } ;
|
||||||
|
|
||||||
|
: <launcher> ( device-id -- launcher )
|
||||||
|
launcher new
|
||||||
|
swap >>device ; inline
|
||||||
|
|
||||||
TUPLE: function-launcher
|
TUPLE: function-launcher
|
||||||
dim-block dim-grid shared-size stream ;
|
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 ]
|
[ 2nip \ function-launcher suffix a:void function-effect ]
|
||||||
3bi define-declared ;
|
3bi define-declared ;
|
||||||
|
|
||||||
|
[ init-cuda ] "cuda-init" add-startup-hook
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
! Copyright (C) 2010 Doug Coleman.
|
! Copyright (C) 2010 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.c-types alien.strings cuda cuda.memory cuda.syntax
|
USING: accessors alien.c-types alien.strings cuda cuda.devices
|
||||||
destructors io io.encodings.utf8 kernel locals math sequences ;
|
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
|
IN: cuda.demos.hello-world
|
||||||
|
|
||||||
CUDA-LIBRARY: hello vocab:cuda/demos/hello-world/hello.ptx
|
CUDA-LIBRARY: hello vocab:cuda/demos/hello-world/hello.ptx
|
||||||
|
|
||||||
CUDA-FUNCTION: helloWorld ( char* string-ptr ) ;
|
CUDA-FUNCTION: helloWorld ( char* string-ptr ) ;
|
||||||
|
|
||||||
:: cuda-hello-world ( -- )
|
: cuda-hello-world ( -- )
|
||||||
T{ launcher { device 0 } } [
|
[
|
||||||
"Hello World!" [ - ] map-index host>device &dispose :> str
|
cuda-launcher get device>> number>string
|
||||||
|
"CUDA device " ": " surround write
|
||||||
|
"Hello World!" [ - ] map-index host>device
|
||||||
|
|
||||||
str { 6 1 1 } { 2 1 } 2<<< helloWorld
|
[ { 6 1 1 } { 2 1 } 2<<< helloWorld ]
|
||||||
|
[ device>host utf8 decode print ] bi
|
||||||
str device>host utf8 alien>string print
|
] with-each-cuda-device ;
|
||||||
] with-cuda ;
|
|
||||||
|
|
||||||
MAIN: cuda-hello-world
|
MAIN: cuda-hello-world
|
||||||
|
|
|
@ -141,3 +141,6 @@ ERROR: no-cuda-library name ;
|
||||||
: function-shared-size ( n -- )
|
: function-shared-size ( n -- )
|
||||||
[ cuda-function get ] dip
|
[ cuda-function get ] dip
|
||||||
cuFuncSetSharedSize cuda-error ;
|
cuFuncSetSharedSize cuda-error ;
|
||||||
|
|
||||||
|
: with-each-cuda-device ( quot -- )
|
||||||
|
[ enumerate-cuda-devices ] dip '[ <launcher> _ with-cuda ] each ; inline
|
||||||
|
|
Loading…
Reference in New Issue