diff --git a/extra/cuda/cuda.factor b/extra/cuda/cuda.factor index c4812a285f..837d13c1c0 100644 --- a/extra/cuda/cuda.factor +++ b/extra/cuda/cuda.factor @@ -6,7 +6,7 @@ combinators continuations cuda.ffi cuda.memory cuda.utils destructors fry init io io.backend io.encodings.string io.encodings.utf8 kernel lexer locals macros math math.parser namespaces nested-comments opengl.gl.extensions parser -prettyprint quotations sequences words ; +prettyprint quotations sequences words cuda.libraries ; QUALIFIED-WITH: alien.c-types a IN: cuda diff --git a/extra/cuda/libraries/authors.txt b/extra/cuda/libraries/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/cuda/libraries/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/extra/cuda/libraries/libraries.factor b/extra/cuda/libraries/libraries.factor new file mode 100644 index 0000000000..93b9842919 --- /dev/null +++ b/extra/cuda/libraries/libraries.factor @@ -0,0 +1,53 @@ +! Copyright (C) 2010 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors alien.c-types alien.data arrays assocs +cuda.ffi cuda.utils io.backend kernel namespaces sequences ; +IN: cuda.libraries + +SYMBOL: cuda-libraries +cuda-libraries [ H{ } clone ] initialize + +SYMBOL: current-cuda-library + +TUPLE: cuda-library name path handle ; + +: ( name path -- obj ) + \ cuda-library new + swap >>path + swap >>name ; + +: add-cuda-library ( name path -- ) + normalize-path + dup name>> cuda-libraries get-global set-at ; + +: ?delete-at ( key assoc -- old/key ? ) + 2dup delete-at* [ 2nip t ] [ 2drop f ] if ; inline + +ERROR: no-cuda-library name ; + +: load-module ( path -- module ) + [ CUmodule ] dip + [ cuModuleLoad cuda-error ] 2keep drop *void* ; + +: unload-module ( module -- ) + cuModuleUnload cuda-error ; + +: load-cuda-library ( library -- handle ) + path>> load-module ; + +: lookup-cuda-library ( name -- cuda-library ) + cuda-libraries get ?at [ no-cuda-library ] unless ; + +: remove-cuda-library ( name -- library ) + cuda-libraries get ?delete-at [ no-cuda-library ] unless ; + +: unload-cuda-library ( name -- ) + remove-cuda-library handle>> unload-module ; + +: cached-module ( module-name -- alien ) + lookup-cuda-library + cuda-modules get-global [ load-cuda-library ] cache ; + +: cached-function ( module-name function-name -- alien ) + [ cached-module ] dip + 2array cuda-functions get [ first2 get-function-ptr* ] cache ; diff --git a/extra/cuda/utils/utils.factor b/extra/cuda/utils/utils.factor index 32e8bf2fac..7422836c84 100644 --- a/extra/cuda/utils/utils.factor +++ b/extra/cuda/utils/utils.factor @@ -44,55 +44,6 @@ ERROR: throw-cuda-error n ; : destroy-context ( context -- ) cuCtxDestroy cuda-error ; -SYMBOL: cuda-libraries -cuda-libraries [ H{ } clone ] initialize - -SYMBOL: current-cuda-library - -TUPLE: cuda-library name path handle ; - -: ( name path -- obj ) - \ cuda-library new - swap >>path - swap >>name ; - -: add-cuda-library ( name path -- ) - normalize-path - dup name>> cuda-libraries get-global set-at ; - -: ?delete-at ( key assoc -- old/key ? ) - 2dup delete-at* [ 2nip t ] [ 2drop f ] if ; inline - -ERROR: no-cuda-library name ; - -: load-module ( path -- module ) - [ CUmodule ] dip - [ cuModuleLoad cuda-error ] 2keep drop *void* ; - -: unload-module ( module -- ) - cuModuleUnload cuda-error ; - -: load-cuda-library ( library -- handle ) - path>> load-module ; - -: lookup-cuda-library ( name -- cuda-library ) - cuda-libraries get ?at [ no-cuda-library ] unless ; - -: remove-cuda-library ( name -- library ) - cuda-libraries get ?delete-at [ no-cuda-library ] unless ; - -: unload-cuda-library ( name -- ) - remove-cuda-library handle>> unload-module ; - - -: cached-module ( module-name -- alien ) - lookup-cuda-library - cuda-modules get-global [ load-cuda-library ] cache ; - -: cached-function ( module-name function-name -- alien ) - [ cached-module ] dip - 2array cuda-functions get [ first2 get-function-ptr* ] cache ; - : launch-function* ( function -- ) cuLaunch cuda-error ; : launch-function ( -- ) cuda-function get cuLaunch cuda-error ;