cuda.contexts, cuda.gl: factor out set-up-cuda-context and clean-up-cuda-context so they can be used by objects that own a cuda context (separate from with-cuda-context)
parent
05227a0e76
commit
9fccc38994
|
@ -1,8 +1,12 @@
|
||||||
! (c)2010 Joe Groff bsd license
|
! (c)2010 Joe Groff bsd license
|
||||||
USING: alien.c-types alien.data continuations cuda cuda.ffi
|
USING: alien.c-types alien.data continuations cuda cuda.ffi
|
||||||
cuda.libraries fry kernel namespaces ;
|
cuda.libraries alien.destructors fry kernel namespaces ;
|
||||||
IN: cuda.contexts
|
IN: cuda.contexts
|
||||||
|
|
||||||
|
: set-up-cuda-context ( -- )
|
||||||
|
H{ } clone cuda-modules set-global
|
||||||
|
H{ } clone cuda-functions set-global ; inline
|
||||||
|
|
||||||
: create-context ( device flags -- context )
|
: create-context ( device flags -- context )
|
||||||
swap
|
swap
|
||||||
[ CUcontext <c-object> ] 2dip
|
[ CUcontext <c-object> ] 2dip
|
||||||
|
@ -16,14 +20,15 @@ IN: cuda.contexts
|
||||||
|
|
||||||
: destroy-context ( context -- ) cuCtxDestroy cuda-error ; inline
|
: destroy-context ( context -- ) cuCtxDestroy cuda-error ; inline
|
||||||
|
|
||||||
: (set-up-cuda-context) ( device flags create-quot -- )
|
: clean-up-context ( context -- )
|
||||||
H{ } clone cuda-modules set-global
|
[ sync-context ] ignore-errors destroy-context ; inline
|
||||||
H{ } clone cuda-functions set
|
|
||||||
call ; inline
|
DESTRUCTOR: destroy-context
|
||||||
|
DESTRUCTOR: clean-up-context
|
||||||
|
|
||||||
: (with-cuda-context) ( context quot -- )
|
: (with-cuda-context) ( context quot -- )
|
||||||
swap '[ [ sync-context ] ignore-errors _ destroy-context ] [ ] cleanup ; inline
|
swap '[ _ clean-up-context ] [ ] cleanup ; inline
|
||||||
|
|
||||||
: with-cuda-context ( device flags quot -- )
|
: with-cuda-context ( device flags quot -- )
|
||||||
[ [ create-context ] (set-up-cuda-context) ] dip (with-cuda-context) ; inline
|
[ set-up-cuda-context create-context ] dip (with-cuda-context) ; inline
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ IN: cuda.gl
|
||||||
[ cuGLCtxCreate cuda-error ] 3keep 2drop *void* ; inline
|
[ cuGLCtxCreate cuda-error ] 3keep 2drop *void* ; inline
|
||||||
|
|
||||||
: with-gl-cuda-context ( device flags quot -- )
|
: with-gl-cuda-context ( device flags quot -- )
|
||||||
[ [ create-gl-cuda-context ] (set-up-cuda-context) ] dip (with-cuda-context) ; inline
|
[ set-up-cuda-context create-gl-cuda-context ] dip (with-cuda-context) ; inline
|
||||||
|
|
||||||
: gl-buffer>resource ( gl-buffer flags -- resource )
|
: gl-buffer>resource ( gl-buffer flags -- resource )
|
||||||
enum>number
|
enum>number
|
||||||
|
|
Loading…
Reference in New Issue