1 ! (c)2010 Joe Groff bsd license
2 USING: alien.c-types alien.data continuations cuda cuda.ffi
3 cuda.libraries alien.destructors fry kernel namespaces ;
6 : set-up-cuda-context ( -- )
7 H{ } clone cuda-modules set-global
8 H{ } clone cuda-functions set-global ; inline
10 : create-context ( device flags -- context )
12 [ { CUcontext } ] 2dip
13 '[ _ _ cuCtxCreate cuda-error ] with-out-parameters ; inline
16 cuCtxSynchronize cuda-error ; inline
18 : context-device ( -- n )
19 { CUdevice } [ cuCtxGetDevice cuda-error ] with-out-parameters ; inline
21 : destroy-context ( context -- ) cuCtxDestroy cuda-error ; inline
23 : clean-up-context ( context -- )
24 [ sync-context ] ignore-errors destroy-context ; inline
26 DESTRUCTOR: destroy-context
27 DESTRUCTOR: clean-up-context
29 : (with-cuda-context) ( context quot -- )
30 swap '[ _ clean-up-context ] [ ] cleanup ; inline
32 : with-cuda-context ( device flags quot -- )
33 [ set-up-cuda-context create-context ] dip (with-cuda-context) ; inline