"torchvision/vscode:/vscode.git/clone" did not exist on "7a4845a99f845d4e2fc3ceb5b6cdf7fed29dc662"
CMakeLists.txt 11.8 KB
Newer Older
1
cmake_minimum_required(VERSION 3.5)
Minjie Wang's avatar
Minjie Wang committed
2
3
4
5
########################################
# Borrowed and adapted from TVM project
########################################
project(dgl C CXX)
6
7
8
9
10
11
message(STATUS "Start configuring project ${PROJECT_NAME}")

# cmake utils
include(cmake/util/Util.cmake)
include(cmake/util/MshadowUtil.cmake)
include(cmake/util/FindCUDA.cmake)
Minjie Wang's avatar
Minjie Wang committed
12
13
14
15
16
17
18
19
20

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()
endif()

21
22
23
24
25
# 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.
dgl_option(USE_CUDA "Build with CUDA" OFF)
26
dgl_option(USE_NCCL "Build with NCCL support" OFF)
27
dgl_option(USE_SYSTEM_NCCL "Build using system's NCCL library" OFF)
28
dgl_option(USE_OPENMP "Build with OpenMP" ON)
29
dgl_option(USE_AVX "Build with AVX optimization" ON)
30
dgl_option(USE_LIBXSMM "Build with LIBXSMM library optimization" ON)
31
dgl_option(USE_FP16 "Build with fp16 support to enable mixed precision training" OFF)
Zhi Lin's avatar
Zhi Lin committed
32
dgl_option(USE_TVM "Build with TVM kernels" OFF)
33
dgl_option(BUILD_CPP_TEST "Build cpp unittest executables" OFF)
34
dgl_option(LIBCXX_ENABLE_PARALLEL_ALGORITHMS "Enable the parallel algorithms library. This requires the PSTL to be available." OFF)
35
36
dgl_option(USE_S3 "Build with S3 support" OFF)
dgl_option(USE_HDFS "Build with HDFS support" OFF) # Set env HADOOP_HDFS_HOME if needed
37
dgl_option(USE_EPOLL "Build with epoll for socket communicator" OFF)
38

VoVAllen's avatar
VoVAllen committed
39
40
# Set debug compile option for gdb, only happens when -DCMAKE_BUILD_TYPE=DEBUG
if (NOT MSVC)
41
  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -O0 -g3 -ggdb")
VoVAllen's avatar
VoVAllen committed
42
endif(NOT MSVC)
43
44
45

if(USE_CUDA)
  message(STATUS "Build with CUDA support")
46
  project(dgl C CXX)
47
  include(cmake/modules/CUDA.cmake)
48
49
50
51
52
53
54
55
  if ((CUDA_VERSION_MAJOR LESS 11) OR
      ((CUDA_VERSION_MAJOR EQUAL 11) AND (CUDA_VERSION_MINOR EQUAL 0)))
    # For cuda<11, use external CUB/Thrust library because CUB is not part of CUDA.
    # For cuda==11.0, use external CUB/Thrust library because there is a bug in the
    #   official CUB library which causes invalid device ordinal error for DGL. The bug
    #   is fixed by https://github.com/NVIDIA/cub/commit/9143e47e048641aa0e6ddfd645bcd54ff1059939
    #   in 11.1.
    message(STATUS "Detected CUDA of version ${CUDA_VERSION}. Use external CUB/Thrust library.")
56
57
    cuda_include_directories(BEFORE "${CMAKE_SOURCE_DIR}/third_party/thrust")
    cuda_include_directories(BEFORE "${CMAKE_SOURCE_DIR}/third_party/cub")
58
  endif()
59
60
endif(USE_CUDA)

Minjie Wang's avatar
Minjie Wang committed
61
# initial variables
62
63
64
65
if(NOT MSVC)
set(DGL_LINKER_LIBS "dl")
endif(NOT MSVC)

