xmake.lua 9.37 KB
Newer Older
PanZezhongQY's avatar
PanZezhongQY committed
1
add_rules("mode.debug", "mode.release")
2
add_requires("boost", {configs = {stacktrace = true}})
3
4
add_requires("pybind11")

PanZezhongQY's avatar
PanZezhongQY committed
5
6
7
8
9
-- Define color codes
local GREEN = '\27[0;32m'
local YELLOW = '\27[1;33m'
local NC = '\27[0m'  -- No Color

10
set_encodings("utf-8")
PanZezhongQY's avatar
PanZezhongQY committed
11

12
add_includedirs("include")
13
add_includedirs("third_party/spdlog/include")
14

PanZezhongQY's avatar
PanZezhongQY committed
15
16
17
18
if is_mode("debug") then
    add_defines("DEBUG_MODE")
end

19
20
if is_plat("windows") then
    set_runtimes("MD")
21
22
    add_ldflags("/utf-8", {force = true})
    add_cxflags("/utf-8", {force = true})
23
24
end

PanZezhongQY's avatar
PanZezhongQY committed
25
26
27
28
-- CPU
option("cpu")
    set_default(true)
    set_showmenu(true)
YdrMaster's avatar
YdrMaster committed
29
    set_description("Whether to compile implementations for CPU")
PanZezhongQY's avatar
PanZezhongQY committed
30
31
32
option_end()

option("omp")
33
    set_default(true)
PanZezhongQY's avatar
PanZezhongQY committed
34
35
36
37
38
39
40
41
42
    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

43
44
45
46
if has_config("omp") then
    add_defines("ENABLE_OMP")
end

PanZezhongQY's avatar
PanZezhongQY committed
47
48
49
50
-- 英伟达
option("nv-gpu")
    set_default(false)
    set_showmenu(true)
YdrMaster's avatar
YdrMaster committed
51
    set_description("Whether to compile implementations for Nvidia GPU")
PanZezhongQY's avatar
PanZezhongQY committed
52
53
54
option_end()

if has_config("nv-gpu") then
55
    add_defines("ENABLE_NVIDIA_API")
56
    includes("xmake/nvidia.lua")
PanZezhongQY's avatar
PanZezhongQY committed
57
58
end

59
60
option("cudnn")
    set_default(true)
YdrMaster's avatar
YdrMaster committed
61
    set_showmenu(true)
YdrMaster's avatar
YdrMaster committed
62
    set_description("Whether to compile cudnn for Nvidia GPU")
YdrMaster's avatar
YdrMaster committed
63
64
option_end()

65
66
if has_config("cudnn") then
    add_defines("ENABLE_CUDNN_API")
YdrMaster's avatar
YdrMaster committed
67
68
end

PanZezhongQY's avatar
PanZezhongQY committed
69
70
71
72
-- 寒武纪
option("cambricon-mlu")
    set_default(false)
    set_showmenu(true)
YdrMaster's avatar
YdrMaster committed
73
    set_description("Whether to compile implementations for Cambricon MLU")
PanZezhongQY's avatar
PanZezhongQY committed
74
75
76
77
option_end()

if has_config("cambricon-mlu") then
    add_defines("ENABLE_CAMBRICON_API")
PanZezhong's avatar
PanZezhong committed
78
    includes("xmake/bang.lua")
PanZezhongQY's avatar
PanZezhongQY committed
79
80
81
82
83
84
end

-- 华为昇腾
option("ascend-npu")
    set_default(false)
    set_showmenu(true)
YdrMaster's avatar
YdrMaster committed
85
    set_description("Whether to compile implementations for Huawei Ascend NPU")
PanZezhongQY's avatar
PanZezhongQY committed
86
87
88
89
option_end()

if has_config("ascend-npu") then
    add_defines("ENABLE_ASCEND_API")
Pan Zezhong's avatar
Pan Zezhong committed
90
    includes("xmake/ascend.lua")
PanZezhongQY's avatar
PanZezhongQY committed
91
92
end

93
94
95
96
-- 天数智芯
option("iluvatar-gpu")
    set_default(false)
    set_showmenu(true)
YdrMaster's avatar
YdrMaster committed
97
    set_description("Whether to compile implementations for Iluvatar GPU")
98
99
100
option_end()

if has_config("iluvatar-gpu") then
101
    add_defines("ENABLE_ILUVATAR_API")
102
103
104
    includes("xmake/iluvatar.lua")
