Skip to content

[Bugfix][TE] Register direct ACL VMM fabric memory as device - #4286

Merged
ascend-direct-dev merged 1 commit into
kvcache-ai:mainfrom
csxxs:fix/ascend-direct-vmm-register-device
Sep 23, 2026
Merged

ascend-direct-dev merged 1 commit into
kvcache-ai:mainfrom
csxxs:fix/ascend-direct-vmm-register-device

Conversation

@csxxs

@csxxs csxxs commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes the memory type used when registering fabric memory, so that fabric memory mode no longer registers every fabric buffer as device memory. Only the buffers that bypass adxl::MallocMem - the direct ACL VMM allocations made by ascend_allocator - are looked back up at registration time and registered as MemType::Device; allocations made through adxl::MallocMem keep using MemType::Host.

Background: the VA of a direct ACL VMM allocation is reported by aclrtPointerGetAttributes() as HOST / HOST_NUMA, so it was classified as MEM_HOST. With the buffer pool enabled, registerMem skips MEM_HOST buffers entirely, and the fabric transfer path does not fall back to a local copy, so D2H/H2D transfers fail. An earlier revision registered everything as MEM_DEVICE whenever use_fabric_mem_ was set, which also changed allocations that ADXL owns and exports through its own host-memory path. This PR instead distinguishes allocations by their origin.

