 ! Copyright (C) 2010 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.data alien.parser arrays
-assocs combinators cuda cuda.ffi fry io.backend kernel macros
-math namespaces sequences words ;
+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 ;
+FROM: classes.struct.private => compute-struct-offsets write-struct-slot ;
 QUALIFIED-WITH: alien.c-types c
 IN: cuda.libraries
 


: <grid-shared-stream> ( dim-grid dim-block shared-size stream -- grid )
    grid boa ; inline

: c-type>cuda-setter ( c-type -- n cuda-type )
    {
        { [ dup c:int = ] [ drop 4 [ cuda-int ] ] }
        { [ dup c:uint = ] [ drop 4 [ cuda-int ] ] }
        { [ dup c:float = ] [ drop 4 [ cuda-float ] ] }
        { [ dup c:pointer? ] [ drop 4 [ cuda-int ] ] }
        { [ dup c:void* = ] [ drop 4 [ cuda-int ] ] }
    } cond ;

<PRIVATE
: block-dim ( block -- x y z )

: ?delete-at ( key assoc -- old/key ? )
    2dup delete-at* [ 2nip t ] [ 2drop f ] if ; inline

: cuda-param-size ( function n -- )
    cuParamSetSize cuda-error ; inline

: cuda-vector ( function offset ptr n -- )
    cuParamSetv cuda-error ; inline

: launch-function-grid ( function width height -- )
    cuLaunchGrid cuda-error ; inline
