]> gitweb.factorcode.org Git - factor.git/commitdiff
cuda.libraries, cuda.syntax: support for both 32- and 64-bit CUDA pointer abis. make...
authorJoe Groff <arcata@gmail.com>
Fri, 21 May 2010 00:56:20 +0000 (17:56 -0700)
committerJoe Groff <arcata@gmail.com>
Fri, 21 May 2010 00:56:45 +0000 (17:56 -0700)
extra/cuda/demos/hello-world/hello-world.factor
extra/cuda/demos/prefix-sum/prefix-sum.factor
extra/cuda/ffi/ffi.factor
extra/cuda/libraries/libraries.factor
extra/cuda/syntax/syntax.factor

index dae6ce83d6671b15238138fc9a2cb44f9d600f77..8a7adb7b4deff499d7f8524ab08e30bf53acb2d9 100644 (file)
@@ -6,7 +6,7 @@ destructors io io.encodings.string io.encodings.utf8 kernel locals
 math math.parser namespaces sequences strings ;
 IN: cuda.demos.hello-world
 
-CUDA-LIBRARY: hello vocab:cuda/demos/hello-world/hello.ptx
+CUDA-LIBRARY: hello cuda32 vocab:cuda/demos/hello-world/hello.ptx
 
 CUDA-FUNCTION: helloWorld ( char* string-ptr ) ;
 
index aedc9aa095bcd218d4d61d0404cb38129661beaa..d217f61c608400c066c7c924ee04d0ad30ec0756 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2010 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types cuda cuda.contexts cuda.syntax locals ;
+USING: alien.c-types cuda cuda.contexts cuda.libraries cuda.syntax locals ;
 IN: cuda.demos.prefix-sum
 
-CUDA-LIBRARY: prefix-sum vocab:cuda/demos/prefix-sum/prefix-sum.ptx
+CUDA-LIBRARY: prefix-sum cuda32 vocab:cuda/demos/prefix-sum/prefix-sum.ptx
 
 CUDA-FUNCTION: prefix_sum_block ( uint* in, uint* out, uint n ) ;
 
index bcbb1ff60a48edf82d97f358fcabe8dd9860b293..c0537bea8dc540348410072cb5309f07ace8b2a3 100644 (file)
@@ -28,15 +28,6 @@ TYPEDEF: void* CUgraphicsResource
 
 SYMBOLS: CUdouble CUlonglong CUulonglong ;
 
