| 129 | } |
| 130 | |
| 131 | static ds_status initDSProfile(ds_profile **p, const char *version) { |
| 132 | int numDevices; |
| 133 | cl_uint numPlatforms; |
| 134 | cl_platform_id *platforms = NULL; |
| 135 | cl_device_id *devices = NULL; |
| 136 | ds_status status = DS_SUCCESS; |
| 137 | unsigned int next; |
| 138 | unsigned int i; |
| 139 | |
| 140 | if (p == NULL) return DS_INVALID_PROFILE; |
| 141 | |
| 142 | ds_profile *profile = (ds_profile *)malloc(sizeof(ds_profile)); |
| 143 | if (profile == NULL) return DS_MEMORY_ERROR; |
| 144 | |
| 145 | memset(profile, 0, sizeof(ds_profile)); |
| 146 | |
| 147 | clGetPlatformIDs(0, NULL, &numPlatforms); |
| 148 | |
| 149 | if (numPlatforms > 0) { |
| 150 | platforms = (cl_platform_id *)malloc(numPlatforms * sizeof(cl_platform_id)); |
| 151 | if (platforms == NULL) { |
| 152 | status = DS_MEMORY_ERROR; |
| 153 | goto cleanup; |
| 154 | } |
| 155 | clGetPlatformIDs(numPlatforms, platforms, NULL); |
| 156 | } |
| 157 | |
| 158 | numDevices = 0; |
| 159 | for (i = 0; i < (unsigned int)numPlatforms; i++) { |
| 160 | cl_uint num; |
| 161 | clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &num); |
| 162 | numDevices += num; |
| 163 | } |
| 164 | |
| 165 | if (numDevices > 0) { |
| 166 | devices = (cl_device_id *)malloc(numDevices * sizeof(cl_device_id)); |
| 167 | if (devices == NULL) { |
| 168 | status = DS_MEMORY_ERROR; |
| 169 | goto cleanup; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | profile->numDevices = |
| 174 | numDevices + 1; // +1 to numDevices to include the native CPU |
| 175 | profile->devices = |
| 176 | (ds_device *)malloc(profile->numDevices * sizeof(ds_device)); |
| 177 | if (profile->devices == NULL) { |
| 178 | profile->numDevices = 0; |
| 179 | status = DS_MEMORY_ERROR; |
| 180 | goto cleanup; |
| 181 | } |
| 182 | memset(profile->devices, 0, profile->numDevices * sizeof(ds_device)); |
| 183 | |
| 184 | next = 0; |
| 185 | for (i = 0; i < (unsigned int)numPlatforms; i++) { |
| 186 | cl_uint num; |
| 187 | unsigned j; |
| 188 | clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, numDevices, devices, &num); |