Skip to content

Commit

Permalink
Add device address sanitizer example (#311)
Browse files Browse the repository at this point in the history
* Update BLT_CXX_STD default to c++17
* Update host config to rocm 6.3.0
* Add working device address sanitizer example
  • Loading branch information
adayton1 authored Jan 28, 2025
1 parent 8a054d3 commit 9583784
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmake/SetupBLTWrapper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if(NOT BLT_LOADED)

option(ENABLE_FORTRAN "Enables Fortran compiler support" OFF)

set(BLT_CXX_STD "c++14" CACHE STRING "Set the c++ standard to use")
set(BLT_CXX_STD "c++17" CACHE STRING "Set the c++ standard to use")

include(${BLT_SOURCE_DIR}/SetupBLT.cmake)
endif()
8 changes: 6 additions & 2 deletions configs/lc/toss_4_x86_64_ib_cray/amdclang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
# SPDX-License-Identifier: BSD-3-Clause
##############################################################################

set(COMPILER_BASE "/usr/tce/packages/rocmcc/rocmcc-6.1.0-magic" CACHE PATH "")
set(ROCM_VER "6.3.0" CACHE STRING "")
set(COMPILER_BASE "/usr/tce/packages/rocmcc/rocmcc-${ROCM_VER}-magic" CACHE PATH "")
set(CMAKE_C_COMPILER "${COMPILER_BASE}/bin/amdclang" CACHE PATH "")
set(CMAKE_CXX_COMPILER "${COMPILER_BASE}/bin/amdclang++" CACHE PATH "")

set(ENABLE_HIP ON CACHE BOOL "Enable Hip")
set(ROCM_PATH "/usr/tce/packages/rocmcc/rocmcc-6.1.0-magic" CACHE PATH "")
set(ROCM_PATH "/usr/tce/packages/rocmcc/rocmcc-${ROCM_VER}-magic" CACHE PATH "")
set(CMAKE_HIP_ARCHITECTURES "gfx942:xnack+" CACHE STRING "")
set(AMDGPU_TARGETS "gfx942:xnack+" CACHE STRING "")

# Used by the DeviceASAN example
set(CARE_ASAN_RPATH_FLAG "-Wl,-rpath,/opt/rocm-${ROCM_VER}/lib/asan/:/opt/rocm-${ROCM_VER}/llvm/lib/asan:/opt/rocm-${ROCM_VER}/lib/llvm/lib/clang/18/lib/linux" CACHE STRING "")
12 changes: 12 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,15 @@ target_include_directories(RaceConditionsExample PRIVATE ${PROJECT_BINARY_DIR}/i

target_compile_options(RaceConditionsExample PRIVATE -fsanitize=thread -g)
target_link_options(RaceConditionsExample PRIVATE -fsanitize=thread)

if (ENABLE_HIP)
blt_add_executable(NAME DeviceASANExample
SOURCES DeviceASAN.cpp
DEPENDS_ON ${care_depends})

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

target_compile_options(DeviceASANExample PRIVATE -fsanitize=address -shared-libsan -g)
target_link_options(DeviceASANExample PRIVATE -fsanitize=address -shared-libsan -g ${CARE_ASAN_RPATH_FLAG})
endif ()
31 changes: 31 additions & 0 deletions examples/DeviceASAN.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//////////////////////////////////////////////////////////////////////////////
// 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"

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

CARE_STREAM_LOOP(i, 0, size) {
data[i] = i;
} CARE_STREAM_LOOP_END

// This will write past the end of the array.
// ASAN should report something like the following:
//
// ==4084715==ERROR: AddressSanitizer: heap-buffer-overflow on amdgpu device 0 at pc 0x153d3cdd3db8
// READ of size 4 in workgroup id (3906,0,0)
// #0 0x153d3cdd3db8 in main::'lambda0'(int)::operator()(int) const at /g/g17/dayton8/ale3d/github_care_4/examples/DeviceASAN.cpp:26:14
CARE_STREAM_LOOP(i, 0, size + 1) {
data[i]++;
} CARE_STREAM_LOOP_END

data.free();
return 0;
}

0 comments on commit 9583784

Please sign in to comment.