Skip to content

Commit ac1a064

Browse files
committed
Add Huawei Ascend C toolchain support
Support for the Bisheng compiler driver and Ascend C kernel language (asc/aicpu source kinds) from the Huawei CANN toolkit. Includes toolchain detection, build rules, NPU architecture flag propagation, and test projects covering static/shared/binary and mixed asc+aicpu targets.
1 parent 267b076 commit ac1a064

22 files changed

Lines changed: 1013 additions & 3 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import("core.language.language")
2+
3+
local function _write_asc_file(name, source)
4+
local sourcefile = os.tmpfile(name) .. ".asc"
5+
io.writefile(sourcefile, source)
6+
return sourcefile
7+
end
8+
9+
function test_check_main(t)
10+
local instance = language.load("ascendc")
11+
t:require(instance)
12+
13+
local check_main = instance:get("check_main")
14+
t:require(check_main)
15+
16+
local mainfile = _write_asc_file("ascendc_check_main", [[
17+
#include "acl/acl.h"
18+
19+
int32_t main(int argc, char const *argv[])
20+
{
21+
return 0;
22+
}
23+
]])
24+
t:are_equal(check_main(mainfile), true)
25+
26+
local commentfile = _write_asc_file("ascendc_check_main_comment", [[
27+
// int main() { return 0; }
28+
/*
29+
int main() { return 1; }
30+
*/
31+
__global__ __vector__ void kernel()
32+
{
33+
}
34+
]])
35+
t:are_equal(check_main(commentfile), false)
36+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "kernel_operator.h"
2+
3+
__global__ __vector__ void hello_world()
4+
{
5+
AscendC::printf("[Block (%lu/%lu)]: Hello World!!!\n", AscendC::GetBlockIdx(), AscendC::GetBlockNum());
6+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "kernel_operator.h"
2+
#include "acl/acl.h"
3+
4+
extern __global__ __vector__ void hello_world();
5+
6+
int32_t main(int argc, char const *argv[])
7+
{
8+
aclInit(nullptr);
9+
int32_t deviceId = 0;
10+
aclrtSetDevice(deviceId);
11+
aclrtStream stream = nullptr;
12+
aclrtCreateStream(&stream);
13+
14+
constexpr uint32_t numBlocks = 8;
15+
hello_world<<<numBlocks, nullptr, stream>>>();
16+
aclrtSynchronizeStream(stream);
17+
18+
aclrtDestroyStream(stream);
19+
aclrtResetDevice(deviceId);
20+
aclFinalize();
21+
return 0;
22+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function main(t)
2+
if not is_host("linux") then
3+
return t:skip("wrong host platform")
4+
end
5+
if not os.getenv("ASCEND_HOME_PATH") then
6+
return t:skip("ASCEND_HOME_PATH not set")
7+
end
8+
t:build()
9+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
add_rules("mode.debug", "mode.release")
2+
3+
target("ascendc_static")
4+
set_kind("static")
5+
set_toolchains("ascendc")
6+
add_files("src/lib.asc")
7+
add_ascnpuarchs("dav-2201")
8+
9+
target("ascendc_shared")
10+
set_kind("shared")
11+
set_toolchains("ascendc")
12+
add_files("src/lib.asc")
13+
add_ascnpuarchs("dav-2201")
14+
15+
target("ascendc_libs_bin")
16+
add_deps("ascendc_static", "ascendc_shared")
17+
set_kind("binary")
18+
set_toolchains("ascendc")
19+
add_files("src/main.asc")
20+
add_ascnpuarchs("dav-2201")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "aicpu_api.h"
2+
3+
__global__ __aicpu__ uint32_t hello_world(void *args)
4+
{
5+
AscendC::printf("Hello World!!!\n");
6+
return 0;
7+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "acl/acl.h"
2+
3+
struct KernelArgs {
4+
int mode;
5+
};
6+
7+
extern __global__ __aicpu__ uint32_t hello_world(void *args);
8+
9+
int32_t main(int argc, char const *argv[])
10+
{
11+
aclInit(nullptr);
12+
int32_t deviceId = 0;
13+
aclrtSetDevice(deviceId);
14+
aclrtStream stream = nullptr;
15+
aclrtCreateStream(&stream);
16+
17+
struct KernelArgs args = {0};
18+
constexpr uint32_t numBlocks = 1;
19+
hello_world<<<numBlocks, nullptr, stream>>>(&args, sizeof(KernelArgs));
20+
aclrtSynchronizeStream(stream);
21+
22+
aclrtDestroyStream(stream);
23+
aclrtResetDevice(deviceId);
24+
aclFinalize();
25+
return 0;
26+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function main(t)
2+
if not is_host("linux") then
3+
return t:skip("wrong host platform")
4+
end
5+
if not os.getenv("ASCEND_HOME_PATH") then
6+
return t:skip("ASCEND_HOME_PATH not set")
7+
end
8+
t:build()
9+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
add_rules("mode.debug", "mode.release")
2+
3+
target("ascendc_mixed")
4+
set_kind("binary")
5+
add_files("src/main.asc", "src/helper.aicpu")
6+
add_ascnpuarchs("dav-2201")

xmake/core/tool/toolchain.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ function _instance:_description(toolkind)
514514
cu = "the cuda compiler",
515515
culd = "the cuda linker",
516516
cuccbin = "the cuda host c++ compiler",
517+
asc = "the ascend c compiler",
518+
aicpu = "the ascend c ai-cpu compiler",
519+
ascld = "the ascend c linker",
520+
ascsh = "the ascend c shared library linker",
517521
nc = "the nim compiler",
518522
ncld = "the nim linker",
519523
ncsh = "the nim shared library linker",

0 commit comments

Comments
 (0)