Add Huawei Ascend C toolchain support#7510
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for the Huawei Ascend C (bisheng) toolchain, adding the ascendc language and associated build rules for .asc and .aicpu files. Feedback points out a potential failure in temporary file creation due to invalid characters in filenames and a regex limitation in the main function detection logic.
9cab4bf to
5dae47e
Compare
| self:set("ascshflags", "-shared") | ||
| -- default C++ standard and source kind for bisheng compiler driver | ||
| self:add("ascflags", "-std=c++17", {force = true}) | ||
| self:add("aicpuflags", "-std=c++17", {force = true}) |
There was a problem hiding this comment.
这种不对,应该放到 rules 里去设置 default languages,并且用户如果配置了 set_languages ,应该优先使用,而不是这里写死。
| target:add("rpathdirs", path.join(hostroot, "lib64")) | ||
| target:add("rpathdirs", path.join(hostroot, "devlib")) | ||
| target:add("rpathdirs", path.join(sdkdir, "lib64")) | ||
| target:add("syslinks", "ascendcl", "acl_rt", "dl") |
| local hostroot = path.join(sdkdir, host_archdir) | ||
|
|
||
| -- aicpu-specific flags (SDK-path-dependent) | ||
| target:add("aicpuflags", "-O2") |
There was a problem hiding this comment.
这个不要用 flags ,跟 languages 一样处理,走 set_optimize , 并且用户可覆盖
| , x64 = "x86_64-linux" | ||
| , arm64 = "aarch64-linux" | ||
| , aarch64 = "aarch64-linux" | ||
| } |
There was a problem hiding this comment.
没必要三个地方去处理 hostdirs, 统一 check 里处理,load 里通过 toolchain:config 获取 hostroot
|
|
||
| -- check toolchain | ||
| on_check(function (toolchain) | ||
| return import("toolchains.ascendc.check", {rootdir = os.programdir()})(toolchain) |
|
|
||
| -- on load | ||
| on_load(function (toolchain) | ||
| import("toolchains.ascendc.load", {rootdir = os.programdir()})(toolchain) |
Add toolchain, language, rules, and compiler modules for the bisheng compiler driver from CANN (Compute Architecture for Neural Networks) toolkit. Supports .asc (Ascend C kernel) and .aicpu (AI-CPU operator) source kinds with binary/static/shared target types. - Toolchain: SDK auto-detection via ASCEND_HOME_PATH env or --sdk - Compiler: bisheng module inherits from clang, adds add_sourceflags for explicit sourcekind overrides - Rules: ascendc.env (default C++17), npuarchs (--npu-arch), build - Language: check_main detection, add_ascnpuarchs API - Tests: unit tests for check_main, project tests for libs/mixed Fixes xmake-io#7506
| rule("ascendc.env") | ||
| after_load(function (target) | ||
| -- set default C++ standard (user can override via set_languages) | ||
| target:add("languages", "c++17") |
| rule("ascendc.env") | ||
| after_load(function (target) | ||
| -- set default C++ standard (user can override via set_languages) | ||
| target:add("languages", "c++17") |
There was a problem hiding this comment.
另外,没必要搞这么多 rules,参考 c++ rules 的。
还有这个 rule 和 ascendc.npuarchs 都没跟 sourcekinds 绑定,会全局影响所有语言。不应该在这里配置。
| -- resolve sdkdir: --sdk= > ASCEND_HOME_PATH > ASCEND_TOOLKIT_HOME | ||
| local sdkroot = toolchain:sdkdir() | ||
| if not sdkroot then | ||
| sdkroot = os.getenv("ASCEND_HOME_PATH") or os.getenv("ASCEND_TOOLKIT_HOME") |
There was a problem hiding this comment.
这里也不对,toolchain:sdkdir 是在 load 里和其他地方用的,check 阶段 ,toolchain:config("sdkdir") 都还没设置上,不能用 sdkdir 。。
另外应该在 detect.sdks. 里取做 sdk 的 find 逻辑,参考其他的,这里 check 搞得太复杂。
| -- | ||
|
|
||
| function main(toolchain) | ||
| local sdkdir = toolchain:config("sdkdir") |
| toolchain:add("syslinks", "ascendcl", "acl_rt", "dl") | ||
|
|
||
| -- aicpu-specific compiler flags (SDK-path-dependent) | ||
| toolchain:add("aicpuflags", "-fvisibility-inlines-hidden") |
| -- aicpu-specific compiler flags (SDK-path-dependent) | ||
| toolchain:add("aicpuflags", "-fvisibility-inlines-hidden") | ||
| toolchain:add("aicpuflags", "-D_GLIBCXX_USE_CXX11_ABI=0") | ||
| toolchain:add("aicpuflags", "-D_GNU_SOURCE") |
Add toolchain support for Huawei Ascend C — the C++ extension
language for writing custom NPU operators on Ascend AI
processors (Da Vinci architecture). This uses the Bisheng compiler
driver (bisheng) from the CANN (Compute Architecture for
Neural Networks) toolkit.
Fixes #7506
ASCEND_HOME_PATH/ASCEND_TOOLKIT_HOMEenv vars or--ascendc=configasc,aicpu) and linker (ascld,ascsh)-std=c++17,-fPIC, and AI-CPU specific flags.asc(Ascend C kernel) and.aicpu(AI-CPU custom operator)binary,static,sharedadd_ascnpuarchs("dav-2201")API for NPU architecture selection--npu-archflags across compile and link stages.asc/.aicpuextensionsascendc.npuarchs: collects NPU arch from targets/options/toolchains, distributes toascflags/shflags/ldflagsascendc.build.asc/ascendc.build.aicpu: batch compilation via jobgraphutils.inherit.links: automatic link inheritance from dependenciestests/projects/ascendc/libs/: static + shared + binary targets with ACL runtimetests/projects/ascendc/mixed_binary/: mixed.asc+.aicpucompilationtests/modules/language/ascendc/: check_main entry-point detection unit testASCEND_HOME_PATHenvironment variableUsage
xmake f --toolchain=ascendc --ascendc=/usr/local/Ascend/ascend-toolkit/latest
xmake
Verification
Tested on a real Ascend NPU server (CANN 8.5.0, aarch64):