This repository has been archived by the owner on Sep 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
common.mk
309 lines (270 loc) · 9.08 KB
/
common.mk
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
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
299
300
301
302
303
304
305
306
307
308
309
#/******************************************************************************
# * Copyright (c) 2011, Duane Merrill. All rights reserved.
# * Copyright (c) 2011-2016, NVIDIA CORPORATION. All rights reserved.
# *
# * Redistribution and use in source and binary forms, with or without
# * modification, are permitted provided that the following conditions are met:
# * * Redistributions of source code must retain the above copyright
# * notice, this list of conditions and the following disclaimer.
# * * Redistributions in binary form must reproduce the above copyright
# * notice, this list of conditions and the following disclaimer in the
# * documentation and/or other materials provided with the distribution.
# * * Neither the name of the NVIDIA CORPORATION nor the
# * names of its contributors may be used to endorse or promote products
# * derived from this software without specific prior written permission.
# *
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
# * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# *
#******************************************************************************/
# HIP_PATH
ifeq (${HIP_PATH}, )
HIP_PATH:=/opt/rocm/hip
else
HIP_PATH:=${HIP_PATH}
endif
# HIPCC executable
HIPCC=$(HIP_PATH)/bin/hipcc
# HIP_PLATFORM info (hcc / nvcc)
HIP_PLATFORM=$(shell $(HIP_PATH)/bin/hipconfig --platform)
#HIP_INC: Hip include paths
HIP_INC=${HIP_PATH}/include/
#-------------------------------------------------------------------------------
# Commandline Options
#-------------------------------------------------------------------------------
# [sm=<XXX,...>] Compute-capability to compile for, e.g., "sm=200,300,350" (SM52 by default).
COMMA = ,
ifdef sm
SM_ARCH = $(subst $(COMMA),-,$(sm))
else
SM_ARCH = 520
endif
ifeq (${HIP_PLATFORM}, nvcc)
ifeq (700, $(findstring 700, $(SM_ARCH)))
SM_TARGETS += -gencode=arch=compute_70,code=sm_70
SM_DEF += -DSM700
TEST_ARCH = 700
endif
ifeq (620, $(findstring 620, $(SM_ARCH)))
SM_TARGETS += -gencode=arch=compute_62,code=sm_62
SM_DEF += -DSM620
TEST_ARCH = 620
endif
ifeq (610, $(findstring 610, $(SM_ARCH)))
SM_TARGETS += -gencode=arch=compute_61,code=sm_61
SM_DEF += -DSM610
TEST_ARCH = 610
endif
ifeq (600, $(findstring 600, $(SM_ARCH)))
SM_TARGETS += -gencode=arch=compute_60,code=sm_60
SM_DEF += -DSM600
TEST_ARCH = 600
endif
ifeq (520, $(findstring 520, $(SM_ARCH)))
SM_TARGETS += -gencode=arch=compute_52,code=sm_52
SM_DEF += -DSM520
TEST_ARCH = 520
endif
ifeq (370, $(findstring 370, $(SM_ARCH)))
SM_TARGETS += -gencode=arch=compute_37,code=sm_37
SM_DEF += -DSM370
TEST_ARCH = 370
endif
ifeq (350, $(findstring 350, $(SM_ARCH)))
SM_TARGETS += -gencode=arch=compute_35,code=sm_35
SM_DEF += -DSM350
TEST_ARCH = 350
endif
ifeq (300, $(findstring 300, $(SM_ARCH)))
SM_TARGETS += -gencode=arch=compute_30,code=sm_30
SM_DEF += -DSM300
TEST_ARCH = 300
endif
ifeq (210, $(findstring 210, $(SM_ARCH)))
SM_TARGETS += -gencode=arch=compute_20,code=sm_21
SM_DEF += -DSM210
TEST_ARCH = 210
endif
ifeq (200, $(findstring 200, $(SM_ARCH)))
SM_TARGETS += -gencode=arch=compute_20,code=sm_20
SM_DEF += -DSM200
TEST_ARCH = 200
endif
ifeq (130, $(findstring 130, $(SM_ARCH)))
SM_TARGETS += -gencode=arch=compute_13,code=sm_13
SM_DEF += -DSM130
TEST_ARCH = 130
endif
ifeq (120, $(findstring 120, $(SM_ARCH)))
SM_TARGETS += -gencode=arch=compute_12,code=sm_12
SM_DEF += -DSM120
TEST_ARCH = 120
endif
ifeq (110, $(findstring 110, $(SM_ARCH)))
SM_TARGETS += -gencode=arch=compute_11,code=sm_11
SM_DEF += -DSM110
TEST_ARCH = 110
endif
ifeq (100, $(findstring 100, $(SM_ARCH)))
SM_TARGETS += -gencode=arch=compute_10,code=sm_10
SM_DEF += -DSM100
TEST_ARCH = 100
endif
endif
ifeq (${HIP_PLATFORM}, hcc)
SM_TARGETS += -Wno-deprecated-register
ifeq (520, $(findstring 520, $(SM_ARCH)))
SM_DEF += -DSM520
TEST_ARCH = 520
endif
ifeq (370, $(findstring 370, $(SM_ARCH)))
SM_DEF += -DSM370
TEST_ARCH = 370
endif
ifeq (350, $(findstring 350, $(SM_ARCH)))
SM_DEF += -DSM350
TEST_ARCH = 350
endif
ifeq (300, $(findstring 300, $(SM_ARCH)))
SM_DEF += -DSM300
TEST_ARCH = 300
endif
ifeq (210, $(findstring 210, $(SM_ARCH)))
SM_DEF += -DSM210
TEST_ARCH = 210
endif
ifeq (200, $(findstring 200, $(SM_ARCH)))
SM_DEF += -DSM200
TEST_ARCH = 200
endif
ifeq (130, $(findstring 130, $(SM_ARCH)))
SM_DEF += -DSM130
TEST_ARCH = 130
endif
ifeq (120, $(findstring 120, $(SM_ARCH)))
SM_DEF += -DSM120
TEST_ARCH = 120
endif
ifeq (110, $(findstring 110, $(SM_ARCH)))
SM_DEF += -DSM110
TEST_ARCH = 110
endif
ifeq (100, $(findstring 100, $(SM_ARCH)))
SM_DEF += -DSM100
TEST_ARCH = 100
endif
endif
# [cdp=<0|1>] CDP enable option (default: no)
ifeq ($(cdp), 1)
DEFINES += -DCUB_CDP
CDP_SUFFIX = cdp
HIPCCFLAGS += -rdc=true -lcudadevrt
else
CDP_SUFFIX = nocdp
endif
# [force32=<0|1>] Device addressing mode option (64-bit device pointers by default)
ifeq ($(force32), 1)
CPU_ARCH = -m32
CPU_ARCH_SUFFIX = i386
else
CPU_ARCH = -m64
CPU_ARCH_SUFFIX = x86_64
NPPI = -lnppi
endif
# [abi=<0|1>] CUDA ABI option (enabled by default)
ifneq ($(abi), 0)
ABI_SUFFIX = abi
else
HIPCCFLAGS += -Xptxas -abi=no
ABI_SUFFIX = noabi
endif
# [open64=<0|1>] Middle-end compiler option (nvvm by default)
ifeq ($(open64), 1)
HIPCCFLAGS += -open64
PTX_SUFFIX = open64
else
PTX_SUFFIX = nvvm
endif
# [verbose=<0|1>] Verbose toolchain output from nvcc option
ifeq ($(verbose), 1)
HIPCCFLAGS += -v
endif
# [keep=<0|1>] Keep intermediate compilation artifacts option
ifeq ($(keep), 1)
HIPCCFLAGS += -keep
endif
# [debug=<0|1>] Generate debug mode code
ifeq ($(debug), 1)
HIPCCFLAGS += -G
endif
CPPFLAGS += $(shell $(HIP_PATH)/bin/hipconfig --cpp_config)
#-------------------------------------------------------------------------------
# Compiler and compilation platform
#-------------------------------------------------------------------------------
CUB_DIR = $(dir $(lastword $(MAKEFILE_LIST)))
ifeq (${HIP_PLATFORM}, nvcc)
HIPCC=${HIP_PATH}/bin/hipcc
ifdef nvccver
HIPCC_VERSION = $(nvccver)
else
HIPCC_VERSION = $(strip $(shell nvcc --version | grep release | sed 's/.*release //' | sed 's/,.*//'))
endif
endif
# detect OS
OSUPPER = $(shell uname -s 2>/dev/null | tr [:lower:] [:upper:])
# Default flags: verbose kernel properties (regs, smem, cmem, etc.); runtimes for compilation phases
ifeq (${HIP_PLATFORM}, nvcc)
HIPCCFLAGS += $(SM_DEF) -Xptxas -v -Xcudafe -\#
else
HIPCCFLAGS += $(SM_DEF)
endif
ifeq (WIN_NT, $(findstring WIN_NT, $(OSUPPER)))
# For MSVC
# Enable more warnings and treat as errors
HIPCCFLAGS += -Xcompiler /W3 -Xcompiler /WX
# Disable excess x86 floating point precision that can lead to results being labeled incorrectly
HIPCCFLAGS += -Xcompiler /fp:strict
# Help the compiler/linker work with huge numbers of kernels on Windows
HIPCCFLAGS += -Xcompiler /bigobj -Xcompiler /Zm500
CC = cl
# Multithreaded runtime
HIPCCFLAGS += -Xcompiler /MT
ifneq ($(force32), 1)
CUDART_CYG = "$(shell dirname $(HIPCC))/../lib/Win32/cudart.lib"
else
CUDART_CYG = "$(shell dirname $(HIPCC))/../lib/x64/cudart.lib"
endif
CUDART = "$(shell cygpath -w $(CUDART_CYG))"
else
# For g++
# Disable excess x86 floating point precision that can lead to results being labeled incorrectly
ifeq (${HIP_PLATFORM}, nvcc)
HIPCCFLAGS += -Xcompiler -ffloat-store
endif
CC = g++
ifneq ($(force32), 1)
CUDART = "$(shell dirname $(HIPCC))/../lib/libcudart_static.a"
else
CUDART = "$(shell dirname $(HIPCC))/../lib64/libcudart_static.a"
endif
endif
# Suffix to append to each binary
ifeq (${HIP_PLATFORM}, nvcc)
BIN_SUFFIX = sm$(SM_ARCH)_$(PTX_SUFFIX)_$(HIPCC_VERSION)_$(ABI_SUFFIX)_$(CDP_SUFFIX)_$(CPU_ARCH_SUFFIX)
else
BIN_SUFFIX = sm$(SM_ARCH)_$(PTX_SUFFIX)_$(ABI_SUFFIX)_$(CDP_SUFFIX)_$(CPU_ARCH_SUFFIX)
endif
#-------------------------------------------------------------------------------
# Dependency Lists
#-------------------------------------------------------------------------------
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
CUB_DEPS = $(call rwildcard, $(CUB_DIR),*.cuh) \
$(CUB_DIR)common.mk