mirror of
https://github.com/amd/blis.git
synced 2026-07-16 08:42:21 +00:00
CMake: CMake is updated to support Address-Sanatizer
CMakelists.txt is updated to support ASAN to find memory related errors in blis library. ASAN is enabled by configuring cmake with the following option . $ cmake .. -DENABLE_ASAN=ON ASAN supports only on linux with clang compiler. And redzone size default size is 16 bytes and maximum redzone size is 2048 bytes. $ ASAN_OPTIONS=redzone=2048 <exe> AMD-Internal: [CPUPL-2748] Change-Id: I0b70af5c41cf5c68602150daeb67d7432bbe5cb8
This commit is contained in:
@@ -282,6 +282,9 @@ mark_as_advanced(ENABLE_SANDBOX)
|
||||
if(NOT WIN32)
|
||||
option(ENABLE_COVERAGE "Enable Code Coverage using gcov(only GCC/Debug build)" OFF)
|
||||
endif()
|
||||
if(NOT WIN32)
|
||||
option(ENABLE_ASAN "Enable Address Sanatizer (Debug build)" OFF)
|
||||
endif()
|
||||
|
||||
#------------------------------------
|
||||
# Check memkind
|
||||
@@ -657,8 +660,7 @@ if(NOT WIN32)
|
||||
cmake_print_variables(ENABLE_COVERAGE)
|
||||
if(ENABLE_COVERAGE)
|
||||
if(NOT (${CMAKE_C_COMPILER_ID} MATCHES "GNU"))
|
||||
message(WARNING "Coverage is only supported for GNU/Linux GCC Debug build")
|
||||
message(" Code Coverage is disabled.")
|
||||
message(FATAL_ERROR "Coverage is only supported for GNU/Linux GCC Debug build")
|
||||
set(ENABLE_COVERAGE OFF)
|
||||
endif()
|
||||
if(NOT(ENABLE_DEBUG STREQUAL "noopt"))
|
||||
@@ -671,11 +673,24 @@ if(NOT WIN32)
|
||||
if(ENABLE_COVERAGE)
|
||||
message(" Code Coverage is enabled.")
|
||||
else()
|
||||
cmake_print_variables(ENABLE_COVERAGE)
|
||||
message(" Code Coverage is disabled.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT WIN32)
|
||||
cmake_print_variables(ENABLE_ASAN)
|
||||
if(ENABLE_ASAN)
|
||||
if(NOT (${CMAKE_C_COMPILER_ID} MATCHES "Clang"))
|
||||
message(FATAL_ERROR "ASAN is supported only for Clang/Linux" )
|
||||
endif()
|
||||
endif()
|
||||
if(ENABLE_ASAN)
|
||||
message(" Address Sanatizer is enabled.")
|
||||
else()
|
||||
message(" Address Sanatizer is disabled.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Initialize threading model, using the corresponding cache variable.
|
||||
set(THREADING_MODEL ${ENABLE_THREADING})
|
||||
|
||||
@@ -852,7 +867,16 @@ endif()
|
||||
# Code-coverage flags
|
||||
#--------------------------------------------
|
||||
if(ENABLE_COVERAGE AND (NOT WIN32))
|
||||
set(CMAKE_C_FLAGS "-fprofile-arcs -ftest-coverage")
|
||||
set(COVERAGE_FLAGS "-fprofile-arcs -ftest-coverage")
|
||||
list(APPEND CMAKE_C_FLAGS ${COVERAGE_FLAGS})
|
||||
endif()
|
||||
|
||||
#--------------------------------------------
|
||||
# Address Sanatizer flags
|
||||
#--------------------------------------------
|
||||
if(ENABLE_ASAN AND (NOT WIN32))
|
||||
set(ASAN_FLAGS "-g -fsanitize=address")
|
||||
list(APPEND CMAKE_C_FLAGS ${ASAN_FLAGS})
|
||||
endif()
|
||||
|
||||
#--------------------------------------------
|
||||
|
||||
@@ -285,6 +285,12 @@ def main():
|
||||
print( " report in html format. Code coverage support is provided" )
|
||||
print( " only on LINUX with GCC compiler." )
|
||||
print( " " )
|
||||
print( " -DENABLE_ASAN=ON or -DENABLE_ASAN=OFF" )
|
||||
print( " " )
|
||||
print( " Enable (disabled by default) Address Sanitizer to find " )
|
||||
print( " memory access error. Address Sanitizer support is provided" )
|
||||
print( " only on LINUX with Clang compiler" )
|
||||
print( " " )
|
||||
print( " Additional CMake Variables:" )
|
||||
print( " " )
|
||||
print( " CMAKE_C_COMPILER Specifies the C compiler to use." )
|
||||
|
||||
@@ -279,12 +279,13 @@ if(LINUX)
|
||||
add_compile_options(-g -Wall -Wno-unused-function -Wfatal-errors -fPIC )
|
||||
|
||||
if(ENABLE_ASAN)
|
||||
add_compile_options(-fsanitize=address)
|
||||
add_definitions(-DENABLE_ASAN)
|
||||
set(ASAN_FLAGS "-fsanitize=address")
|
||||
list(APPEND CMAKE_C_FLAGS ${ASAN_FLAGS})
|
||||
endif()
|
||||
|
||||
if(ENABLE_COVERAGE)
|
||||
set(CMAKE_CXX_FLAGS "-O0 --coverage")
|
||||
set(COVERAGE_FLAGS "-O0 --coverage")
|
||||
list(APPEND CMAKE_C_FLAGS ${COVERAGE_FLAGS})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -307,20 +308,23 @@ if(BLIS_LINKING_TYPE STREQUAL "static")
|
||||
if(ENABLE_THREADING STREQUAL "openmp")
|
||||
try_run(RUNRESULT COMPILERESULT "${CMAKE_BINARY_DIR}/temp" SOURCES ${CMAKE_SOURCE_DIR}/cmake/config_ukr_tests.cpp
|
||||
COMPILE_DEFINITIONS -I${BLIS_PATH}/include/ -I${BLIS_PATH}/include/blis
|
||||
LINK_LIBRARIES ${BLIS_LIBRARY} ${COMMON_LIBS} OpenMP::OpenMP_CXX
|
||||
LINK_LIBRARIES ${BLIS_LIBRARY} ${COMMON_LIBS} OpenMP::OpenMP_CXX ${ASAN_FLAGS} ${COVERAGE_FLAGS}
|
||||
RUN_OUTPUT_VARIABLE UKR_CONFIG
|
||||
COMPILE_OUTPUT_VARIABLE COMP_VAR
|
||||
)
|
||||
else()
|
||||
try_run(RUNRESULT COMPILERESULT "${CMAKE_BINARY_DIR}/temp" SOURCES ${CMAKE_SOURCE_DIR}/cmake/config_ukr_tests.cpp
|
||||
COMPILE_DEFINITIONS -I${BLIS_PATH}/include/ -I${BLIS_PATH}/include/blis
|
||||
LINK_LIBRARIES ${BLIS_LIBRARY} ${COMMON_LIBS}
|
||||
LINK_LIBRARIES ${BLIS_LIBRARY} ${COMMON_LIBS} ${ASAN_FLAGS} ${COVERAGE_FLAGS}
|
||||
RUN_OUTPUT_VARIABLE UKR_CONFIG
|
||||
COMPILE_OUTPUT_VARIABLE COMP_VAR
|
||||
)
|
||||
endif()
|
||||
# Uncomment this to debug this snippet above, if necessary.
|
||||
#message("Build output: ${COMP_VAR}")
|
||||
message("Build output: ${COMP_VAR}")
|
||||
if(NOT COMPILERESULT)
|
||||
message(FATAL_ERROR "Compiling config_ukr_tests.cpp failed with the following error ${COMP_VAR}.")
|
||||
endif()
|
||||
# Remove all empty items from the list.
|
||||
list(REMOVE_ITEM UKR_CONFIG "")
|
||||
# We iterate through the list returned from the snippet above.
|
||||
|
||||
@@ -86,7 +86,13 @@ For threaded MKL the following OpenMP runtimes are used:
|
||||
* For testing a 64-bit integer BLIS library, use `-DINT_SIZE=64`.
|
||||
## Address Sanitizer (Linux Only)
|
||||
* To build using address sanitizer, configure using `-DENABLE_ASAN=ON`. [**OFF by default**]
|
||||
* An installation to BLIS which was build with ASAN flags[CFLAGS="-O0 -g -fsanitize=address"] needs to be provided.
|
||||
* An installation to BLIS which was build with ASAN flags needs to be provided.
|
||||
* Set -DENABLE_ASAN=ON when building BLIS with CMake, or set CFLAGS="-O0 -g -fsanitize=address" when building with make.
|
||||
* By default redzone size is 16 bytes and can redzone size can be increase to 2048 bytes.
|
||||
```console
|
||||
$ ASAN_OPTIONS=redzone=2048 <executable>
|
||||
```
|
||||
|
||||
## Code Coverage (Only GCC Compiler)
|
||||
* BLIS : Configure BLIS Library with code coverage flags[CFLAGS="-O0 -fprofile-arcs -ftest-coverage"], compile and install.
|
||||
* Gtestsuite : To build for code coverage, configure cmake with `-DENABLE_COVERAGE=ON`. [**OFF by default**] and then compile and run the executable.
|
||||
|
||||
@@ -93,12 +93,8 @@ foreach(dir ${DIRS})
|
||||
if( (ENABLE_THREADING STREQUAL "openmp") OR (MKL_ENABLE_THREADING STREQUAL "openmp"))
|
||||
target_link_libraries(${target_name}.${dir}.${subdir} OpenMP::OpenMP_CXX)
|
||||
endif()
|
||||
if(ENABLE_ASAN)
|
||||
target_link_libraries(${target_name}.${dir}.${subdir} -fsanitize=address)
|
||||
endif()
|
||||
if(ENABLE_COVERAGE)
|
||||
target_link_libraries(${target_name}.${dir}.${subdir} "--coverage")
|
||||
endif()
|
||||
target_link_libraries(${target_name}.${dir}.${subdir} ${ASAN_FLAGS})
|
||||
target_link_libraries(${target_name}.${dir}.${subdir} ${COVERAGE_FLAGS})
|
||||
if(TEST_INTERFACE STREQUAL "BLAS")
|
||||
target_compile_definitions(${target_name}.${dir}.${subdir} PUBLIC TEST_BLAS)
|
||||
elseif(TEST_INTERFACE STREQUAL "CBLAS")
|
||||
|
||||
@@ -25,7 +25,10 @@ file(GLOB testsuite_sources LIST_DIRECTORIES false ${CMAKE_CURRENT_SOURCE_DIR}/s
|
||||
set(CINFLAGS ${INC_PATH})
|
||||
if((NOT WIN32) AND ENABLE_COVERAGE)
|
||||
include(coverage.cmake)
|
||||
set(LDFLAGS "${LDFLAGS} -ftest-coverage")
|
||||
list(APPEND LDFLAGS ${COVERAGE_FLAGS})
|
||||
endif()
|
||||
if((NOT WIN32) AND ENABLE_ASAN)
|
||||
list(APPEND LDFLAGS ${ASAN_FLAGS})
|
||||
endif()
|
||||
|
||||
# Create an executable using the sources above.
|
||||
|
||||
Reference in New Issue
Block a user