forked from Theano/libgpuarray
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprivate_opencl.h
More file actions
79 lines (67 loc) · 1.69 KB
/
Copy pathprivate_opencl.h
File metadata and controls
79 lines (67 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef _GPUARRAY_PRIVATE_OPENCL
#define _GPUARRAY_PRIVATE_OPENCL
#include "private.h"
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/opencl.h>
#endif
#ifdef DEBUG
#include <assert.h>
#define CTX_TAG "ocl ctx "
#define BUF_TAG "ocl buf "
#define KER_TAG "ocl kern"
#define TAG_CTX(c) memcpy((c)->tag, CTX_TAG, 8)
#define TAG_BUF(b) memcpy((b)->tag, BUF_TAG, 8)
#define TAG_KER(k) memcpy((k)->tag, KER_TAG, 8)
#define ASSERT_CTX(c) assert(memcmp((c)->tag, CTX_TAG, 8) == 0)
#define ASSERT_BUF(b) assert(memcmp((b)->tag, BUF_TAG, 8) == 0)
#define ASSERT_KER(k) assert(memcmp((k)->tag, KER_TAG, 8) == 0)
#define CLEAR(o) memset((o)->tag, 0, 8);
#else
#define TAG_CTX(c)
#define TAG_BUF(b)
#define TAG_KER(k)
#define ASSERT_CTX(c)
#define ASSERT_BUF(b)
#define ASSERT_KER(k)
#define CLEAR(o)
#endif
typedef struct _cl_ctx {
GPUCONTEXT_HEAD;
cl_context ctx;
cl_command_queue q;
char *exts;
char *preamble;
cl_int err;
} cl_ctx;
STATIC_ASSERT(sizeof(cl_ctx) <= sizeof(gpucontext), sizeof_struct_gpucontext_cl);
struct _gpudata {
cl_mem buf;
cl_ctx *ctx;
/* Don't change anyhting above this without checking
struct _partial_gpudata */
cl_event ev;
unsigned int refcnt;
#ifdef DEBUG
char tag[8];
#endif
};
struct _gpukernel {
cl_ctx *ctx; /* Keep the context first */
cl_kernel k;
cl_event ev;
cl_event **evr;
int *types;
unsigned int argcount;
unsigned int refcnt;
cl_uint num_ev;
#ifdef DEBUG
char tag[8];
#endif
};
GPUARRAY_LOCAL cl_ctx *cl_make_ctx(cl_context ctx, int flags);
GPUARRAY_LOCAL cl_command_queue cl_get_stream(gpucontext *ctx);
GPUARRAY_LOCAL gpudata *cl_make_buf(gpucontext *c, cl_mem buf);
GPUARRAY_LOCAL cl_mem cl_get_buf(gpudata *g);
#endif