-: >cuda-param-type ( c-type -- c-type' )
-    {
-        { CUdeviceptr [ void* ] }
-        { double      [ CUdouble ] }
-        { longlong    [ CUlonglong ] }
-        { ulonglong   [ CUulonglong ] }
-        [ ]
-    } case ;
-
 <<
 : always-8-byte-align ( c-type -- c-type )
     8 >>align 8 >>align-first ;
index b4a3e35e9f41eba143ef9b386ad5ab3b911aad9d..157a4e2fcaf1dbeb84297170d19c07103991e0c0 100644 (file)
@@ -3,11 +3,14 @@
 USING: accessors alien.data alien.parser arrays assocs
 byte-arrays classes.struct combinators combinators.short-circuit
 cuda cuda.ffi fry generalizations io.backend kernel macros math
-namespaces sequences words ;
+namespaces sequences variants words ;
 FROM: classes.struct.private => compute-struct-offsets write-struct-slot ;
 QUALIFIED-WITH: alien.c-types c
 IN: cuda.libraries
 
+VARIANT: cuda-abi
+    cuda32 cuda64 ;
+
 SYMBOL: cuda-modules
 SYMBOL: cuda-functions
 
@@ -95,14 +98,29 @@ ERROR: no-cuda-library name ;
 : fill-param-buffer ( values... buffer quots... n -- )
     [ cleave-curry ] [ spread* ] bi ; inline
 
-: >argument-type ( c-type -- c-type' )
-    dup { [ c:void* = ] [ c:pointer? ] } 1|| [ drop CUdeviceptr ] when ;
-
-: >argument-struct-slot ( type -- slot )
-    "cuda-arg" swap >argument-type { } <struct-slot-spec> ;
+: pointer-argument-type? ( c-type -- ? )
+    { [ c:void* = ] [ CUdeviceptr = ] [ c:pointer? ] } 1|| ;
 
-: [cuda-arguments] ( c-types -- quot )
-    [ >argument-struct-slot ] map
+: abi-pointer-type ( abi -- type )
+    {
+        { cuda32 [ c:uint ] }
+        { cuda64 [ CUulonglong ] }
+    } case ;
+
+: >argument-type ( c-type abi -- c-type' )
+    swap {
+        { [ dup pointer-argument-type? ] [ drop abi-pointer-type ] }
+        { [ dup c:double    = ] [ 2drop CUdouble ] }
+        { [ dup c:longlong  = ] [ 2drop CUlonglong ] }
+        { [ dup c:ulonglong = ] [ 2drop CUulonglong ] }
+        [ nip ]
+    } cond ;
+
+: >argument-struct-slot ( c-type abi -- slot )
+    >argument-type "cuda-arg" swap { } <struct-slot-spec> ;
+
+: [cuda-arguments] ( c-types abi -- quot )
+    '[ _ >argument-struct-slot ] map
     [ compute-struct-offsets ]
     [ [ '[ _ write-struct-slot ] ] [ ] map-as ]
     [ length ] tri
@@ -112,8 +130,8 @@ ERROR: no-cuda-library name ;
     ] ;
 PRIVATE>
 
-MACRO: cuda-arguments ( c-types -- quot: ( args... function -- ) )
-    [ [ 0 cuda-param-size ] ] [ [cuda-arguments] ] if-empty ;
+MACRO: cuda-arguments ( c-types abi -- quot: ( args... function -- ) )
+    [ [ 0 cuda-param-size ] ] swap '[ _ [cuda-arguments] ] if-empty ;
 
 : get-function-ptr ( module string -- function )
     [ CUfunction <c-object> ] 2dip
@@ -128,9 +146,9 @@ MACRO: cuda-arguments ( c-types -- quot: ( args... function -- ) )
     2array cuda-functions get [ first2 get-function-ptr ] cache ;
 
 MACRO: cuda-invoke ( module-name function-name arguments -- )
-    '[
+    pick lookup-cuda-library abi>> '[
         _ _ cached-function
-        [ nip _ cuda-arguments ]
+        [ nip _ cuda-arguments ]
         [ run-grid ] 2bi
     ] ;
 
@@ -150,14 +168,19 @@ MACRO: cuda-invoke ( module-name function-name arguments -- )
 : define-cuda-global ( word module-name symbol-name -- )
     '[ _ _ cuda-global ] (( -- device-ptr )) define-declared ;
 
-TUPLE: cuda-library name path handle ;
+TUPLE: cuda-library name abi path handle ;
+ERROR: bad-cuda-abi abi ;
+
+: check-cuda-abi ( abi -- abi )
+    dup cuda-abi? [ bad-cuda-abi ] unless ; inline
 
-: <cuda-library> ( name path -- obj )
+: <cuda-library> ( name abi path -- obj )
     \ cuda-library new
         swap >>path
-        swap >>name ;
+        swap check-cuda-abi >>abi
+        swap >>name ; inline
 
-: add-cuda-library ( name path -- )
+: add-cuda-library ( name abi path -- )
     normalize-path <cuda-library>
     dup name>> cuda-libraries get-global set-at ;
 
index b09fff4739239528b32c33ec4e3d5f4a18915579..09b7786cf96fec22ddcd2466fc0d5a70c2a47948 100644 (file)
@@ -1,13 +1,13 @@
 ! Copyright (C) 2010 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien.parser cuda cuda.libraries io.backend
-kernel lexer namespaces parser ;
+fry kernel lexer namespaces parser ;
 IN: cuda.syntax
 
 SYNTAX: CUDA-LIBRARY:
-    scan scan normalize-path
-    [ add-cuda-library ]
-    [ drop current-cuda-library set-global ] 2bi ;
+    scan scan-word scan
+    '[ _ _ add-cuda-library ]
+    [ current-cuda-library set-global ] bi ;
 
 SYNTAX: CUDA-FUNCTION:
     scan [ create-in current-cuda-library get ] keep