@@ -22,9 +22,26 @@ extern "C" {
2222#ifdef CONFUSE_EMACS
2323}
2424#endif
25-
2625struct _gpudata ;
2726
27+ #define GPUCONTEXT_HEAD \
28+ void *blas_handle; \
29+ unsigned int refcnt; \
30+ int flags; \
31+ struct _gpudata *errbuf; \
32+ char bin_id[64]; \
33+ char tag[8]
34+
35+ /**
36+ * Partially opaque struct for context data.
37+ */
38+ typedef struct _gpucontext {
39+ GPUCONTEXT_HEAD ;
40+ void * ctx_ptr ;
41+ void * private [7 ];
42+ } gpucontext ;
43+
44+
2845/**
2946 * Opaque struct for buffer data.
3047 */
@@ -37,11 +54,14 @@ struct _gpukernel;
3754 */
3855typedef struct _gpukernel gpukernel ;
3956
57+ struct _gpuarray_buffer_ops ;
4058/**
4159 * Function table that a backend must provide.
4260 * \headerfile gpuarray/buffer.h
4361 */
44- typedef struct _gpuarray_buffer_ops {
62+ typedef struct _gpuarray_buffer_ops gpuarray_buffer_ops ;
63+
64+ struct _gpuarray_buffer_ops {
4565 /**
4666 * Create a context on the specified device.
4767 *
@@ -55,7 +75,7 @@ typedef struct _gpuarray_buffer_ops {
5575 * \returns An opaque pointer to the created context or NULL if an
5676 * error occured.
5777 */
58- void * (* buffer_init )(int dev , int flags , int * ret );
78+ gpucontext * (* buffer_init )(int dev , int flags , int * ret );
5979
6080/**
6181 * \defgroup context_flags Context flags
@@ -108,7 +128,7 @@ typedef struct _gpuarray_buffer_ops {
108128 *
109129 * \param ctx a valid context pointer.
110130 */
111- void (* buffer_deinit )(void * ctx );
131+ void (* buffer_deinit )(gpucontext * ctx );
112132
113133 /**
114134 * Allocates a buffer of size `sz` in context `ctx`.
@@ -126,7 +146,7 @@ typedef struct _gpuarray_buffer_ops {
126146 * structure is intentionally opaque as its content may change
127147 * according to the backend used.
128148 */
129- gpudata * (* buffer_alloc )(void * ctx , size_t sz , void * data , int flags ,
149+ gpudata * (* buffer_alloc )(gpucontext * ctx , size_t sz , void * data , int flags ,
130150 int * ret );
131151
132152/**
@@ -308,7 +328,7 @@ typedef struct _gpuarray_buffer_ops {
308328 * \returns Allocated kernel structure or NULL if an error occured.
309329 * `ret` will be updated with the error code if not NULL.
310330 */
311- gpukernel * (* kernel_alloc )(void * ctx , unsigned int count ,
331+ gpukernel * (* kernel_alloc )(gpucontext * ctx , unsigned int count ,
312332 const char * * strings , const size_t * lengths ,
313333 const char * fname , unsigned int numargs ,
314334 const int * typecodes , int flags , int * ret , char * * err_str );
@@ -453,7 +473,7 @@ typedef struct _gpuarray_buffer_ops {
453473 * transfer could be found.
454474 */
455475 gpudata * (* buffer_transfer )(gpudata * src , size_t offset , size_t sz ,
456- void * dst_ctx , int may_share );
476+ gpucontext * dst_ctx , int may_share );
457477
458478 /**
459479 * Fetch a property.
@@ -471,7 +491,7 @@ typedef struct _gpuarray_buffer_ops {
471491 *
472492 * \returns GA_NO_ERROR or an error code if an error occurred.
473493 */
474- int (* property )(void * ctx , gpudata * buf , gpukernel * k , int prop_id ,
494+ int (* property )(gpucontext * ctx , gpudata * buf , gpukernel * k , int prop_id ,
475495 void * res );
476496
477497 /**
@@ -488,8 +508,8 @@ typedef struct _gpuarray_buffer_ops {
488508 *
489509 * \returns string description of the last error
490510 */
491- const char * (* ctx_error )(void * ctx );
492- } gpuarray_buffer_ops ;
511+ const char * (* ctx_error )(gpucontext * ctx );
512+ };
493513
494514/**
495515 * \defgroup props Properties
@@ -640,7 +660,7 @@ typedef struct _gpuarray_buffer_ops {
640660/**
641661 * Get the context in which this buffer was allocated.
642662 *
643- * Type: `void *`
663+ * Type: `gpucontext *`
644664 */
645665#define GA_BUFFER_PROP_CTX 512
646666
@@ -665,7 +685,7 @@ typedef struct _gpuarray_buffer_ops {
665685/**
666686 * Get the context for which this kernel was compiled.
667687 *
668- * Type: `void *`
688+ * Type: `gpucontext *`
669689 */
670690#define GA_KERNEL_PROP_CTX 1024
671691
@@ -769,8 +789,8 @@ typedef enum _ga_usefl {
769789 *
770790 * \returns A string description of the error.
771791 */
772- GPUARRAY_PUBLIC const char * Gpu_error (const gpuarray_buffer_ops * o , void * ctx ,
773- int err );
792+ GPUARRAY_PUBLIC const char * Gpu_error (const gpuarray_buffer_ops * o ,
793+ gpucontext * ctx , int err );
774794/**
775795 * Get operations vector for a backend.
776796 *
@@ -790,14 +810,14 @@ GPUARRAY_PUBLIC const gpuarray_buffer_ops *gpuarray_get_ops(const char *name);
790810 * can be done.
791811 */
792812GPUARRAY_PUBLIC gpudata * gpuarray_buffer_transfer (gpudata * buf , size_t offset ,
793- size_t sz , void * src_ctx ,
813+ size_t sz , gpucontext * src_ctx ,
794814 const gpuarray_buffer_ops * src_ops ,
795- void * dst_ctx ,
815+ gpucontext * dst_ctx ,
796816 const gpuarray_buffer_ops * dst_ops ,
797817 int may_share , int * ret );
798818
799- GPUARRAY_PUBLIC void * gpuarray_buffer_context (const gpuarray_buffer_ops * ops ,
800- gpudata * b );
819+ GPUARRAY_PUBLIC gpucontext * gpuarray_buffer_context (const gpuarray_buffer_ops * ops ,
820+ gpudata * b );
801821
802822#ifdef __cplusplus
803823}
0 commit comments