diff --git a/extra/cuda/demos/hello-world/hello-world.factor b/extra/cuda/demos/hello-world/hello-world.factor index 8855ce6fea..19951c709c 100644 --- a/extra/cuda/demos/hello-world/hello-world.factor +++ b/extra/cuda/demos/hello-world/hello-world.factor @@ -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 ; diff --git a/extra/cuda/memory/memory.factor b/extra/cuda/memory/memory.factor index c3dfe56a53..1ababcb8a0 100644 --- a/extra/cuda/memory/memory.factor +++ b/extra/cuda/memory/memory.factor @@ -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 [ ptr [ ptr>> ] [ byte-length ] bi cuMemcpyDtoH cuda-error ] keep ; - -: malloc-device-string ( string -- n ) - utf8 encode - [ length cuda-malloc ] keep - [ host>device ] [ drop ] 2bi ; diff --git a/extra/cuda/syntax/syntax.factor b/extra/cuda/syntax/syntax.factor index 1cd5edb9d4..ad19c696ec 100644 --- a/extra/cuda/syntax/syntax.factor +++ b/extra/cuda/syntax/syntax.factor @@ -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 ;