]> gitweb.factorcode.org Git - factor.git/blob - extra/cuda/contexts/contexts.factor
Remove usages of <void*> and *void*
[factor.git] / extra / cuda / contexts / contexts.factor
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 ;
4 IN: cuda.contexts
5
6 : set-up-cuda-context ( -- )
7     H{ } clone cuda-modules set-global
8     H{ } clone cuda-functions set-global ; inline
9
10 : create-context ( device flags -- context )
11     swap
12     [ CUcontext <c-object> ] 2dip
13     [ cuCtxCreate cuda-error ] 3keep 2drop void* deref ; inline
14
15 : sync-context ( -- )
16     cuCtxSynchronize cuda-error ; inline
17
18 : context-device ( -- n )
19     CUdevice <c-object> [ cuCtxGetDevice cuda-error ] keep int deref ; inline
20
21 : destroy-context ( context -- ) cuCtxDestroy cuda-error ; inline
22
23 : clean-up-context ( context -- )
24     [ sync-context ] ignore-errors destroy-context ; inline
25
26 DESTRUCTOR: destroy-context
27 DESTRUCTOR: clean-up-context
28
29 : (with-cuda-context) ( context quot -- )
30     swap '[ _ clean-up-context ] [ ] cleanup ; inline
31
32 : with-cuda-context ( device flags quot -- )
33     [ set-up-cuda-context create-context ] dip (with-cuda-context) ; inline
34