Skip to content

Commit 1d6781d

Browse files
authored
Resolved conflicts in xmake.lua
1 parent fc15152 commit 1d6781d

File tree

1 file changed

+160
-9
lines changed

1 file changed

+160
-9
lines changed

xmake.lua

Lines changed: 160 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
add_rules("mode.debug", "mode.release")
2-
3-
-- Define color codes
42
-- Define color codes
5-
local GREEN = "\027[0;32m"
6-
local YELLOW = "\027[1;33m"
7-
local NC = "\027[0m" -- No Color
8-
3+
local GREEN = '\27[0;32m'
4+
local YELLOW = '\27[1;33m'
5+
local NC = '\27[0m' -- No Color
96

107
add_includedirs("include")
11-
add_cxxflags("-fPIC")
128

139
option("cpu")
1410
set_default(true)
@@ -44,12 +40,36 @@ option("ascend-npu")
4440
add_defines("ENABLE_ASCEND_NPU")
4541
option_end()
4642

43+
option("metax-gpu")
44+
set_default(false)
45+
set_showmenu(true)
46+
set_description("Enable or disable Metax GPU kernel")
47+
add_defines("ENABLE_METAX_GPU")
48+
option_end()
49+
50+
51+
option("mthreads-gpu")
52+
set_default(false)
53+
set_showmenu(true)
54+
set_description("Enable or disable MThreads GPU kernel")
55+
add_defines("ENABLE_MTHREADS_GPU")
56+
option_end()
57+
58+
option("sugon-dcu")
59+
set_default(false)
60+
set_showmenu(true)
61+
set_description("Enable or disable Sugon DCU kernel")
62+
add_defines("ENABLE_SUGON_DCU")
63+
add_defines("ENABLE_NV_GPU")
64+
option_end()
65+
4766
if is_mode("debug") then
4867
add_cxflags("-g -O0")
4968
add_defines("DEBUG_MODE")
5069
end
5170

5271
if has_config("cpu") then
72+
5373
add_defines("ENABLE_CPU")
5474
target("cpu")
5575
on_install(function (target) end)
@@ -66,10 +86,14 @@ if has_config("cpu") then
6686
add_ldflags("-fopenmp")
6787
end
6888
target_end()
89+
6990
end
7091

71-
if has_config("nv-gpu") then
92+
if has_config("nv-gpu", "sugon-dcu") then
7293
add_defines("ENABLE_NV_GPU")
94+
if has_config("sugon-dcu") then
95+
add_defines("ENABLE_SUGON_DCU")
96+
end
7397
local CUDA_ROOT = os.getenv("CUDA_ROOT") or os.getenv("CUDA_HOME") or os.getenv("CUDA_PATH")
7498
local CUDNN_ROOT = os.getenv("CUDNN_ROOT") or os.getenv("CUDNN_HOME") or os.getenv("CUDNN_PATH")
7599
if CUDA_ROOT ~= nil then
@@ -104,9 +128,11 @@ if has_config("nv-gpu") then
104128
add_files("src/devices/cuda/*.cc", "src/ops/*/cuda/*.cu")
105129
add_files("src/ops/*/cuda/*.cc")
106130
target_end()
131+
107132
end
108133

109134
if has_config("cambricon-mlu") then
135+
110136
add_defines("ENABLE_CAMBRICON_MLU")
111137
add_includedirs("/usr/local/neuware/include")
112138
add_linkdirs("/usr/local/neuware/lib64")
@@ -139,6 +165,7 @@ if has_config("cambricon-mlu") then
139165
os.execv(cc, args)
140166
table.insert(target:objectfiles(), objectfile)
141167
end)
168+
142169
rule_end()
143170

144171
target("cambricon-mlu")
@@ -149,9 +176,56 @@ if has_config("cambricon-mlu") then
149176
add_files("src/ops/*/bang/*.mlu", {rule = "mlu"})
150177
add_cxflags("-lstdc++ -Wall -Werror -fPIC")
151178
target_end()
179+
180+
end
181+
182+
if has_config("mthreads-gpu") then
183+
184+
add_defines("ENABLE_MTHREADS_GPU")
185+
local musa_home = os.getenv("MUSA_INSTALL_PATH")
186+
-- Add include dirs
187+
add_includedirs(musa_home .. "/include")
188+
-- Add shared lib
189+
add_linkdirs(musa_home .. "/lib")
190+
add_links("libmusa.so")
191+
add_links("libmusart.so")
192+
add_links("libmudnn.so")
193+
add_links("libmublas.so")
194+
195+
rule("mu")
196+
set_extensions(".mu")
197+
on_load(function (target)
198+
target:add("includedirs", "include")
199+
end)
200+
201+
on_build_file(function (target, sourcefile)
202+
local objectfile = target:objectfile(sourcefile)
203+
os.mkdir(path.directory(objectfile))
204+
205+
local mcc = "/usr/local/musa/bin/mcc"
206+
local includedirs = table.concat(target:get("includedirs"), " ")
207+
local args = {"-c", sourcefile, "-o", objectfile, "-I/usr/local/musa/include", "-O3", "-fPIC", "-Wall", "-std=c++17", "-pthread"}
208+
for _, includedir in ipairs(target:get("includedirs")) do
209+
table.insert(args, "-I" .. includedir)
210+
end
211+
212+
os.execv(mcc, args)
213+
table.insert(target:objectfiles(), objectfile)
214+
end)
215+
rule_end()
216+
217+
target("mthreads-gpu")
218+
set_kind("static")
219+
set_languages("cxx17")
220+
add_files("src/devices/musa/*.cc", "src/ops/*/musa/*.cc")
221+
add_files("src/ops/*/musa/*.mu", {rule = "mu"})
222+
add_cxflags("-lstdc++ -Wall -fPIC")
223+
target_end()
224+
152225
end
153226

