! Copyright (C) 2010 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.data alien.strings arrays
-assocs byte-arrays classes.struct combinators cuda
-cuda.contexts cuda.ffi cuda.libraries fry io io.encodings.utf8
-kernel locals math math.order math.parser namespaces
-prettyprint sequences ;
+assocs byte-arrays combinators cuda cuda.contexts cuda.ffi
+cuda.libraries io io.encodings.utf8 kernel math math.order
+math.parser prettyprint sequences splitting ;
IN: cuda.devices
: #cuda-devices ( -- n )
- int <c-object> [ cuDeviceGetCount cuda-error ] keep int deref ;
+ { int } [ cuDeviceGetCount cuda-error ] with-out-parameters ;
: n>cuda-device ( n -- device )
- [ CUdevice <c-object> ] dip [ cuDeviceGet cuda-error ] 2keep
- drop int deref ;
+ [ { CUdevice } ] dip '[ _ cuDeviceGet cuda-error ] with-out-parameters ;
: enumerate-cuda-devices ( -- devices )
- #cuda-devices iota [ n>cuda-device ] map ;
+ #cuda-devices <iota> [ n>cuda-device ] map ;
: with-each-cuda-device ( quot -- )
[ enumerate-cuda-devices ] dip '[ 0 _ with-cuda-context ] each ; inline
: cuda-device-properties ( n -- properties )
- [ CUdevprop <struct> ] dip
- [ cuDeviceGetProperties cuda-error ] 2keep drop ;
+ [ CUdevprop new ] dip
+ [ cuDeviceGetProperties cuda-error ] keepd ;
: cuda-devices ( -- assoc )
enumerate-cuda-devices [ dup cuda-device-properties ] { } map>assoc ;
[ 2drop utf8 alien>string ] 3bi ;
: cuda-device-capability ( n -- pair )
- [ int <c-object> int <c-object> ] dip
- [ cuDeviceComputeCapability cuda-error ]
- [ drop [ int deref ] bi@ ] 3bi 2array ;
+ [ { int int } ] dip
+ '[ _ cuDeviceComputeCapability cuda-error ] with-out-parameters
+ 2array ;
: cuda-device-memory ( n -- bytes )
- [ uint <c-object> ] dip
- [ cuDeviceTotalMem cuda-error ]
- [ drop uint deref ] 2bi ;
+ [ { ulonglong } ] dip
+ '[ _ cuDeviceTotalMem_v2 cuda-error ] with-out-parameters ;
: cuda-device-attribute ( attribute n -- n )
- [ int <c-object> ] 2dip
- [ cuDeviceGetAttribute cuda-error ]
- [ 2drop int deref ] 3bi ;
+ [ { int } ] 2dip
+ '[ _ _ cuDeviceGetAttribute cuda-error ] with-out-parameters ;
: cuda-device. ( n -- )
{
[ "Memory: " write cuda-device-memory number>string print ]
[
"Capability: " write
- cuda-device-capability [ number>string ] map " " join print
+ cuda-device-capability [ number>string ] map join-words print
]
[ "Properties: " write cuda-device-properties . ]
[
]
} cleave ;
+: cuda-devices. ( -- )
+ init-cuda
+ enumerate-cuda-devices [ cuda-device. ] each ;
+
: cuda. ( -- )
init-cuda
"CUDA Version: " write cuda-version number>string print nl
- #cuda-devices iota [ nl ] [ cuda-device. ] interleave ;
+ #cuda-devices <iota> [ nl ] [ cuda-device. ] interleave ;
: up/i ( x y -- z )
[ 1 - + ] keep /i ; inline