Skip to content

cuda::span redefinition and ambiguous constructor errors in CUDA 12 #771

@StonerLing

Description

@StonerLing

Description

When compiling a .cu file with CUDA 12, using cuda-api-wrappers together with Thrust leads to cuda::span redefinition and ambiguous constructor errors. The same code compiles fine under CUDA 11.


Minimal Reproducer

#include <cuda/api.hpp> // Must come first to trigger the error

#include <thrust/device_vector.h>
#include <thrust/execution_policy.h>

void trigger() { cuda::span<float> s{nullptr, 0}; }

int main() {
    trigger();
    return 0;
}

Compile with:

nvcc -x cu -std=c++20 -arch=sm_75 -cudart shared \
     -I <path-to-cuda-api-wrappers> \
     -I <CUDA-include-path> \
     -c main.cpp -o main.obj

Observed Behavior

Errors like:

error C2977: 'cuda::span': too many template arguments
error C2641: cannot deduce template arguments for 'cuda::span'
error C2780: expects 0 arguments - 2 provided

Notes

  • The issue only appears when compiling the file as a CUDA source (-x cu) in CUDA 12.
  • Treated as a normal C++ file, the code compiles fine.
  • Likely related to changes in CUDA 12 handling of cuda::span and C++20 aggregate initialization.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions