Skip to content

Commit ec2ec99

Browse files
author
Alexander Batashev
authored
[SYCL] Optionally enable STL assertions (#2326)
This is a followup for #2310. The patch adds an option to enable assertions in standard containers and algorithms (such as bounds and null pointer checks) both in SYCL runtime and tests. These checks are also enabled in post-commit to catch possible regressions.
1 parent b97ca3b commit ec2ec99

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

sycl/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD 14)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_EXTENSIONS OFF)
88
option(SYCL_ENABLE_WERROR "Treat all warnings as errors in SYCL project" OFF)
9+
option(SYCL_DISABLE_STL_ASSERTIONS "Disable assertions in STL containers" OFF)
910
option(SYCL_ADD_DEV_VERSION_POSTFIX "Adds -V postfix to version string" ON)
1011

1112
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
@@ -248,6 +249,17 @@ function( add_common_options LIB_NAME)
248249
endif()
249250
endfunction(add_common_options)
250251

252+
253+
if (LLVM_ENABLE_ASSERTIONS AND NOT SYCL_DISABLE_STL_ASSERTIONS)
254+
if(SYCL_USE_LIBCXX)
255+
add_definitions(-D_LIBCPP_DEBUG=1)
256+
set(SYCL_CLANG_EXTRA_FLAGS "${SYCL_CLANG_EXTRA_FLAGS} -D_LIBCPP_DEBUG=1")
257+
else()
258+
add_definitions(-D_GLIBCXX_ASSERTIONS=1)
259+
set(SYCL_CLANG_EXTRA_FLAGS "${SYCL_CLANG_EXTRA_FLAGS} -D_GLIBCXX_ASSERTIONS=1")
260+
endif()
261+
endif()
262+
251263
set(SYCL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
252264

253265
# SYCL runtime library

sycl/cmake/modules/AddSYCLExecutable.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ macro(add_sycl_executable ARG_TARGET_NAME)
1919
list(APPEND LINKED_LIBS "${LIB_PREFIX}${_lib}${LIB_POSTFIX}")
2020
endforeach()
2121

22+
if (LLVM_ENABLE_ASSERTIONS AND NOT SYCL_DISABLE_STL_ASSERTIONS)
23+
if(SYCL_USE_LIBCXX)
24+
set(_SYCL_EXTRA_FLAGS -D_LIBCPP_DEBUG=1)
25+
else()
26+
set(_SYCL_EXTRA_FLAGS -D_GLIBCXX_ASSERTIONS=1)
27+
endif()
28+
endif()
29+
2230
add_custom_target(${ARG_TARGET_NAME}_exec ALL
2331
COMMAND ${DEVICE_COMPILER_EXECUTABLE} -fsycl ${ARG_SOURCES}
2432
-o ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET_NAME}
25-
${LINKED_LIBS} ${ARG_OPTIONS}
33+
${LINKED_LIBS} ${ARG_OPTIONS} ${_SYCL_EXTRA_FLAGS}
2634
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET_NAME}
2735
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
2836
COMMAND_EXPAND_LISTS)

sycl/test/lit.cfg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
config.available_features.add('linux')
4444
llvm_config.with_system_environment('LD_LIBRARY_PATH')
4545
llvm_config.with_environment('LD_LIBRARY_PATH', config.sycl_libs_dir, append_path=True)
46+
llvm_config.with_system_environment('CFLAGS')
47+
llvm_config.with_environment('CFLAGS', config.sycl_clang_extra_flags)
4648

4749
elif platform.system() == "Windows":
4850
config.available_features.add('windows')

sycl/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ config.cuda_toolkit_include = "@CUDA_TOOLKIT_INCLUDE@"
1717
config.sycl_tools_src_dir = "@SYCL_TOOLS_SRC_DIR@"
1818
config.llvm_build_lib_dir = "@LLVM_BUILD_LIBRARY_DIRS@"
1919
config.llvm_build_bin_dir = "@LLVM_BUILD_BINARY_DIRS@"
20+
config.sycl_clang_extra_flags = "@SYCL_CLANG_EXTRA_FLAGS@"
2021

2122
config.llvm_enable_projects = "@LLVM_ENABLE_PROJECTS@"
2223

0 commit comments

Comments
 (0)