154227
if has_config("ascend-npu") then
228+
155229
add_defines("ENABLE_ASCEND_NPU")
156230
local ASCEND_HOME = os.getenv("ASCEND_HOME")
157231
local SOC_VERSION = os.getenv("SOC_VERSION")
@@ -180,13 +254,15 @@ if has_config("ascend-npu") then
180254
os.exec("make")
181255
os.exec("cp $(projectdir)/src/devices/ascend/build/lib/libascend_kernels.a "..builddir.."/")
182256
os.cd(os.projectdir())
257+
183258
end)
184259
after_clean(function ()
185260
local ascend_build_dir = path.join(os.projectdir(), "src/devices/ascend")
186261
os.cd(ascend_build_dir)
187262
os.exec("make clean")
188263
os.cd(os.projectdir())
189264
os.rm(builddir.. "/libascend_kernels.a")
265+
190266
end)
191267
rule_end()
192268

@@ -202,9 +278,62 @@ if has_config("ascend-npu") then
202278
-- Add operator
203279
add_rules("ascend-kernels")
204280
add_links(builddir.."/libascend_kernels.a")
281+
282+
target_end()
283+
end
284+
285+
if has_config("metax-gpu") then
286+
287+
add_defines("ENABLE_METAX_GPU")
288+
local MACA_ROOT = os.getenv("MACA_PATH") or os.getenv("MACA_HOME") or os.getenv("MACA_ROOT")
289+
290+
add_includedirs(MACA_ROOT .. "/include")
291+
add_linkdirs(MACA_ROOT .. "/lib")
292+
-- add_linkdirs(MACA_ROOT .. "htgpu_llvm/lib")
293+
add_links("libhcdnn.so")
294+
add_links("libhcblas.so")
295+
add_links("libhcruntime.so")
296+
297+
rule("maca")
298+
set_extensions(".maca")
299+
300+
on_load(function (target)
301+
target:add("includedirs", "include")
302+
end)
303+
304+
on_build_file(function (target, sourcefile)
305+
local objectfile = target:objectfile(sourcefile)
306+
os.mkdir(path.directory(objectfile))
307+
local htcc = "/opt/hpcc/htgpu_llvm/bin/htcc"
308+
309+
local includedirs = table.concat(target:get("includedirs"), " ")
310+
local args = { "-x", "hpcc", "-c", sourcefile, "-o", objectfile, "-I/opt/hpcc/include", "-O3", "-fPIC", "-Werror", "-std=c++17"}
311+
312+
for _, includedir in ipairs(target:get("includedirs")) do
313+
table.insert(args, "-I" .. includedir)
314+
end
315+
316+
os.execv(htcc, args)
317+
table.insert(target:objectfiles(), objectfile)
318+
end)
319+
rule_end()
320+
321+
target("metax-gpu")
322+
set_kind("static")
323+
on_install(function (target) end)
324+
set_languages("cxx17")
325+
add_files("src/devices/maca/*.cc", "src/ops/*/maca/*.cc")
326+
add_files("src/ops/*/maca/*.maca", {rule = "maca"})
327+
add_cxflags("-lstdc++ -Werror -fPIC")
205328
target_end()
329+
206330
end
207331

332+
333+
toolchain("sugon-dcu-linker")
334+
set_toolset("sh", "nvcc")
335+
toolchain_end()
336+
208337
target("infiniop")
209338
set_kind("shared")
210339

@@ -214,12 +343,33 @@ target("infiniop")
214343
if has_config("nv-gpu") then
215344
add_deps("nv-gpu")
216345
end
346+
if has_config("sugon-dcu") then
347+
local builddir = string.format(
348+
"build/%s/%s/%s",
349+
get_config("plat"),
350+
get_config("arch"),
351+
get_config("mode")
352+
)
353+
add_shflags("-s", "-shared", "-fPIC")
354+
add_links("cublas", "cudnn", "cudadevrt", "cudart_static", "rt", "pthread", "dl")
355+
-- Using -lnv-gpu will fail, manually link the target using full path
356+
add_deps("nv-gpu", {inherit = false})
357+
add_links(builddir.."/libnv-gpu.a")
358+
set_toolchains("sugon-dcu-linker")
359+
end
360+
217361
if has_config("cambricon-mlu") then
218362
add_deps("cambricon-mlu")
219363
end
220364
if has_config("ascend-npu") then
221365
add_deps("ascend-npu")
222366
end
367+
if has_config("metax-gpu") then
368+
add_deps("metax-gpu")
369+
end
370+
if has_config("mthreads-gpu") then
371+
add_deps("mthreads-gpu")
372+
end
223373
set_languages("cxx17")
224374
add_files("src/devices/handle.cc")
225375
add_files("src/ops/*/operator.cc")
@@ -229,4 +379,5 @@ target("infiniop")
229379
set_installdir(os.getenv("INFINI_ROOT") or (os.getenv(is_host("windows") and "HOMEPATH" or "HOME") .. "/.infini"))
230380
add_installfiles("include/(**/*.h)", {prefixdir = "include"})
231381
add_installfiles("include/*.h", {prefixdir = "include"})
232-
target_end()
382+
383+
target_end()

0 commit comments

Comments
 (0)