Skip to content

Commit

Permalink
cmake: Set DMLC_LOG_FATAL_THROW only for building mxnet and not for t…
Browse files Browse the repository at this point in the history
…vm (apache#17878)

Building TVM with DMLC_LOG_FATAL_THROW=0 is unsupported and causes `tvmop/compile.py` to crash.

Further

* remove duplicate "if(MSVC)" in CMakeLists.txt
* Don't set USE_OPENMP=1 in TVM if building MXNet with USE_OPENMP=0
  • Loading branch information
leezu authored and MoisesHer committed Apr 10, 2020
1 parent bbc2b68 commit 44fb987
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 49 deletions.
88 changes: 42 additions & 46 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ option(USE_ASAN "Enable Clang/GCC ASAN sanitizers." OFF)
option(ENABLE_TESTCOVERAGE "Enable compilation with test coverage metric output" OFF)
option(USE_INT64_TENSOR_SIZE "Use int64_t to represent the total number of elements in a tensor" OFF)
option(BUILD_CYTHON_MODULES "Build cython modules." OFF)
option(LOG_FATAL_THROW "Log exceptions but do not abort" ON)
cmake_dependent_option(USE_SPLIT_ARCH_DLL "Build a separate DLL for each Cuda arch (Windows only)." ON "MSVC" OFF)
cmake_dependent_option(USE_CCACHE "Attempt using CCache to wrap the compilation" ON "UNIX" OFF)

Expand Down Expand Up @@ -151,7 +152,6 @@ endif()
add_definitions(-DDMLC_MODERN_THREAD_LOCAL=0)
# disable stack trace in exception by default.
add_definitions(-DDMLC_LOG_STACK_TRACE_SIZE=0)
add_definitions(-DDMLC_LOG_FATAL_THROW=1)

if(MSVC)
add_definitions(-DWIN32_LEAN_AND_MEAN)
Expand Down Expand Up @@ -693,6 +693,7 @@ if(UNIX)
list(APPEND MXNET_INSTALL_TARGETS mxnet_static)
add_library(mxnet_static STATIC ${SOURCE})
target_link_libraries(mxnet_static PUBLIC mshadow)
target_compile_definitions(mxnet_static PUBLIC DMLC_LOG_FATAL_THROW=$<BOOL:${LOG_FATAL_THROW}>)
add_library(mxnet SHARED ${DUMMY_SOURCE})
target_link_libraries(mxnet PRIVATE ${BEGIN_WHOLE_ARCHIVE} $<TARGET_FILE:mxnet_static> ${END_WHOLE_ARCHIVE})
target_link_libraries(mxnet PRIVATE mxnet_static)
Expand All @@ -710,59 +711,54 @@ if(UNIX)
endif()
elseif(MSVC)
if(USE_CUDA)
if(MSVC)
if(USE_SPLIT_ARCH_DLL)
add_executable(gen_warp tools/windowsbuild/gen_warp.cpp)
add_library(mxnet SHARED tools/windowsbuild/warp_dll.cpp ${CMAKE_BINARY_DIR}/warp_gen_cpp.cpp
${CMAKE_BINARY_DIR}/warp_gen.asm)
target_link_libraries(mxnet PRIVATE cudart Shlwapi)
list(GET arch_code_list 0 mxnet_first_arch)
foreach(arch ${arch_code_list})
add_library(mxnet_${arch} SHARED ${SOURCE})
target_link_libraries(mxnet_${arch} PUBLIC mshadow)
target_compile_options(
mxnet_${arch}
PRIVATE
"$<$<COMPILE_LANGUAGE:CUDA>:--gpu-architecture=compute_${arch}>"
)
target_compile_options(
mxnet_${arch}
PRIVATE
"$<$<COMPILE_LANGUAGE:CUDA>:--gpu-code=sm_${arch},compute_${arch}>"
)
target_compile_options(
mxnet_${arch}
PRIVATE "$<$<AND:$<CONFIG:DEBUG>,$<COMPILE_LANGUAGE:CUDA>>:-Xcompiler=-MTd -Gy /bigobj>")
target_compile_options(
mxnet_${arch}
PRIVATE "$<$<AND:$<CONFIG:RELEASE>,$<COMPILE_LANGUAGE:CUDA>>:-Xcompiler=-MT -Gy /bigobj>")
endforeach()

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/warp_gen_cpp.cpp ${CMAKE_BINARY_DIR}/warp_gen.asm
COMMAND gen_warp $<TARGET_FILE:mxnet_${mxnet_first_arch}> WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/ DEPENDS $<TARGET_FILE:mxnet_${mxnet_first_arch}>)
else(USE_SPLIT_ARCH_DLL)
string(REPLACE ";" " " NVCC_FLAGS_ARCH "${NVCC_FLAGS_ARCH}")
set(CMAKE_CUDA_FLAGS " ${CUDA_ARCH_FLAGS_SPACES}")
add_library(mxnet SHARED ${SOURCE})
target_link_libraries(mxnet PUBLIC mshadow)
if(USE_SPLIT_ARCH_DLL)
add_executable(gen_warp tools/windowsbuild/gen_warp.cpp)
add_library(mxnet SHARED tools/windowsbuild/warp_dll.cpp ${CMAKE_BINARY_DIR}/warp_gen_cpp.cpp
${CMAKE_BINARY_DIR}/warp_gen.asm)
target_link_libraries(mxnet PRIVATE cudart Shlwapi)
list(GET arch_code_list 0 mxnet_first_arch)
foreach(arch ${arch_code_list})
add_library(mxnet_${arch} SHARED ${SOURCE})
target_link_libraries(mxnet_${arch} PUBLIC mshadow)
target_compile_definitions(mxnet_${arch} PUBLIC DMLC_LOG_FATAL_THROW=$<BOOL:${LOG_FATAL_THROW}>)
target_compile_options(
mxnet
PRIVATE "$<$<AND:$<CONFIG:DEBUG>,$<COMPILE_LANGUAGE:CUDA>>:-Xcompiler=-MTd -Gy /bigobj>")
mxnet_${arch}
PRIVATE
"$<$<COMPILE_LANGUAGE:CUDA>:--gpu-architecture=compute_${arch}>"
)
target_compile_options(
mxnet
PRIVATE "$<$<AND:$<CONFIG:RELEASE>,$<COMPILE_LANGUAGE:CUDA>>:-Xcompiler=-MT -Gy /bigobj>")

