]> gitweb.factorcode.org Git - factor.git/commitdiff
cuda: rearrange function-launcher grid and block dim to be in the right order
authorJoe Groff <arcata@gmail.com>
Thu, 6 May 2010 00:38:37 +0000 (17:38 -0700)
committerJoe Groff <arcata@gmail.com>
Thu, 6 May 2010 00:38:37 +0000 (17:38 -0700)
extra/cuda/cuda.factor
extra/cuda/demos/hello-world/hello-world.factor
extra/cuda/syntax/syntax.factor

index 9c9b74a9bb383f1034137b2701db2c341a09050c..d4202ba66577f88f849125b7051e6d39a6108afc 100644 (file)
@@ -19,7 +19,7 @@ TUPLE: launcher
         swap >>device ; inline
 
 TUPLE: function-launcher
-dim-block dim-grid shared-size stream ;
+dim-grid dim-block shared-size stream ;
 
 : with-cuda-context ( flags device quot -- )
     H{ } clone cuda-modules set-global
@@ -48,16 +48,23 @@ dim-block dim-grid shared-size stream ;
         { [ dup a:void* = ] [ drop 4 [ cuda-int* ] ] }
     } cond ;
 
+<PRIVATE
+: block-dim ( block -- x y z )
+    dup sequence? [ 3 1 pad-tail first3 ] [ 1 1 ] if ; inline
+: grid-dim ( block -- x y )
+    dup sequence? [ 2 1 pad-tail first2 ] [ 1 ] if ; inline
+PRIVATE>
+
 : run-function-launcher ( function-launcher function -- )
     swap
     {
-        [ dim-block>> first3 function-block-shape* ]
+        [ dim-block>> block-dim function-block-shape* ]
         [ shared-size>> function-shared-size* ]
         [
             dim-grid>> [
                 launch-function*
             ] [
-                first2 launch-function-grid*
+                grid-dim launch-function-grid*
             ] if-empty
         ]
     } 2cleave ;
index 1c9b8a51f7c0a8dc3df173f2bffba1b2e7dad1c1..5db01e412ac576c84baff215b6539839e3a175f8 100644 (file)
@@ -17,7 +17,7 @@ CUDA-FUNCTION: helloWorld ( char* string-ptr ) ;
             "CUDA device " ": " surround write
             "Hello World!" >byte-array [ - ] map-index host>device &cuda-free
 
-            [ { 6 1 1 } { 2 1 } 2<<< helloWorld ]
+            [ { 2 1 } { 6 1 1 } 2<<< helloWorld ]
             [ 12 device>host >string print ] bi
         ] with-destructors
     ] with-each-cuda-device ;
index 4e15fa383ef54d374eea3e40f55dc175b7d1e472..237a87f90099449da38e93a2d4b1a36246d3cce9 100644 (file)
@@ -13,11 +13,11 @@ SYNTAX: CUDA-FUNCTION:
     scan [ create-in current-cuda-library get ] [ ] bi
     ";" scan-c-args drop define-cuda-word ;
 
-: 2<<< ( dim-block dim-grid -- function-launcher )
+: 2<<< ( dim-grid dim-block -- function-launcher )
     0 f function-launcher boa ; inline
 
-: 3<<< ( dim-block dim-grid shared-size -- function-launcher )
+: 3<<< ( dim-grid dim-block shared-size -- function-launcher )
     f function-launcher boa ; inline
 
-: 4<<< ( dim-block dim-grid shared-size stream -- function-launcher )
+: 4<<< ( dim-grid dim-block shared-size stream -- function-launcher )
     function-launcher boa ; inline