2
2
// SPDX-License-Identifier: BSD-3-Clause
3
3
4
4
// System headers.
5
+ #include < algorithm>
5
6
#include < assert.h>
6
7
#include < string.h>
7
8
@@ -209,6 +210,8 @@ CL_API_ENTRY cl_int CL_API_CALL clGetDeviceInfoIntelFPGA(
209
210
RESULT_INT (0 );
210
211
break ;
211
212
case CL_DEVICE_GLOBAL_MEM_SIZE: {
213
+ #ifdef __arm__
214
+ // TODO: legacy code here, need to verify correctness with ARM board
212
215
auto gmem_id = acl_get_default_device_global_memory (device->def );
213
216
if (gmem_id < 0 ) {
214
217
RESULT_INT (0 );
@@ -217,10 +220,20 @@ CL_API_ENTRY cl_int CL_API_CALL clGetDeviceInfoIntelFPGA(
217
220
cl_ulong size =
218
221
ACL_RANGE_SIZE (device->def .autodiscovery_def .global_mem_defs [gmem_id]
219
222
.get_usable_range ());
220
- #ifdef __arm__
221
223
// on SoC board, two DDR systems are not equivalent
222
224
// so only half can be accessed with a single alloc.
223
225
size /= 2 ;
226
+ #else
227
+ cl_ulong size = 0 ;
228
+ for (unsigned gmem_idx = 0 ;
229
+ gmem_idx < device->def .autodiscovery_def .num_global_mem_systems ;
230
+ gmem_idx++) {
231
+ if (device->def .autodiscovery_def .global_mem_defs [gmem_idx].type ==
232
+ ACL_GLOBAL_MEM_DEVICE_PRIVATE) {
233
+ size += ACL_RANGE_SIZE (
234
+ device->def .autodiscovery_def .global_mem_defs [gmem_idx].range );
235
+ }
236
+ }
224
237
#endif
225
238
RESULT_ULONG (size);
226
239
break ;
@@ -251,13 +264,9 @@ CL_API_ENTRY cl_int CL_API_CALL clGetDeviceInfoIntelFPGA(
251
264
RESULT_UINT (acl_platform.max_constant_args );
252
265
break ;
253
266
254
- // "desktop" profile says global memory must be at least 128MB
255
- // "embedded" profile says global memory must be at least 1MB
256
267
case CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE: {
257
- // Constant memory is global memory.
258
- // However conformance_test_api min_max_constant_buffer_size
259
- // expects to allocate two buffers of the size we say here.
260
- // So be a shade conservative and cut it down by 4.
268
+ #ifdef __arm__
269
+ // TODO: legacy code here, need to verify correctness with ARM board
261
270
auto gmem_id = acl_get_default_device_global_memory (device->def );
262
271
if (gmem_id < 0 ) {
263
272
RESULT_INT (0 );
@@ -267,13 +276,32 @@ CL_API_ENTRY cl_int CL_API_CALL clGetDeviceInfoIntelFPGA(
267
276
ACL_RANGE_SIZE (device->def .autodiscovery_def .global_mem_defs [gmem_id]
268
277
.get_usable_range ()) /
269
278
4 ;
270
- #ifdef __arm__
271
- // see above
279
+ // Cut by 2 again, see comment for CL_DEVICE_GLOBAL_MEM_SIZE
272
280
size /= 2 ;
281
+ #else
282
+ // Constant memory is global memory.
283
+ cl_ulong size = 0 ;
284
+ for (unsigned gmem_idx = 0 ;
285
+ gmem_idx < device->def .autodiscovery_def .num_global_mem_systems ;
286
+ gmem_idx++) {
287
+ if (device->def .autodiscovery_def .global_mem_defs [gmem_idx].type ==
288
+ ACL_GLOBAL_MEM_DEVICE_PRIVATE) {
289
+ size += ACL_RANGE_SIZE (
290
+ device->def .autodiscovery_def .global_mem_defs [gmem_idx].range );
291
+ }
292
+ }
293
+ // Note that OpenCL 1.2 specifies the minimum value for devices not of
294
+ // type CL_DEVICE_TYPE_CUSTOM to be 64KB, however, the OpenCL conformance
295
+ // test api:test_min_max_constant_buffer_size expects to allocate two
296
+ // buffers of the size returned here, so following the spec may result
297
+ // in conformance test failures.
298
+ size = std::max (size, (cl_ulong)64 * 1024 );
273
299
#endif
274
300
RESULT_ULONG (size);
275
301
} break ;
276
302
case CL_DEVICE_MAX_MEM_ALLOC_SIZE: {
303
+ #ifdef __arm__
304
+ // TODO: legacy code here, need to verify correctness with ARM board
277
305
auto gmem_id = acl_get_default_device_global_memory (device->def );
278
306
if (gmem_id < 0 ) {
279
307
RESULT_INT (0 );
@@ -282,7 +310,6 @@ CL_API_ENTRY cl_int CL_API_CALL clGetDeviceInfoIntelFPGA(
282
310
cl_ulong size =
283
311
ACL_RANGE_SIZE (device->def .autodiscovery_def .global_mem_defs [gmem_id]
284
312
.get_usable_range ());
285
- #ifdef __arm__
286
313
// on SoC board, two DDR systems are not equivalent
287
314
// so only half can be accessed with a single alloc.
288
315
@@ -294,6 +321,28 @@ CL_API_ENTRY cl_int CL_API_CALL clGetDeviceInfoIntelFPGA(
294
321
} else {
295
322
size = size / 8 ;
296
323
}
324
+ #else
325
+ cl_ulong global_mem_size = 0 ;
326
+ cl_ulong size = 0 ;
327
+ for (unsigned gmem_idx = 0 ;
328
+ gmem_idx < device->def .autodiscovery_def .num_global_mem_systems ;
329
+ gmem_idx++) {
330
+ if (device->def .autodiscovery_def .global_mem_defs [gmem_idx].type ==
331
+ ACL_GLOBAL_MEM_DEVICE_PRIVATE) {
332
+ global_mem_size += ACL_RANGE_SIZE (
333
+ device->def .autodiscovery_def .global_mem_defs [gmem_idx].range );
334
+ cl_ulong curr_size = ACL_RANGE_SIZE (
335
+ device->def .autodiscovery_def .global_mem_defs [gmem_idx]
336
+ .get_usable_range ());
337
+ if (curr_size > size) {
338
+ size = curr_size;
339
+ }
340
+ }
341
+ }
342
+ // OpenCL 1.2: min value = max(CL_DEVICE_GLOBAL_MEM_SIZE/4, 1*1024*1024)
343
+ // for devices that are not of type CL_DEVICE_TYPE_CUSTOM
344
+ size = std::max (size,
345
+ std::max (global_mem_size / 4 , (cl_ulong)1 * 1024 * 1024 ));
297
346
#endif
298
347
RESULT_ULONG (size);
299
348
} break ;
0 commit comments