Skip to content

Commit 4ac7ca8

Browse files
sherry-yuanpcolberg
authored andcommitted
Define function to return string literal for checking all extensions
--------------------------------------------------------------------------- The string literall returned is statically allocated so that it is safe to return one from a function. The reason why std::string was not used. once modified, the c_cstr() pointer may no longer be valid. Futher tsan reported a heap use after free error if the acl_platform_extensions return std::string instead.
1 parent 0c777cc commit 4ac7ca8

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

include/acl_platform.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extern int platform_owner_tid;
2121
void acl_init_platform(void);
2222
void acl_finalize_init_platform(unsigned int num_devices,
2323
const cl_device_id *devices);
24+
const char *acl_platform_extensions(void);
2425

2526
#if defined(__cplusplus)
2627
} /* extern "C" */

src/acl_platform.cpp

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,34 @@ int acl_platform_is_valid(cl_platform_id platform) {
257257
return platform == &acl_platform;
258258
}
259259

260+
const char *acl_platform_extensions() {
261+
return "cl_khr_byte_addressable_store" // yes, we have correct access to
262+
// individual bytes!
263+
" cles_khr_int64" // yes, we support 64-bit ints in the embedded
264+
// profile
265+
266+
" cl_khr_icd"
267+
#if ACL_SUPPORT_IMAGES == 1
268+
" cl_khr_3d_image_writes"
269+
#endif
270+
#if ACL_SUPPORT_DOUBLE == 1
271+
" cl_khr_fp64"
272+
#endif
273+
#ifdef ACL_120
274+
" cl_khr_global_int32_base_atomics"
275+
" cl_khr_global_int32_extended_atomics"
276+
" cl_khr_local_int32_base_atomics"
277+
" cl_khr_local_int32_extended_atomics"
278+
#endif
279+
#ifndef __arm__
280+
// Add the following once all USM APIs are implemented, Intel publishes
281+
// the spec, and published USM conformance tests pass
282+
//" cl_intel_unified_shared_memory"
283+
#endif
284+
" cl_intel_create_buffer_with_properties"
285+
" cl_intel_mem_channel_property";
286+
}
287+
260288
// Initialize the internal bookkeeping based on the system definition
261289
// provided to us.
262290
void acl_init_platform(void) {
@@ -298,31 +326,7 @@ void acl_init_platform(void) {
298326
// The extensions string specifies the extensions supported by our framework.
299327
// To add an extension, append a flag name and separate it from others using a
300328
// space.
301-
acl_platform.extensions =
302-
"cl_khr_byte_addressable_store" // yes, we have correct access to
303-
// individual bytes!
304-
" cles_khr_int64" // yes, we support 64-bit ints in the embedded profile
305-
306-
" cl_khr_icd"
307-
#if ACL_SUPPORT_IMAGES == 1
308-
" cl_khr_3d_image_writes"
309-
#endif
310-
#if ACL_SUPPORT_DOUBLE == 1
311-
" cl_khr_fp64"
312-
#endif
313-
#ifdef ACL_120
314-
" cl_khr_global_int32_base_atomics"
315-
" cl_khr_global_int32_extended_atomics"
316-
" cl_khr_local_int32_base_atomics"
317-
" cl_khr_local_int32_extended_atomics"
318-
#endif
319-
#ifndef __arm__
320-
// Add the following once all USM APIs are implemented, Intel publishes
321-
// the spec, and published USM conformance tests pass
322-
//" cl_intel_unified_shared_memory"
323-
#endif
324-
" cl_intel_create_buffer_with_properties"
325-
" cl_intel_mem_channel_property";
329+
acl_platform.extensions = acl_platform_extensions();
326330

327331
acl_platform.profile = "EMBEDDED_PROFILE";
328332
acl_platform.hal = acl_get_hal();

test/acl_device_test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <acl.h>
1616
#include <acl_context.h>
17+
#include <acl_platform.h>
1718
#include <acl_types.h>
1819
#include <acl_util.h>
1920

@@ -326,6 +327,10 @@ MT_TEST(DeviceInfo, basic) {
326327

327328
CHECK(size_ret > 0);
328329

330+
if (queries[i] == CL_DEVICE_EXTENSIONS) {
331+
CHECK(strcmp(str, acl_platform_extensions()) == 0);
332+
}
333+
329334
switch (queries[i]) {
330335
case CL_DEVICE_VENDOR:
331336
case CL_DEVICE_VERSION:

0 commit comments

Comments
 (0)