forked from YdrMaster/operators
-
Notifications
You must be signed in to change notification settings - Fork 5
/
xmake.lua
170 lines (133 loc) · 4.61 KB
/
xmake.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
add_rules("mode.debug", "mode.release")
add_includedirs("include")
option("cpu")
set_default(true)
set_showmenu(true)
set_description("Enable or disable cpu kernel")
add_defines("ENABLE_CPU")
option_end()
option("nv-gpu")
set_default(false)
set_showmenu(true)
set_description("Enable or disable Nvidia GPU kernel")
add_defines("ENABLE_NV_GPU")
option_end()
option("cambricon-mlu")
set_default(false)
set_showmenu(true)
set_description("Enable or disable Cambricon MLU kernel")
add_defines("ENABLE_CAMBRICON_MLU")
option_end()
if is_mode("debug") then
add_cxflags("-g -O0")
add_defines("DEBUG_MODE")
end
if has_config("cpu") then
add_defines("ENABLE_CPU")
target("cpu")
set_kind("static")
if not is_plat("windows") then
add_cxflags("-fPIC")
end
set_languages("cxx17")
add_files("src/devices/cpu/*.cc", "src/ops/*/cpu/*.cc")
add_cxflags("-fopenmp")
add_ldflags("-fopenmp")
target_end()
end
if has_config("nv-gpu") then
add_defines("ENABLE_NV_GPU")
target("nv-gpu")
set_kind("static")
set_policy("build.cuda.devlink", true)
set_toolchains("cuda")
add_links("cublas")
add_cugencodes("native")
if is_plat("windows") then
add_cuflags("-Xcompiler=/utf-8", "--expt-relaxed-constexpr", "--allow-unsupported-compiler")
else
add_cuflags("-Xcompiler=-fPIC")
add_culdflags("-Xcompiler=-fPIC")
end
set_languages("cxx17")
add_files("src/devices/cuda/*.cc", "src/ops/*/cuda/*.cu")
target_end()
end
if has_config("cambricon-mlu") then
add_defines("ENABLE_CAMBRICON_MLU")
add_includedirs("/usr/local/neuware/include")
add_linkdirs("/usr/local/neuware/lib64")
add_linkdirs("/usr/local/neuware/lib")
add_links("libcnrt.so")
add_links("libcnnl.so")
add_links("libcnnl_extra.so")
add_links("libcnpapi.so")
rule("mlu")
set_extensions(".mlu")
on_load(function (target)
target:add("includedirs", "include")
end)
on_build_file(function (target, sourcefile)
local objectfile = target:objectfile(sourcefile)
os.mkdir(path.directory(objectfile))
local cc = "/usr/local/neuware/bin/cncc"
local includedirs = table.concat(target:get("includedirs"), " ")
local args = {"-c", sourcefile, "-o", objectfile, "-I/usr/local/neuware/include", "--bang-mlu-arch=mtp_592", "-O3", "-fPIC", "-Wall", "-Werror", "-std=c++17", "-pthread"}
for _, includedir in ipairs(target:get("includedirs")) do
table.insert(args, "-I" .. includedir)
end
os.execv(cc, args)
table.insert(target:objectfiles(), objectfile)
end)
rule_end()
target("cambricon-mlu")
set_kind("static")
set_languages("cxx17")
add_files("src/devices/bang/*.cc", "src/ops/*/bang/*.cc")
add_files("src/ops/*/bang/*.mlu", {rule = "mlu"})
add_cxflags("-lstdc++ -Wall -Werror -fPIC")
target_end()
end
target("operators")
set_kind("shared")
if has_config("cpu") then
add_deps("cpu")
end
if has_config("nv-gpu") then
add_deps("nv-gpu")
end
if has_config("cambricon-mlu") then
add_deps("cambricon-mlu")
end
set_languages("cxx17")
add_files("src/ops/*/operator.cc")
add_files("src/tensor/*.cc")
target_end()
target("main")
set_kind("binary")
add_deps("operators")
set_languages("c11")
add_files("src/main.c")
target_end()
task("install-operators")
set_menu {
usage = "xmake install-operators",
description = "Build and install the operators",
options = {}
}
on_run(function ()
os.exec("xmake --root")
os.exec("mkdir -p $(projectdir)/lib/")
os.exec("cp $(projectdir)/build/linux/x86_64/release/liboperators.so $(projectdir)/lib/")
os.exec("cp -r $(projectdir)/include $(projectdir)/lib/")
-- Define color codes
local GREEN = '\27[0;32m'
local YELLOW = '\27[1;33m'
local NC = '\27[0m' -- No Color
-- Get the current directory
local current_dir = os.curdir()
-- Output messages with colors
os.exec("echo -e '" .. GREEN .. "Compilation completed successfully." .. NC .. "'")
os.exec("echo -e '" .. YELLOW .. "To set the environment variable, please run the following command:" .. NC .. "'")
os.exec("echo -e '" .. YELLOW .. "echo \"export INFINI_ROOT=" .. current_dir .. "/lib\" >> ~/.bashrc" .. NC .. "'")
end)