endif(USE_SPLIT_ARCH_DLL)
else()
mxnet_${arch}
PRIVATE
"$<$<COMPILE_LANGUAGE:CUDA>:--gpu-code=sm_${arch},compute_${arch}>"
)
target_compile_options(
mxnet_${arch}
PRIVATE "$<$<AND:$<CONFIG:DEBUG>,$<COMPILE_LANGUAGE:CUDA>>:-Xcompiler=-MTd -Gy /bigobj>")
target_compile_options(
mxnet_${arch}
PRIVATE "$<$<AND:$<CONFIG:RELEASE>,$<COMPILE_LANGUAGE:CUDA>>:-Xcompiler=-MT -Gy /bigobj>")
endforeach()

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/warp_gen_cpp.cpp ${CMAKE_BINARY_DIR}/warp_gen.asm
COMMAND gen_warp $<TARGET_FILE:mxnet_${mxnet_first_arch}> WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/ DEPENDS $<TARGET_FILE:mxnet_${mxnet_first_arch}>)
else(USE_SPLIT_ARCH_DLL)
string(REPLACE ";" " " NVCC_FLAGS_ARCH "${NVCC_FLAGS_ARCH}")
set(CMAKE_CUDA_FLAGS " ${CUDA_ARCH_FLAGS_SPACES}")
add_library(mxnet SHARED ${SOURCE})
target_link_libraries(mxnet PUBLIC mshadow)
endif()
target_compile_options(
mxnet
PRIVATE "$<$<AND:$<CONFIG:DEBUG>,$<COMPILE_LANGUAGE:CUDA>>:-Xcompiler=-MTd -Gy /bigobj>")
target_compile_options(
mxnet
PRIVATE "$<$<AND:$<CONFIG:RELEASE>,$<COMPILE_LANGUAGE:CUDA>>:-Xcompiler=-MT -Gy /bigobj>")
endif(USE_SPLIT_ARCH_DLL)
else()
add_library(mxnet SHARED ${SOURCE})
target_compile_definitions(mxnet PUBLIC DMLC_LOG_FATAL_THROW=$<BOOL:${LOG_FATAL_THROW}>)
target_link_libraries(mxnet PUBLIC mshadow)
endif()

endif()

add_library(customop_lib SHARED ${CMAKE_CURRENT_SOURCE_DIR}/example/extensions/lib_custom_op/gemm_lib.cc)
Expand Down
8 changes: 5 additions & 3 deletions cmake/BuildTVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ set(USE_VTA_TSIM OFF)
# Whether use Relay debug mode
set(USE_RELAY_DEBUG OFF)

# Use OPENMP thread pool to be compatible with MXNet
set(USE_OPENMP ON)

# Disable USE_MKLDNN for TVM
set(USE_MKLDNN OFF)

# Sanity checks
if(NOT DEFINED USE_OPENMP)
message(FATAL_ERROR "TVM expects USE_OPENMP is set. But USE_OPENMP was neither ON nor OFF.")
endif()

0 comments on commit 44fb987

Please sign in to comment.