CMakeLists.txt 10.8 KB
Newer Older
1
cmake_minimum_required(VERSION 3.2)
2
project(tvm C CXX)
3

4 5
# Utility functions
include(cmake/util/Util.cmake)
6 7
include(cmake/util/FindCUDA.cmake)
include(cmake/util/FindVulkan.cmake)
8
include(cmake/util/FindLLVM.cmake)
9 10
include(cmake/util/FindROCM.cmake)

11 12 13 14 15 16
if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/config.cmake)
  include(${CMAKE_CURRENT_BINARY_DIR}/config.cmake)
else()
  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/config.cmake)
    include(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake)
  endif()
17 18
endif()

19 20 21 22 23
# NOTE: do not modify this file to change option values.
# You can create a config.cmake at build folder
# and add set(OPTION VALUE) to override these build options.
# Alernatively, use cmake -DOPTION=VALUE through command-line.
tvm_option(USE_CUDA "Build with CUDA" OFF)
24
tvm_option(USE_OPENCL "Build with OpenCL" OFF)
25
tvm_option(USE_VULKAN "Build with Vulkan" OFF)
26
tvm_option(USE_OPENGL "Build with OpenGL" OFF)
27
tvm_option(USE_METAL "Build with Metal" OFF)
28 29
tvm_option(USE_ROCM "Build with ROCM" OFF)
tvm_option(ROCM_PATH "The path to rocm" /opt/rocm)
30
tvm_option(USE_RPC "Build with RPC" ON)
31
tvm_option(USE_LLVM "Build with LLVM, can be set to specific llvm-config path" OFF)
32
tvm_option(USE_STACKVM_RUNTIME "Include stackvm into the runtime" OFF)
33
tvm_option(USE_GRAPH_RUNTIME "Build with tiny graph runtime" ON)
34
tvm_option(USE_GRAPH_RUNTIME_DEBUG "Build with tiny graph runtime debug mode" OFF)
35
tvm_option(USE_RELAY_DEBUG "Building Relay in debug mode..." OFF)
nhynes committed
36
tvm_option(USE_SGX "Build with SGX" OFF)
37
tvm_option(USE_RTTI "Build with RTTI" ON)
38
tvm_option(USE_MSVC_MT "Build with MT" OFF)
39
tvm_option(INSTALL_DEV "Install compiler infrastructure" OFF)
40
tvm_option(HIDE_PRIVATE_SYMBOLS "Compile with -fvisibility=hidden." OFF)
41

42 43 44 45 46 47
# 3rdparty libraries
tvm_option(DLPACK_PATH "Path to DLPACK" "3rdparty/dlpack/include")
tvm_option(DMLC_PATH "Path to DMLC" "3rdparty/dmlc-core/include")
tvm_option(RANG_PATH "Path to RANG" "3rdparty/rang/include")
tvm_option(COMPILER_RT_PATH "Path to COMPILER-RT" "3rdparty/compiler-rt")

48 49
# Contrib library options
tvm_option(USE_BLAS "The blas library to be linked" none)
50
tvm_option(USE_MKL_PATH "MKL root path when use MKL blas" none)
51
tvm_option(USE_CUDNN "Build with cuDNN" OFF)
52 53 54 55 56 57
tvm_option(USE_CUBLAS "Build with cuBLAS" OFF)
tvm_option(USE_MIOPEN "Build with ROCM:MIOpen" OFF)
tvm_option(USE_ROCBLAS "Build with ROCM:RoCBLAS" OFF)
tvm_option(USE_SORT "Build with sort support" OFF)
tvm_option(USE_NNPACK "Build with nnpack support" OFF)
tvm_option(USE_RANDOM "Build with random support" OFF)
58
tvm_option(USE_ANTLR "Build with ANTLR for Relay parsing" OFF)
59 60

# include directories
61
include_directories(${CMAKE_INCLUDE_PATH})
62
include_directories("include")
63 64 65 66
include_directories(${DLPACK_PATH})
include_directories(${DMLC_PATH})
include_directories(${RANG_PATH})
include_directories(${COMPILER_RT_PATH})
67

68
# initial variables
69
set(TVM_LINKER_LIBS "")
70
set(TVM_RUNTIME_LINKER_LIBS ${CMAKE_DL_LIBS})
71
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
72

