nvcc with MSVC as host compiler (Windows) can't compile stdexec: compiler detection takes the nvcc branch and skips the MSVC settings

未關閉
#2,402 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 2 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
18/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
cpp, csharp

研究方向

The detection logic is in include/stdexec/__detail/__config.hpp, where the NVCC branch runs before the MSVC checks, so STDEXEC_MSVC() and STDEXEC_MSVC_HEADERS() are never set under nvcc with an MSVC host. Related spots are __spin_loop_pause.hpp, __meta.hpp (__mk_indices) and __connect.hpp (__connect_declfn_v). Done would mean the minimal nvcc_msvc.cu example compiles with nvcc on Windows, or the header fails early with a clear #error; the maintainers have not yet decided which, so confirm the direction first.

由索引模型根據 Issue 內容生成。

描述

With nvcc on Windows (MSVC as host compiler), even a minimal program fails to compile at current main (1d58877ad898fa3422658d47b28f67deb9c10e80). We ran into this while building HPX with CUDA on Windows.

Versions: CUDA 13.0 (nvcc V13.0.88), MSVC 19.44.35229 (VS 2022 17.14, x64), Windows 11. CUDA 13.0 doesn't accept MSVC 19.52 (VS 18) as host compiler.

// nvcc_msvc.cu
#include <stdexec/execution.hpp>

int main()
{
    auto s = stdexec::just(41) | stdexec::then([](int i) { return i + 1; });
    auto [v] = stdexec::sync_wait(std::move(s)).value();
    return v == 42 ? 0 : 1;
}
nvcc -std=c++20 -Xcompiler=-Zc:__cplusplus -Xcompiler=-Zc:preprocessor -Xcompiler=/EHsc --extended-lambda --expt-relaxed-constexpr -arch=sm_89 -I stdexec/include nvcc_msvc.cu

(-Zc:__cplusplus and -Zc:preprocessor are needed to get past the C++20 check and the preprocessor check in __config.hpp.)

Output (paths shortened, repeated lines removed):

include/stdexec/__detail/__meta.hpp(168): error: declaration is incompatible with variable template "stdexec::__pack::__mk_indices" (declared at line 163)
include/stdexec/__detail/__connect.hpp(83): error: declaration is incompatible with variable template "stdexec::__connect::__connect_declfn_v" (declared at line 77)
include/stdexec/__detail/__connect.hpp(90): error: declaration is incompatible with variable template "stdexec::__connect::__connect_declfn_v" (declared at line 77)
include/stdexec/__detail/__connect.hpp(103): error: declaration is incompatible with variable template "stdexec::__connect::__connect_declfn_v" (declared at line 97)
include/stdexec/__detail/__connect.hpp(110): error: declaration is incompatible with variable template "stdexec::__connect::__connect_declfn_v" (declared at line 97)
include/stdexec/__detail/__spin_loop_pause.hpp(48): error: identifier "__builtin_ia32_pause" is undefined
include/stdexec/__detail/__transform_completion_signatures.hpp(360): error: type name is not allowed
include/stdexec/__detail/__transform_completion_signatures.hpp(360): error: too many initializer values
include/stdexec/__detail/__transform_completion_signatures.hpp(400): error: type name is not allowed
include/stdexec/__detail/__transform_completion_signatures.hpp(400): error: too many initializer values
include/stdexec/__detail/__sync_wait.hpp(353): error: no instance of function template "stdexec::connect_t::operator()" matches the argument list
include/stdexec/__detail/__sync_wait.hpp(355): error: static assertion failed with "..."
nvcc_msvc.cu(6): error: expression must have class type but it has type "void"
15 errors detected in the compilation of "nvcc_msvc.cu".

The cause seems to be the compiler detection in __config.hpp: the __NVCC__ branch comes first, so with an MSVC host neither STDEXEC_MSVC() nor STDEXEC_MSVC_HEADERS() is ever set, although _MSC_VER is defined and the MSVC standard library is used. As a result:

  • __spin_loop_pause() takes the GCC branch (__builtin_ia32_pause()) instead of _mm_pause() from <intrin.h>.
  • __make_indices falls back to the extern variable template partial specializations (__mk_indices), and __connect.hpp uses the __connect_declfn_v specializations instead of the function-based version it already has for MSVC. nvcc's front end in MSVC mode rejects both ("declaration is incompatible with variable template").
  • After the front end, cl compiles nvcc's preprocessed output (.cudafe1.cpp). The macros were already expanded with __NVCC__ defined, so the MSVC workarounds keyed on STDEXEC_MSVC() are missing there too.

What we tried in a local copy of 04de75de58 (the revision HPX uses today, which fails with the same __mk_indices and __builtin_ia32_pause errors): setting STDEXEC_MSVC_HEADERS() to 1 in the nvcc branch when _MSC_VER is defined fixes the __builtin_ia32_pause error, and using std::make_index_sequence for __make_indices fixes the __mk_indices error. With HPX's CUDA test files, and with the MSVC __msplice_helper variant enabled for nvcc as well, the front end then gets through, but cl fails on the .cudafe1.cpp file: first an internal compiler error (C1001) at __typeinfo.hpp(289), then errors such as C7571 (enable_sender: variable template has already been initialized) at __execution_fwd.hpp(287) and C7608 (atomic constraint should be a constant expression) at __sender_concepts.hpp(131) and __sender_introspection.hpp(259). So it takes more than a few local fixes, and the MSVC code paths would have to apply to both nvcc's front end and the host compilation.

Is nvcc with an MSVC host meant to be supported? If yes, would a separate STDEXEC_NVCC_MSVC_HOST() (or setting STDEXEC_MSVC_HEADERS() and the MSVC workarounds whenever _MSC_VER is defined) be the direction you'd want? If not, it would help to say so in the README and to fail early with an #error, so users don't get errors from deep inside the library.

主要語言
C++
星號
2.5k
分支
285
平均合併
2 天 5 小時
30 天內合併 PR
82

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

NVIDIA/stdexec 的其他 Issue

查看 NVIDIA/stdexec 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。