xmake.lua 8.11 KB
Newer Older
PanZezhongQY's avatar
PanZezhongQY committed
1
add_rules("mode.debug", "mode.release")
2
3
add_requires("pybind11")

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

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

11
12
add_includedirs("include")

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

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

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

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

41
42
43
44
if has_config("omp") then
    add_defines("ENABLE_OMP")
end

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

139
140
141
142
143
144
145
146
147
148
149
-- 昆仑芯
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
150

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

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

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

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

    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
189
            add_ldflags("-fopenmp", {force = true})
190
191
192
        end
    end

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

196
197
198
199
200
201
202
target("infinirt")
    set_kind("shared")

    if has_config("cpu") then
        add_deps("infinirt-cpu")
    end
    if has_config("nv-gpu") then
203
        add_deps("infinirt-nvidia")
204
    end
205
206
207
    if has_config("cambricon-mlu") then
        add_deps("infinirt-cambricon")
    end
208
209
210
    if has_config("ascend-npu") then
        add_deps("infinirt-ascend")
    end
211
212
213
    if has_config("metax-gpu") then
        add_deps("infinirt-metax")
    end
qinyiqun's avatar
qinyiqun committed
214
215
216
    if has_config("moore-gpu") then
        add_deps("infinirt-moore")
    end
YdrMaster's avatar
YdrMaster committed
217
218
219
    if has_config("iluvatar-gpu") then
        add_deps("infinirt-iluvatar")
    end
zhangyue's avatar
zhangyue committed
220
221
222
    if has_config("kunlun-xpu") then
        add_deps("infinirt-kunlun")
    end
223
224
225
    if has_config("hygon-dcu") then
        add_deps("infinirt-hygon")
    end
226
227
228
    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")
229
    add_installfiles("include/infinirt.h", {prefixdir = "include"})
230
231
target_end()

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

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

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

276
277
278
279
280
target("infiniccl")
    set_kind("shared")
    add_deps("infinirt")

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

spike-zhu's avatar
spike-zhu committed
296
297
298
    if has_config("moore-gpu") then
        add_deps("infiniccl-moore")
    end
299
300
301
    if has_config("kunlun-xpu") then
        add_deps("infiniccl-kunlun")
    end
302
303
304
    if has_config("hygon-dcu") then
        add_deps("infiniccl-hygon")
    end
spike-zhu's avatar
spike-zhu committed
305
    
306
307
308
309
310
311
312
    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()
313

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

320
321
322
323
324
325
326
327
328
329
330
331
target("infinicore")
    add_rules("python.library", {soabi = true})
    add_packages("pybind11")

    set_kind("shared")
    add_deps("infinicore_c_api")

    add_files("src/infinicore/*.cc")

    set_installdir(os.getenv("INFINI_ROOT") or (os.getenv(is_host("windows") and "HOMEPATH" or "HOME") .. "/.infini"))
target_end()

332
333
-- Tests
includes("xmake/test.lua")