forked from mmperf/mmperf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
201 lines (187 loc) · 6.59 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
project(mmperf C CXX)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/")
if(NOT DEFINED ${MMPERF_SOURCE})
set(MMPERF_SOURCE ${CMAKE_CURRENT_SOURCE_DIR})
endif()
include(common)
include(ExternalProject)
if(NOT DEFINED MLIR_SOURCE)
set(MLIR_SOURCE ${MMPERF_SOURCE}/external/llvm-project/llvm)
endif()
if(NOT DEFINED MLIR_BUILD)
set(MLIR_BUILD ${CMAKE_BINARY_DIR}/mlir)
endif()
set(RUY_SOURCE ${MMPERF_SOURCE}/external/ruy)
# Build cpuinfo
set(CPUINFO_SOURCE ${MMPERF_SOURCE}/external/cpuinfo)
set(CPUINFO_BUILD_BENCHMARKS OFF)
set(CPUINFO_BUILD_MOCK_TESTS OFF)
set(CPUINFO_BUILD_UNIT_TESTS OFF)
set(CPUINFO_INSTALL ${CMAKE_BINARY_DIR}/cpuinfo-install)
ExternalProject_Add(cpuinfo
PREFIX ${CMAKE_BINARY_DIR}/cpuinfo
SOURCE_DIR ${CPUINFO_SOURCE}
BINARY_DIR ${CPUINFO_BUILD}
INSTALL_DIR ${CPUINFO_INSTALL}
CMAKE_ARGS
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE:STRING=Release
-DCPUINFO_BUILD_BENCHMARKS=OFF
-DCPUINFO_BUILD_MOCK_TESTS=OFF
-DCPUINFO_BUILD_UNIT_TESTS=OFF
)
# Build flatbuffers
set(FLATBUFFERS_SOURCE ${MMPERF_SOURCE}/external/flatbuffers)
set(FLATBUFFERS_INSTALL ${CMAKE_BINARY_DIR}/flatbuffers-install)
ExternalProject_Add(flatbuffers
PREFIX ${CMAKE_BINARY_DIR}/flatbuffers
SOURCE_DIR ${FLATBUFFERS_SOURCE}
BINARY_DIR ${FLATBUFFERS_BUILD}
INSTALL_DIR ${FLATBUFFERS_INSTALL}
CMAKE_ARGS
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE:STRING=Release
)
set(MATMUL_DEPS flatbuffers)
# Build MLIR
if(${USE_MLIR} OR ${USE_MLIR_CUDA} OR ${USE_IREE_LLVM_SANDBOX})
find_package(Git REQUIRED)
set(MLIR_INSTALL ${CMAKE_BINARY_DIR}/mlir-install)
set(MLIR_LIB ${MLIR_INSTALL}/cmake/lib/mlir)
set(MLIR_ENABLE_CUDA_RUNNER OFF)
set(MLIR_ENABLE_BINDINGS_PYTHON OFF)
set(LLVM_EXTERNAL_PROJECTS "")
set(LLVM_SANDBOX_DIR ${MMPERF_SOURCE}/external/iree-llvm-sandbox)
if(${USE_MLIR_CUDA} OR ${USE_IREE_LLVM_SANDBOX})
set(MLIR_ENABLE_CUDA_RUNNER ON)
endif()
if(${USE_IREE_LLVM_SANDBOX})
set(MLIR_ENABLE_BINDINGS_PYTHON ON)
set(LLVM_EXTERNAL_PROJECTS iree_llvm_sandbox)
endif()
ExternalProject_Add(mlir
PREFIX ${CMAKE_BINARY_DIR}/mlir
SOURCE_DIR ${MLIR_SOURCE}
BINARY_DIR ${MLIR_BUILD}
INSTALL_DIR ${MLIR_INSTALL}
CMAKE_ARGS
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CUDA_COMPILER=${CMAKE_CUDA_COMPILER}
-DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF
-DLLVM_LINK_LLVM_DYLIB:BOOL=OFF
-DLLVM_INSTALL_UTILS:BOOL=ON
-DLLVM_TARGETS_TO_BUILD:STRING=X86$<SEMICOLON>AArch64$<SEMICOLON>NVPTX$<SEMICOLON>AMDGPU
-DLLVM_ENABLE_PROJECTS:STRING=mlir
-DLLVM_INCLUDE_TOOLS:BOOL=ON
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE:STRING=Release
-DLLVM_ENABLE_ASSERTIONS:BOOL=ON
-DLLVM_ENABLE_RTTI:BOOL=ON
-DMLIR_ENABLE_CUDA_RUNNER:BOOL=${MLIR_ENABLE_CUDA_RUNNER}
-DLLVM_EXTERNAL_PROJECTS=${LLVM_EXTERNAL_PROJECTS}
-DLLVM_EXTERNAL_IREE_LLVM_SANDBOX_SOURCE_DIR=${LLVM_SANDBOX_DIR}
-DMLIR_ENABLE_BINDINGS_PYTHON=${MLIR_ENABLE_BINDINGS_PYTHON}
-DPython3_EXECUTABLE=$(which python3)
)
list(APPEND MATMUL_DEPS mlir)
endif()
# Build Halide
if(${USE_HALIDE})
find_package(LLVM REQUIRED)
set(HALIDE_SOURCE ${MMPERF_SOURCE}/external/Halide)
set(HALIDE_BUILD ${CMAKE_BINARY_DIR}/halide)
set(HALIDE_INSTALL ${CMAKE_BINARY_DIR}/halide-install)
ExternalProject_Add(halide
PREFIX ${CMAKE_BINARY_DIR}/halide
SOURCE_DIR ${HALIDE_SOURCE}
BINARY_DIR ${HALIDE_BUILD}
INSTALL_DIR ${HALIDE_INSTALL}
CMAKE_ARGS
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_BUILD_TYPE:STRING=Release
-DTARGET_WEBASSEMBLY:BOOL=OFF
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DWITH_PYTHON_BINDINGS=OFF
)
list(APPEND MATMUL_DEPS halide)
endif()
# Build TVM
if(${USE_TVM})
set(TVM_SOURCE ${MMPERF_SOURCE}/external/tvm)
set(TVM_BUILD ${CMAKE_BINARY_DIR}/tvm)
set(TVM_INSTALL ${CMAKE_BINARY_DIR}/tvm-install)
option(TVM_ENABLE_CUDA "Enable CUDA in TVM" OFF)
option(TVM_ENABLE_ROCM "Enable ROCM in TVM" OFF)
option(TVM_ENABLE_METAL "Enable METAL in TVM" OFF)
ExternalProject_Add(tvm
PREFIX ${CMAKE_BINARY_DIR}/tvm
SOURCE_DIR ${TVM_SOURCE}
BINARY_DIR ${TVM_BUILD}
INSTALL_DIR ${TVM_INSTALL}
CMAKE_ARGS
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DUSE_CUDA=${TVM_ENABLE_CUDA}
-DUSE_ROCM=${TVM_ENABLE_ROCM}
-DUSE_METAL=${TVM_ENABLE_METAL}
-DUSE_RPC:BOOL=ON
-DUSE_THREADS:BOOL=OFF
-DUSE_LLVM:BOOL=ON
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
)
list(APPEND MATMUL_DEPS tvm)
endif()
set(MATMUL_CMAKE_ARGS "")
foreach(var IN LISTS VARS_TO_COPY)
list(APPEND MATMUL_CMAKE_ARGS -D${var}=${${var}})
endforeach()
# Build matmul-iree
if(${USE_IREE} STREQUAL "ON")
set(IREE_SOURCE ${MMPERF_SOURCE}/external/iree)
ExternalProject_Add(matmul-iree
PREFIX ${CMAKE_BINARY_DIR}/matmul-iree
SOURCE_DIR ${MMPERF_SOURCE}/matmul-iree
BINARY_DIR ${CMAKE_BINARY_DIR}/matmul-iree
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping install step."
CMAKE_ARGS
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON
-DIREE_SOURCE=${IREE_SOURCE}
${MATMUL_CMAKE_ARGS}
)
endif()
# Build matmul for compiling and running various compiled matmuls
ExternalProject_Add(matmul
DEPENDS ${MATMUL_DEPS}
PREFIX ${CMAKE_BINARY_DIR}/matmul
SOURCE_DIR ${MMPERF_SOURCE}/matmul
BINARY_DIR ${CMAKE_BINARY_DIR}/matmul
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping install step."
CMAKE_ARGS
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DPREBUILT_LLVM_PATH=${PREBUILT_LLVM_PATH} # switch if want to compile with a prebuilt llvm
-DMLIR_DIR=${MLIR_INSTALL}/lib/cmake/mlir
-DMLIR_BUILD=${MLIR_BUILD}
-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo
-DMKL_DIR=${MKL_DIR}
-DHALIDE_DIR=${HALIDE_INSTALL}
-DBLASFEO_DIR=${BLASFEO_DIR}
-DBLIS_DIR=${BLIS_DIR}
-DRUY_SOURCE=${RUY_SOURCE}
-DTVM_LIB_DIR=${TVM_LIB_DIR}
-DTVM_ENABLE_CUDA=${TVM_ENABLE_CUDA}
-DTVM_ENABLE_ROCM=${TVM_ENABLE_ROCM}
-DTVM_ENABLE_METAL=${TVM_ENABLE_METAL}
-DSANDBOX_TILE_FILE=${SANDBOX_TILE_FILE}
${MATMUL_CMAKE_ARGS}
)