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

Aberta
#2,402 3 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 2 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
18/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
cpp, csharp

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
C++
Estrelas
2.5k
Forks
285
Merge médio
2d 5h
PRs com merge (30d)
81

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de NVIDIA/stdexec

Todas as issues de NVIDIA/stdexec

Issues semelhantes

Mais issues de C++

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.