factor/extra/cuda/utils/utils.factor

97 lines
2.6 KiB
Factor
Raw Normal View History

! Copyright (C) 2010 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
2010-04-19 02:21:21 -04:00
USING: accessors alien.c-types alien.data alien.strings arrays
2010-05-10 20:50:28 -04:00
assocs byte-arrays classes.struct combinators cuda.ffi
io io.backend io.encodings.utf8 kernel math.parser namespaces
2010-04-19 02:21:21 -04:00
prettyprint sequences ;
IN: cuda.utils
SYMBOL: cuda-module
SYMBOL: cuda-function
SYMBOL: cuda-modules
SYMBOL: cuda-functions
ERROR: throw-cuda-error n ;
: cuda-error ( n -- )
dup CUDA_SUCCESS = [ drop ] [ throw-cuda-error ] if ;
: cuda-version ( -- n )
2010-04-19 02:21:21 -04:00
int <c-object> [ cuDriverGetVersion cuda-error ] keep *int ;
: get-function-ptr* ( module string -- function )
[ CUfunction <c-object> ] 2dip
2010-04-19 02:21:21 -04:00
[ cuModuleGetFunction cuda-error ] 3keep 2drop *void* ;
: get-function-ptr ( string -- function )
[ cuda-module get ] dip get-function-ptr* ;
: with-cuda-function ( string quot -- )
[
get-function-ptr* cuda-function set
] dip call ; inline
: create-context ( device flags -- context )
swap
[ CUcontext <c-object> ] 2dip
2010-05-10 18:06:15 -04:00
[ cuCtxCreate cuda-error ] 3keep 2drop *void* ; inline
2010-05-10 18:06:15 -04:00
: sync-context ( -- )
cuCtxSynchronize cuda-error ; inline
: context-device ( -- n )
CUdevice <c-object> [ cuCtxGetDevice cuda-error ] keep *int ; inline
2010-05-10 18:06:15 -04:00
: destroy-context ( context -- ) cuCtxDestroy cuda-error ; inline
2010-05-10 18:06:15 -04:00
: launch-function* ( function -- ) cuLaunch cuda-error ; inline
: launch-function ( -- ) cuda-function get cuLaunch cuda-error ; inline
: cuda-int* ( function offset value -- )
2010-05-10 18:06:15 -04:00
cuParamSeti cuda-error ; inline
: cuda-int ( offset value -- )
2010-05-10 18:06:15 -04:00
[ cuda-function get ] 2dip cuda-int* ; inline
: cuda-float* ( function offset value -- )
2010-05-10 18:06:15 -04:00
cuParamSetf cuda-error ; inline
: cuda-float ( offset value -- )
2010-05-10 18:06:15 -04:00
[ cuda-function get ] 2dip cuda-float* ; inline
: cuda-vector* ( function offset ptr n -- )
2010-05-10 18:06:15 -04:00
cuParamSetv cuda-error ; inline
: cuda-vector ( offset ptr n -- )
2010-05-10 18:06:15 -04:00
[ cuda-function get ] 3dip cuda-vector* ; inline
: param-size* ( function n -- )
2010-05-10 18:06:15 -04:00
cuParamSetSize cuda-error ; inline
: param-size ( n -- )
2010-05-10 18:06:15 -04:00
[ cuda-function get ] dip param-size* ; inline
: launch-function-grid* ( function width height -- )
2010-05-10 18:06:15 -04:00
cuLaunchGrid cuda-error ; inline
: launch-function-grid ( width height -- )
[ cuda-function get ] 2dip
2010-05-10 18:06:15 -04:00
cuLaunchGrid cuda-error ; inline
: function-block-shape* ( function x y z -- )
2010-05-10 18:06:15 -04:00
cuFuncSetBlockShape cuda-error ; inline
: function-block-shape ( x y z -- )
[ cuda-function get ] 3dip
2010-05-10 18:06:15 -04:00
cuFuncSetBlockShape cuda-error ; inline
: function-shared-size* ( function n -- )
2010-05-10 18:06:15 -04:00
cuFuncSetSharedSize cuda-error ; inline
: function-shared-size ( n -- )
[ cuda-function get ] dip
2010-05-10 18:06:15 -04:00
cuFuncSetSharedSize cuda-error ; inline