source: CIVL/examples/translation/opencl/setup/openCL.cvl@ 1a54e12

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 1a54e12 was 1a54e12, checked in by Jacob Trieu <fuufusuu@…>, 12 years ago

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1097 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 5.1 KB
Line 
1
2#include "cl.cvl"
3#include <stdlib.h>
4#include <string.h>
5#include <stdio.h>
6
7$input int DEVICE_ID;
8$input int DEVICE_ID_BOUND;
9
10$assume 0 < DEVICE_ID && DEVICE_ID < DEVICE_ID_BOUND;
11
12
13/*
14 Gives back an int for the error code, fills devices with ids of devices
15 See cl.cvl for files
16 platform - The platform, can be NULL
17 device_type - Has the device type
18 num_entries - Is the max number of devices that can be filled
19 devices - A pointer that will contain the IDs
20 num_devices - Says how many devices were added, can be NULL
21*/
22int clGetDeviceIDs(cl_platform_id platform,
23 cl_device_type device_type,
24 cl_uint num_entries,
25 cl_device_id *devices,
26 cl_uint *num_devices)
27 {
28 //$assume device_type == CL_DEVICE_TYPE_DEFAULT;
29 int i = 0;
30 //cl_platform_id int value can be null
31
32 //num_entries number of devices that can be added
33 /*
34 if(num_entries == 0 && devices != 0)
35 {
36 return CL_INVALID_VALUE;
37 }
38
39 if(num_entries == 0 && devices == 0)
40 {
41 return CL_INVALID_VALUE;
42 }
43
44 //CIVL cannot pass this if block if not commented out
45 /*
46 if(device_type & (CL_DEVICE_TYPE_DEFAULT | CL_DEVICE_TYPE_CPU |
47 CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_ACCELERATOR |
48 CL_DEVICE_TYPE_CUSTOM | CL_DEVICE_TYPE_ALL))
49 {
50 */
51 while (i < num_entries)
52 {
53 if(devices)
54 {
55 devices[0] = (cl_device_id)(&DEVICE_ID);
56 //how to say "use anything"?
57 i++;
58 }
59 else
60 {
61 break;
62 }
63
64 }
65 if (num_devices)
66 {
67 *num_devices = i;
68 }
69 //}
70/*
71 else
72 {
73 return CL_DEVICE_NOT_FOUND;
74 }
75*/
76 //*devices list of devices found, use
77 //cl_device_id device_id;
78 //&device_id
79
80 return CL_SUCCESS;
81
82}
83
84/*
85 Creates the cl_context that will be used in later types to be made
86 properties - Context property names
87 num_devices - Number of devices
88 devices - Pointer to the devices from clGetDeviceIDs
89 pfn_notify - Callback function to report errors. Can be NULL
90 user_data - Part of pfn_notify. Can be NULL
91 errcode_ret - Returns proper error code.
92*/
93
94cl_context clCreateContext(const cl_context_properties *properties,
95 cl_uint num_devices,
96 const cl_device_id * devices,
97 void (CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *),
98 void * user_data,
99 cl_int * errcode_ret)
100{
101 cl_int default_errcode_ret;
102 cl_context ctx;
103
104 if(!errcode_ret)
105 {
106 errcode_ret = &default_errcode_ret;
107 }
108
109 if (!devices || !num_devices || (!pfn_notify && user_data))
110 {
111 *errcode_ret = CL_INVALID_VALUE;
112 return 0;
113 }
114
115 *errcode_ret = CL_SUCCESS;
116
117 ctx = (cl_context)malloc(sizeof(_cl_context));
118
119
120 ctx->properties = properties;
121 ctx->num_devices = num_devices;
122 ctx->devices = devices;
123 ctx->pfn_notify = pfn_notify;
124 ctx->user_data = user_data;
125 ctx->errcode_ret = errcode_ret;
126
127
128 if(*errcode_ret != CL_SUCCESS)
129 {
130 //delete ctx;
131 return 0;
132 }
133
134 return(cl_context) ctx;
135
136}
137
138/* Creates a cl_command_queue
139 context - The context created from clCreateContext
140 device - The pointer to IDs from clGetDeviceIDs
141 properties - Bitfield for properties, see cl.cvl
142 errcode_ret - Returns proper error code.
143*/
144cl_command_queue clCreateCommandQueue(cl_context context,
145 cl_device_id device,
146 cl_command_queue_properties properties,
147 cl_int* errcode_ret)
148{
149 cl_int default_errcode_ret;
150 cl_command_queue cmd;
151
152 // No errcode_ret ?
153 if (!errcode_ret)
154 {
155 errcode_ret = &default_errcode_ret;
156 }
157
158 cmd = (cl_command_queue)malloc(sizeof(_cl_command_queue));
159
160 cmd->context = context;
161 cmd->device = device;
162 cmd->properties = properties;
163 cmd->errcode_ret = errcode_ret;
164
165 return cmd;
166}
167
168/*Makes a program from context. Not quite like the original implementation
169 context - From clCreateContext
170 count - number of source codes for strings
171 strings - Array of chars that makes up code
172 lengths - string length, if NULL nulls the strings
173 errcode_ret - Returns proper error code
174*/
175cl_program clCreateProgramWithSource(cl_context context,
176 cl_uint count,
177 const char** strings,
178 const size_t * lengths,
179 cl_int * errcode_ret)
180{
181 cl_int default_errcode_ret;
182 cl_program program;
183
184 program = (cl_program)malloc(sizeof(_cl_program));
185
186 if(!errcode_ret)
187 {
188 errcode_ret = &default_errcode_ret;
189 }
190
191 *errcode_ret = CL_SUCCESS;
192 //*errcode_ret = program->loadSources(count, strings, lengths);
193
194
195 //corrects lengths, not implemented fully yet
196 /*
197 for (cl_uint i = 0; i < count; i++)
198 {
199 size_t len = 0;
200 const char *data = strings[i];
201
202 if (lengths && lengths[i])
203 {
204 len = lengths[i];
205 }
206 else
207 {
208 //len = strlen(data);
209 //strlen is not supported
210 }
211
212
213 //remove trailing \0's, or null characters
214 while (len > 0 && (data[len-1] == ))
215 {
216 len--;
217 }
218
219 }
220 */
221 program->context = context;
222 program->count = count;
223 program->strings = strings;
224 program->lengths = lengths;
225 $assert (*errcode_ret == CL_SUCCESS);
226 //the original for loop can make *errcode_ret not CL_SUCCESS, this is a placeholder
227
228 return (cl_program) program;
229}
230
231
Note: See TracBrowser for help on using the repository browser.