Skip to content

Commit

Permalink
Add ASAN check for github action (pytorch#294)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#294

1. Add ASAN check for github action.
USE_SANITIZAER is defined a cmake var,
can be defined as "address", and "leak" now.
2. Enable parallel build in github action

Reviewed By: jianyuh

Differential Revision: D19842258

fbshipit-source-id: b2faa473bf71a9c6183976e42e0bd96927477c0a
  • Loading branch information
Hongzhang Shan authored and facebook-github-bot committed Feb 12, 2020
1 parent 07dbb5d commit 805ab66
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/fbgemmci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ jobs:
set -e
mkdir build_static
cd build_static
cmake -DFBGEMM_LIBRARY_TYPE=static ..
make
cmake -DUSE_SANITIZER=address -DFBGEMM_LIBRARY_TYPE=static ..
make -j
- name: Test static FBGEMM lib
if: contains(runner.os, 'linux') # not run on macos-latest now due to supporting AVX2
Expand All @@ -58,8 +58,8 @@ jobs:
set -e
mkdir build_shared
cd build_shared
cmake -DFBGEMM_LIBRARY_TYPE=shared ..
make
cmake -DUSE_SANITIZER=address -DFBGEMM_LIBRARY_TYPE=shared ..
make -j
- name: Test shared FBGEMM lib
if: contains(runner.os, 'linux') # not run on macos-latest now due to supporting AVX2
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
mkdir build_static
cd build_static
echo "STARTING CMAKE"
cmake -G Ninja -DFBGEMM_BUILD_BENCHMARKS=OFF -DFBGEMM_LIBRARY_TYPE=static -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" ..
cmake -G Ninja -DUSE_SANITIZER=address -DFBGEMM_BUILD_BENCHMARKS=OFF -DFBGEMM_LIBRARY_TYPE=static -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" ..
ninja all
echo "Build Success"
Expand All @@ -115,7 +115,7 @@ jobs:
mkdir build_shared
cd build_shared
echo "STARTING CMAKE"
cmake -G Ninja -DFBGEMM_BUILD_BENCHMARKS=OFF -DFBGEMM_LIBRARY_TYPE=shared -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" ..
cmake -G Ninja -DUSE_SANITIZER=address -DFBGEMM_BUILD_BENCHMARKS=OFF -DFBGEMM_LIBRARY_TYPE=shared -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" ..
ninja all
if errorlevel 1 exit /b 1
Expand Down
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ set(FBGEMM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(FBGEMM_THIRDPARTY_DIR ${FBGEMM_BINARY_DIR}/third_party)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

#add address sanitizer
set(USE_SANITIZER "" CACHE string "options include address, leak, ...")

#All the source files that either use avx2 instructions statically or JIT
#avx2/avx512 instructions.
Expand Down Expand Up @@ -179,6 +181,26 @@ else(MSVC)
"-mavx512vl" "-masm=intel")
endif(MSVC)

if(USE_SANITIZER)
if (USE_SANITIZER MATCHES "([Aa]ddress)")
target_compile_options(fbgemm_generic PRIVATE
"-fsanitize=address" "-fno-omit-frame-pointer")
target_compile_options(fbgemm_avx2 PRIVATE
"-fsanitize=address" "-fno-omit-frame-pointer")
target_compile_options(fbgemm_avx512 PRIVATE
"-fsanitize=address" "-fno-omit-frame-pointer")
elseif (USE_SANITIZER MATCHES "([Ll]eak)")
target_compile_options(fbgemm_generic PRIVATE
"-fsanitize=leak" "-fno-omit-frame-pointer")
target_compile_options(fbgemm_avx2 PRIVATE
"-fsanitize=leak" "-fno-omit-frame-pointer")
target_compile_options(fbgemm_avx512 PRIVATE
"-fsanitize=leak" "-fno-omit-frame-pointer")
else()
message(FATAL_ERROR "USE_SANITIZER = ${USE_SANITIZER}: not supported!")
endif()
endif()

message(WARNING "==========")
message(WARNING "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
message(WARNING "CMAKE_CXX_FLAGS_DEBUG is ${CMAKE_CXX_FLAGS_DEBUG}")
Expand Down Expand Up @@ -270,6 +292,11 @@ else()
message(FATAL_ERROR "Unsupported library type ${FBGEMM_LIBRARY_TYPE}")
endif()

if(USE_SANITIZER)
target_link_options(fbgemm PRIVATE
"-fsanitize=address" "-fno-omit-frame-pointer")
endif()

target_include_directories(fbgemm BEFORE
PUBLIC $<BUILD_INTERFACE:${FBGEMM_SOURCE_DIR}>
PUBLIC $<BUILD_INTERFACE:${FBGEMM_SOURCE_DIR}/include>)
Expand Down
7 changes: 7 additions & 0 deletions bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ macro(add_benchmark BENCHNAME)
target_link_libraries(${BENCHNAME} fbgemm)
add_dependencies(${BENCHNAME} fbgemm)

if (USE_SANITIZER)
message(WARNING "USING SANITIZER IN TEST")
target_compile_options(${BENCHNAME} PRIVATE
"-fsanitize=${USE_SANITIZER}" "-fno-omit-frame-pointer")
target_link_options(${BENCHNAME} PRIVATE "-fsanitize=${USE_SANITIZER}")
endif()

if(${OpenMP_FOUND})
message(STATUS "OpenMP_LIBRARIES= ${OpenMP_CXX_LIBRARIES}")
target_link_libraries(${BENCHNAME} "${OpenMP_CXX_LIBRARIES}")
Expand Down
7 changes: 7 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ macro(add_gtest TESTNAME)
target_compile_options(${TESTNAME} PRIVATE
"-m64" "-mavx2" "-mfma" "-masm=intel")
endif(MSVC)
if (USE_SANITIZER)
message(WARNING "USING SANITIZER IN TEST")
target_compile_options(${TESTNAME} PRIVATE
"-fsanitize=${USE_SANITIZER}" "-fno-omit-frame-pointer")
target_link_options(${TESTNAME} PRIVATE "-fsanitize=${USE_SANITIZER}")
endif()

target_link_libraries(${TESTNAME} gtest gmock gtest_main fbgemm)

if(${OpenMP_FOUND})
Expand Down

0 comments on commit 805ab66

Please sign in to comment.