[PAL] Add NPU device support for FlagCX Ascend communicator - #536
Open
Joiin0392 wants to merge 2 commits into
Open
[PAL] Add NPU device support for FlagCX Ascend communicator#536Joiin0392 wants to merge 2 commits into
Joiin0392 wants to merge 2 commits into
Conversation
- ascend.mk: add default_dev_api_backend.cc to PLATFORM_EXTRA_SRCS
(fixes missing devApiBackend symbols when building with USE_ASCEND=1)
- backend_flagcx.hpp: change devName from 'cann' to 'npu'
(torch_npu registers device type as 'npu' via PrivateUse1,
torch.device('cann') is not recognized by PyTorch)
- _build_config.py: prepend CANN include path before torch_npu bundled
ACL headers (torch_npu 2.11.0 bundles newer ACL headers incompatible
with CANN 8.5.1, causing undefined type errors like aclmdlRITask)
- flagcx_wrapper.py: use getattr chain for stream attribute access
(cuda_stream / npu_stream / musa_stream) to support NPU streams
Tested on Ascend 910B2C / CANN 8.5.1 / torch_npu 2.11.0.
Add package-directory lookup as fallback before source-tree path, so flagcx works without FLAGCX_PATH when build.sh copies libflagcx.so into the installed package directory (industry standard: .so ships with the Python package, like torch/torch_npu).
Joiin0392
requested review from
MC952-arch,
aoyulong and
mikethegoblin
as code owners
August 12, 2026 06:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Category
PAL (Portable Abstraction Layer)
PR Types
Bug Fixes, New Features
PR Description
The FlagCX Ascend adaptor was added in commit #196 (2025-07-22) but has never been CI-tested or successfully built end-to-end. Four bugs prevent
libflagcx.sofrom building and the torch plugin from working on Ascend 910B NPU:1.
makefiles/ascend.mk— MissingPLATFORM_EXTRA_SRCSCommit #522 (2026-07-30) introduced the
device_api/refactor but only updatednvidia.mk. All non-NVIDIA.mkfiles (includingascend.mk) have emptyPLATFORM_EXTRA_SRCS, causingundefined symbol: devApiBackendwhen loadinglibflagcx.so.Fix: Add
default_dev_api_backend.cctoPLATFORM_EXTRA_SRCS.2.
backend_flagcx.hpp— Wrong device name"cann"→"npu"The Ascend adaptor sets
devName = "cann", buttorch_npuregisters the device type as"npu"viaPrivateUse1(from v2.5.1 through v2.11.0).torch.device("cann")is not recognized by PyTorch, causingRuntimeError: Expected one of cpu, cuda, ..., privateuseone device type.Fix: Change
devNamefrom"cann"to"npu".3.
_build_config.py— Missing CANN include pathThe Ascend adaptor config only adds
torch_npu's include directory, but not the CANN toolkit's include path (containinghccl.hand other essential headers). Additionally,torch_npu2.11.0 bundles newer ACL headers (with types likeaclmdlRITask) that are incompatible with CANN 8.5.1, causing compile errors.Fix: Prepend
ASCEND_HOME_PATH/$ARCH-linux/includetoinclude_dirsbeforetorch_npu's bundled headers. The code auto-detects architecture (x86_64-linuxoraarch64-linux).4.
flagcx_wrapper.py— NPU Stream attribute accessadaptor_stream_copy()accessesold_stream.cuda_streamdirectly, but NPUStreamobjects havenpu_stream(notcuda_stream), causingAttributeError: 'Stream' object has no attribute 'cuda_stream'.Fix: Use
getattrchain:musa_stream→npu_stream→cuda_stream→ 0.Additionally,
_find_default_library()now checks the installed flagcx package directory forlibflagcx.so(before falling back to source tree), enabling the industry-standard pattern where.sofiles ship inside the Python package (liketorch/torch_npu).Testing
Environment: Ascend 910B2C x86_64 / CANN 8.5.1 / torch_npu 2.11.0
Tested end-to-end with vllm-plugin-FL on Qwen3.6-35B-A3B (4-card TP=4):
backend=flagcx(HCCL, not NCCL)communicator=CommunicatorFL