66
if(MSVC OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
Minjie Wang's avatar
Minjie Wang committed
67
set(DGL_RUNTIME_LINKER_LIBS "")
68
69
70
else(MSVC OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(DGL_RUNTIME_LINKER_LIBS "rt")
endif(MSVC OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
Minjie Wang's avatar
Minjie Wang committed
71
72
73
74
75
76

# Generic compilation options
if(MSVC)
  add_definitions(-DWIN32_LEAN_AND_MEAN)
  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  add_definitions(-D_SCL_SECURE_NO_WARNINGS)
77
  add_definitions(-DNOMINMAX)
VoVAllen's avatar
VoVAllen committed
78
  set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS 1)
Minjie Wang's avatar
Minjie Wang committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
  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()
else(MSVC)
  include(CheckCXXCompilerFlag)
93
  check_cxx_compiler_flag("-std=c++11"    SUPPORT_CXX11)
94
  set(CMAKE_C_FLAGS "-O2 -Wall -fPIC ${CMAKE_C_FLAGS}")
95
96
  # We still use c++11 flag in CPU build because gcc5.4 (our default compiler) is
  # not fully compatible with c++14 feature.
97
  set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -std=c++11 ${CMAKE_CXX_FLAGS}")
98
99
100
  if(NOT APPLE)
    set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--warn-common ${CMAKE_SHARED_LINKER_FLAGS}")
  endif(NOT APPLE)
101
endif(MSVC)
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
102

103
if(USE_OPENMP)
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
104
105
106
107
108
  include(FindOpenMP)
  if(OPENMP_FOUND)
    set(CMAKE_C_FLAGS "${OpenMP_C_FLAGS} ${CMAKE_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
  endif(OPENMP_FOUND)
109
  message(STATUS "Build with OpenMP.")
110
111
endif(USE_OPENMP)

112
if(USE_AVX)
113
114
115
116
117
118
119
120
121
  if(USE_LIBXSMM)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_AVX -DUSE_LIBXSMM -DDGL_CPU_LLC_SIZE=40000000")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_AVX -DUSE_LIBXSMM -DDGL_CPU_LLC_SIZE=40000000")
    message(STATUS "Build with LIBXSMM optimization.")
  else(USE_LIBXSMM)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_AVX")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_AVX")
    message(STATUS "Build with AVX optimization.")
  endif(USE_LIBXSMM)
122
123
endif(USE_AVX)

124
125
126
127
128
129
130
131
if (USE_EPOLL)
  check_include_file("sys/epoll.h" USE_EPOLL)
  if (USE_EPOLL)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_EPOLL")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_EPOLL")
  endif()
endif ()

132
133
134
135
136
137
138
# Build with fp16 to support mixed precision training.
if(USE_FP16)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_FP16")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_FP16")
  message(STATUS "Build with fp16 to support mixed precision training")
endif(USE_FP16)

139
# To compile METIS correct for DGL.
140
141
142
143
144
145
146
if(MSVC)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DIDXTYPEWIDTH=64 /DREALTYPEWIDTH=32")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DIDXTYPEWIDTH=64 /DREALTYPEWIDTH=32")
else(MSVC)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIDXTYPEWIDTH=64 -DREALTYPEWIDTH=32")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIDXTYPEWIDTH=64 -DREALTYPEWIDTH=32")
endif(MSVC)
147

