| 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 |
|
|---|
| 15 | int clGetDeviceIDs(cl_platform_id platform,
|
|---|
| 16 | cl_device_type device_type,
|
|---|
| 17 | cl_uint num_entries,
|
|---|
| 18 | cl_device_id *devices,
|
|---|
| 19 | cl_uint *num_devices)
|
|---|
| 20 | {
|
|---|
| 21 | //$assume device_type == CL_DEVICE_TYPE_DEFAULT;
|
|---|
| 22 | int i = 0;
|
|---|
| 23 | //cl_platform_id int value can be null
|
|---|
| 24 |
|
|---|
| 25 | //num_entries number of devices that can be added
|
|---|
| 26 | /*
|
|---|
| 27 | if(num_entries == 0 && devices != 0)
|
|---|
| 28 | {
|
|---|
| 29 | return CL_INVALID_VALUE;
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | if(num_entries == 0 && devices == 0)
|
|---|
| 33 | {
|
|---|
| 34 | return CL_INVALID_VALUE;
|
|---|
| 35 | }
|
|---|
| 36 | */
|
|---|
| 37 | //device_type type a bitfield that somehow gets type of OpenCL device
|
|---|
| 38 | //use the device types, look in openCLtypes and look for CL_DEVICE_TYPE_...
|
|---|
| 39 |
|
|---|
| 40 | /*
|
|---|
| 41 | if(device_type & (CL_DEVICE_TYPE_DEFAULT | CL_DEVICE_TYPE_CPU |
|
|---|
| 42 | CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_ACCELERATOR |
|
|---|
| 43 | CL_DEVICE_TYPE_CUSTOM | CL_DEVICE_TYPE_ALL))
|
|---|
| 44 | {
|
|---|
| 45 | */
|
|---|
| 46 | while (i < num_entries)
|
|---|
| 47 | {
|
|---|
| 48 | if(devices)
|
|---|
| 49 | {
|
|---|
| 50 | devices[0] = (cl_device_id)(&DEVICE_ID);
|
|---|
| 51 | //how to say "use anything"?
|
|---|
| 52 | i++;
|
|---|
| 53 | }
|
|---|
| 54 | else
|
|---|
| 55 | {
|
|---|
| 56 | break;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | }
|
|---|
| 60 | if (num_devices)
|
|---|
| 61 | {
|
|---|
| 62 | *num_devices = i;
|
|---|
| 63 | }
|
|---|
| 64 | //}
|
|---|
| 65 | /*
|
|---|
| 66 | else
|
|---|
| 67 | {
|
|---|
| 68 | return CL_DEVICE_NOT_FOUND;
|
|---|
| 69 | }
|
|---|
| 70 | */
|
|---|
| 71 | //*devices list of devices found, use
|
|---|
| 72 | //cl_device_id device_id;
|
|---|
| 73 | //&device_id
|
|---|
| 74 |
|
|---|
| 75 | return CL_SUCCESS;
|
|---|
| 76 |
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 | cl_context clCreateContext(const cl_context_properties *properties,
|
|---|
| 83 | cl_uint num_devices,
|
|---|
| 84 | const cl_device_id * devices,
|
|---|
| 85 | void (CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *),
|
|---|
| 86 | void * user_data,
|
|---|
| 87 | cl_int * errcode_ret)
|
|---|
| 88 | {
|
|---|
| 89 | cl_int default_errcode_ret;
|
|---|
| 90 | cl_context ctx;
|
|---|
| 91 |
|
|---|
| 92 | if(!errcode_ret)
|
|---|
| 93 | {
|
|---|
| 94 | errcode_ret = &default_errcode_ret;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | if (!devices || !num_devices || (!pfn_notify && user_data))
|
|---|
| 98 | {
|
|---|
| 99 | *errcode_ret = CL_INVALID_VALUE;
|
|---|
| 100 | return 0;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | *errcode_ret = CL_SUCCESS;
|
|---|
| 104 |
|
|---|
| 105 | ctx = (cl_context)malloc(sizeof(_cl_context));
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 | ctx->properties = properties;
|
|---|
| 109 | ctx->num_devices = num_devices;
|
|---|
| 110 | ctx->devices = devices;
|
|---|
| 111 | ctx->pfn_notify = pfn_notify;
|
|---|
| 112 | ctx->user_data = user_data;
|
|---|
| 113 | ctx->errcode_ret = errcode_ret;
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 | if(*errcode_ret != CL_SUCCESS)
|
|---|
| 117 | {
|
|---|
| 118 | //delete ctx;
|
|---|
| 119 | return 0;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | return(cl_context) ctx;
|
|---|
| 123 |
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | cl_command_queue clCreateCommandQueue(cl_context context,
|
|---|
| 127 | cl_device_id device,
|
|---|
| 128 | cl_command_queue_properties properties,
|
|---|
| 129 | cl_int* errcode_ret)
|
|---|
| 130 | {
|
|---|
| 131 | cl_int default_errcode_ret;
|
|---|
| 132 | cl_command_queue cmd;
|
|---|
| 133 |
|
|---|
| 134 | // No errcode_ret ?
|
|---|
| 135 | if (!errcode_ret)
|
|---|
| 136 | {
|
|---|
| 137 | errcode_ret = &default_errcode_ret;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | cmd = (cl_command_queue)malloc(sizeof(_cl_command_queue));
|
|---|
| 141 |
|
|---|
| 142 | cmd->context = context;
|
|---|
| 143 | cmd->device = device;
|
|---|
| 144 | cmd->properties = properties;
|
|---|
| 145 | cmd->errcode_ret = errcode_ret;
|
|---|
| 146 |
|
|---|
| 147 | return cmd;
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | cl_program clCreateProgramWithSource(cl_context context,
|
|---|
| 153 | cl_uint count,
|
|---|
| 154 | const char** strings,
|
|---|
| 155 | const size_t * lengths,
|
|---|
| 156 | cl_int * errcode_ret)
|
|---|
| 157 | {
|
|---|
| 158 | cl_int default_errcode_ret;
|
|---|
| 159 |
|
|---|
| 160 | if(!errcode_ret)
|
|---|
| 161 | {
|
|---|
| 162 | errcode_ret = &default_errcode_ret;
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | *errcode_ret = CL_SUCCESS;
|
|---|
| 166 | //*errcode_ret = loadSources(count, strings, lengths);
|
|---|
| 167 |
|
|---|
| 168 | //corrects
|
|---|
| 169 | for (cl_uint i = 0; i < count; i++)
|
|---|
| 170 | {
|
|---|
| 171 | size_t len = 0;
|
|---|
| 172 | const char *data = strings[i];
|
|---|
| 173 |
|
|---|
| 174 | if (lengths && lengths[i])
|
|---|
| 175 | {
|
|---|
| 176 | len = lengths[i];
|
|---|
| 177 | }
|
|---|
| 178 | else
|
|---|
| 179 | {
|
|---|
| 180 | len = strlen(data);
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | //remove trailing \0's, or null characters
|
|---|
| 184 | while (len > 0 && data[len-1] == 0)
|
|---|
| 185 | {
|
|---|
| 186 | len--;
|
|---|
| 187 | }
|
|---|
| 188 | //merge strings? The assignment isn't used anywhere
|
|---|
| 189 | //consider it later, if needed
|
|---|
| 190 |
|
|---|
| 191 | }
|
|---|
| 192 | $assert (*errcode_ret != CL_SUCCESS);
|
|---|
| 193 | //the original for loop can make *errcode_ret not CL_SUCCESS, this is a placeholder
|
|---|
| 194 |
|
|---|
| 195 | return (cl_program) program;
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|