【Hackathon 10th Spring No.46】[Build] Windows compilation: platform guards for C++/Python -part1#6772
Draft
cloudforge1 wants to merge 10 commits intoPaddlePaddle:developfrom
Draft
【Hackathon 10th Spring No.46】[Build] Windows compilation: platform guards for C++/Python -part1#6772cloudforge1 wants to merge 10 commits intoPaddlePaddle:developfrom
cloudforge1 wants to merge 10 commits intoPaddlePaddle:developfrom
Conversation
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)
|
Thanks for your contribution! |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #6772 +/- ##
==========================================
Coverage ? 72.32%
==========================================
Files ? 394
Lines ? 54305
Branches ? 8507
==========================================
Hits ? 39276
Misses ? 12216
Partials ? 2813
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
84db6a8 to
db1e6df
Compare
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.
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), andmultiprocessing.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-)
helper.h,msg_utils.h,save_with_output_msg.h,speculate_msg.h,remote_cache_kv_ipc.h): Wrap POSIX includes with#ifndef _WIN32.cc/.cu): Wrap both includes AND function bodies with#ifdef _WIN32 / PD_THROW("... not supported on Windows") / #else / ... / #endif— following the existing pattern incuda_multiprocess.hPart 2: Build System (1 file, 8+/2-)
custom_ops/setup_ops.py: Platform-conditional CUDA link args (-lcuda -lnvidia-mlon Linux,/DEFAULTLIB:cuda.lib /DEFAULTLIB:nvml.libon Windows)Part 3: Python Runtime Guards (10 files, 72+/28-)
/dev/shmpaths withtempfile.gettempdir()fallback on Windowsos.killpg/os.getpgidcalls withsys.platformcheck, usingp.terminate()on Windows (3 files, 5 sites)preexec_fn=os.setsidwith conditional kwargs (3 files, 4 sites)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.hKnown 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:
IPC-based operators will raise a clear
PD_THROWerror on Windows rather than silently failing or producing cryptic MSVC errors.Accuracy Tests
#elsebranches preserve original code paths exactly)Checklist
PD_THROWon Windows (fail loud, not silent)/dev/shmpaths have Windows fallbackkillpg,setsid,fork) guarded#else/elsebranches)