Skip to content

【Hackathon 10th Spring No.46】[Build] Windows compilation: platform guards for C++/Python -part1#6772

Draft
cloudforge1 wants to merge 10 commits intoPaddlePaddle:developfrom
cloudforge1:task/h10-046-windows-build
Draft

【Hackathon 10th Spring No.46】[Build] Windows compilation: platform guards for C++/Python -part1#6772
cloudforge1 wants to merge 10 commits intoPaddlePaddle:developfrom
cloudforge1:task/h10-046-windows-build

Conversation

@cloudforge1
Copy link
Contributor

Motivation

FastDeploy's custom_ops C++ source files include POSIX-only headers (<sys/mman.h>, <sys/ipc.h>, <sys/msg.h>, <unistd.h>) and call POSIX-only APIs (System V IPC, mmap/munmap, shm_open) unconditionally, causing compilation failures on Windows (MSVC). Similarly, Python runtime code uses Linux-specific paths (/dev/shm), process APIs (os.killpg, os.getpgid, os.setsid), and multiprocessing.get_context("fork") — all of which fail on Windows.

This is part of Hackathon 10th Spring No.46: adding Windows build support to FastDeploy.

Related upstream work: PaddlePaddle/Paddle#77690 (Paddle-side phi.lib packaging fix by @ccsuzzh).

Modifications

Part 1: C++ Include Guards + Function Body Guards (26 files, 147+/21-)

  • 5 root headers (helper.h, msg_utils.h, save_with_output_msg.h, speculate_msg.h, remote_cache_kv_ipc.h): Wrap POSIX includes with #ifndef _WIN32
  • 6 source files with include-only guards (they include POSIX headers but don't call POSIX APIs directly)
  • 15 IPC source files (.cc/.cu): Wrap both includes AND function bodies with #ifdef _WIN32 / PD_THROW("... not supported on Windows") / #else / ... / #endif — following the existing pattern in cuda_multiprocess.h

Part 2: Build System (1 file, 8+/2-)

  • custom_ops/setup_ops.py: Platform-conditional CUDA link args (-lcuda -lnvidia-ml on Linux, /DEFAULTLIB:cuda.lib /DEFAULTLIB:nvml.lib on Windows)

Part 3: Python Runtime Guards (10 files, 72+/28-)

  • Replace 13 hardcoded /dev/shm paths with tempfile.gettempdir() fallback on Windows
  • Guard os.killpg/os.getpgid calls with sys.platform check, using p.terminate() on Windows (3 files, 5 sites)
  • Guard preexec_fn=os.setsid with conditional kwargs (3 files, 4 sites)
  • Use multiprocessing.get_context("spawn") instead of "fork" on Windows (1 site)

Files NOT modified (already Windows-aware): cuda_multiprocess.h, set_data_ipc.cu, unset_data_ipc.cu, cutlass_heuristic.cu, fpA_intB_gemm_template.h

Known limitation: ZMQ IPC transport URIs (ipc:///dev/shm/...) in input processor files are unchanged — they require ZMQ transport-layer changes for full Windows support (future work).

Usage or Command

No new commands. Existing Linux builds are unaffected. On Windows with MSVC + CUDA Toolkit:

python custom_ops/setup_ops.py install

IPC-based operators will raise a clear PD_THROW error on Windows rather than silently failing or producing cryptic MSVC errors.

Accuracy Tests

  • No accuracy changes — this PR only adds platform guards
  • All existing Linux functionality remains identical (#else branches preserve original code paths exactly)
  • IPC ops on Windows will throw a clear error message instead of compilation failure

Checklist

  • No POSIX headers included unconditionally on Windows
  • IPC function bodies guarded with PD_THROW on Windows (fail loud, not silent)
  • Python /dev/shm paths have Windows fallback
  • Process management APIs (killpg, setsid, fork) guarded
  • Build system link args are platform-conditional
  • All pre-commit checks pass (black, isort, flake8, ruff)
  • No regressions on Linux (original code paths preserved in #else/else branches)

Guard POSIX-only headers (sys/ipc.h, sys/msg.h, sys/mman.h, unistd.h)
with #ifndef _WIN32 and add PD_THROW guards to function bodies that
use System V IPC (ftok/msgget/msgsnd/msgrcv) or POSIX shared memory
(shm_open/mmap/ftruncate/munmap).

Files changed: 26 (headers, IPC sources, step_reschedule, stop_generation)
Pattern: inline #ifdef _WIN32 per-file, matching cuda_multiprocess.h style
Use sys.platform check to select Windows (/DEFAULTLIB:cuda.lib,
/DEFAULTLIB:nvml.lib) vs Linux (-lcuda, -lnvidia-ml) linker flags.
…d, fork -part3

- Replace hardcoded /dev/shm paths with platform-aware tempfile.gettempdir()
  fallback on Windows (10 files, 13 occurrences)
- Guard os.killpg/os.getpgid with sys.platform check, use p.terminate()
  on Windows (engine.py, common_engine.py, expert_service.py)
- Guard preexec_fn=os.setsid with conditional kwargs on Windows
  (engine.py, common_engine.py, prefix_cache_manager.py)
- Use multiprocessing.get_context('spawn') instead of 'fork' on Windows
  (engine.py)
- ZMQ IPC transport URIs (ipc:///dev/shm/...) left unchanged — require
  ZMQ transport layer changes for full Windows support (future work)
@paddle-bot
Copy link

paddle-bot bot commented Mar 10, 2026

Thanks for your contribution!

@paddle-bot paddle-bot bot added the contributor External developers label Mar 10, 2026
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 67.21311% with 20 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@b05a6c4). Learn more about missing BASE report.

Files with missing lines Patch % Lines
fastdeploy/engine/common_engine.py 38.46% 6 Missing and 2 partials ⚠️
fastdeploy/engine/engine.py 41.66% 5 Missing and 2 partials ⚠️
fastdeploy/engine/expert_service.py 60.00% 1 Missing and 1 partial ⚠️
fastdeploy/worker/worker_process.py 50.00% 2 Missing ⚠️
fastdeploy/eplb/async_expert_loader.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #6772   +/-   ##
==========================================
  Coverage           ?   72.32%           
==========================================
  Files              ?      394           
  Lines              ?    54305           
  Branches           ?     8507           
==========================================
  Hits               ?    39276           
  Misses             ?    12216           
  Partials           ?     2813           
Flag Coverage Δ
GPU 72.32% <67.21%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cloudforge1 cloudforge1 force-pushed the task/h10-046-windows-build branch from 84db6a8 to db1e6df Compare March 11, 2026 02:52
@cloudforge1 cloudforge1 marked this pull request as draft March 11, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants