Skip to content

Commit 491b7bd

Browse files
committed
sanitizer build
1 parent 22bec1f commit 491b7bd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

build.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ REPODIR=$(cd "$(dirname "$0")"; pwd)
2727
LIBCUOPT_BUILD_DIR=${LIBCUOPT_BUILD_DIR:=${REPODIR}/cpp/build}
2828
LIBMPS_PARSER_BUILD_DIR=${LIBMPS_PARSER_BUILD_DIR:=${REPODIR}/cpp/libmps_parser/build}
2929

30-
VALIDARGS="clean libcuopt libmps_parser cuopt_mps_parser cuopt cuopt_server cuopt_sh_client docs deb -a -b -g -v -l= --verbose-pdlp --build-lp-only --no-fetch-rapids --skip-c-python-adapters --skip-tests-build --skip-routing-build --skip-fatbin-write [--cmake-args=\\\"<args>\\\"] [--cache-tool=<tool>] -n --allgpuarch --ci-only-arch --show_depr_warn -h --help"
30+
VALIDARGS="clean libcuopt libmps_parser cuopt_mps_parser cuopt cuopt_server cuopt_sh_client docs deb -a -b -g -s -v -l= --verbose-pdlp --build-lp-only --no-fetch-rapids --skip-c-python-adapters --skip-tests-build --skip-routing-build --skip-fatbin-write [--cmake-args=\\\"<args>\\\"] [--cache-tool=<tool>] -n --allgpuarch --ci-only-arch --show_depr_warn -h --help"
3131
HELP="$0 [<target> ...] [<flag> ...]
3232
where <target> is:
3333
clean - remove all existing build artifacts and configuration (start over)
@@ -44,6 +44,7 @@ HELP="$0 [<target> ...] [<flag> ...]
4444
-g - build for debug
4545
-a - Enable assertion (by default in debug mode)
4646
-b - Build with benchmark settings
47+
-s - Build with sanitizer
4748
-n - no install step
4849
--no-fetch-rapids - don't fetch rapids dependencies
4950
-l= - log level. Options are: TRACE | DEBUG | INFO | WARN | ERROR | CRITICAL | OFF. Default=INFO
@@ -85,6 +86,7 @@ BUILD_DISABLE_DEPRECATION_WARNING=ON
8586
BUILD_ALL_GPU_ARCH=0
8687
BUILD_CI_ONLY=0
8788
BUILD_LP_ONLY=0
89+
BUILD_SANITIZER=0
8890
SKIP_C_PYTHON_ADAPTERS=0
8991
SKIP_TESTS_BUILD=0
9092
SKIP_ROUTING_BUILD=0
@@ -235,6 +237,9 @@ if hasArg --build-lp-only; then
235237
BUILD_LP_ONLY=1
236238
SKIP_ROUTING_BUILD=1 # Automatically skip routing when building LP-only
237239
fi
240+
if hasArg -s; then
241+
BUILD_SANITIZER=1
242+
fi
238243
if hasArg --skip-c-python-adapters; then
239244
SKIP_C_PYTHON_ADAPTERS=1
240245
fi
@@ -345,6 +350,7 @@ if buildAll || hasArg libcuopt; then
345350
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
346351
-DFETCH_RAPIDS=${FETCH_RAPIDS} \
347352
-DBUILD_LP_ONLY=${BUILD_LP_ONLY} \
353+
-DBUILD_SANITIZER=${BUILD_SANITIZER} \
348354
-DSKIP_C_PYTHON_ADAPTERS=${SKIP_C_PYTHON_ADAPTERS} \
349355
-DBUILD_TESTS=$((1 - ${SKIP_TESTS_BUILD})) \
350356
-DSKIP_ROUTING_BUILD=${SKIP_ROUTING_BUILD} \

cpp/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ if(CMAKE_COMPILER_IS_GNUCXX)
8484
list(APPEND CUOPT_CXX_FLAGS -Werror -Wno-error=deprecated-declarations)
8585
endif(CMAKE_COMPILER_IS_GNUCXX)
8686

87+
# To use sanitizer with cuda runtime, one must follow a few steps:
88+
# 1. Find libasan.so with "gcc -print-file-name=libasan.so"
89+
# 2. Run the binary with env var set: LD_PRELOAD=$PATH_TO_LIBASAN ASAN_OPTIONS='protect_shadow_gap=0:replace_intrin=0'
90+
# 3. (Optional) To run with a debugger (gdb or cuda-gdb) use the additional ASAN option alloc_dealloc_mismatch=0
91+
if(BUILD_SANITIZER)
92+
list(APPEND CUOPT_CXX_FLAGS -fsanitize=address,undefined -fno-omit-frame-pointer -g -Wno-error=maybe-uninitialized)
93+
add_link_options(-fsanitize=address,undefined)
94+
endif(BUILD_SANITIZER)
95+
8796
if(DEFINE_ASSERT)
8897
add_definitions(-DASSERT_MODE)
8998
endif(DEFINE_ASSERT)

0 commit comments

Comments
 (0)