make host>device only take one parameter, add 2<<< for calling cuda functions where shared-memory is 0, simplify hello-world example

db4
Doug Coleman 2010-04-23 13:57:35 -05:00
parent e5c65b2204
commit d6036b6d5b
3 changed files with 14 additions and 11 deletions

View File

@ -10,10 +10,9 @@ CUDA-FUNCTION: helloWorld ( char* string-ptr ) ;
:: cuda-hello-world ( -- )
T{ launcher { device 0 } } [
"Hello World!" [ - ] map-index malloc-device-string
&dispose dup :> str
"Hello World!" [ - ] map-index host>device &dispose :> str
{ 6 1 1 } { 2 1 } 1 3<<< helloWorld
str { 6 1 1 } { 2 1 } 2<<< helloWorld
str device>host utf8 alien>string print
] with-cuda ;

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.data assocs byte-arrays cuda.ffi
cuda.utils destructors io.encodings.string io.encodings.utf8
kernel locals namespaces sequences ;
kernel locals namespaces sequences strings ;
QUALIFIED-WITH: alien.c-types a
IN: cuda.memory
@ -61,14 +61,15 @@ M: cuda-memory dispose ( ptr -- )
: memcpy-array>array ( dest-array dest-index src-array src-ptr count -- )
cuMemcpyAtoA cuda-error ;
: host>device ( dest-ptr src-ptr -- )
[ ptr>> ] dip dup length cuMemcpyHtoD cuda-error ;
GENERIC: host>device ( obj -- ptr )
M: string host>device utf8 encode host>device ;
M: byte-array host>device ( byte-array -- ptr )
[ length cuda-malloc ] keep
[ [ ptr>> ] dip dup length cuMemcpyHtoD cuda-error ]
[ drop ] 2bi ;
:: device>host ( ptr -- seq )
ptr byte-length <byte-array>
[ ptr [ ptr>> ] [ byte-length ] bi cuMemcpyDtoH cuda-error ] keep ;
: malloc-device-string ( string -- n )
utf8 encode
[ length cuda-malloc ] keep
[ host>device ] [ drop ] 2bi ;

View File

@ -13,6 +13,9 @@ SYNTAX: CUDA-FUNCTION:
scan [ create-in current-cuda-library get ] [ ] bi
";" scan-c-args drop define-cuda-word ;
: 2<<< ( dim-block dim-grid -- function-launcher )
0 f function-launcher boa ;
: 3<<< ( dim-block dim-grid shared-size -- function-launcher )
f function-launcher boa ;