-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathxmake.lua
More file actions
515 lines (432 loc) · 13.7 KB
/
xmake.lua
File metadata and controls
515 lines (432 loc) · 13.7 KB
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
add_rules("mode.debug", "mode.release")
add_requires("boost", {configs = {stacktrace = true}})
add_requires("pybind11")
-- Define color codes
local GREEN = '\27[0;32m'
local YELLOW = '\27[1;33m'
local NC = '\27[0m' -- No Color
set_encodings("utf-8")
add_includedirs("include")
add_includedirs("third_party/spdlog/include")
add_includedirs("third_party/nlohmann_json/single_include/")
if is_mode("debug") then
add_defines("DEBUG_MODE")
end
if is_plat("windows") then
set_runtimes("MD")
add_ldflags("/utf-8", {force = true})
add_cxxflags("/utf-8", {force = true})
end
-- CPU
option("cpu")
set_default(true)
set_showmenu(true)
set_description("Whether to compile implementations for CPU")
option_end()
option("omp")
set_default(true)
set_showmenu(true)
set_description("Enable or disable OpenMP support for cpu kernel")
option_end()
if has_config("cpu") then
includes("xmake/cpu.lua")
add_defines("ENABLE_CPU_API")
end
if has_config("omp") then
add_defines("ENABLE_OMP")
end
-- 英伟达
option("nv-gpu")
set_default(false)
set_showmenu(true)
set_description("Whether to compile implementations for Nvidia GPU")
option_end()
if has_config("nv-gpu") then
add_defines("ENABLE_NVIDIA_API")
includes("xmake/nvidia.lua")
end
option("cudnn")
set_default(true)
set_showmenu(true)
set_description("Whether to compile cudnn for Nvidia GPU")
option_end()
if has_config("cudnn") then
add_defines("ENABLE_CUDNN_API")
end
option("cutlass")
set_default(false)
set_showmenu(true)
set_description("Whether to compile cutlass for Nvidia GPU")
option_end()
if has_config("cutlass") then
add_defines("ENABLE_CUTLASS_API")
end
option("cuda_arch")
set_showmenu(true)
set_description("Set CUDA GPU architecture (e.g. sm_90)")
set_values("sm_50", "sm_60", "sm_70", "sm_75", "sm_80", "sm_86", "sm_89", "sm_90", "sm_90a")
set_category("option")
option_end()
-- 寒武纪
option("cambricon-mlu")
set_default(false)
set_showmenu(true)
set_description("Whether to compile implementations for Cambricon MLU")
option_end()
if has_config("cambricon-mlu") then
add_defines("ENABLE_CAMBRICON_API")
includes("xmake/bang.lua")
end
-- 华为昇腾
option("ascend-npu")
set_default(false)
set_showmenu(true)
set_description("Whether to compile implementations for Huawei Ascend NPU")
option_end()
if has_config("ascend-npu") then
add_defines("ENABLE_ASCEND_API")
includes("xmake/ascend.lua")
end
-- 天数智芯
option("iluvatar-gpu")
set_default(false)
set_showmenu(true)
set_description("Whether to compile implementations for Iluvatar GPU")
option_end()
option("iluvatar_arch")
set_default("ivcore20")
set_showmenu(true)
set_description("Set Iluvatar GPU architecture (e.g. ivcore20)")
set_values("ivcore20")
set_category("option")
option_end()
if has_config("iluvatar-gpu") then
add_defines("ENABLE_ILUVATAR_API")
includes("xmake/iluvatar.lua")
end
-- ali
option("ali-ppu")
set_default(false)
set_showmenu(true)
set_description("Whether to compile implementations for Ali PPU")
option_end()
if has_config("ali-ppu") then
add_defines("ENABLE_ALI_API")
includes("xmake/ali.lua")
end
-- qy
option("qy-gpu")
set_default(false)
set_showmenu(true)
set_description("Whether to compile implementations for Qy GPU")
option_end()
if has_config("qy-gpu") then
add_defines("ENABLE_QY_API")
includes("xmake/qy.lua")
end
-- 沐曦
option("metax-gpu")
set_default(false)
set_showmenu(true)
set_description("Whether to compile implementations for MetaX GPU")
option_end()
option("use-mc")
set_default(false)
set_showmenu(true)
set_description("Use MC version")
option_end()
if has_config("metax-gpu") then
add_defines("ENABLE_METAX_API")
if has_config("use-mc") then
add_defines("ENABLE_METAX_MC_API")
end
includes("xmake/metax.lua")
end
-- 摩尔线程
option("moore-gpu")
set_default(false)
set_showmenu(true)
set_description("Whether to compile implementations for Moore Threads GPU")
option_end()
option("moore-gpu-arch")
set_default("mp_31")
set_showmenu(true)
set_description("Set Moore GPU architecture (e.g. mp_31)")
option_end()
if has_config("moore-gpu") then
add_defines("ENABLE_MOORE_API")
includes("xmake/moore.lua")
end
-- 海光DCU
option("hygon-dcu")
set_default(false)
set_showmenu(true)
set_description("Whether to compile implementations for Hygon DCU")
option_end()
if has_config("hygon-dcu") then
add_defines("ENABLE_HYGON_API")
includes("xmake/hygon.lua")
end
-- 昆仑芯
option("kunlun-xpu")
set_default(false)
set_showmenu(true)
set_description("Enable or disable Kunlun XPU kernel")
option_end()
if has_config("kunlun-xpu") then
add_defines("ENABLE_KUNLUN_API")
includes("xmake/kunlun.lua")
end
-- 九齿
option("ninetoothed")
set_default(false)
set_showmenu(true)
set_description("Whether to complie NineToothed implementations")
option_end()
if has_config("ninetoothed") then
add_defines("ENABLE_NINETOOTHED")
end
-- cuda graph
option("graph")
set_default(false)
set_showmenu(true)
set_description("Whether to use device graph instantiating feature, such as cuda graph for nvidia")
option_end()
if has_config("graph") then
add_defines("USE_INFINIRT_GRAPH")
end
-- InfiniCCL
option("ccl")
set_default(false)
set_showmenu(true)
set_description("Wether to compile implementations for InfiniCCL")
option_end()
if has_config("ccl") then
add_defines("ENABLE_CCL")
end
target("infini-utils")
set_kind("static")
on_install(function (target) end)
set_languages("cxx17")
set_warnings("all", "error")
if is_plat("windows") then
add_cxxflags("/wd4068")
if has_config("omp") then
add_cxxflags("/openmp")
end
else
add_cxflags("-fPIC", "-Wno-unknown-pragmas")
add_cxxflags("-fPIC", "-Wno-unknown-pragmas")
if has_config("omp") then
add_cxxflags("-fopenmp")
add_ldflags("-fopenmp", {force = true})
end
end
add_files("src/utils/*.cc")
target_end()
target("infinirt")
set_kind("shared")
if has_config("cpu") then
add_deps("infinirt-cpu")
end
if has_config("nv-gpu") then
add_deps("infinirt-nvidia")
end
if has_config("cambricon-mlu") then
add_deps("infinirt-cambricon")
end
if has_config("ascend-npu") then
add_deps("infinirt-ascend")
end
if has_config("metax-gpu") then
add_deps("infinirt-metax")
end
if has_config("moore-gpu") then
add_deps("infinirt-moore")
end
if has_config("iluvatar-gpu") then
add_deps("infinirt-iluvatar")
end
if has_config("ali-ppu") then
add_deps("infinirt-ali")
end
if has_config("qy-gpu") then
add_deps("infinirt-qy")
add_files("build/.objs/infinirt-qy/rules/qy.cuda/src/infinirt/cuda/*.cu.o", {public = true})
end
if has_config("kunlun-xpu") then
add_deps("infinirt-kunlun")
end
if has_config("hygon-dcu") then
add_deps("infinirt-hygon")
end
set_languages("cxx17")
if not is_plat("windows") then
add_cxflags("-fPIC")
add_cxxflags("-fPIC")
end
set_installdir(os.getenv("INFINI_ROOT") or (os.getenv(is_host("windows") and "HOMEPATH" or "HOME") .. "/.infini"))
add_files("src/infinirt/*.cc")
add_installfiles("include/infinirt.h", {prefixdir = "include"})
target_end()
target("infiniop")
set_kind("shared")
add_deps("infinirt")
if has_config("cpu") then
add_deps("infiniop-cpu")
end
if has_config("nv-gpu") then
add_deps("infiniop-nvidia")
end
if has_config("iluvatar-gpu") then
add_deps("infiniop-iluvatar")
end
if has_config("ali-ppu") then
add_deps("infiniop-ali")
end
if has_config("qy-gpu") then
add_deps("infiniop-qy")
add_files("build/.objs/infiniop-qy/rules/qy.cuda/src/infiniop/ops/*/nvidia/*.cu.o", {public = true})
add_files("build/.objs/infiniop-qy/rules/qy.cuda/src/infiniop/ops/*/*/nvidia/*.cu.o", {public = true})
add_files("build/.objs/infiniop-qy/rules/qy.cuda/src/infiniop/devices/nvidia/*.cu.o", {public = true})
end
if has_config("cambricon-mlu") then
add_deps("infiniop-cambricon")
end
if has_config("ascend-npu") then
add_deps("infiniop-ascend")
end
if has_config("metax-gpu") then
add_deps("infiniop-metax")
end
if has_config("moore-gpu") then
add_deps("infiniop-moore")
end
if has_config("kunlun-xpu") then
add_deps("infiniop-kunlun")
end
if has_config("hygon-dcu") then
add_deps("infiniop-hygon")
end
set_languages("cxx17")
add_files("src/infiniop/devices/handle.cc")
add_files("src/infiniop/ops/*/operator.cc", "src/infiniop/ops/*/*/operator.cc")
add_files("src/infiniop/*.cc")
set_installdir(os.getenv("INFINI_ROOT") or (os.getenv(is_host("windows") and "HOMEPATH" or "HOME") .. "/.infini"))
add_installfiles("include/infiniop/(**/*.h)", {prefixdir = "include/infiniop"})
add_installfiles("include/infiniop/*.h", {prefixdir = "include/infiniop"})
add_installfiles("include/infiniop.h", {prefixdir = "include"})
add_installfiles("include/infinicore.h", {prefixdir = "include"})
target_end()
target("infiniccl")
set_kind("shared")
add_deps("infinirt")
if has_config("nv-gpu") then
add_deps("infiniccl-nvidia")
end
if has_config("ascend-npu") then
add_deps("infiniccl-ascend")
end
if has_config("cambricon-mlu") then
add_deps("infiniccl-cambricon")
end
if has_config("metax-gpu") then
add_deps("infiniccl-metax")
end
if has_config("iluvatar-gpu") then
add_deps("infiniccl-iluvatar")
end
if has_config("ali-ppu") then
add_deps("infiniccl-ali")
end
if has_config("qy-gpu") then
add_deps("infiniccl-qy")
add_files("build/.objs/infiniccl-qy/rules/qy.cuda/src/infiniccl/cuda/*.cu.o", {public = true})
end
if has_config("moore-gpu") then
add_deps("infiniccl-moore")
end
if has_config("kunlun-xpu") then
add_deps("infiniccl-kunlun")
end
if has_config("hygon-dcu") then
add_deps("infiniccl-hygon")
end
set_languages("cxx17")
add_files("src/infiniccl/*.cc")
add_installfiles("include/infiniccl.h", {prefixdir = "include"})
set_installdir(os.getenv("INFINI_ROOT") or (os.getenv(is_host("windows") and "HOMEPATH" or "HOME") .. "/.infini"))
target_end()
target("infinicore_c_api")
set_kind("phony")
add_deps("infiniop", "infinirt", "infiniccl")
after_build(function (target) print(YELLOW .. "[Congratulations!] Now you can install the libraries with \"xmake install\"" .. NC) end)
target_end()
target("infinicore_cpp_api")
set_kind("shared")
add_deps("infiniop", "infinirt", "infiniccl")
set_languages("cxx17")
set_symbols("visibility")
local INFINI_ROOT = os.getenv("INFINI_ROOT") or (os.getenv(is_host("windows") and "HOMEPATH" or "HOME") .. "/.infini")
add_includedirs("include")
add_includedirs(INFINI_ROOT.."/include", { public = true })
add_linkdirs(INFINI_ROOT.."/lib")
add_links("infiniop", "infinirt", "infiniccl")
-- Add InfiniCore C++ source files (needed for RoPE and other nn modules)
add_files("src/infinicore/*.cc")
add_files("src/infinicore/context/*.cc")
add_files("src/infinicore/context/*/*.cc")
add_files("src/infinicore/tensor/*.cc")
add_files("src/infinicore/graph/*.cc")
add_files("src/infinicore/nn/*.cc")
add_files("src/infinicore/ops/*/*.cc")
add_files("src/utils/*.cc")
set_installdir(INFINI_ROOT)
add_installfiles("include/infinicore/(**.h)", {prefixdir = "include/infinicore"})
add_installfiles("include/infinicore/(**.hpp)", {prefixdir = "include/infinicore"})
add_installfiles("include/infinicore/(**/*.h)", {prefixdir = "include/infinicore"})
add_installfiles("include/infinicore/(**/*.hpp)",{prefixdir = "include/infinicore"})
add_installfiles("include/infinicore.h", {prefixdir = "include"})
add_installfiles("include/infinicore.hpp", {prefixdir = "include"})
after_build(function (target) print(YELLOW .. "[Congratulations!] Now you can install the libraries with \"xmake install\"" .. NC) end)
target_end()
target("_infinicore")
add_packages("boost")
if is_mode("debug") then
add_defines("BOOST_STACKTRACE_USE_BACKTRACE")
add_links("backtrace")
else
add_defines("BOOST_STACKTRACE_USE_NOOP")
end
set_default(false)
add_rules("python.library", {soabi = true})
add_packages("pybind11")
set_languages("cxx17")
add_deps("infinicore_cpp_api")
set_kind("shared")
local INFINI_ROOT = os.getenv("INFINI_ROOT") or (os.getenv(is_host("windows") and "HOMEPATH" or "HOME") .. "/.infini")
add_includedirs(INFINI_ROOT.."/include", { public = true })
add_linkdirs(INFINI_ROOT.."/lib")
add_links("infiniop", "infinirt", "infiniccl")
add_files("src/infinicore/pybind11/**.cc")
set_installdir("python/infinicore")
target_end()
option("editable")
set_default(false)
set_showmenu(true)
set_description("Install the `infinicore` Python package in editable mode")
option_end()
target("infinicore")
set_kind("phony")
set_default(false)
add_deps("_infinicore")
on_install(function (target)
local pip_install_args = {}
if has_config("editable") then
table.insert(pip_install_args, "--editable")
end
os.execv("python", table.join({"-m", "pip", "install"}, pip_install_args, {"."}))
end)
target_end()
-- Tests
includes("xmake/test.lua")