xmake.lua 7.52 KB
Newer Older
PanZezhongQY's avatar
PanZezhongQY committed
1
2
3
4
5
6
add_rules("mode.debug", "mode.release")
-- Define color codes
local GREEN = '\27[0;32m'
local YELLOW = '\27[1;33m'
local NC = '\27[0m'  -- No Color

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

9
10
add_includedirs("include")

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

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

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

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

39
40
41
42
if has_config("omp") then
    add_defines("ENABLE_OMP")
end

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

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

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

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

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

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

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

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

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

if has_config("iluvatar-gpu") then
    add_defines("ENABLE_CUDA_API")
    add_defines("ENABLE_ILUVATAR_CUDA_API")
    includes("xmake/iluvatar.lua")
end

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

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

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

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

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

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

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

149
150
151
152
153
-- InfiniCCL
option("ccl")
set_default(false)
    set_default(false)
    set_showmenu(true)
YdrMaster's avatar
YdrMaster committed
154
    set_description("Wether to compile implementations for InfiniCCL")
155
156
157
158
159
160
option_end()

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

PanZezhong's avatar
PanZezhong committed
161
162
target("infini-utils")
    set_kind("static")
PanZezhong's avatar
PanZezhong committed
163
    on_install(function (target) end)
PanZezhong's avatar
PanZezhong committed
164
    set_languages("cxx17")
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180

    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")
            add_ldflags("-fopenmp")
        end
    end

PanZezhong's avatar
PanZezhong committed
181
182
183
    add_files("src/utils/*.cc")
target_end()

184
185
186
187
188
189
190
191
192
target("infinirt")
    set_kind("shared")

    if has_config("cpu") then
        add_deps("infinirt-cpu")
    end
    if has_config("nv-gpu") then
        add_deps("infinirt-cuda")
    end
193
194
195
    if has_config("cambricon-mlu") then
        add_deps("infinirt-cambricon")
    end
196
197
198
    if has_config("ascend-npu") then
        add_deps("infinirt-ascend")
    end
199
200
201
    if has_config("metax-gpu") then
        add_deps("infinirt-metax")
    end
qinyiqun's avatar
qinyiqun committed
202
203
204
    if has_config("moore-gpu") then
        add_deps("infinirt-moore")
    end
YdrMaster's avatar
YdrMaster committed
205
206
207
    if has_config("iluvatar-gpu") then
        add_deps("infinirt-iluvatar")
    end
zhangyue's avatar
zhangyue committed
208
209
210
    if has_config("kunlun-xpu") then
        add_deps("infinirt-kunlun")
    end
211
212
213
    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")
214
    add_installfiles("include/infinirt.h", {prefixdir = "include"})
215
216
target_end()

PanZezhongQY's avatar
PanZezhongQY committed
217
218
target("infiniop")
    set_kind("shared")
219
220
    add_deps("infinirt")

PanZezhongQY's avatar
PanZezhongQY committed
221
222
223
224
225
226
    if has_config("cpu") then
        add_deps("infiniop-cpu")
    end
    if has_config("nv-gpu") then
        add_deps("infiniop-cuda")
    end
YdrMaster's avatar
YdrMaster committed
227
228
229
    if has_config("iluvatar-gpu") then
        add_deps("infiniop-iluvatar")
    end
PanZezhongQY's avatar
PanZezhongQY committed
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
    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")
        -- Using -linfiniop-cuda will fail, manually link the target using full path
        add_deps("nv-gpu", {inherit = false})
        add_links(builddir.."/libinfiniop-cuda.a")
        set_toolchains("sugon-dcu-linker")
    end

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

272
273
274
275
276
277
278
target("infiniccl")
    set_kind("shared")
    add_deps("infinirt")

    if has_config("nv-gpu") then
        add_deps("infiniccl-cuda")
    end
Pan Zezhong's avatar
Pan Zezhong committed
279
280
281
    if has_config("ascend-npu") then
        add_deps("infiniccl-ascend")
    end
PanZezhong's avatar
PanZezhong committed
282
283
284
    if has_config("metax-gpu") then
        add_deps("infiniccl-metax")
    end
YdrMaster's avatar
YdrMaster committed
285

286
287
288
289
290
291
292
    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()
293

294
295
target("all")
    set_kind("phony")
296
    add_deps("infiniop", "infinirt", "infiniccl")
297
298
    after_build(function (target) print(YELLOW .. "[Congratulations!] Now you can install the libraries with \"xmake install\"" .. NC) end)
target_end()
299
300
301

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