make host>device only take one parameter, add 2<<< for calling cuda functions where shared-memory is 0, simplify hello-world example
parent
e5c65b2204
commit
d6036b6d5b
|
@ -10,10 +10,9 @@ CUDA-FUNCTION: helloWorld ( char* string-ptr ) ;
|
||||||
|
|
||||||
:: cuda-hello-world ( -- )
|
:: cuda-hello-world ( -- )
|
||||||
T{ launcher { device 0 } } [
|
T{ launcher { device 0 } } [
|
||||||
"Hello World!" [ - ] map-index malloc-device-string
|
"Hello World!" [ - ] map-index host>device &dispose :> str
|
||||||
&dispose dup :> str
|
|
||||||
|
|
||||||
{ 6 1 1 } { 2 1 } 1 3<<< helloWorld
|
str { 6 1 1 } { 2 1 } 2<<< helloWorld
|
||||||
|
|
||||||
str device>host utf8 alien>string print
|
str device>host utf8 alien>string print
|
||||||
] with-cuda ;
|
] with-cuda ;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien alien.data assocs byte-arrays cuda.ffi
|
USING: accessors alien alien.data assocs byte-arrays cuda.ffi
|
||||||
cuda.utils destructors io.encodings.string io.encodings.utf8
|
cuda.utils destructors io.encodings.string io.encodings.utf8
|
||||||
kernel locals namespaces sequences ;
|
kernel locals namespaces sequences strings ;
|
||||||
QUALIFIED-WITH: alien.c-types a
|
QUALIFIED-WITH: alien.c-types a
|
||||||
IN: cuda.memory
|
IN: cuda.memory
|
||||||
|
|
||||||
|
@ -61,14 +61,15 @@ M: cuda-memory dispose ( ptr -- )
|
||||||
: memcpy-array>array ( dest-array dest-index src-array src-ptr count -- )
|
: memcpy-array>array ( dest-array dest-index src-array src-ptr count -- )
|
||||||
cuMemcpyAtoA cuda-error ;
|
cuMemcpyAtoA cuda-error ;
|
||||||
|
|
||||||
: host>device ( dest-ptr src-ptr -- )
|
GENERIC: host>device ( obj -- ptr )
|
||||||
[ ptr>> ] dip dup length cuMemcpyHtoD cuda-error ;
|
|
||||||
|
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 )
|
:: device>host ( ptr -- seq )
|
||||||
ptr byte-length <byte-array>
|
ptr byte-length <byte-array>
|
||||||
[ ptr [ ptr>> ] [ byte-length ] bi cuMemcpyDtoH cuda-error ] keep ;
|
[ ptr [ ptr>> ] [ byte-length ] bi cuMemcpyDtoH cuda-error ] keep ;
|
||||||
|
|
||||||
: malloc-device-string ( string -- n )
|
|
||||||
utf8 encode
|
|
||||||
[ length cuda-malloc ] keep
|
|
||||||
[ host>device ] [ drop ] 2bi ;
|
|
||||||
|
|
|
@ -13,6 +13,9 @@ SYNTAX: CUDA-FUNCTION:
|
||||||
scan [ create-in current-cuda-library get ] [ ] bi
|
scan [ create-in current-cuda-library get ] [ ] bi
|
||||||
";" scan-c-args drop define-cuda-word ;
|
";" 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 )
|
: 3<<< ( dim-block dim-grid shared-size -- function-launcher )
|
||||||
f function-launcher boa ;
|
f function-launcher boa ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue