Skip to content

Commit fecafdb

Browse files
committed
build: 适配沐曦
Signed-off-by: YdrMaster <ydrml@hotmail.com>
1 parent 01b39e8 commit fecafdb

22 files changed

Lines changed: 130 additions & 78 deletions

File tree

Cargo.toml

100644100755
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ infini-op = { git = "https://github.com/InfiniTensor/infini-toolkit", rev = "e83
1212
infini-ccl = { git = "https://github.com/InfiniTensor/infini-toolkit", rev = "e8362c3" }
1313
search-infini-tools = { git = "https://github.com/InfiniTensor/infini-toolkit", rev = "e8362c3" }
1414

15-
cuda = { git = "https://github.com/YdrMaster/cuda-driver", rev = "b0148c0" }
16-
cublas = { git = "https://github.com/YdrMaster/cuda-driver", rev = "b0148c0" }
17-
nccl = { git = "https://github.com/YdrMaster/cuda-driver", rev = "b0148c0" }
18-
search-cuda-tools = { git = "https://github.com/YdrMaster/cuda-driver", rev = "b0148c0" }
19-
search-corex-tools = { git = "https://github.com/YdrMaster/cuda-driver", rev = "b0148c0" }
15+
cuda = { git = "https://github.com/YdrMaster/cuda-driver", rev = "40e91cd" }
16+
cublas = { git = "https://github.com/YdrMaster/cuda-driver", rev = "40e91cd" }
17+
nccl = { git = "https://github.com/YdrMaster/cuda-driver", rev = "40e91cd" }
18+
search-cuda-tools = { git = "https://github.com/YdrMaster/cuda-driver", rev = "40e91cd" }
19+
search-corex-tools = { git = "https://github.com/YdrMaster/cuda-driver", rev = "40e91cd" }
20+
search-maca-tools = { git = "https://github.com/YdrMaster/cuda-driver", rev = "40e91cd" }

operators/Cargo.toml

100644100755
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ edition.workspace = true
55
authors = ["YdrMaster <ydrml@hotmail.com>"]
66

77
[features]
8-
default = ["common-cpu", "opencl", "infini", "nvidia-gpu", "iluvatar-gpu"]
8+
default = [
9+
"common-cpu",
10+
"opencl",
11+
"infini",
12+
"nvidia-gpu",
13+
"iluvatar-gpu",
14+
"metax-gpu",
15+
]
916
common-cpu = ["gemm"]
1017
opencl = ["clrt"]
1118
infini = ["infini-rt", "infini-op", "infini-ccl"]
1219
nvidia-gpu = ["cuda", "cublas", "nccl", "fslock", "libloading"]
1320
iluvatar-gpu = ["cuda", "cublas", "fslock", "libloading"]
21+
metax-gpu = ["cuda", "cublas", "nccl", "fslock", "libloading"]
1422

1523
[dependencies]
1624
digit-layout = "0.3"
@@ -42,6 +50,7 @@ search-cl-tools.workspace = true
4250
search-infini-tools.workspace = true
4351
search-cuda-tools.workspace = true
4452
search-corex-tools.workspace = true
53+
search-maca-tools.workspace = true
4554

4655
[dev-dependencies]
4756
gemm = "0.18"

operators/build.rs

100644100755
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ fn main() {
44
use search_corex_tools::find_corex;
55
use search_cuda_tools::{find_cuda_root, find_nccl_root};
66
use search_infini_tools::{find_infini_ccl, find_infini_op, find_infini_rt};
7+
use search_maca_tools::find_maca_root;
78

89
let cpu = Cfg::new("use_cpu");
910
let cl = Cfg::new("use_cl");
@@ -12,6 +13,7 @@ fn main() {
1213
let nvidia = Cfg::new("use_nvidia");
1314
let nccl = Cfg::new("use_nccl");
1415
let iluvatar = Cfg::new("use_iluvatar");
16+
let metax = Cfg::new("use_metax");
1517

1618
if cfg!(feature = "common-cpu") {
1719
cpu.define()
@@ -27,20 +29,22 @@ fn main() {
2729
infini.define()
2830
}
2931

30-
// iluvatar
31-
let use_iluvatar = cfg!(feature = "iluvatar-gpu") && find_corex().is_some();
32-
if use_iluvatar {
33-
iluvatar.define();
34-
cuda.define();
35-
return;
36-
}
37-
3832
let use_nvidia = cfg!(feature = "nvidia-gpu") && find_cuda_root().is_some();
39-
if use_nvidia {
33+
let use_iluvatar = cfg!(feature = "iluvatar-gpu") && find_corex().is_some();
34+
let use_metax = cfg!(feature = "metax-gpu") && find_maca_root().is_some();
35+
if use_metax {
36+
metax.define();
37+
nccl.define()
38+
} else if use_iluvatar {
39+
iluvatar.define()
40+
} else if use_nvidia {
4041
nvidia.define();
4142
if find_nccl_root().is_some() {
4243
nccl.define()
4344
}
44-
cuda.define();
45+
}
46+
47+
if use_nvidia || use_iluvatar || use_metax {
48+
cuda.define()
4549
}
4650
}

operators/src/add/cuda/mod.rs

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ mod test {
162162
rand::rng().fill(&mut b[..]);
163163
let data_ans = gpu.apply(|ctx| {
164164
let stream = ctx.stream();
165-
#[cfg(use_nvidia)]
165+
#[cfg(not(use_iluvatar))]
166166
let rt = &stream;
167167
#[cfg(use_iluvatar)]
168168
let rt = ctx;

operators/src/all_reduce/nccl.rs

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ impl crate::Operator for Operator {
6060
fn convert_enum(op: ReduceOp) -> nccl::ReduceType {
6161
use nccl::ReduceType::*;
6262
match op {
63-
ReduceOp::Sum => ncclSum,
64-
ReduceOp::Prod => ncclProd,
65-
ReduceOp::Min => ncclMin,
66-
ReduceOp::Max => ncclMax,
67-
ReduceOp::Mean => ncclAvg,
63+
ReduceOp::Sum => hcclSum,
64+
ReduceOp::Prod => hcclProd,
65+
ReduceOp::Min => hcclMin,
66+
ReduceOp::Max => hcclMax,
67+
ReduceOp::Mean => hcclAvg,
6868
}
6969
}

operators/src/attention/cuda.rs

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ mod test {
6969

7070
let o_ans = gpu.apply(|ctx| {
7171
let stream = ctx.stream();
72-
#[cfg(use_nvidia)]
72+
#[cfg(not(use_iluvatar))]
7373
let rt = &stream;
7474
#[cfg(use_iluvatar)]
7575
let rt = ctx;

operators/src/attention_kv_cached/cuda.rs

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ mod test {
8080

8181
let o_ans = gpu.apply(|ctx| {
8282
let stream = ctx.stream();
83-
#[cfg(use_nvidia)]
83+
#[cfg(not(use_iluvatar))]
8484
let rt = &stream;
8585
#[cfg(use_iluvatar)]
8686
let rt = ctx;

operators/src/fuesd_softmax/cuda/fused_softmax.cuh

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static __device__ void block_padding(
2828
unsigned int const tok_id,
2929
unsigned int const seq_len) {
3030

31-
auto att_idx = threadIdx.x, att_len = blockDim.x;
31+
unsigned int att_idx = threadIdx.x, att_len = blockDim.x;
3232
auto thread_data = mask(tok_id, seq_len, att_idx, att_len)
3333
? float(att[att_idx])
3434
: -__FLT_MAX__;

operators/src/handle/cuda/alloc.rs

100644100755
File mode changed.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
local MACA_ROOT = os.getenv("MACA_PATH") or os.getenv("MACA_HOME") or os.getenv("MACA_ROOT")
2+
add_includedirs(MACA_ROOT .. "/include")
3+
add_linkdirs(MACA_ROOT .. "/lib")
4+
add_links("hcdnn", "hcblas", "hcruntime")
5+
6+
rule("maca")
7+
set_extensions(".maca")
8+
9+
on_load(function (target)
10+
target:add("includedirs", "include")
11+
end)
12+
13+
on_build_file(function (target, sourcefile)
14+
local objectfile = target:objectfile(sourcefile)
15+
os.mkdir(path.directory(objectfile))
16+
local htcc = path.join(MACA_ROOT, "htgpu_llvm/bin/htcc")
17+
local includedirs = target:get("includedirs") .. " "
18+
19+
local args = { "-x", "hpcc", "-c", sourcefile, "-o", objectfile, "-I" .. MACA_ROOT .. "/include", "-O3", "-fPIC", "-Werror", "-std=c++17"}
20+
21+
for _, includedir in ipairs(target:get("includedirs")) do
22+
table.insert(args, "-I" .. includedir)
23+
end
24+
25+
os.execv(htcc, args)
26+
table.insert(target:objectfiles(), objectfile)
27+
end)
28+
rule_end()
29+
30+
target("lib")
31+
set_kind("shared")
32+
set_optimize("aggressive")
33+
set_languages("cxx17")
34+
set_warnings("all", "error")
35+
add_cxflags("-lstdc++", "-fPIC", "-Wno-defaulted-function-deleted", "-Wno-strict-aliasing")
36+
add_files("src.maca", {rule = "maca"})
37+
target_end()

0 commit comments

Comments
 (0)