148
149
# configure minigun
add_definitions(-DENABLE_PARTIAL_FRONTIER=0)  # disable minigun partial frontier compile
Minjie Wang's avatar
Minjie Wang committed
150
# Source file lists
151
152
file(GLOB DGL_SRC
  src/*.cc
153
154
  src/array/*.cc
  src/array/cpu/*.cc
155
156
  src/random/*.cc
  src/random/cpu/*.cc
157
  src/runtime/*.cc
158
159
  src/geometry/*.cc
  src/geometry/cpu/*.cc
160
  src/dataloading/*.cc
161
  src/partition/*.cc
162
163
164
)

file(GLOB_RECURSE DGL_SRC_1
165
  src/api/*.cc
166
167
  src/graph/*.cc
  src/scheduler/*.cc
168
  src/rpc/*.cc
169
)
Minjie Wang's avatar
Minjie Wang committed
170

171
list(APPEND DGL_SRC ${DGL_SRC_1})
Minjie Wang's avatar
Minjie Wang committed
172

173
# Configure cuda
174
175
176
if(USE_CUDA)
  dgl_config_cuda(DGL_CUDA_SRC)
  list(APPEND DGL_SRC ${DGL_CUDA_SRC})
177
178
179
180
181
182
183
184
185
186
  if(USE_NCCL)
    add_definitions(-DDGL_USE_NCCL)
    if (USE_SYSTEM_NCCL)
      include(cmake/util/FindNccl.cmake)
      include_directories(${NCCL_INCLUDE_DIR})
    else()
      include(cmake/modules/NCCL.cmake)
      cuda_include_directories(BEFORE ${NCCL_INCLUDE_DIR})
    endif()
  endif(USE_NCCL)
187

188
  list(APPEND DGL_LINKER_LIBS ${NCCL_LIBRARY})
189
endif(USE_CUDA)
Minjie Wang's avatar
Minjie Wang committed
190

191
192
if(USE_CUDA)
  cuda_add_library(dgl SHARED ${DGL_SRC})
193
  if (USE_NCCL AND NOT USE_SYSTEM_NCCL)
194
195
    add_dependencies(dgl nccl_external)
  endif()
196
197
198
else(USE_CUDA)
  add_library(dgl SHARED ${DGL_SRC})
endif(USE_CUDA)
Minjie Wang's avatar
Minjie Wang committed
199

Zhi Lin's avatar
Zhi Lin committed
200
201
202
203
204
205
206
207
208
209
# include directories
target_include_directories(dgl PRIVATE "include")
target_include_directories(dgl PRIVATE "third_party/dlpack/include")
target_include_directories(dgl PRIVATE "third_party/dmlc-core/include")
target_include_directories(dgl PRIVATE "third_party/minigun/minigun")
target_include_directories(dgl PRIVATE "third_party/minigun/third_party/moderngpu/src")
target_include_directories(dgl PRIVATE "third_party/phmap/")
target_include_directories(dgl PRIVATE "third_party/xbyak/")
target_include_directories(dgl PRIVATE "third_party/METIS/include/")
target_include_directories(dgl PRIVATE "tensoradapter/include")
210
target_include_directories(dgl PRIVATE "third_party/nanoflann/include")
211
target_include_directories(dgl PRIVATE "third_party/libxsmm/include")
Zhi Lin's avatar
Zhi Lin committed
212

VoVAllen's avatar
VoVAllen committed
213
# For serialization
214
215
216
if (USE_HDFS)
  option(DMLC_HDFS_SHARED "dgl has to build with dynamic hdfs library" ON)
endif()
VoVAllen's avatar
VoVAllen committed
217
218
219
220
add_subdirectory("third_party/dmlc-core")
list(APPEND DGL_LINKER_LIBS dmlc)
set(GOOGLE_TEST 0) # Turn off dmlc-core test

221
# Compile METIS
222
223
224
225
if(NOT MSVC)
  set(GKLIB_PATH "${CMAKE_SOURCE_DIR}/third_party/METIS/GKlib")
  include(${GKLIB_PATH}/GKlibSystem.cmake)
  include_directories(${GKLIB_PATH})
Zhi Lin's avatar
Zhi Lin committed
226
  include_directories("third_party/METIS/include/")
227
228
229
  add_subdirectory("third_party/METIS/libmetis/")
  list(APPEND DGL_LINKER_LIBS metis)
endif(NOT MSVC)
230

231
232
233
234
235
236
237
238
239
# Compile LIBXSMM
if((NOT MSVC) AND USE_LIBXSMM)
  add_custom_target(libxsmm COMMAND make realclean COMMAND make -j BLAS=0
                     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/third_party/libxsmm
                     )
  add_dependencies(dgl libxsmm)
  list(APPEND DGL_LINKER_LIBS -L${CMAKE_SOURCE_DIR}/third_party/libxsmm/lib/ xsmm)
endif((NOT MSVC) AND USE_LIBXSMM)

Zhi Lin's avatar
Zhi Lin committed
240
241
242
243
244
245
246
247
248
249
# Compile TVM Runtime and Featgraph
# (NOTE) We compile a dynamic library called featgraph_runtime, which the DGL library links to.
# Kernels are packed in a separate dynamic library called featgraph_kernels, which DGL
# will load during runtime.
if(USE_TVM)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_TVM")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_TVM")
  target_include_directories(dgl PRIVATE "featgraph/include")
  add_subdirectory("featgraph/")
  list(APPEND DGL_LINKER_LIBS featgraph_runtime)
250
  message(STATUS "Build with TVM runtime and featgraph kernels.")
Zhi Lin's avatar
Zhi Lin committed
251
252
endif(USE_TVM)

253
254
255
256
# support PARALLEL_ALGORITHMS
if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS)
  add_definitions(-DPARALLEL_ALGORITHMS)
endif(LIBCXX_ENABLE_PARALLEL_ALGORITHMS)
257

Minjie Wang's avatar
Minjie Wang committed
258
target_link_libraries(dgl ${DGL_LINKER_LIBS} ${DGL_RUNTIME_LINKER_LIBS})
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
if(MSVC)
  add_custom_command(
    TARGET dgl POST_BUILD COMMAND
    cmd.exe /c "COPY /Y Release\\dgl.dll .")
endif(MSVC)

# Tensor adapter libraries
# Linking against LibTorch involves linking against a bunch of other libraries
# returned by PyTorch's CMake (e.g. C10 or NVTools).  Because CMake caches
# the found libraries in find_library(), often times CMake will look into the libraries
# of the wrong version when I build everything in the same CMake process.  As
# a result, I (BarclayII) am launching an individual CMake build for every PyTorch version.
if(BUILD_TORCH)
  file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR} BINDIR)
  file(TO_NATIVE_PATH ${CMAKE_COMMAND} CMAKE_CMD)
  if(MSVC)
    file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/tensoradapter/pytorch/build.bat BUILD_SCRIPT)
    add_custom_target(
      tensoradapter_pytorch
      ${CMAKE_COMMAND} -E env
      CMAKE_COMMAND=${CMAKE_CMD}
      CUDA_TOOLKIT_ROOT_DIR=${CUDA_TOOLKIT_ROOT_DIR}
      BINDIR=${BINDIR}
      cmd /e:on /c ${BUILD_SCRIPT} ${TORCH_PYTHON_INTERPS}
      DEPENDS ${BUILD_SCRIPT}
      WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tensoradapter/pytorch)
  else(MSVC)
    file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/tensoradapter/pytorch/build.sh BUILD_SCRIPT)
    add_custom_target(
      tensoradapter_pytorch
      ${CMAKE_COMMAND} -E env
      CMAKE_COMMAND=${CMAKE_CMD}
      CUDA_TOOLKIT_ROOT_DIR=${CUDA_TOOLKIT_ROOT_DIR}
      BINDIR=${CMAKE_CURRENT_BINARY_DIR}
      bash ${BUILD_SCRIPT} ${TORCH_PYTHON_INTERPS}
      DEPENDS ${BUILD_SCRIPT}
      WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tensoradapter/pytorch)
  endif(MSVC)
  add_dependencies(dgl tensoradapter_pytorch)
endif(BUILD_TORCH)
Minjie Wang's avatar
Minjie Wang committed
299
300
301

# Installation rules
install(TARGETS dgl DESTINATION lib${LIB_SUFFIX})
VoVAllen's avatar
VoVAllen committed
302
303
304

# Testing
if(BUILD_CPP_TEST)
305
  message(STATUS "Build with unittest")
VoVAllen's avatar
VoVAllen committed
306
307
308
  add_subdirectory(./third_party/googletest)
  enable_testing()
  include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
Zhi Lin's avatar
Zhi Lin committed
309
310
311
312
  include_directories("include")
  include_directories("third_party/dlpack/include")
  include_directories("third_party/xbyak")
  include_directories("third_party/dmlc-core/include")
313
  include_directories("third_party/phmap")
314
  include_directories("third_party/libxsmm/include")
VoVAllen's avatar
VoVAllen committed
315
316
317
318
319
320
  file(GLOB_RECURSE TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/tests/cpp/*.cc)
  add_executable(runUnitTests ${TEST_SRC_FILES})
  target_link_libraries(runUnitTests gtest gtest_main)
  target_link_libraries(runUnitTests dgl)
  add_test(UnitTests runUnitTests)
endif(BUILD_CPP_TEST)