1
- cmake_minimum_required (VERSION 3.6 )
1
+ cmake_minimum_required (VERSION 3.20 )
2
2
3
+ # Introduced in cmake 3.20
4
+ # https://cmake.org/cmake/help/latest/policy/CMP0116.html
3
5
cmake_policy (SET CMP0116 OLD )
4
6
5
7
include (ExternalProject )
@@ -10,6 +12,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
10
12
11
13
project (triton )
12
14
include (CTest )
15
+
13
16
if (NOT WIN32 )
14
17
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
15
18
endif ()
@@ -19,7 +22,7 @@ option(TRITON_BUILD_TUTORIALS "Build C++ Triton tutorials" ON)
19
22
option (TRITON_BUILD_PYTHON_MODULE "Build Python Triton bindings" OFF )
20
23
21
24
# Ensure Python3 vars are set correctly
22
- # used conditionally in this file and by lit tests
25
+ # used conditionally in this file and by lit tests
23
26
24
27
# Customized release build type with assertions: TritonRelBuildWithAsserts
25
28
set (CMAKE_C_FLAGS_TRITONRELBUILDWITHASSERTS "-O2 -g" )
@@ -32,7 +35,7 @@ if(NOT CMAKE_BUILD_TYPE)
32
35
endif ()
33
36
34
37
if (NOT WIN32 )
35
- find_library (TERMINFO_LIBRARY tinfo )
38
+ find_library (TERMINFO_LIBRARY tinfo )
36
39
endif ()
37
40
38
41
# Compiler flags
@@ -42,22 +45,21 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
42
45
include_directories (${PYBIND11_INCLUDE_DIR} )
43
46
44
47
if (WIN32 )
45
- SET (BUILD_SHARED_LIBS OFF )
46
- find_package (dlfcn-win32 REQUIRED )
47
- set (CMAKE_DL_LIBS dlfcn-win32::dl )
48
+ SET (BUILD_SHARED_LIBS OFF )
49
+ find_package (dlfcn-win32 REQUIRED )
50
+ set (CMAKE_DL_LIBS dlfcn-win32::dl )
48
51
endif ()
49
52
50
53
set (CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -D__STDC_FORMAT_MACROS -fPIC -std=gnu++17 -fvisibility=hidden -fvisibility-inlines-hidden" )
54
+
51
55
if (APPLE )
52
56
set (CMAKE_OSX_DEPLOYMENT_TARGET 11.6 )
53
57
endif ()
54
58
55
-
56
-
57
- ##########
59
+ # #########
58
60
# LLVM
59
- ##########
60
- if (NOT MLIR_DIR )
61
+ # #########
62
+ if (NOT MLIR_DIR )
61
63
if (NOT LLVM_LIBRARY_DIR )
62
64
if (WIN32 )
63
65
find_package (LLVM 13 REQUIRED COMPONENTS nvptx amdgpu )
@@ -73,12 +75,16 @@ if (NOT MLIR_DIR)
73
75
else ()
74
76
find_package (LLVM 11 REQUIRED COMPONENTS "nvptx;amdgpu" )
75
77
endif ()
78
+
76
79
message (STATUS "Found LLVM ${LLVM_PACKAGE_VERSION} " )
80
+
77
81
# FindLLVM outputs LLVM_LIBRARY_DIRS but we expect LLVM_LIBRARY_DIR here
78
82
set (LLVM_LIBRARY_DIR ${LLVM_LIBRARY_DIRS} )
83
+
79
84
if (APPLE )
80
85
set (CMAKE_OSX_DEPLOYMENT_TARGET "10.14" )
81
86
endif ()
87
+
82
88
# sometimes we don't want to use llvm-config, since it may have been downloaded for some specific linux distros
83
89
else ()
84
90
set (LLVM_LDFLAGS "-L${LLVM_LIBRARY_DIR} " )
@@ -138,37 +144,38 @@ if (NOT MLIR_DIR)
138
144
libLLVMAnalysis.a
139
145
)
140
146
endif ()
141
- set (MLIR_DIR ${LLVM_LIBRARY_DIR} /cmake/mlir )
147
+
148
+ set (MLIR_DIR ${LLVM_LIBRARY_DIR} /cmake/mlir )
142
149
endif ()
143
150
144
151
# Python module
145
152
if (TRITON_BUILD_PYTHON_MODULE )
146
- message (STATUS "Adding Python module" )
147
- set (PYTHON_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR} /python/src )
148
- set (PYTHON_SRC ${PYTHON_SRC_PATH} /main.cc ${PYTHON_SRC_PATH} /triton.cc )
149
- include_directories ("." ${PYTHON_SRC_PATH} )
150
- if (PYTHON_INCLUDE_DIRS )
151
- include_directories (${PYTHON_INCLUDE_DIRS} )
152
- else ()
153
- find_package (Python3 REQUIRED COMPONENTS Development Interpreter )
154
- include_directories (${Python3_INCLUDE_DIRS} )
155
- link_directories (${Python3_LIBRARY_DIRS} )
156
- link_libraries (${Python3_LIBRARIES} )
157
- add_link_options (${Python3_LINK_OPTIONS} )
158
- endif ()
153
+ message (STATUS "Adding Python module" )
154
+ set (PYTHON_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR} /python/src )
155
+ set (PYTHON_SRC ${PYTHON_SRC_PATH} /main.cc ${PYTHON_SRC_PATH} /triton.cc )
156
+ include_directories ("." ${PYTHON_SRC_PATH} )
157
+
158
+ if (PYTHON_INCLUDE_DIRS )
159
+ include_directories (${PYTHON_INCLUDE_DIRS} )
160
+ else ()
161
+ find_package (Python3 REQUIRED COMPONENTS Development Interpreter )
162
+ include_directories (${Python3_INCLUDE_DIRS} )
163
+ link_directories (${Python3_LIBRARY_DIRS} )
164
+ link_libraries (${Python3_LIBRARIES} )
165
+ add_link_options (${Python3_LINK_OPTIONS} )
166
+ endif ()
159
167
endif ()
160
168
161
169
# # Triton
162
170
# file(GLOB_RECURSE LIBTRITON_SRC lib/*.cc)
163
171
# if (WIN32 AND TRITON_BUILD_PYTHON_MODULE)
164
- # Python3_add_library(triton SHARED ${LIBTRITON_SRC} ${PYTHON_SRC})
165
- # set_target_properties(triton PROPERTIES SUFFIX ".pyd")
166
- # set_target_properties(triton PROPERTIES PREFIX "lib")
172
+ # Python3_add_library(triton SHARED ${LIBTRITON_SRC} ${PYTHON_SRC})
173
+ # set_target_properties(triton PROPERTIES SUFFIX ".pyd")
174
+ # set_target_properties(triton PROPERTIES PREFIX "lib")
167
175
# else()
168
- # add_library(triton SHARED ${LIBTRITON_SRC} ${PYTHON_SRC})
176
+ # add_library(triton SHARED ${LIBTRITON_SRC} ${PYTHON_SRC})
169
177
# endif()
170
178
171
-
172
179
# MLIR
173
180
find_package (MLIR REQUIRED CONFIG PATHS ${MLIR_DIR} )
174
181
@@ -186,14 +193,13 @@ include_directories(${MLIR_INCLUDE_DIRS})
186
193
include_directories (${LLVM_INCLUDE_DIRS} )
187
194
include_directories (${PROJECT_SOURCE_DIR} /include )
188
195
include_directories (${PROJECT_BINARY_DIR} /include ) # Tablegen'd files
189
- # link_directories(${LLVM_LIBRARY_DIR})
190
196
197
+ # link_directories(${LLVM_LIBRARY_DIR})
191
198
add_subdirectory (include )
192
199
add_subdirectory (lib )
193
200
add_subdirectory (bin )
194
201
195
202
# find_package(PythonLibs REQUIRED)
196
-
197
203
set (TRITON_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR} " )
198
204
set (TRITON_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR} " )
199
205
@@ -210,6 +216,7 @@ if(TRITON_BUILD_PYTHON_MODULE)
210
216
TritonPTX
211
217
${dialect_libs}
212
218
${conversion_libs}
219
+
213
220
# optimizations
214
221
MLIRPass
215
222
MLIRTransforms
@@ -221,6 +228,7 @@ if(TRITON_BUILD_PYTHON_MODULE)
221
228
MLIRNVVMToLLVMIRTranslation
222
229
MLIRIR
223
230
)
231
+
224
232
if (WIN32 )
225
233
target_link_libraries (triton PRIVATE ${LLVM_LIBRARIES} ${CMAKE_DL_LIBS}
226
234
${TRITON_LIBRARIES}
@@ -234,21 +242,23 @@ if(TRITON_BUILD_PYTHON_MODULE)
234
242
${TRITON_LIBRARIES}
235
243
)
236
244
endif ()
237
-
245
+
238
246
target_link_options (triton PRIVATE ${LLVM_LDFLAGS} )
239
247
endif ()
240
248
241
- if (UNIX AND NOT APPLE )
249
+ if (UNIX AND NOT APPLE )
242
250
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--exclude-libs,ALL" )
243
251
endif ()
244
252
245
253
if (TRITON_BUILD_PYTHON_MODULE AND NOT WIN32 )
246
- set (CMAKE_SHARED_LIBRARY_SUFFIX ".so" )
247
- # Check if the platform is MacOS
248
- if (APPLE )
249
- set (PYTHON_LDFLAGS "-undefined dynamic_lookup -flto" )
250
- endif ()
251
- target_link_libraries (triton ${CUTLASS_LIBRARIES} ${PYTHON_LDFLAGS} )
254
+ set (CMAKE_SHARED_LIBRARY_SUFFIX ".so" )
255
+
256
+ # Check if the platform is MacOS
257
+ if (APPLE )
258
+ set (PYTHON_LDFLAGS "-undefined dynamic_lookup -flto" )
259
+ endif ()
260
+
261
+ target_link_libraries (triton ${CUTLASS_LIBRARIES} ${PYTHON_LDFLAGS} )
252
262
endif ()
253
263
254
264
add_subdirectory (test )
0 commit comments