Skip to content

feat(server): add C++ backend placement foundation - #236

Merged
davide221 merged 1 commit into
Luce-Org:mainfrom
weicj:refactor-cpp-placement-config
May 22, 2026
Merged

davide221 merged 1 commit into
Luce-Org:mainfrom
weicj:refactor-cpp-placement-config

Conversation

@weicj

@weicj weicj commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds the C++ backend placement foundation for the native dflash_server path, including the minimal server-side plumbing needed to expose and validate placement options.

Before this change, backend placement wiring mainly lived in Python bench/launcher helpers. Those helpers are still useful for bench execution, but the native C++ server also needs its own small placement structure for backend selection, device selection, logging, and unsupported-combination errors.

This PR does not implement CUDA/HIP mixed execution or native target layer split yet. It prepares the native server/runtime surface those follow-up PRs will use.

Changes

  1. Add a dedicated C++ backend placement directory

    New files:

    • dflash/src/placement/placement_backend.h
    • dflash/src/placement/placement_config.h

    placement_backend.h defines PlacementBackend (auto, cuda, hip) plus helpers for parsing, logging, compiled-backend detection, and support checks.

    placement_config.h owns DevicePlacement, including target backend, primary GPU, target layer-split GPU list, split weights, peer-access flag, and max context.

    This is intentionally a directory instead of one larger common header. Later backend placement work can add focused files for parsing, validation, runtime application, memory policy, or placement recommendation without growing server_main.cpp or common/device_placement.h.

  2. Keep existing includes compatible

    dflash/src/common/device_placement.h is kept as a compatibility include that forwards to placement/placement_config.h.

    Existing model/backend code is updated to include the new placement header directly where practical, without turning this PR into a broad include cleanup.

  3. Carry draft placement through the C++ backend boundary

    dflash/src/common/backend_factory.h now carries a draft_device placement next to the target device placement.

    This keeps target and draft placement explicit at the native server/backend factory boundary without splitting backend and GPU id into separate public concepts.

  4. Add native server backend-device CLI plumbing

    dflash/src/server/server_main.cpp now parses:

    • --target-device <backend:gpu> such as cuda:0, hip:0, or auto:0
    • --draft-device <backend:gpu>
    • --target-devices <backend:gpu,...> for the reserved target layer-split surface
    • --target-layer-split <weights>
    • --peer-access

    The previous split CLI shape (--target-backend, --draft-backend, --gpu, --draft-gpu, --target-gpus) is removed from the native server surface so backend and device id are expressed as one placement value from the start.

  5. Add backend placement logs and clear unsupported errors

    The native server config block now prints target device, draft device, optional target shard devices, and peer-access state.

    --peer-access is bridged into the existing runtime peer-access opt-in path before backend creation.

    Unsupported combinations are rejected explicitly instead of being silently ignored:

    • backend different from the compiled backend
    • mixed target/draft backend before mixed execution is implemented
    • target layer split before native server layer-split support is implemented

Follow-up Path

This PR intentionally includes the first server-side backend placement plumbing. Follow-up feature PRs can build on this native surface instead of adding more ad hoc parsing in server_main.cpp.

For native dflash_server behavior, C++ backend placement should become the source of truth for accepted backend placement options and explicit unsupported combinations. Existing Python backend placement helpers remain the orchestration layer for bench/launcher flows, visible-device/env setup, and test_dflash daemon arguments until native server support catches up.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 14 files

Re-trigger cubic

Comment thread dflash/src/server/server_main.cpp Outdated
" --draft-gpu <N> Draft GPU device (default: 0)\n"
" --target-backend <auto|cuda|hip> Target backend (default: auto)\n"
" --draft-backend <auto|cuda|hip> Draft backend (default: auto)\n"
" --target-gpus <ids> Reserved target layer-split GPU list (comma-separated)\n"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shall we consider to merge targetbackend and target_gpu? named target-device=cuda:0? and draft-device=hip:0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes i think we should do so, let me unify it

The native server needs a placement contract that can carry target and draft backend/device choices into later mixed-backend and layer-split work without growing ad hoc CLI flags. Backend and GPU id are one placement concept, so the server now exposes device specs instead of separate backend and GPU options.

This keeps the current native server behavior conservative: the parser accepts target and draft device specs, logs resolved placement, and rejects unsupported mixed-backend or target layer-split combinations until the runtime paths are implemented.

Constraint: Native C++ server binaries are still compiled for one GPU backend at a time.

Constraint: Target layer split remains rejected in the native server until the runtime path is wired.

Rejected: Keep --target-backend plus --gpu as the long-term public surface | backend and device id should not be split across unrelated CLI flags.

Confidence: high

Scope-risk: low

Tested: cmake --build dflash/build-cuda-draft-gpu-placement --target dflash_server -j 4

Tested: cmake --build dflash/build-hip-draft-gpu-placement --target dflash_server -j 4

Tested: dflash_server usage and placement-parse smoke checks

Tested: git diff --check
@davide221
davide221 force-pushed the refactor-cpp-placement-config branch from 6a2b7bd to 4aaa065 Compare May 22, 2026 08:56
@davide221
davide221 merged commit 839f912 into Luce-Org:main May 22, 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.

3 participants