1
1
add_rules (" mode.debug" , " mode.release" )
2
-
3
- -- Define color codes
4
2
-- Define color codes
5
- local GREEN = " \027 [0;32m"
6
- local YELLOW = " \027 [1;33m"
7
- local NC = " \027 [0m" -- No Color
8
-
3
+ local GREEN = ' \27 [0;32m'
4
+ local YELLOW = ' \27 [1;33m'
5
+ local NC = ' \27 [0m' -- No Color
9
6
10
7
add_includedirs (" include" )
11
- add_cxxflags (" -fPIC" )
12
8
13
9
option (" cpu" )
14
10
set_default (true )
@@ -44,12 +40,36 @@ option("ascend-npu")
44
40
add_defines (" ENABLE_ASCEND_NPU" )
45
41
option_end ()
46
42
43
+ option (" metax-gpu" )
44
+ set_default (false )
45
+ set_showmenu (true )
46
+ set_description (" Enable or disable Metax GPU kernel" )
47
+ add_defines (" ENABLE_METAX_GPU" )
48
+ option_end ()
49
+
50
+
51
+ option (" mthreads-gpu" )
52
+ set_default (false )
53
+ set_showmenu (true )
54
+ set_description (" Enable or disable MThreads GPU kernel" )
55
+ add_defines (" ENABLE_MTHREADS_GPU" )
56
+ option_end ()
57
+
58
+ option (" sugon-dcu" )
59
+ set_default (false )
60
+ set_showmenu (true )
61
+ set_description (" Enable or disable Sugon DCU kernel" )
62
+ add_defines (" ENABLE_SUGON_DCU" )
63
+ add_defines (" ENABLE_NV_GPU" )
64
+ option_end ()
65
+
47
66
if is_mode (" debug" ) then
48
67
add_cxflags (" -g -O0" )
49
68
add_defines (" DEBUG_MODE" )
50
69
end
51
70
52
71
if has_config (" cpu" ) then
72
+
53
73
add_defines (" ENABLE_CPU" )
54
74
target (" cpu" )
55
75
on_install (function (target ) end )
@@ -66,10 +86,14 @@ if has_config("cpu") then
66
86
add_ldflags (" -fopenmp" )
67
87
end
68
88
target_end ()
89
+
69
90
end
70
91
71
- if has_config (" nv-gpu" ) then
92
+ if has_config (" nv-gpu" , " sugon-dcu " ) then
72
93
add_defines (" ENABLE_NV_GPU" )
94
+ if has_config (" sugon-dcu" ) then
95
+ add_defines (" ENABLE_SUGON_DCU" )
96
+ end
73
97
local CUDA_ROOT = os.getenv (" CUDA_ROOT" ) or os.getenv (" CUDA_HOME" ) or os.getenv (" CUDA_PATH" )
74
98
local CUDNN_ROOT = os.getenv (" CUDNN_ROOT" ) or os.getenv (" CUDNN_HOME" ) or os.getenv (" CUDNN_PATH" )
75
99
if CUDA_ROOT ~= nil then
@@ -104,9 +128,11 @@ if has_config("nv-gpu") then
104
128
add_files (" src/devices/cuda/*.cc" , " src/ops/*/cuda/*.cu" )
105
129
add_files (" src/ops/*/cuda/*.cc" )
106
130
target_end ()
131
+
107
132
end
108
133
109
134
if has_config (" cambricon-mlu" ) then
135
+
110
136
add_defines (" ENABLE_CAMBRICON_MLU" )
111
137
add_includedirs (" /usr/local/neuware/include" )
112
138
add_linkdirs (" /usr/local/neuware/lib64" )
@@ -139,6 +165,7 @@ if has_config("cambricon-mlu") then
139
165
os .execv (cc , args )
140
166
table.insert (target :objectfiles (), objectfile )
141
167
end )
168
+
142
169
rule_end ()
143
170
144
171
target (" cambricon-mlu" )
@@ -149,9 +176,56 @@ if has_config("cambricon-mlu") then
149
176
add_files (" src/ops/*/bang/*.mlu" , {rule = " mlu" })
150
177
add_cxflags (" -lstdc++ -Wall -Werror -fPIC" )
151
178
target_end ()
179
+
180
+ end
181
+
182
+ if has_config (" mthreads-gpu" ) then
183
+
184
+ add_defines (" ENABLE_MTHREADS_GPU" )
185
+ local musa_home = os.getenv (" MUSA_INSTALL_PATH" )
186
+ -- Add include dirs
187
+ add_includedirs (musa_home .. " /include" )
188
+ -- Add shared lib
189
+ add_linkdirs (musa_home .. " /lib" )
190
+ add_links (" libmusa.so" )
191
+ add_links (" libmusart.so" )
192
+ add_links (" libmudnn.so" )
193
+ add_links (" libmublas.so" )
194
+
195
+ rule (" mu" )
196
+ set_extensions (" .mu" )
197
+ on_load (function (target )
198
+ target :add (" includedirs" , " include" )
199
+ end )
200
+
201
+ on_build_file (function (target , sourcefile )
202
+ local objectfile = target :objectfile (sourcefile )
203
+ os .mkdir (path.directory (objectfile ))
204
+
205
+ local mcc = " /usr/local/musa/bin/mcc"
206
+ local includedirs = table.concat (target :get (" includedirs" ), " " )
207
+ local args = {" -c" , sourcefile , " -o" , objectfile , " -I/usr/local/musa/include" , " -O3" , " -fPIC" , " -Wall" , " -std=c++17" , " -pthread" }
208
+ for _ , includedir in ipairs (target :get (" includedirs" )) do
209
+ table.insert (args , " -I" .. includedir )
210
+ end
211
+
212
+ os .execv (mcc , args )
213
+ table.insert (target :objectfiles (), objectfile )
214
+ end )
215
+ rule_end ()
216
+
217
+ target (" mthreads-gpu" )
218
+ set_kind (" static" )
219
+ set_languages (" cxx17" )
220
+ add_files (" src/devices/musa/*.cc" , " src/ops/*/musa/*.cc" )
221
+ add_files (" src/ops/*/musa/*.mu" , {rule = " mu" })
222
+ add_cxflags (" -lstdc++ -Wall -fPIC" )
223
+ target_end ()
224
+
152
225
end
153
226
154
227
if has_config (" ascend-npu" ) then
228
+
155
229
add_defines (" ENABLE_ASCEND_NPU" )
156
230
local ASCEND_HOME = os.getenv (" ASCEND_HOME" )
157
231
local SOC_VERSION = os.getenv (" SOC_VERSION" )
@@ -180,13 +254,15 @@ if has_config("ascend-npu") then
180
254
os .exec (" make" )
181
255
os .exec (" cp $(projectdir)/src/devices/ascend/build/lib/libascend_kernels.a " .. builddir .. " /" )
182
256
os .cd (os.projectdir ())
257
+
183
258
end )
184
259
after_clean (function ()
185
260
local ascend_build_dir = path.join (os.projectdir (), " src/devices/ascend" )
186
261
os .cd (ascend_build_dir )
187
262
os .exec (" make clean" )
188
263
os .cd (os.projectdir ())
189
264
os .rm (builddir .. " /libascend_kernels.a" )
265
+
190
266
end )
191
267
rule_end ()
192
268
@@ -202,9 +278,62 @@ if has_config("ascend-npu") then
202
278
-- Add operator
203
279
add_rules (" ascend-kernels" )
204
280
add_links (builddir .. " /libascend_kernels.a" )
281
+
282
+ target_end ()
283
+ end
284
+
285
+ if has_config (" metax-gpu" ) then
286
+
287
+ add_defines (" ENABLE_METAX_GPU" )
288
+ local MACA_ROOT = os.getenv (" MACA_PATH" ) or os.getenv (" MACA_HOME" ) or os.getenv (" MACA_ROOT" )
289
+
290
+ add_includedirs (MACA_ROOT .. " /include" )
291
+ add_linkdirs (MACA_ROOT .. " /lib" )
292
+ -- add_linkdirs(MACA_ROOT .. "htgpu_llvm/lib")
293
+ add_links (" libhcdnn.so" )
294
+ add_links (" libhcblas.so" )
295
+ add_links (" libhcruntime.so" )
296
+
297
+ rule (" maca" )
298
+ set_extensions (" .maca" )
299
+
300
+ on_load (function (target )
301
+ target :add (" includedirs" , " include" )
302
+ end )
303
+
304
+ on_build_file (function (target , sourcefile )
305
+ local objectfile = target :objectfile (sourcefile )
306
+ os .mkdir (path.directory (objectfile ))
307
+ local htcc = " /opt/hpcc/htgpu_llvm/bin/htcc"
308
+
309
+ local includedirs = table.concat (target :get (" includedirs" ), " " )
310
+ local args = { " -x" , " hpcc" , " -c" , sourcefile , " -o" , objectfile , " -I/opt/hpcc/include" , " -O3" , " -fPIC" , " -Werror" , " -std=c++17" }
311
+
312
+ for _ , includedir in ipairs (target :get (" includedirs" )) do
313
+ table.insert (args , " -I" .. includedir )
314
+ end
315
+
316
+ os .execv (htcc , args )
317
+ table.insert (target :objectfiles (), objectfile )
318
+ end )
319
+ rule_end ()
320
+
321
+ target (" metax-gpu" )
322
+ set_kind (" static" )
323
+ on_install (function (target ) end )
324
+ set_languages (" cxx17" )
325
+ add_files (" src/devices/maca/*.cc" , " src/ops/*/maca/*.cc" )
326
+ add_files (" src/ops/*/maca/*.maca" , {rule = " maca" })
327
+ add_cxflags (" -lstdc++ -Werror -fPIC" )
205
328
target_end ()
329
+
206
330
end
207
331
332
+
333
+ toolchain (" sugon-dcu-linker" )
334
+ set_toolset (" sh" , " nvcc" )
335
+ toolchain_end ()
336
+
208
337
target (" infiniop" )
209
338
set_kind (" shared" )
210
339
@@ -214,12 +343,33 @@ target("infiniop")
214
343
if has_config (" nv-gpu" ) then
215
344
add_deps (" nv-gpu" )
216
345
end
346
+ if has_config (" sugon-dcu" ) then
347
+ local builddir = string.format (
348
+ " build/%s/%s/%s" ,
349
+ get_config (" plat" ),
350
+ get_config (" arch" ),
351
+ get_config (" mode" )
352
+ )
353
+ add_shflags (" -s" , " -shared" , " -fPIC" )
354
+ add_links (" cublas" , " cudnn" , " cudadevrt" , " cudart_static" , " rt" , " pthread" , " dl" )
355
+ -- Using -lnv-gpu will fail, manually link the target using full path
356
+ add_deps (" nv-gpu" , {inherit = false })
357
+ add_links (builddir .. " /libnv-gpu.a" )
358
+ set_toolchains (" sugon-dcu-linker" )
359
+ end
360
+
217
361
if has_config (" cambricon-mlu" ) then
218
362
add_deps (" cambricon-mlu" )
219
363
end
220
364
if has_config (" ascend-npu" ) then
221
365
add_deps (" ascend-npu" )
222
366
end
367
+ if has_config (" metax-gpu" ) then
368
+ add_deps (" metax-gpu" )
369
+ end
370
+ if has_config (" mthreads-gpu" ) then
371
+ add_deps (" mthreads-gpu" )
372
+ end
223
373
set_languages (" cxx17" )
224
374
add_files (" src/devices/handle.cc" )
225
375
add_files (" src/ops/*/operator.cc" )
@@ -229,4 +379,5 @@ target("infiniop")
229
379
set_installdir (os.getenv (" INFINI_ROOT" ) or (os.getenv (is_host (" windows" ) and " HOMEPATH" or " HOME" ) .. " /.infini" ))
230
380
add_installfiles (" include/(**/*.h)" , {prefixdir = " include" })
231
381
add_installfiles (" include/*.h" , {prefixdir = " include" })
232
- target_end ()
382
+
383
+ target_end ()
0 commit comments