]> gitweb.factorcode.org Git - factor.git/blob - extra/cuda/contexts/contexts.factor
Update some copyright headers to follow the current convention
[factor.git] / extra / cuda / contexts / contexts.factor
1 ! Copyright (C) 2010 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.c-types alien.data continuations cuda cuda.ffi
4 cuda.libraries alien.destructors fry kernel namespaces ;
5 IN: cuda.contexts
6
7 : set-up-cuda-context ( -- )
8     H{ } clone cuda-modules set-global
9     H{ } clone cuda-functions set-global ; inline
10
11 : create-context ( device flags -- context )
12     swap
13     [ { CUcontext } ] 2dip
14     '[ _ _ cuCtxCreate cuda-error ] with-out-parameters ; inline
15
16 : sync-context ( -- )
17     cuCtxSynchronize cuda-error ; inline
18
19 : context-device ( -- n )
20     { CUdevice } [ cuCtxGetDevice cuda-error ] with-out-parameters ; inline
21
22 : destroy-context ( context -- ) cuCtxDestroy cuda-error ; inline
23
24 : clean-up-context ( context -- )
25     [ sync-context ] ignore-errors destroy-context ; inline
26
27 DESTRUCTOR: destroy-context
28 DESTRUCTOR: clean-up-context
29
30 : (with-cuda-context) ( context quot -- )
31     swap '[ _ clean-up-context ] [ ] cleanup ; inline
32
33 : with-cuda-context ( device flags quot -- )
34     [ set-up-cuda-context create-context ] dip (with-cuda-context) ; inline