Skip to content

[SYCL] Optionally enable STL assertions #2326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
option(SYCL_ENABLE_WERROR "Treat all warnings as errors in SYCL project" OFF)
option(SYCL_DISABLE_STL_ASSERTIONS "Disable assertions in STL containers" OFF)
option(SYCL_ADD_DEV_VERSION_POSTFIX "Adds -V postfix to version string" ON)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
Expand Down Expand Up @@ -248,6 +249,17 @@ function( add_common_options LIB_NAME)
endif()
endfunction(add_common_options)


if (LLVM_ENABLE_ASSERTIONS AND NOT SYCL_DISABLE_STL_ASSERTIONS)
if(SYCL_USE_LIBCXX)
add_definitions(-D_LIBCPP_DEBUG=1)
set(SYCL_CLANG_EXTRA_FLAGS "${SYCL_CLANG_EXTRA_FLAGS} -D_LIBCPP_DEBUG=1")
else()
add_definitions(-D_GLIBCXX_ASSERTIONS=1)
set(SYCL_CLANG_EXTRA_FLAGS "${SYCL_CLANG_EXTRA_FLAGS} -D_GLIBCXX_ASSERTIONS=1")
endif()
endif()

set(SYCL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

# SYCL runtime library
Expand Down
10 changes: 9 additions & 1 deletion sycl/cmake/modules/AddSYCLExecutable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ macro(add_sycl_executable ARG_TARGET_NAME)
list(APPEND LINKED_LIBS "${LIB_PREFIX}${_lib}${LIB_POSTFIX}")
endforeach()

if (LLVM_ENABLE_ASSERTIONS AND NOT SYCL_DISABLE_STL_ASSERTIONS)
if(SYCL_USE_LIBCXX)
set(_SYCL_EXTRA_FLAGS -D_LIBCPP_DEBUG=1)
else()
set(_SYCL_EXTRA_FLAGS -D_GLIBCXX_ASSERTIONS=1)
endif()
endif()

add_custom_target(${ARG_TARGET_NAME}_exec ALL
COMMAND ${DEVICE_COMPILER_EXECUTABLE} -fsycl ${ARG_SOURCES}
-o ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET_NAME}
${LINKED_LIBS} ${ARG_OPTIONS}
${LINKED_LIBS} ${ARG_OPTIONS} ${_SYCL_EXTRA_FLAGS}
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND_EXPAND_LISTS)
Expand Down
2 changes: 2 additions & 0 deletions sycl/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
config.available_features.add('linux')
llvm_config.with_system_environment('LD_LIBRARY_PATH')
llvm_config.with_environment('LD_LIBRARY_PATH', config.sycl_libs_dir, append_path=True)
llvm_config.with_system_environment('CFLAGS')
llvm_config.with_environment('CFLAGS', config.sycl_clang_extra_flags)

elif platform.system() == "Windows":
config.available_features.add('windows')
Expand Down
1 change: 1 addition & 0 deletions sycl/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ config.cuda_toolkit_include = "@CUDA_TOOLKIT_INCLUDE@"
config.sycl_tools_src_dir = "@SYCL_TOOLS_SRC_DIR@"
config.llvm_build_lib_dir = "@LLVM_BUILD_LIBRARY_DIRS@"
config.llvm_build_bin_dir = "@LLVM_BUILD_BINARY_DIRS@"
config.sycl_clang_extra_flags = "@SYCL_CLANG_EXTRA_FLAGS@"

config.llvm_enable_projects = "@LLVM_ENABLE_PROJECTS@"

Expand Down