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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
#include <CL/cl.h>
#include "core/context.h"
#include "core/device.h"
#include "cpuwinsys/cpuwinsys.h"
// Context APIs
cl_context
clCreateContext(const cl_context_properties *properties,
cl_uint num_devices,
const cl_device_id * devices,
void (*pfn_notify)(const char *, const void *, size_t, void *),
void * user_data,
cl_int * errcode_ret)
{
cl_context ret_context = NULL;
cl_device_type type;
cl_device_id device = devices[0];
cl_int device_info;
device_info = clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof(type), &type, NULL);
if (device_info != CL_INVALID_DEVICE) {
ret_context = clCreateContextFromType(properties, type,
pfn_notify, user_data, errcode_ret);
}
return ret_context;
}
cl_context
clCreateContextFromType(const cl_context_properties *properties,
cl_device_type device_type,
void (*pfn_notify)(const char *, const void *, size_t, void *) /* pfn_notify */,
void * user_data,
cl_int * errcode_ret)
{
struct pipe_context *context = NULL;
switch (device_type) {
case CL_DEVICE_TYPE_CPU:
context =
cl_create_context(cpu_winsys());
break;
default:
if (errcode_ret) {
*errcode_ret = CL_INVALID_DEVICE_TYPE;
}
goto fail;
}
fail:
return cl_convert_context(context);
}
cl_int
clRetainContext(cl_context context)
{
cl_int ret;
if (context) {
context->id++;
ret = CL_SUCCESS;
} else {
ret = CL_INVALID_CONTEXT;
}
return ret;
}
cl_int
clReleaseContext(cl_context context)
{
cl_uint ret;
if (context) {
if( !context->id ) {
context->pipe.destroy(&context->pipe);
} else {
context->id--;
}
ret = CL_SUCCESS;
} else {
ret = CL_INVALID_CONTEXT;
}
return ret;
}
cl_int
clGetContextInfo(cl_context context,
cl_context_info param_name,
size_t param_value_size,
void * param_value,
size_t * param_value_size_ret)
{
return 0;
}
|