73
# Generic compilation options
74 75 76 77
if(MSVC)
  add_definitions(-DWIN32_LEAN_AND_MEAN)
  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  add_definitions(-D_SCL_SECURE_NO_WARNINGS)
78
  add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
79
  add_definitions(-DHalide_SHARED)
80 81
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
82 83 84 85 86 87 88 89 90 91
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj")
  if(USE_MSVC_MT)
    foreach(flag_var
        CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
        CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
      if(${flag_var} MATCHES "/MD")
        string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
      endif(${flag_var} MATCHES "/MD")
    endforeach(flag_var)
  endif()
92 93 94
else(MSVC)
  include(CheckCXXCompilerFlag)
  check_cxx_compiler_flag("-std=c++11"    SUPPORT_CXX11)
95
  if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
96
    message("Build in Debug mode")
97 98
    set(CMAKE_C_FLAGS "-O0 -g -Wall -fPIC ${CMAKE_C_FLAGS} -rdynamic")
    set(CMAKE_CXX_FLAGS "-O0 -g -Wall -fPIC -std=c++11 ${CMAKE_CXX_FLAGS} -rdynamic")
99
  else()
100 101 102 103 104 105 106
    set(CMAKE_C_FLAGS "-O2 -Wall -fPIC ${CMAKE_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -std=c++11 ${CMAKE_CXX_FLAGS}")
    if (HIDE_PRIVATE_SYMBOLS)
      message("Hide private symbols...")
      set(CMAKE_C_FLAGS "-fvisibility=hidden ${CMAKE_C_FLAGS}")
      set(CMAKE_CXX_FLAGS "-fvisibility=hidden ${CMAKE_CXX_FLAGS}")
    endif(HIDE_PRIVATE_SYMBOLS)
107
  endif ()
108 109 110 111
  if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND
      CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
    set(CMAKE_CXX_FLAGS "-faligned-new ${CMAKE_CXX_FLAGS}")
  endif()
112 113
endif(MSVC)

114
# add source group
115 116
FILE(GLOB_RECURSE GROUP_SOURCE "src/*.cc" "3rdparty/HalideIR/src/*.cpp" "nnvm/src/*.cc")
FILE(GLOB_RECURSE GROUP_INCLUDE "src/*.h" "include/*.h" "3rdparty/HalideIR/src/*.h"
abergeron committed
117
                                "nnvm/src/*.h" "nnvm/include/*.h")
118
assign_source_group("Source" ${GROUP_SOURCE})
119
assign_source_group("Include" ${GROUP_INCLUDE})
120

121
# Source file lists
122 123 124
file(GLOB COMPILER_SRCS
    src/api/*.cc
    src/arithmetic/*.cc
125
    src/autotvm/*.cc
126 127 128
    src/codegen/*.cc
    src/lang/*.cc
    src/pass/*.cc
129
    src/op/*.cc
130
    src/schedule/*.cc
abergeron committed
131 132
    )

133 134 135 136 137
file(GLOB_RECURSE RELAY_SRCS
    src/relay/*.cc
    )
list(APPEND COMPILER_SRCS ${RELAY_SRCS})

138 139
file(GLOB DATATYPE_SRCS src/codegen/datatype/*.cc)
list(APPEND COMPILER_SRCS ${DATATYPE_SRCS})
140

141 142 143 144 145
if(NOT MSVC)
  file(GLOB COMPILER_VERILOG_SRCS src/codegen/verilog/*.cc)
  list(APPEND COMPILER_SRCS ${COMPILER_VERILOG_SRCS})
endif()

abergeron committed
146 147 148 149 150 151 152 153
file(GLOB_RECURSE NNVM_COMPILER_SRCS
    nnvm/src/c_api/*.cc
    nnvm/src/core/*.cc
    nnvm/src/pass/*.cc
    nnvm/src/compiler/*.cc
    nnvm/src/top/*.cc
    )

154 155 156
file(GLOB TOPI_SRCS
    topi/src/*.cc
)
157 158 159 160 161
file(GLOB_RECURSE HALIDEIR_SRCS
  3rdparty/HalideIR/src/base/*.cpp
  3rdparty/HalideIR/src/ir/*.cpp
  3rdparty/HalideIR/src/tvm/*.cpp
)
162
list(APPEND COMPILER_SRCS ${HALIDEIR_SRCS})
163 164 165 166
file(GLOB RUNTIME_SRCS
  src/runtime/*.cc
  src/runtime/vm/*.cc
)
167

168 169 170 171
# Package runtime rules
if(NOT USE_RTTI)
  add_definitions(-DDMLC_ENABLE_RTTI=0)
endif()
172

173 174
list(APPEND RUNTIME_SRCS 3rdparty/bfloat16/bfloat16.cc)

175 176
if(USE_RPC)
  message(STATUS "Build with RPC support...")
177
  file(GLOB RUNTIME_RPC_SRCS src/runtime/rpc/*.cc)
178 179 180
  list(APPEND RUNTIME_SRCS ${RUNTIME_RPC_SRCS})
endif(USE_RPC)

181 182 183 184 185 186 187 188 189 190
file(GLOB STACKVM_RUNTIME_SRCS src/runtime/stackvm/*.cc)
file(GLOB STACKVM_CODEGEN_SRCS src/codegen/stackvm/*.cc)
list(APPEND COMPILER_SRCS ${STACKVM_CODEGEN_SRCS})
if(USE_STACKVM_RUNTIME)
  message(STATUS "Build with stackvm support in runtime...")
  list(APPEND RUNTIME_SRCS ${STACKVM_RUNTIME_SRCS})
else()
  list(APPEND COMPILER_SRCS ${STACKVM_RUNTIME_SRCS})
endif(USE_STACKVM_RUNTIME)

191 192
if(USE_GRAPH_RUNTIME)
  message(STATUS "Build with Graph runtime support...")
193
  file(GLOB RUNTIME_GRAPH_SRCS src/runtime/graph/*.cc)
194
  list(APPEND RUNTIME_SRCS ${RUNTIME_GRAPH_SRCS})
195

196
  if(USE_GRAPH_RUNTIME_DEBUG)
197 198 199
    message(STATUS "Build with Graph runtime debug support...")
    file(GLOB RUNTIME_GRAPH_DEBUG_SRCS src/runtime/graph/debug/*.cc)
    list(APPEND RUNTIME_SRCS ${RUNTIME_GRAPH_DEBUG_SRCS})
200 201 202 203
    set_source_files_properties(${RUNTIME_GRAPH_SRCS}
      PROPERTIES COMPILE_DEFINITIONS "TVM_GRAPH_RUNTIME_DEBUG")
  endif(USE_GRAPH_RUNTIME_DEBUG)
endif(USE_GRAPH_RUNTIME)
204

205
# Module rules
206
include(cmake/modules/VTA.cmake)
207 208 209 210 211 212
include(cmake/modules/CUDA.cmake)
include(cmake/modules/OpenCL.cmake)
include(cmake/modules/OpenGL.cmake)
include(cmake/modules/Vulkan.cmake)
include(cmake/modules/Metal.cmake)
include(cmake/modules/ROCM.cmake)
nhynes committed
213
include(cmake/modules/SGX.cmake)
214
include(cmake/modules/LLVM.cmake)
215
include(cmake/modules/ANTLR.cmake)
216 217 218 219
include(cmake/modules/contrib/BLAS.cmake)
include(cmake/modules/contrib/Random.cmake)
include(cmake/modules/contrib/Sort.cmake)
include(cmake/modules/contrib/NNPack.cmake)
220
include(cmake/modules/contrib/HybridDump.cmake)
221

222
add_library(tvm SHARED ${COMPILER_SRCS} ${RUNTIME_SRCS})
223
add_library(tvm_topi SHARED ${TOPI_SRCS})
224
add_library(tvm_runtime SHARED ${RUNTIME_SRCS})
225 226 227 228

if(USE_RELAY_DEBUG)
  message(STATUS "Building Relay in debug mode...")
  set_target_properties(tvm PROPERTIES COMPILE_DEFINITIONS "USE_RELAY_DEBUG")
229
else()
230 231 232
  set_target_properties(tvm PROPERTIES COMPILE_DEFINITIONS "NDEBUG")
endif(USE_RELAY_DEBUG)

nhynes committed
233
if(NOT USE_SGX STREQUAL "OFF")
234 235 236
  add_dependencies(tvm sgx_edl)
  add_dependencies(tvm_runtime sgx_edl tvm_t)
  install(TARGETS tvm_t ARCHIVE DESTINATION lib${LIB_SUFFIX})
nhynes committed
237
endif()
abergeron committed
238
add_library(nnvm_compiler SHARED ${NNVM_COMPILER_SRCS})
239

240
target_link_libraries(tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS})
241
target_link_libraries(tvm_topi tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS})
abergeron committed
242 243 244
target_link_libraries(tvm_runtime ${TVM_RUNTIME_LINKER_LIBS})
target_link_libraries(nnvm_compiler tvm)

245 246 247
# Related headers
target_include_directories(
  tvm
248
  PUBLIC "3rdparty/HalideIR/src"
249 250 251 252 253 254 255 256 257
  PUBLIC "topi/include")
target_include_directories(
  tvm_topi
  PUBLIC "topi/include")
target_include_directories(
  nnvm_compiler
  PUBLIC "nnvm/include"
  PUBLIC "topi/include")

258 259 260
# Tests
set(TEST_EXECS "")
file(GLOB TEST_SRCS tests/cpp/*.cc)
261
find_library(GTEST_LIB gtest "$ENV{GTEST_LIB}")
262 263 264 265 266 267 268 269

if(GTEST_LIB)
  foreach(__srcpath ${TEST_SRCS})
    get_filename_component(__srcname ${__srcpath} NAME)
    string(REPLACE ".cc" "" __execname ${__srcname})
    add_executable(${__execname} ${__srcpath})
    list(APPEND TEST_EXECS ${__execname})
    target_link_libraries(${__execname}
270
      tvm ${GTEST_LIB} pthread dl)
271 272 273 274 275
    set_target_properties(${__execname} PROPERTIES EXCLUDE_FROM_ALL 1)
    set_target_properties(${__execname} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
  endforeach()
  add_custom_target(cpptest DEPENDS ${TEST_EXECS})
endif()
abergeron committed
276

277 278 279
# Custom targets
add_custom_target(runtime DEPENDS tvm_runtime)

280 281 282
# Installation rules
install(TARGETS tvm DESTINATION lib${LIB_SUFFIX})
install(TARGETS tvm_topi DESTINATION lib${LIB_SUFFIX})
283
install(TARGETS tvm_runtime DESTINATION lib${LIB_SUFFIX})
284
install(TARGETS nnvm_compiler DESTINATION lib${LIB_SUFFIX})
abergeron committed
285

286 287 288 289 290 291
if (INSTALL_DEV)
  install(
    DIRECTORY "include/." DESTINATION "include"
    FILES_MATCHING
    PATTERN "*.h"
  )
292 293 294 295 296 297
  install(
    DIRECTORY "topi/include/." DESTINATION "include"
    FILES_MATCHING
    PATTERN "*.h"
  )
  install(
298
    DIRECTORY "3rdparty/HalideIR/src/." DESTINATION "include/HalideIR"
299 300 301 302
    FILES_MATCHING
    PATTERN "*.h"
  )
  install(
303
    DIRECTORY "3rdparty/dlpack/include/." DESTINATION "include"
304 305
    FILES_MATCHING
    PATTERN "*.h"
abergeron committed
306 307 308 309 310 311
    )
  install(
    DIRECTORY "nnvm/include/." DESTINATION "include"
    FILES_MATCHING
    PATTERN "*.h"
    )
312 313 314 315 316
else(INSTALL_DEV)
  install(
    DIRECTORY "include/tvm/runtime/." DESTINATION "include/tvm/runtime"
    FILES_MATCHING
    PATTERN "*.h"
abergeron committed
317
    )
318
endif(INSTALL_DEV)
319

320
# More target definitions
321 322 323 324 325
if(MSVC)
  target_compile_definitions(tvm PRIVATE -DHalide_EXPORTS)
  target_compile_definitions(tvm_runtime PRIVATE -DHalide_EXPORTS)
  target_compile_definitions(tvm PRIVATE -DTVM_EXPORTS)
  target_compile_definitions(tvm_runtime PRIVATE -DTVM_EXPORTS)
abergeron committed
326
  target_compile_definitions(nnvm_compiler PRIVATE -DNNVM_EXPORTS)
327
endif()