end

PanZezhongQY's avatar
PanZezhongQY committed
105
106
107
108
-- 沐曦
option("metax-gpu")
    set_default(false)
    set_showmenu(true)
YdrMaster's avatar
YdrMaster committed
109
    set_description("Whether to compile implementations for MetaX GPU")
PanZezhongQY's avatar
PanZezhongQY committed
110
111
112
option_end()

if has_config("metax-gpu") then
113
    add_defines("ENABLE_METAX_API")
114
    includes("xmake/metax.lua")
PanZezhongQY's avatar
PanZezhongQY committed
115
116
117
118
119
120
end

-- 摩尔线程
option("moore-gpu")
    set_default(false)
    set_showmenu(true)
YdrMaster's avatar
YdrMaster committed
121
    set_description("Whether to compile implementations for Moore Threads GPU")
PanZezhongQY's avatar
PanZezhongQY committed
122
123
option_end()

124
if has_config("moore-gpu") then
125
    add_defines("ENABLE_MOORE_API")
126
    includes("xmake/moore.lua")
127
end
PanZezhongQY's avatar
PanZezhongQY committed
128

129
130
-- 海光DCU
option("hygon-dcu")
PanZezhongQY's avatar
PanZezhongQY committed
131
132
    set_default(false)
    set_showmenu(true)
133
    set_description("Whether to compile implementations for Hygon DCU")
PanZezhongQY's avatar
PanZezhongQY committed
134
135
option_end()

136
137
138
if has_config("hygon-dcu") then
    add_defines("ENABLE_HYGON_API")
    includes("xmake/hygon.lua")
PanZezhongQY's avatar
PanZezhongQY committed
139
140
end

141
142
143
144
145
146
147
148
149
150
151
-- 昆仑芯
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
PanZezhongQY's avatar
PanZezhongQY committed
152

153
154
155
156
157
158
159
160
161
162
163
-- 九齿
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

164
165
166
167
-- InfiniCCL
option("ccl")
    set_default(false)
    set_showmenu(true)
YdrMaster's avatar
YdrMaster committed
168
    set_description("Wether to compile implementations for InfiniCCL")
169
170
171
172
173
174
option_end()

if has_config("ccl") then
    add_defines("ENABLE_CCL")
end

PanZezhong's avatar
PanZezhong committed
175
176
target("infini-utils")
    set_kind("static")
PanZezhong's avatar
PanZezhong committed
177
    on_install(function (target) end)
PanZezhong's avatar
PanZezhong committed
178
    set_languages("cxx17")
179
180
181
182
183
184
185
186
187
188
189
190

    set_warnings("all", "error")

    if is_plat("windows") then
        add_cxflags("/wd4068")
        if has_config("omp") then
            add_cxflags("/openmp")
        end
    else
        add_cxflags("-fPIC", "-Wno-unknown-pragmas")
        if has_config("omp") then
            add_cxflags("-fopenmp")
PanZezhong's avatar
PanZezhong committed
191
            add_ldflags("-fopenmp", {force = true})
192
193
194
        end
    end

PanZezhong's avatar
PanZezhong committed
195
196
197
    add_files("src/utils/*.cc")
target_end()

198
199
200
201
202
203
204
target("infinirt")
    set_kind("shared")

    if has_config("cpu") then
        add_deps("infinirt-cpu")
    end
    if has_config("nv-gpu") then
205
        add_deps("infinirt-nvidia")
206
    end
207
208
209
    if has_config("cambricon-mlu") then
        add_deps("infinirt-cambricon")
    end
210
211
212
    if has_config("ascend-npu") then
        add_deps("infinirt-ascend")
    end
213
214
215
    if has_config("metax-gpu") then
        add_deps("infinirt-metax")
    end
qinyiqun's avatar
qinyiqun committed
216
217
218
    if has_config("moore-gpu") then
        add_deps("infinirt-moore")
    end
YdrMaster's avatar
YdrMaster committed
219
220
221
    if has_config("iluvatar-gpu") then
        add_deps("infinirt-iluvatar")
    end
zhangyue's avatar
zhangyue committed
222
223
224
    if has_config("kunlun-xpu") then
        add_deps("infinirt-kunlun")
    end
225
226
227
    if has_config("hygon-dcu") then
        add_deps("infinirt-hygon")
    end
