xmake.lua 4.93 KB
Newer Older
PanZezhongQY's avatar
PanZezhongQY committed
1
2
3
4
5
6
7
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

add_includedirs("include")
8
set_encodings("utf-8")
PanZezhongQY's avatar
PanZezhongQY committed
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

if is_mode("debug") then
    add_cxflags("-g -O0")
    add_defines("DEBUG_MODE")
end

-- CPU
option("cpu")
    set_default(true)
    set_showmenu(true)
    set_description("Whether to complie implementations for CPU")
option_end()

option("omp")
    set_default(false)
    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

-- 英伟达
option("nv-gpu")
    set_default(false)
    set_showmenu(true)
    set_description("Whether to complie implementations for Nvidia GPU")
option_end()

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

-- 寒武纪
option("cambricon-mlu")
    set_default(false)
    set_showmenu(true)
    set_description("Whether to complie implementations for Cambricon MLU")
option_end()

if has_config("cambricon-mlu") then
    add_defines("ENABLE_CAMBRICON_API")
PanZezhong's avatar
PanZezhong committed
54
    includes("xmake/bang.lua")
PanZezhongQY's avatar
PanZezhongQY committed
55
56
57
58
59
60
61
62
63
64
65
end

-- 华为昇腾
option("ascend-npu")
    set_default(false)
    set_showmenu(true)
    set_description("Whether to complie implementations for Huawei Ascend NPU")
option_end()

if has_config("ascend-npu") then
    add_defines("ENABLE_ASCEND_API")
Pan Zezhong's avatar
Pan Zezhong committed
66
    includes("xmake/ascend.lua")
PanZezhongQY's avatar
PanZezhongQY committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
end

-- 沐曦
option("metax-gpu")
    set_default(false)
    set_showmenu(true)
    set_description("Whether to complie implementations for MetaX GPU")
option_end()

if has_config("metax-gpu") then
    add_defines("ENABLE_MACA_API")
end

-- 摩尔线程
option("moore-gpu")
    set_default(false)
    set_showmenu(true)
    set_description("Whether to complie implementations for Moore Threads GPU")
option_end()

87
if has_config("moore-gpu") then
88
89
    add_defines("ENABLE_MUSA_API")
end
PanZezhongQY's avatar
PanZezhongQY committed
90
91
92
93
94
95
96
97
98
99
100
101
102

-- 海光
option("sugon-dcu")
    set_default(false)
    set_showmenu(true)
    set_description("Whether to complie implementations for Sugon DCU")
option_end()

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

103
104
105
106
107
108
109
110
111
112
113
-- 昆仑芯
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
114

PanZezhong's avatar
PanZezhong committed
115
116
target("infini-utils")
    set_kind("static")
PanZezhong's avatar
PanZezhong committed
117
    on_install(function (target) end)
PanZezhong's avatar
PanZezhong committed
118
119
120
121
    set_languages("cxx17")
    add_files("src/utils/*.cc")
target_end()

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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
    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")
    add_installfiles("include/infinirt.h")
target_end()

PanZezhongQY's avatar
PanZezhongQY committed
137
138
target("infiniop")
    set_kind("shared")
139
140
    add_deps("infinirt")

PanZezhongQY's avatar
PanZezhongQY committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
    if has_config("cpu") then
        add_deps("infiniop-cpu")
    end
    if has_config("nv-gpu") then
        add_deps("infiniop-cuda")
    end
    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
163
        add_deps("infiniop-cambricon")
PanZezhongQY's avatar
PanZezhongQY committed
164
165
    end
    if has_config("ascend-npu") then
Pan Zezhong's avatar
Pan Zezhong committed
166
        add_deps("infiniop-ascend")
PanZezhongQY's avatar
PanZezhongQY committed
167
168
169
170
    end
    if has_config("metax-gpu") then
        add_deps("metax-gpu")
    end
171
172
173
    if has_config("kunlun-xpu") then
        add_deps("infiniop-kunlun")
    end
PanZezhongQY's avatar
PanZezhongQY committed
174
175
176
177
178
179
180
181
182
183
184
    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()
185
186
187
188
189
190

target("all")
    set_kind("phony")
    add_deps("infiniop", "infinirt")
    after_build(function (target) print(YELLOW .. "[Congratulations!] Now you can install the libraries with \"xmake install\"" .. NC) end)
target_end()