Skip to content

Commit

Permalink
Add checks for address sanitizer build (#1562)
Browse files Browse the repository at this point in the history
* Address sanitization build causes errors for python bindings and shared libs.
Other MLIR based projects (IREE, Stablehlo) seem to have similar issues and just
skip building these components for sanitization builds.
* Address sanitizer build can be enabled by setting '-DCMAKE_BUILD_TYPE=Asan
-DTTMLIR_ENABLE_SHARED_LIB=OFF -DTTMLIR_ENABLE_BINDINGS_PYTHON=OFF' options with
cmake command.
mmanzoorTT authored Dec 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 0ce883a commit be179fc
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -9,6 +9,11 @@ option(TT_RUNTIME_ENABLE_PERF_TRACE "Enable performance mode" OFF)
option(TTMLIR_ENABLE_RUNTIME "Enable runtime" OFF)
option(TTMLIR_ENABLE_STABLEHLO "Enable StableHLO support" OFF)
option(TTMLIR_ENABLE_OP_MODEL "Enable OpModel support" OFF)
option(TTMLIR_ENABLE_SHARED_LIB "Enable Shared lib building" ON)

if (NOT TTMLIR_ENABLE_RUNTIME)
set (TTMLIR_ENABLE_SHARED_LIB OFF)
endif()

if (TTMLIR_ENABLE_STABLEHLO)
add_compile_definitions(TTMLIR_ENABLE_STABLEHLO)
@@ -50,6 +55,17 @@ set(Python3_EXECUTABLE $ENV{TTMLIR_VENV_DIR}/bin/python3)
include(FindMLIR)
include(TTMLIRVersion)

if (CMAKE_BUILD_TYPE STREQUAL "Asan")
# Address sanitization does not work with python bindings.
if(MLIR_ENABLE_BINDINGS_PYTHON AND TTMLIR_ENABLE_BINDINGS_PYTHON)
message(FATAL_ERROR "TTMLIR_ENABLE_BINDINGS_PYTHON must be set to OFF when building TTMLIR with address sanitization")
endif()
# Clang only links in the sanitizer runtime for the main executable, not for the shared libraries.
if (TTMLIR_ENABLE_SHARED_LIB)
message(FATAL_ERROR "TTMLIR_ENABLE_SHARED_LIB must be set to OFF when building TTMLIR with address sanitization")
endif()
endif()

set(TTMLIR_TOOLCHAIN_DIR $ENV{TTMLIR_TOOLCHAIN_DIR})
set(TTMLIR_SOURCE_DIR ${PROJECT_SOURCE_DIR})
set(TTMLIR_BINARY_DIR ${PROJECT_BINARY_DIR})
2 changes: 1 addition & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ add_subdirectory(Scheduler)

# Shared library will include runtime code
# so we only build it if runtime is enabled
if (TTMLIR_ENABLE_RUNTIME)
if (TTMLIR_ENABLE_SHARED_LIB)
add_subdirectory(SharedLib)
endif()

0 comments on commit be179fc

Please sign in to comment.