Add an option to build with -pthread (ON by default) (#3671)
authorabergeron <abergeron@gmail.com>
Sat, 3 Aug 2019 04:09:44 +0000 (00:09 -0400)
committerTianqi Chen <tqchen@users.noreply.github.com>
Sat, 3 Aug 2019 04:09:44 +0000 (21:09 -0700)
CMakeLists.txt

index 04e1f2e..43bf5ea 100644 (file)
@@ -28,6 +28,7 @@ tvm_option(USE_METAL "Build with Metal" OFF)
 tvm_option(USE_ROCM "Build with ROCM" OFF)
 tvm_option(ROCM_PATH "The path to rocm" /opt/rocm)
 tvm_option(USE_RPC "Build with RPC" ON)
+tvm_option(USE_THREADS "Build with thread support" ON)
 tvm_option(USE_LLVM "Build with LLVM, can be set to specific llvm-config path" OFF)
 tvm_option(USE_STACKVM_RUNTIME "Include stackvm into the runtime" OFF)
 tvm_option(USE_GRAPH_RUNTIME "Build with tiny graph runtime" ON)
@@ -233,6 +234,17 @@ if(NOT USE_SGX STREQUAL "OFF")
 endif()
 add_library(nnvm_compiler SHARED ${NNVM_COMPILER_SRCS})
 
+if(USE_THREADS)
+  message(STATUS "Build with thread support...")
+  set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
+  set(THREADS_PREFER_PTHREAD_FLAG TRUE)
+  find_package(Threads REQUIRED)
+  target_link_libraries(tvm Threads::Threads)
+  target_link_libraries(tvm_topi Threads::Threads)
+  target_link_libraries(tvm_runtime Threads::Threads)
+  target_link_libraries(nnvm_compiler Threads::Threads)
+endif(USE_THREADS)
+
 target_link_libraries(tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS})
 target_link_libraries(tvm_topi tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS})
 target_link_libraries(tvm_runtime ${TVM_RUNTIME_LINKER_LIBS})