| 1 |
|
|---|
| 2 | #include "cl.cvl"
|
|---|
| 3 |
|
|---|
| 4 | $input int DEVICE_ID;
|
|---|
| 5 | $input int DEVICE_ID_BOUND;
|
|---|
| 6 |
|
|---|
| 7 | $assume 0 < DEVICE_ID && DEVICE_ID < DEVICE_ID_BOUND;
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 | int clGetDeviceIDs(cl_platform_id platform,
|
|---|
| 13 | cl_device_type device_type,
|
|---|
| 14 | cl_uint num_entries,
|
|---|
| 15 | cl_device_id *devices,
|
|---|
| 16 | cl_uint *num_devices)
|
|---|
| 17 | {
|
|---|
| 18 | //$assume device_type == CL_DEVICE_TYPE_DEFAULT;
|
|---|
| 19 | int i = 0;
|
|---|
| 20 | //cl_platform_id int value can be null
|
|---|
| 21 |
|
|---|
| 22 | //num_entries number of devices that can be added
|
|---|
| 23 | /*
|
|---|
| 24 | if(num_entries == 0 && devices != 0)
|
|---|
| 25 | {
|
|---|
| 26 | return CL_INVALID_VALUE;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | if(num_entries == 0 && devices == 0)
|
|---|
| 30 | {
|
|---|
| 31 | return CL_INVALID_VALUE;
|
|---|
| 32 | }
|
|---|
| 33 | */
|
|---|
| 34 | //device_type type a bitfield that somehow gets type of OpenCL device
|
|---|
| 35 | //use the device types, look in openCLtypes and look for CL_DEVICE_TYPE_...
|
|---|
| 36 |
|
|---|
| 37 | /*
|
|---|
| 38 | if(device_type & (CL_DEVICE_TYPE_DEFAULT | CL_DEVICE_TYPE_CPU |
|
|---|
| 39 | CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_ACCELERATOR |
|
|---|
| 40 | CL_DEVICE_TYPE_CUSTOM | CL_DEVICE_TYPE_ALL))
|
|---|
| 41 | {
|
|---|
| 42 | */
|
|---|
| 43 | while (i < num_entries)
|
|---|
| 44 | {
|
|---|
| 45 | if(devices)
|
|---|
| 46 | {
|
|---|
| 47 | devices[0] = (cl_device_id)(&DEVICE_ID);
|
|---|
| 48 | //how to say "use anything"?
|
|---|
| 49 | i++;
|
|---|
| 50 | }
|
|---|
| 51 | else
|
|---|
| 52 | {
|
|---|
| 53 | break;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | }
|
|---|
| 57 | if (num_devices)
|
|---|
| 58 | {
|
|---|
| 59 | *num_devices = i;
|
|---|
| 60 | }
|
|---|
| 61 | //}
|
|---|
| 62 | /*
|
|---|
| 63 | else
|
|---|
| 64 | {
|
|---|
| 65 | return CL_DEVICE_NOT_FOUND;
|
|---|
| 66 | }
|
|---|
| 67 | */
|
|---|
| 68 | //*devices list of devices found, use
|
|---|
| 69 | //cl_device_id device_id;
|
|---|
| 70 | //&device_id
|
|---|
| 71 |
|
|---|
| 72 | return CL_SUCCESS;
|
|---|
| 73 |
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 | cl_context clCreateContext(const cl_context_properties *properties,
|
|---|
| 80 | cl_uint num_devices,
|
|---|
| 81 | const cl_device_id * devices,
|
|---|
| 82 | void (CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *),
|
|---|
| 83 | void * user_data,
|
|---|
| 84 | cl_int * errcode_ret)
|
|---|
| 85 | {
|
|---|
| 86 | cl_int default_errcode_ret;
|
|---|
| 87 |
|
|---|
| 88 | if(!errcode_ret)
|
|---|
| 89 | {
|
|---|
| 90 | errcode_ret = &default_errcode_ret;
|
|---|
| 91 | }
|
|---|
| 92 | /*
|
|---|
| 93 | if (!devices || !num_devices || !pfn_notify && user_data}}
|
|---|
| 94 | {
|
|---|
| 95 | *errcode_ret = CL_INVALID_VALUE;
|
|---|
| 96 | return 0;
|
|---|
| 97 | }
|
|---|
| 98 | */
|
|---|
| 99 | *errcode_ret = CL_SUCCESS;
|
|---|
| 100 | cl_context *ctx;
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 | ctx->properties = properties;
|
|---|
| 104 | ctx->num_devices = num_devices;
|
|---|
| 105 | ctx->devices = devices;
|
|---|
| 106 | ctx->pfn_notify = pfn_notify;
|
|---|
| 107 | ctx->user_data = user_data;
|
|---|
| 108 | ctx->errcode_ret = errorcode_ret;
|
|---|
| 109 | /*
|
|---|
| 110 | if(*errcode_ret != CL_SUCCESS)
|
|---|
| 111 | {
|
|---|
| 112 | delete ctx;
|
|---|
| 113 | return 0;
|
|---|
| 114 | }
|
|---|
| 115 | */
|
|---|
| 116 | return(_cl_context*) ctx;
|
|---|
| 117 |
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|