Skip to content

fix: add CPU memory space detection - #79

Merged
Ziminli merged 2 commits into
InfiniTensor:masterfrom
xingjiangjun:fix/cpu-memory-space
Oct 15, 2026
Merged

Ziminli merged 2 commits into
InfiniTensor:masterfrom
xingjiangjun:fix/cpu-memory-space

Conversation

@xingjiangjun

Copy link
Copy Markdown
Contributor

Summary

Add the missing GetMemorySpace<Device::Type::kCpu> specialization in src/devices/cpu/device_.h.

The CPU device currently lacks this specialization, which can cause undefined reference errors when CPU execution paths use GetMemorySpace<kCpu>.

This change completes the CPU memory-space interface by returning MemorySpace::kHost.

Changes

  • CPU Device
    • Implement the missing GetMemorySpace<kCpu> specialization.
    • Classify CPU memory as MemorySpace::kHost.
    • Keep the change limited to src/devices/cpu/device_.h, without modifying public APIs or communication algorithms.

Platform and Backend Affected

Platform

  • CPU
  • NVIDIA GPU
  • Iluvatar GPU
  • MetaX GPU
  • Moore Threads GPU
  • Cambricon MLU
  • HYGON DCU
  • T-Head PPU

Backend

  • OpenMPI
  • MPICH
  • NCCL/RCCL
  • MCCL
  • CNCL

The implementation is device-level and is not inherently tied to a specific communication backend. OpenMPI is the validated configuration.

Performance Impact

  • No performance impact
  • Performance improved
  • Performance regression possible

No performance impact is expected because this change provides a missing memory-space specialization without modifying existing communication algorithms.

Benchmark: N/A.

Known Issues & Future Work

  • No functional regressions were observed in the tested CPU/OpenMPI configuration.
  • Other backend and device configurations have not been validated.

Test Results

Test Environment

  • Container: NVIDIA PyTorch 24.10
  • Compiler: GCC 11.4
  • MPI: OpenMPI 4.1.7
  • Platform: CPU-only
  • MPI ranks: 2 local ranks
  • Base code: Current PR branch based on upstream master

Build configuration:

-DAUTO_DETECT_DEVICES=OFF
-DWITH_NVIDIA=OFF
-DWITH_OMPI=ON
-DBUILD_EXAMPLES=ON

Test Execution

Executed the official scripts/run_examples.py test suite using the CPU-only OpenMPI configuration.

Results:

  • Total tests: 9
  • Passed: 9
  • Failed: 0
  • Success rate: 100%

Passed examples:

  • mpi/all_reduce
  • mpi/all_gather
  • mpi/reduce
  • mpi/all_to_all
  • mpi/reduce_scatter
  • mpi/scatter
  • mpi/broadcast
  • mpi/gather
  • mpi/send_recv

The Broadcast example also passed all three scenarios:

  • Out-of-Place Broadcast
  • In-Place Broadcast
  • Legacy In-Place Bcast

All selected examples completed successfully.

Per-example test logs were generated by the official test harness and will be provided as an archive in a follow-up PR comment.

Test Involved Platform

  • CPU
  • NVIDIA GPU
  • Iluvatar GPU
  • MetaX GPU
  • Moore Threads GPU
  • Cambricon MLU
  • HYGON DCU
  • T-Head PPU

Test Involved Backend

  • OpenMPI
  • MPICH
  • NCCL/RCCL
  • MCCL
  • CNCL

Checklist

Title, Branch, and Commits

  • PR title follows Conventional Commits.
  • Branch name follows the fix/ naming convention.
  • Commit message follows Conventional Commits.
  • The PR contains a single focused commit.
  • No unrelated merge commits are included.
  • No fixup!, squash!, or wip commits remain.

Scope and Design

  • Changes are minimal and limited to the CPU memory-space specialization.
  • No unrelated code, debug output, or TODOs were introduced.
  • No unrelated formatting changes were introduced.
  • No public API changes were made.

General Code Hygiene

  • The implementation is concise and self-explanatory.
  • The trailing newline and whitespace conventions have not been independently checked by a formatting tool.
  • The added code follows the surrounding indentation style.
  • N/A: No new diagnostic messages or explanatory comments were introduced.

C++ Specific

  • The implementation follows the surrounding C++ code structure and indentation conventions.
  • clang-format-16 has not been run because it is unavailable in the current environment.
  • No exceptions are thrown by the new implementation.
  • No unsafe pointer arithmetic or memory operations were introduced.
  • The added function is separated from the preceding declaration by one blank line.
  • Namespace spacing follows the existing source layout.
  • N/A: No constructors, class members, or diagnostic messages were added.

Python Specific

  • N/A: No Python files were modified.

Testing

  • The CPU-only OpenMPI build completed successfully.
  • All nine selected MPI examples passed using two local CPU ranks.
  • Broadcast passed all three supported scenarios in its example.
  • A separate heterogeneous multi-node cluster test has not been performed.

Build, CI, and Tooling

  • N/A: No new device or backend was introduced, so CMake auto-detection does not require changes.
  • Local CI formatting workflows have not been executed.
  • GitHub CI results are pending.

Documentation

  • N/A: No new public API, build option, or user-facing workflow was introduced.
  • N/A: No breaking changes were introduced.

Security and Safety

  • No secrets, access tokens, internal URLs, customer data, or personal hardware identifiers were added.
  • N/A: No third-party code was introduced.
  • No unsafe pointer arithmetic, uninitialized reads, or missing bounds checks were introduced.
    run_20261014_121207.zip

Add the missing GetMemorySpace specialization for the CPU device.
CPU memory is classified as host memory.
@Ziminli
Ziminli self-requested a review October 15, 2026 06:02
@Ziminli
Ziminli merged commit c787883 into InfiniTensor:master Oct 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants