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
RevLine 
[e01b89d]1
[9c7b25c]2#include "cl.cvl"
[0744ab0]3#include <stdlib.h>
[8472eb5]4#include <string.h>
5#include <stdio.h>
[e01b89d]6
7$input int DEVICE_ID;
8$input int DEVICE_ID_BOUND;
9
10$assume 0 < DEVICE_ID && DEVICE_ID < DEVICE_ID_BOUND;
[6267964]11
12
[1a54e12]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*/
[9c7b25c]22int clGetDeviceIDs(cl_platform_id platform,
23 cl_device_type device_type,
24 cl_uint num_entries,
25 cl_device_id *devices,
[e01b89d]26 cl_uint *num_devices)
27 {
[9c7b25c]28 //$assume device_type == CL_DEVICE_TYPE_DEFAULT;
[e01b89d]29 int i = 0;
30 //cl_platform_id int value can be null
31
32 //num_entries number of devices that can be added
[9c7b25c]33 /*
[e01b89d]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 }
[1a54e12]43
44 //CIVL cannot pass this if block if not commented out
[6777880]45 /*
[e01b89d]46 if(device_type & (CL_DEVICE_TYPE_DEFAULT | CL_DEVICE_TYPE_CPU |
47 CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_ACCELERATOR |
[9c7b25c]48 CL_DEVICE_TYPE_CUSTOM | CL_DEVICE_TYPE_ALL))
[e01b89d]49 {
[6777880]50 */
[e01b89d]51 while (i < num_entries)
52 {
53 if(devices)
54 {
[9c7b25c]55 devices[0] = (cl_device_id)(&DEVICE_ID);
[e01b89d]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 }
[6777880]69 //}
[9c7b25c]70/*
[e01b89d]71 else
72 {
73 return CL_DEVICE_NOT_FOUND;
74 }
[9c7b25c]75*/
[e01b89d]76 //*devices list of devices found, use
77 //cl_device_id device_id;
78 //&device_id
79
80 return CL_SUCCESS;
81
[8472eb5]82}
83
[1a54e12]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*/
[6267964]93
[9c7b25c]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;
[8472eb5]102 cl_context ctx;
[6267964]103
[9c7b25c]104 if(!errcode_ret)
[6267964]105 {
[9c7b25c]106 errcode_ret = &default_errcode_ret;
[6267964]107 }
[0744ab0]108
109 if (!devices || !num_devices || (!pfn_notify && user_data))
[6267964]110 {
111 *errcode_ret = CL_INVALID_VALUE;
112 return 0;
113 }
[0744ab0]114
[6267964]115 *errcode_ret = CL_SUCCESS;
[8472eb5]116
[0744ab0]117 ctx = (cl_context)malloc(sizeof(_cl_context));
[6267964]118
[0744ab0]119
[6267964]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;
[0744ab0]125 ctx->errcode_ret = errcode_ret;
126
127
[6267964]128 if(*errcode_ret != CL_SUCCESS)
129 {
[0744ab0]130 //delete ctx;
[6267964]131 return 0;
132 }
[0744ab0]133
134 return(cl_context) ctx;
[6267964]135
[9c7b25c]136}
[8472eb5]137
[1a54e12]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*/
[0744ab0]144cl_command_queue clCreateCommandQueue(cl_context context,
145 cl_device_id device,
146 cl_command_queue_properties properties,
147 cl_int* errcode_ret)
148{
[8472eb5]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;
[0744ab0]166}
[8472eb5]167
[1a54e12]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*/
[8472eb5]175cl_program clCreateProgramWithSource(cl_context context,
176 cl_uint count,
177 const char** strings,
178 const size_t * lengths,
179 cl_int * errcode_ret)
[0744ab0]180{
[8472eb5]181 cl_int default_errcode_ret;
[1a54e12]182 cl_program program;
183
184 program = (cl_program)malloc(sizeof(_cl_program));
[8472eb5]185
186 if(!errcode_ret)
187 {
188 errcode_ret = &default_errcode_ret;
189 }
190
191 *errcode_ret = CL_SUCCESS;
[1a54e12]192 //*errcode_ret = program->loadSources(count, strings, lengths);
193
[8472eb5]194
[1a54e12]195 //corrects lengths, not implemented fully yet
196 /*
[8472eb5]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 {
[1a54e12]208 //len = strlen(data);
209 //strlen is not supported
[8472eb5]210 }
211
[1a54e12]212
[8472eb5]213 //remove trailing \0's, or null characters
[1a54e12]214 while (len > 0 && (data[len-1] == ))
[8472eb5]215 {
216 len--;
217 }
218
219 }
[1a54e12]220 */
221 program->context = context;
222 program->count = count;
223 program->strings = strings;
224 program->lengths = lengths;
225 $assert (*errcode_ret == CL_SUCCESS);
[8472eb5]226 //the original for loop can make *errcode_ret not CL_SUCCESS, this is a placeholder
227
228 return (cl_program) program;
[0744ab0]229}
[9c7b25c]230
231
Note: See TracBrowser for help on using the repository browser.