228
229
230
    set_languages("cxx17")
    set_installdir(os.getenv("INFINI_ROOT") or (os.getenv(is_host("windows") and "HOMEPATH" or "HOME") .. "/.infini"))
    add_files("src/infinirt/*.cc")
231
    add_installfiles("include/infinirt.h", {prefixdir = "include"})
232
233
target_end()

PanZezhongQY's avatar
PanZezhongQY committed
234
235
target("infiniop")
    set_kind("shared")
236
237
    add_deps("infinirt")

PanZezhongQY's avatar
PanZezhongQY committed
238
239
240
241
    if has_config("cpu") then
        add_deps("infiniop-cpu")
    end
    if has_config("nv-gpu") then
242
        add_deps("infiniop-nvidia")
PanZezhongQY's avatar
PanZezhongQY committed
243
    end
YdrMaster's avatar
YdrMaster committed
244
245
246
    if has_config("iluvatar-gpu") then
        add_deps("infiniop-iluvatar")
    end
PanZezhongQY's avatar
PanZezhongQY committed
247
248

    if has_config("cambricon-mlu") then
PanZezhong's avatar
PanZezhong committed
249
        add_deps("infiniop-cambricon")
PanZezhongQY's avatar
PanZezhongQY committed
250
251
    end
    if has_config("ascend-npu") then
Pan Zezhong's avatar
Pan Zezhong committed
252
        add_deps("infiniop-ascend")
PanZezhongQY's avatar
PanZezhongQY committed
253
254
    end
    if has_config("metax-gpu") then
255
        add_deps("infiniop-metax")
PanZezhongQY's avatar
PanZezhongQY committed
256
    end
257
    if has_config("moore-gpu") then
258
        add_deps("infiniop-moore")
259
    end
260
261
262
    if has_config("kunlun-xpu") then
        add_deps("infiniop-kunlun")
    end
263
264
265
    if has_config("hygon-dcu") then
        add_deps("infiniop-hygon")
    end
PanZezhongQY's avatar
PanZezhongQY committed
266
267
268
269
270
271
272
273
274
275
276
    set_languages("cxx17")
    add_files("src/infiniop/devices/handle.cc")
    add_files("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()
277

278
279
280
281
282
target("infiniccl")
    set_kind("shared")
    add_deps("infinirt")

    if has_config("nv-gpu") then
283
        add_deps("infiniccl-nvidia")
284
    end
Pan Zezhong's avatar
Pan Zezhong committed
285
286
287
    if has_config("ascend-npu") then
        add_deps("infiniccl-ascend")
    end
wooway777's avatar
wooway777 committed
288
289
290
    if has_config("cambricon-mlu") then
        add_deps("infiniccl-cambricon")
    end
PanZezhong's avatar
PanZezhong committed
291
292
293
    if has_config("metax-gpu") then
        add_deps("infiniccl-metax")
    end
YdrMaster's avatar
YdrMaster committed
294
295
296
    if has_config("iluvatar-gpu") then
        add_deps("infiniccl-iluvatar")
    end
YdrMaster's avatar
YdrMaster committed
297

spike-zhu's avatar
spike-zhu committed
298
299
300
    if has_config("moore-gpu") then
        add_deps("infiniccl-moore")
    end
301

302
303
304
    if has_config("kunlun-xpu") then
        add_deps("infiniccl-kunlun")
    end
305
306
307
    if has_config("hygon-dcu") then
        add_deps("infiniccl-hygon")
    end
308

309
310
311
312
313
314
315
    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()
316

317
target("infinicore_c_api")
318
    set_kind("phony")
319
    add_deps("infiniop", "infinirt", "infiniccl")
320
321
    after_build(function (target) print(YELLOW .. "[Congratulations!] Now you can install the libraries with \"xmake install\"" .. NC) end)
target_end()
322

323
324
325
326
327
328
329
330
331
332
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)
333
334
    add_rules("python.library", {soabi = true})
    add_packages("pybind11")
335
    set_languages("cxx17")
336
337

    set_kind("shared")
338
339
340
341
342
    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")
343
344

    add_files("src/infinicore/*.cc")
345
346
347
    add_files("src/infinicore/context/*.cc")
    add_files("src/infinicore/context/*/*.cc")
    add_files("src/infinicore/tensor/*.cc")
348
    add_files("src/infinicore/ops/*/*.cc")
349
    add_files("src/infinicore/pybind11/**.cc")
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
    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)
376
377
target_end()

378
379
-- Tests
includes("xmake/test.lua")