Skip to content

【Hackathon 10th Spring No.46】Add Windows C++ compile guards (Part 1/3)#7501

Open
bobby-cloudforge wants to merge 1 commit intoPaddlePaddle:developfrom
CloudForge-Solutions:task/h10-046-win-cpp-guards-1
Open

【Hackathon 10th Spring No.46】Add Windows C++ compile guards (Part 1/3)#7501
bobby-cloudforge wants to merge 1 commit intoPaddlePaddle:developfrom
CloudForge-Solutions:task/h10-046-win-cpp-guards-1

Conversation

@bobby-cloudforge
Copy link
Copy Markdown

@bobby-cloudforge bobby-cloudforge commented Apr 20, 2026

Motivation

FastDeploy's custom_ops/gpu_ops/ C++ source files include POSIX-only headers
(<sys/mman.h>, <sys/ipc.h>, <sys/shm.h>, <sys/msg.h>, <unistd.h>) that
are unavailable on MSVC, preventing compilation on Windows.

Additionally, env.h relies on std::stoi, std::stoul, and std::string
without explicitly including <cstdlib> and <string>. GCC's <iostream>
transitively provides these, but MSVC 14.44 does not.

This is Part 1 of 3 for 【Hackathon 10th Spring No.46】(Windows Build Support):

  • Part 1 (this PR): C++ #ifndef _WIN32 guards on POSIX-only includes + env.h portability fix
  • Part 2: Build system — setup_ops.py platform-conditional link args + build.bat
  • Part 3: Python runtime — platform guards for /dev/shm, os.killpg, os.setsid, fork

Modifications

  • Added #ifndef _WIN32 / #endif guards around POSIX-only includes in 26 .cu/.cc/.h files
  • Added #include <cstdlib> and #include <string> to env.h for MSVC portability
  • Applied clang-format to all touched files

Files changed: 27 (26 guard additions + 1 include fix)

All guards are _WIN32-only — zero functional change on Linux.

Usage or Command

# Verify no compilation regression on Linux (CI handles this automatically)
cd custom_ops && python setup_ops.py install

On Windows with MSVC + CUDA toolkit:

cl.exe /EHsc /std:c++17 /I<cuda>/include /I gpu_ops/ /E gpu_ops/helper.h

Accuracy Tests

Not applicable — pure preprocessor changes. No functional code modified.

Verified via MSVC 14.44 (VS 2022 Build Tools) preprocess test on Windows Server 2022:
all 27 modified headers parse cleanly with cl.exe /E.

Pipeline Evidence:

Checklist

  • #ifndef _WIN32 guards only wrap POSIX-specific includes
  • No functional behavior change on Linux
  • clang-format applied to all touched files
  • pre-commit hooks pass
  • Tested compilation on MSVC 14.44 (Windows Server 2022)

@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented Apr 20, 2026

Thanks for your contribution!

@paddle-bot paddle-bot Bot added the contributor External developers label Apr 20, 2026
@bobby-cloudforge bobby-cloudforge changed the title 【Hackathon 10th Spring No.46】Add Windows C++ compile guards (Part 1/3) 【Hackathon 10th Spring No.46】[Build] Windows C++ compilation guards -part Apr 20, 2026
Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

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

🤖 AI Code Review | 2026-04-20 13:57 CST

📋 Review 摘要

PR 概述:为 custom_ops/gpu_ops/ 下 28 个 C++ 源文件添加 Windows 编译守卫,将 POSIX-only 头文件(fcntl.hsys/mman.hunistd.hsys/ipc.hsys/msg.h)包裹在 #if !defined(_WIN32) 中,并在使用 POSIX API 的函数体中添加 PD_THROW 运行时保护。
变更范围custom_ops/gpu_ops/ 及其 speculate_decoding/ 子目录
影响面 TagOP

📝 PR 规范检查

PR 标题使用了 【Hackathon 10th Spring No.46】 格式,缺少官方 [Tag]。根据变更目录 custom_ops/gpu_ops/,应添加 [OP] Tag。

标题建议(可直接复制):

  • [OP] Add Windows C++ compile guards for custom_ops (Part 1/3)

问题

级别 文件 概述
🟡 建议 custom_ops/gpu_ops/env.h 新增 <cstdlib><string> 是修复隐式依赖,非注释/守卫,建议在 PR 描述中补充说明

✅ 验证结果

经逐文件审查与代码探索,确认以下关键点均正确:

  1. 头文件守卫一致性:所有 POSIX-only 头文件(fcntl.hsys/mman.hunistd.hsys/ipc.hsys/msg.h)均已正确包裹在 #if !defined(_WIN32) 中;Windows 上可用的标准头文件(sys/stat.hsys/types.hstdio.h)保留在守卫外。
  2. 函数体守卫完整性:所有使用 POSIX API(msgsnd/msgrcv/msgget/shm_open/mmap 等)的函数体均添加了 #if defined(_WIN32) PD_THROW 守卫。
  3. 仅有头文件守卫的 .cu 文件beam_search_softmax.cudequant_int8.cufused_get_rotary_embedding.cufused_hadamard_quant_fp8.custop_generation_multi_ends.cushare_external_data.cu)已验证其函数体中不直接调用 POSIX API,无需函数体守卫。
  4. 结构体可移植性msgdatamsgdatakvspeculate_msgdata 等结构体仅使用 long/int 等标准 C++ 类型,在 Windows 上可正常编译(虽不会实际用于 IPC 通信)。
  5. custom_ftok.h 整文件守卫正确:该文件使用 key_tstat() 等 POSIX-only 类型/函数,整文件包裹在 #if !defined(_WIN32) 中是合理的。所有调用方均在 #else(非 Windows)分支内使用 custom_ftok()
  6. cuda_multiprocess.h 兼容性:该文件(未在本 PR 中修改)已具备完整的 Windows/POSIX 双平台支持,sharedMemoryInfo 结构体和 sharedMemoryOpen/sharedMemoryClose 函数均为跨平台实现。

总体评价

变更机械性强、模式一致,28 个文件的守卫位置均正确。未发现阻塞性问题。作为 Part 1/3,建议后续部分覆盖 set_data_ipc.curead_data_ipc.cu 等同样使用 POSIX 共享内存的文件。

Comment thread custom_ops/gpu_ops/env.h

#include <cstdlib>
#include <string>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 建议 env.h 新增了 <cstdlib><string> 两个头文件,这不是注释或 #ifdef 守卫,而是修复了原有的隐式头文件依赖(std::getenv 需要 <cstdlib>std::string 需要 <string>)。

建议在 PR 描述的 Modifications 中补充说明此项改动,例如:

Added missing <cstdlib> and <string> includes to env.h to fix implicit header dependencies.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated PR description — the env.h portability fix (<cstdlib> + <string>) is now documented in the Modifications section.

@bobby-cloudforge bobby-cloudforge changed the title 【Hackathon 10th Spring No.46】[Build] Windows C++ compilation guards -part [CI]【Hackathon 10th Spring No.46】Add Windows C++ compile guards (Part 1/3) Apr 20, 2026
@bobby-cloudforge bobby-cloudforge changed the title [CI]【Hackathon 10th Spring No.46】Add Windows C++ compile guards (Part 1/3) 【Hackathon 10th Spring No.46】Add Windows C++ compile guards (Part 1/3) Apr 20, 2026
@luotao1 luotao1 self-assigned this Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants