xmake.lua 8.33 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
129
130

-- 海光
option("sugon-dcu")
    set_default(false)
    set_showmenu(true)
YdrMaster's avatar
YdrMaster committed
131
    set_description("Whether to compile implementations for Sugon DCU")
PanZezhongQY's avatar
PanZezhongQY committed
132
133
134
135
136
137
option_end()

if has_config("sugon-dcu") then
    add_defines("ENABLE_SUGON_CUDA_API")
end

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

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

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

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

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

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

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

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

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

PanZezhongQY's avatar
PanZezhongQY committed
228
229
target("infiniop")
    set_kind("shared")
230
231
    add_deps("infinirt")

PanZezhongQY's avatar
PanZezhongQY committed
232
233
234
235
    if has_config("cpu") then
        add_deps("infiniop-cpu")
    end
    if has_config("nv-gpu") then
236
        add_deps("infiniop-nvidia")
PanZezhongQY's avatar
PanZezhongQY committed
237
    end
YdrMaster's avatar
YdrMaster committed
238
239
240
    if has_config("iluvatar-gpu") then
        add_deps("infiniop-iluvatar")
    end
PanZezhongQY's avatar
PanZezhongQY committed
241
242
243
244
245
246
247
248
249
    if has_config("sugon-dcu") then
        local builddir = string.format(
            "build/%s/%s/%s",
            get_config("plat"),
            get_config("arch"),
            get_config("mode")
        )
        add_shflags("-s", "-shared", "-fPIC")
        add_links("cublas", "cudnn", "cudadevrt", "cudart_static", "rt", "pthread", "dl")
250
        -- Using -linfiniop-nvidia will fail, manually link the target using full path
PanZezhongQY's avatar
PanZezhongQY committed
251
        add_deps("nv-gpu", {inherit = false})
252
        add_links(builddir.."/libinfiniop-nvidia.a")
PanZezhongQY's avatar
PanZezhongQY committed
253
254
255
256
        set_toolchains("sugon-dcu-linker")
    end

    if has_config("cambricon-mlu") then
PanZezhong's avatar
PanZezhong committed
257
        add_deps("infiniop-cambricon")
PanZezhongQY's avatar
PanZezhongQY committed
258
259
    end
    if has_config("ascend-npu") then
Pan Zezhong's avatar
Pan Zezhong committed
260
        add_deps("infiniop-ascend")
PanZezhongQY's avatar
PanZezhongQY committed
261
262
    end
    if has_config("metax-gpu") then
263
        add_deps("infiniop-metax")
PanZezhongQY's avatar
PanZezhongQY committed
264
    end
265
    if has_config("moore-gpu") then
266
        add_deps("infiniop-moore")
267
    end
268
269
270
    if has_config("kunlun-xpu") then
        add_deps("infiniop-kunlun")
    end
PanZezhongQY's avatar
PanZezhongQY committed
271
272
273
274
275
276
277
278
279
280
281
    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()
282

283
284
285
286
287
target("infiniccl")
    set_kind("shared")
    add_deps("infinirt")

    if has_config("nv-gpu") then
288
        add_deps("infiniccl-nvidia")
289
    end
Pan Zezhong's avatar
Pan Zezhong committed
290
291
292
    if has_config("ascend-npu") then
        add_deps("infiniccl-ascend")
    end
wooway777's avatar
wooway777 committed
293
294
295
    if has_config("cambricon-mlu") then
        add_deps("infiniccl-cambricon")
    end
PanZezhong's avatar
PanZezhong committed
296
297
298
    if has_config("metax-gpu") then
        add_deps("infiniccl-metax")
    end
YdrMaster's avatar
YdrMaster committed
299
300
301
    if has_config("iluvatar-gpu") then
        add_deps("infiniccl-iluvatar")
    end
YdrMaster's avatar
YdrMaster committed
302

spike-zhu's avatar
spike-zhu committed
303
304
305
306
    if has_config("moore-gpu") then
        add_deps("infiniccl-moore")
    end
    
307
308
309
310
311
312
313
    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()
314

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

321
322
323
324
325
326
327
328
329
330
331
332
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()

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