Changes:

  1. ascend_allocator: the allocation table (AllocRecord) now records the allocation size, and a new ascend_is_direct_vmm_memory() looks an address back up in it. The lookup only matches records flagged as direct allocations, so buffers returned by adxl::MallocMem (recorded with is_direct_alloc == false) can never match. Both insertion points of AllocRecord record the length.
  2. AscendDirectTransport::registerLocalMemory(): when this TE is a fabric TE and the buffer is a direct VMM allocation, mem_type is overridden to adxl::MEM_DEVICE. The override is one-way (Host -> Device), so explicitly device memory such as location="npu" is unaffected. The gate is use_fabric_mem_ (this TE's own fabric flag) rather than the process-wide config, so a co-located non-fabric TE is not affected.
  3. ascend_allocator: the direct VMM path now calls aclrtMemSetAccess after aclrtMapMem, granting the current device read/write access, and rolls back with Unmap + ReleaseMemAddress + FreePhysical if the grant fails. aclrtMapMem only binds the pages to the host, so the NPU needs this explicit grant; adxl::MallocMem does the same for its own allocations.

Per request, this PR contains no unit test changes.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake Conductor (mooncake-conductor)
  • Reshard (mooncake-reshard)
  • Mooncake EP (mooncake-ep)
  • Mooncake PG (mooncake-pg)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • Common (mooncake-common)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Performance improvement
  • Other

How Has This Been Tested?

Built and ran the Ascend transport unit tests on an aarch64 Linux VM with -DUSE_ASCEND_DIRECT=ON.

Test commands:

cmake -DUSE_ASCEND_DIRECT=ON ..
make mooncake_store transfer_engine ascend_transport
make ascend_direct_transport_test && ./ascend_direct_transport_test
./scripts/code_format.sh

Test results:

  • Unit tests pass (ascend_direct_transport_test: 79 tests passed)
  • Integration tests pass (if applicable)
  • Manual testing done (describe below)

There is no NPU on this host, so verification covers compilation, the unit test suite, and code_format only. End-to-end fabric D2H/H2D transfers on real hardware, plus the RegisterMem return value, still need a run on an A3 machine.

Checklist

  • I have performed a self-review of my own code
  • I have formatted my code using ./scripts/code_format.sh
  • I have run pre-commit on the files changed in this PR and all hooks pass
  • I have updated the documentation (if applicable)
  • I have added tests to prove my changes are effective
  • For changes >500 LOC: I have filed an RFC issue

Notes for reviewers

  • The lookup matches on the start address only and does not require the registered range to be contained in the allocation. A caller may register a longer range than was allocated - a store segment is mounted at its requested size, while best-effort fabric allocation (align_down_1g or a percentile step down) can return less. Requiring full containment would silently keep that buffer as MEM_HOST, which is exactly the bug this PR fixes, so the lookup would not take effect on the store segment path.
  • Related but out of scope: with split_limit set, real_client.cpp mounts segment_size even when mapped_size is smaller, so the capacity reported to the master can exceed the memory that was actually mapped (mapped_size < segment_size). Worth a separate look; it is not touched here.
  • The location.id for aclrtMemSetAccess must be a driver logical id while aclrtGetDevice returns a user id. The conversion follows the existing code in shared_segment/ascend_shared_segment.cpp. Deployments that expose only a subset through ASCEND_RT_VISIBLE_DEVICES are worth a confirmation on real hardware.
  • The existing mock unit test ascend_direct_transport_test.cpp implements its own set of ACL stubs, and the two calls added here (aclrtGetLogicDevIdByUserDevId, aclrtMemSetAccess) are not stubbed. Per request this PR does not touch test files; if needed later, the stubs are aclrtGetLogicDevIdByUserDevId writing back its argument and aclrtMemSetAccess returning ACL_ERROR_NONE.
    • Impact: that test's aclrtReserveMemAddress stub returns a malloc(64) pointer rather than a real ACL VMM address. On a machine without an NPU these two real library calls "succeed" spuriously (measured: aclrtGetLogicDevIdByUserDevId(0) == 0 and aclrtMemSetAccess(malloc_ptr) == 0), which is why all 79 tests pass here. On an A3 machine with an NPU, aclrtMemSetAccess will likely reject that non-ACL address, the grant returns -1, allocation returns nullptr, and AgentModeAllocTest.DirectVmmDoesNotRotateSequencer plus FabricMemBestEffortAllocTest.* would fail.
    • The Ascend CI runs with BUILD_UNIT_TESTS=OFF, so CI will not surface this.

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used (specify below)

The changes were written with AI assistance and reviewed; the submitter is responsible for the content.

Fabric memory mode must not register every fabric buffer as device memory.
Only the allocations that bypass adxl::MallocMem - the direct ACL VMM
allocations made by ascend_allocator - need MEM_DEVICE registration, because
ADXL does not know about them and reads their VA back as HOST. Allocations
made through adxl::MallocMem stay MEM_HOST and keep using ADXL's own
host-memory export path.

Changes:
- Record the allocation size in the VMM allocation table and look an address
  back up in it: ascend_is_direct_vmm_memory() only matches records flagged as
  direct allocations, so adxl::MallocMem records never match. It matches on
  the start address only, because a caller may register a longer range than
  was allocated and requiring full containment would silently keep that buffer
  as MEM_HOST.
- AscendDirectTransport::registerLocalMemory() overrides mem_type to
  MEM_DEVICE when this TE is fabric enabled and the buffer is a direct VMM
  allocation.
- Grant the current device read/write access after aclrtMapMem in the direct
  VMM path, and roll back unmap/release/free if the grant fails. Host pages are
  only bound to the host by aclrtMapMem, so the NPU needs this explicit grant
  before SDMA can reach them; adxl::MallocMem does the same for its own
  allocations.

Co-authored-by: Cursor <[email protected]>
@csxxs
csxxs force-pushed the fix/ascend-direct-vmm-register-device branch from 9041064 to 2e21aa5 Compare September 23, 2026 01:40
@ascend-direct-dev
ascend-direct-dev marked this pull request as ready for review September 23, 2026 03:49

@ascend-direct-dev ascend-direct-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ascend-direct-dev
ascend-direct-dev enabled auto-merge (squash) September 23, 2026 03:50
@ascend-direct-dev
ascend-direct-dev enabled auto-merge (squash) September 23, 2026 03:50
@ascend-direct-dev
ascend-direct-dev merged commit 5772765 into kvcache-ai:main Sep 23, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants