diff --git a/extra/cuda/libraries/libraries.factor b/extra/cuda/libraries/libraries.factor index 91c715b4c1..e0f4d9d01c 100644 --- a/extra/cuda/libraries/libraries.factor +++ b/extra/cuda/libraries/libraries.factor @@ -155,17 +155,29 @@ MACRO: cuda-arguments ( c-types -- quot: ( args... function -- ) ) [ cached-module ] dip 2array cuda-functions get [ first2 get-function-ptr* ] cache ; -: define-cuda-word ( word module-name function-name arguments -- ) - [ - '[ - _ _ cached-function - [ nip _ cuda-arguments ] - [ run-grid ] 2bi - ] - ] +MACRO: cuda-invoke ( module-name function-name arguments -- ) + '[ + _ _ cached-function + [ nip _ cuda-arguments ] + [ run-grid ] 2bi + ] ; + +: cuda-global* ( module-name symbol-name -- device-ptr size ) + [ CUdeviceptr c:uint ] 2dip + [ cached-module ] dip + '[ _ _ cuModuleGetGlobal cuda-error ] 2keep [ c:*uint ] bi@ ; inline + +: cuda-global ( module-name symbol-name -- device-ptr ) + cuda-global* drop ; inline + +: define-cuda-function ( word module-name function-name arguments -- ) + [ '[ _ _ _ cuda-invoke ] ] [ 2nip \ grid suffix c:void function-effect ] 3bi define-declared ; +: define-cuda-global ( word module-name symbol-name -- ) + '[ _ _ cuda-global ] (( -- device-ptr )) define-declared ; + TUPLE: cuda-library name path handle ; : ( name path -- obj ) diff --git a/extra/cuda/syntax/syntax.factor b/extra/cuda/syntax/syntax.factor index 0e2dafc790..b09fff4739 100644 --- a/extra/cuda/syntax/syntax.factor +++ b/extra/cuda/syntax/syntax.factor @@ -10,6 +10,9 @@ SYNTAX: CUDA-LIBRARY: [ drop current-cuda-library set-global ] 2bi ; SYNTAX: CUDA-FUNCTION: - scan [ create-in current-cuda-library get ] [ ] bi - ";" scan-c-args drop define-cuda-word ; + scan [ create-in current-cuda-library get ] keep + ";" scan-c-args drop define-cuda-function ; +SYNTAX: CUDA-GLOBAL: + scan [ create-in current-cuda-library get ] keep + define-cuda-global ;