Skip to content
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

Add config file and example for thread sanitizer support #261

Merged
merged 8 commits into from
May 28, 2024
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
19 changes: 19 additions & 0 deletions configs/lc/toss_4_x86_64_ib/clang_tsan.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
##############################################################################
# Copyright (c) 2024, Lawrence Livermore National Security, LLC and CARE
# project contributors. See the CARE LICENSE file for details.
#
# SPDX-License-Identifier: BSD-3-Clause
##############################################################################

set(COMPILER_BASE "/usr/tce/packages/clang/clang-14.0.6-magic" CACHE PATH "")
set(CMAKE_C_COMPILER "${COMPILER_BASE}/bin/clang" CACHE PATH "")
set(CMAKE_CXX_COMPILER "${COMPILER_BASE}/bin/clang++" CACHE PATH "")

set(GCC_HOME "/usr/tce/packages/gcc/gcc-10.3.1-magic" CACHE PATH "")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --gcc-toolchain=${GCC_HOME} -fsanitize=thread -g" CACHE STRING "")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --gcc-toolchain=${GCC_HOME} -fsanitize=thread -g" CACHE STRING "")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread" CACHE STRING "")

set(ENABLE_OPENMP ON CACHE BOOL "")
set(BLT_EXPORT_THIRDPARTY OFF CACHE BOOL "")

17 changes: 17 additions & 0 deletions configs/lc/toss_4_x86_64_ib/intel.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
##############################################################################
# Copyright (c) 2020-24, Lawrence Livermore National Security, LLC and CARE
# project contributors. See the CARE LICENSE file for details.
#
# SPDX-License-Identifier: BSD-3-Clause
##############################################################################

set(COMPILER_BASE "/usr/tce/packages/intel/intel-2022.1.0-magic" CACHE PATH "")
set(CMAKE_C_COMPILER "${COMPILER_BASE}/bin/icx" CACHE PATH "")
set(CMAKE_CXX_COMPILER "${COMPILER_BASE}/bin/icpx" CACHE PATH "")

set(GCC_HOME "/usr/tce/packages/gcc/gcc-10.3.1-magic" CACHE PATH "")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --gcc-toolchain=${GCC_HOME}" CACHE STRING "")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --gcc-toolchain=${GCC_HOME}" CACHE STRING "")

set(BLT_EXPORT_THIRDPARTY OFF CACHE BOOL "")

9 changes: 9 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ blt_add_executable(NAME ScanLoopExample
target_include_directories(ScanLoopExample PRIVATE ${PROJECT_SOURCE_DIR}/src)
target_include_directories(ScanLoopExample PRIVATE ${PROJECT_BINARY_DIR}/include)

blt_add_executable(NAME RaceConditionsExample
SOURCES RaceConditions.cpp
DEPENDS_ON ${care_depends})

target_include_directories(RaceConditionsExample PRIVATE ${PROJECT_SOURCE_DIR}/src)
target_include_directories(RaceConditionsExample PRIVATE ${PROJECT_BINARY_DIR}/include)

target_compile_options(RaceConditionsExample PRIVATE -fsanitize=thread -g)
target_link_options(RaceConditionsExample PRIVATE -fsanitize=thread)
37 changes: 37 additions & 0 deletions examples/RaceConditions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2024, Lawrence Livermore National Security, LLC and CARE
// project contributors. See the CARE LICENSE file for details.
//
// SPDX-License-Identifier: BSD-3-Clause
//////////////////////////////////////////////////////////////////////////////

// CARE library header
#include "care/care.h"
#include "care/algorithm.h"

// Std library headers
#include <algorithm>
#include <iostream>
#include <limits>
#include <vector>

int main(int, char**) {
const int size = 10;
care::host_device_ptr<int> data(size);

CARE_OPENMP_LOOP(i, 0, size) {
data[0] += i; // clang tsan catches this
} CARE_OPENMP_LOOP_END

CARE_OPENMP_LOOP(i, 0, size - 1) {
data[i] = data[i + 1]; // clang tsan catches this
} CARE_OPENMP_LOOP_END

CARE_OPENMP_LOOP(i, 0, size) {
data[0] = 1; // clang tsan does not report
} CARE_OPENMP_LOOP_END

data.free();
return 0;
}

Loading