Files
TheRock/rocm-libraries/dnn-providers/cmake/Sanitizers.cmake
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

62 lines
2.4 KiB
CMake

# Copyright © Advanced Micro Devices, Inc., or its affiliates.
# SPDX-License-Identifier: MIT
# Enable Address Sanitizer and set linker flags. This configuration is for standalone builds outside
# of TheRock
if(BUILD_ADDRESS_SANITIZER)
# Address Sanitizer requires specific GPU targets which support XNACK.
set(GPU_TARGETS
gfx908:xnack+ # MI100 (Arcturus)
gfx90a:xnack+ # MI200 series (MI210, MI250, MI250X)
gfx942:xnack+ # MI300X (GPU)
)
# Query the compiler for the resource directory to locate sanitizer libraries reliably
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -print-resource-dir OUTPUT_VARIABLE CLANG_RESOURCE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
link_directories(${CLANG_RESOURCE_DIR}/lib/linux)
# Define sanitizer flags as variables for reuse
set(SANITIZER_COMPILE_FLAGS -fsanitize=address -fno-omit-frame-pointer)
set(SANITIZER_LINK_FLAGS -fsanitize=address -fno-omit-frame-pointer -shared-libasan)
# Apply sanitizer flags globally (can be overridden per target)
add_compile_options(${SANITIZER_COMPILE_FLAGS})
add_link_options(${SANITIZER_LINK_FLAGS})
endif()
# These settings are applied whether building with TheRock or standalone
if(BUILD_ADDRESS_SANITIZER OR THEROCK_SANITIZER STREQUAL "ASAN" OR THEROCK_SANITIZER STREQUAL "HOST_ASAN")
message(STATUS "Building with Address Sanitizer: ON")
# Add compile definition for conditional compilation
add_compile_definitions(ADDRESS_SANITIZER)
# Ensure the LLVM symbolizer is located before setting TEST_ENVIRONMENT.
include(CheckToolVersion)
findandcheckllvmsymbolizer()
# Set environment variables for Address Sanitizer.
# HSA_XNACK is only required for device-side ASAN (not HOST_ASAN).
# ASAN_SYMBOLIZER_PATH is set to the LLVM symbolizer to make the output from leak detection
# more readable.
if(BUILD_ADDRESS_SANITIZER OR THEROCK_SANITIZER STREQUAL "ASAN")
set(TEST_ENVIRONMENT "ASAN_SYMBOLIZER_PATH=${CMAKE_SYMBOLIZER}" "HSA_XNACK=1"
# "ASAN_OPTIONS=halt_on_error=1:abort_on_error=1"
)
else()
# HOST_ASAN only needs the symbolizer, not HSA_XNACK
set(TEST_ENVIRONMENT "ASAN_SYMBOLIZER_PATH=${CMAKE_SYMBOLIZER}"
# "ASAN_OPTIONS=halt_on_error=1:abort_on_error=1"
)
endif()
message(VERBOSE "ASAN ${CMAKE_CURRENT_SOURCE_DIR} TEST_ENVIRONMENT=${TEST_ENVIRONMENT}")
endif()