Skip to content

Commit

Permalink
Allow disabling of OneDNN and OpenMP (libxsmm#725)
Browse files Browse the repository at this point in the history
Makes sure libraries are not build/included in tools and tests not run
if the libraries are disabled.
  • Loading branch information
rengolin authored Sep 21, 2023
1 parent 2030827 commit 3a12090
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 24 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ include(xsmm)
message (STATUS "LIBXSMM Include dir: ${XSMM_INCLUDE_DIRS}")
include(xsmm-dnn)
message (STATUS "LIBXSMM-DNN Include dir: ${XSMM_DNN_INCLUDE_DIRS}")

# onednn
include(one-dnn)
message (STATUS "ONE-DNN Include dir: ${DNNL_INCLUDE_DIR}")

# Sanitizers (include as late as possible aka append)
include(sanitizers)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ This setup assumes that you have built LLVM and MLIR in `$CUSTOM_LLVM_ROOT` as a
_Note: OpenMP is a requirement to get multi-threaded performance on our code.
If you don't want to build with OpenMP, disable with the CMake flag `-DUSE_OpenMP=False`._

_Note: OneDNN is a requirement to get performance comparisons against our code.
If you don't want to build with OneDNN, disable with the CMake flag `-DUSE_OneDNN=False`._

```sh
# Clone
git clone https://github.com/plaidml/tpp-mlir.git
Expand Down
41 changes: 23 additions & 18 deletions cmake/modules/one-dnn.cmake
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
include (ExternalProject)
option(USE_OneDNN "Use OneDNN" ON)

set(DNNL_SOURCE ${CMAKE_CURRENT_BINARY_DIR}/dnnl/src/dnnl/src)
set(DNNL_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/dnnl/install)
set(DNNL_LIB_DIR ${DNNL_INSTALL}/${CMAKE_INSTALL_LIBDIR})
set(DNNL_INCLUDE_DIR ${DNNL_INSTALL}/include)
if(USE_OneDNN)
include (ExternalProject)

ExternalProject_Add(project_dnnl
PREFIX dnnl
GIT_REPOSITORY https://github.com/oneapi-src/onednn.git
GIT_TAG 03691d7898b5a4fd1f471c8e30c97d394a5fdec2
SOURCE_DIR ${DNNL_SOURCE}
INSTALL_DIR ${DNNL_INSTALL}
GIT_PROGRESS true
USES_TERMINAL_BUILD true
CMAKE_ARGS -DDNNL_BUILD_TESTS=OFF -DDNNL_ENABLE_CONCURRENT_EXEC=ON -DDNNL_BUILD_EXAMPLES=OFF
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${DNNL_INSTALL}
)
set(DNNL_SOURCE ${CMAKE_CURRENT_BINARY_DIR}/dnnl/src/dnnl/src)
set(DNNL_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/dnnl/install)
set(DNNL_LIB_DIR ${DNNL_INSTALL}/${CMAKE_INSTALL_LIBDIR})
set(DNNL_INCLUDE_DIR ${DNNL_INSTALL}/include)
message (STATUS "ONE-DNN Include dir: ${DNNL_INCLUDE_DIR}")

include_directories(${DNNL_INCLUDE_DIR})
link_directories(${DNNL_LIB_DIR})
ExternalProject_Add(project_dnnl
PREFIX dnnl
GIT_REPOSITORY https://github.com/oneapi-src/onednn.git
GIT_TAG 03691d7898b5a4fd1f471c8e30c97d394a5fdec2
SOURCE_DIR ${DNNL_SOURCE}
INSTALL_DIR ${DNNL_INSTALL}
GIT_PROGRESS true
USES_TERMINAL_BUILD true
CMAKE_ARGS -DDNNL_BUILD_TESTS=OFF -DDNNL_ENABLE_CONCURRENT_EXEC=ON -DDNNL_BUILD_EXAMPLES=OFF
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${DNNL_INSTALL}
)

include_directories(${DNNL_INCLUDE_DIR})
link_directories(${DNNL_LIB_DIR})
endif()
5 changes: 4 additions & 1 deletion runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
add_subdirectory(Xsmm)
add_subdirectory(OneDnnl)

if(USE_OneDNN)
add_subdirectory(OneDnnl)
endif()
2 changes: 2 additions & 0 deletions test/Integration/onednn/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if not config.use_onednn or "ON" not in config.use_onednn:
config.unsupported = True
2 changes: 2 additions & 0 deletions test/Integration/openmp/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if not config.use_openmp or "ON" not in config.use_openmp:
config.unsupported = True
File renamed without changes.
2 changes: 2 additions & 0 deletions test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ config.host_arch = "@HOST_ARCH@"
config.tpp_src_root = "@CMAKE_SOURCE_DIR@"
config.tpp_obj_root = "@CMAKE_BINARY_DIR@"
config.tpp_gpu = "@TPP_GPU@"
config.use_openmp = "@USE_OpenMP@"
config.use_onednn = "@USE_OneDNN@"

# Support substitution of the tools_dir with user parameters. This is
# used when we can't determine the tool dir at configuration time.
Expand Down
7 changes: 6 additions & 1 deletion tools/tpp-opt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)

if(USE_OneDNN)
set(ONEDNN_LIBS "tpp_dnnl_runner_utils")
endif()

set(LIBS
${dialect_libs}
${conversion_libs}
MLIRToLLVMIRTranslationRegistration
MLIROptLib
MLIRTPP
tpp_xsmm_runner_utils
tpp_dnnl_runner_utils
${ONEDNN_LIBS}
)
add_llvm_executable(tpp-opt tpp-opt.cpp)

Expand Down
16 changes: 13 additions & 3 deletions tools/tpp-run/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)

if(USE_OneDNN)
set(ONEDNN_LIBS "tpp_dnnl_runner_utils")
set(ONEDNN_LIBS_INCL "-ltpp_dnnl_runner_utils")
endif()

if(USE_OpenMP)
set(OPENMP_LIBS_INCL "-lomp")
endif()

set(LIBS
${dialect_libs}
${conversion_libs}
Expand All @@ -16,7 +26,7 @@ set(LIBS
MLIROptLib
MLIRTPP
tpp_xsmm_runner_utils
tpp_dnnl_runner_utils
${ONEDNN_LIBS}
)

set(LLVM_LINK_COMPONENTS
Expand Down Expand Up @@ -57,13 +67,13 @@ target_link_options(tpp-run PRIVATE
-Wl,--no-as-needed
-L${CMAKE_BINARY_DIR}/lib
-ltpp_xsmm_runner_utils
-ltpp_dnnl_runner_utils
${ONEDNN_LIBS_INCL}
-L${LLVM_LIBRARY_DIR}
-lmlir_c_runner_utils
-lmlir_runner_utils
-lmlir_async_runtime
${TPP_GPU_LINK_FLAGS}
-lomp
${OPENMP_LIBS_INCL}
-Wl,--as-needed
)

Expand Down

0 comments on commit 3a12090

Please sign in to comment.