Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Cuda 12.1: error: expected template-name before ‘<’ token #4606

Closed
3 tasks done
dcbishop opened this issue Apr 4, 2023 · 7 comments · Fixed by #4893
Closed
3 tasks done

[BUG]: Cuda 12.1: error: expected template-name before ‘<’ token #4606

dcbishop opened this issue Apr 4, 2023 · 7 comments · Fixed by #4893

Comments

@dcbishop
Copy link

dcbishop commented Apr 4, 2023

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

2.10.4

Problem description

/usr/include/pybind11/detail/../cast.h: In function ‘typename pybind11::detail::type_caster<typename pybind11::detail::intrinsic_type<T>::type
>::cast_op_type<T> pybind11::detail::cast_op(make_caster<T>&)’:
/usr/include/pybind11/detail/../cast.h:45:120: error: expected template-name before ‘<’ token
   45 |     return caster.operator typename make_caster<T>::template cast_op_type<T>();
      |                                                                                                                        ^
/usr/include/pybind11/detail/../cast.h:45:120: error: expected identifier before ‘<’ token
/usr/include/pybind11/detail/../cast.h:45:123: error: expected primary-expression before ‘>’ token
   45 |     return caster.operator typename make_caster<T>::template cast_op_type<T>();
      |                                                                                                                           ^
/usr/include/pybind11/detail/../cast.h:45:126: error: expected primary-expression before ‘)’ token
   45 |     return caster.operator typename make_caster<T>::template cast_op_type<T>();
      |                                                                                                                              ^

Reproducible example code

echo "#include <pybind11/functional.h>" >> t.cu
nvcc -isystem=/usr/include/python3.10 -c t.cu

Is this a regression? Put the last known working version here if it is.

Not a regression

@dcbishop dcbishop added the triage New bug, unverified label Apr 4, 2023
@archibate
Copy link

I fixed this by editing /usr/include/pybind11/cast.h:

-    return caster.operator typename make_caster<T>::template cast_op_type<T>();
+    return caster;

It seems nvcc 12.x cannot parse correctly... not sure if this is a nvcc bug, maybe we should just use the unfancy syntax to do the cast, either implicit cast or c-style cast, rather than .operator T...

@hubutui
Copy link

hubutui commented Apr 21, 2023

I also encounter this issue when I build https://github.com/NVIDIA/apex on ArchLinux with cuda 12.1.0, gcc 12.2.1, pybind11 2.10.4.

/opt/cuda/bin/nvcc -I/usr/lib/python3.10/site-packages/torch/include -I/usr/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -I/usr/lib/python3.10/site-packages/torch/include/TH -I/usr/lib/python3.10/site-packages/torch/include/THC -I/opt/cuda/include -I/usr/include/python3.10 -c csrc/mlp_cuda.cu -o build/temp.linux-x86_64-cpython-310/csrc/mlp_cuda.o -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr --compiler-options '-fPIC' -O3 -DVERSION_GE_1_1 -DVERSION_GE_1_3 -DVERSION_GE_1_5 -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1017\" -DTORCH_EXTENSION_NAME=mlp_cuda -D_GLIBCXX_USE_CXX11_ABI=1 -gencode=arch=compute_75,code=sm_75 -std=c++17
/usr/include/pybind11/detail/../cast.h: In function ‘typename pybind11::detail::type_caster<typename pybind11::detail::intrinsic_type<T>::type>::cast_op_type<T> pybind11::detail::cast_op(make_caster<T>&)’:
/usr/include/pybind11/detail/../cast.h:45:120: error: expected template-name before ‘<’ token
   45 |     return caster.operator typename make_caster<T>::template cast_op_type<T>();
      |                                                                                                                        ^
/usr/include/pybind11/detail/../cast.h:45:120: error: expected identifier before ‘<’ token
/usr/include/pybind11/detail/../cast.h:45:123: error: expected primary-expression before ‘>’ token
   45 |     return caster.operator typename make_caster<T>::template cast_op_type<T>();
      |                                                                                                                           ^
/usr/include/pybind11/detail/../cast.h:45:126: error: expected primary-expression before ‘)’ token
   45 |     return caster.operator typename make_caster<T>::template cast_op_type<T>();
      |                                                                                                                              ^
error: command '/opt/cuda/bin/nvcc' failed with exit code 1

But I could build it with gcc 10.4.0.

@thwalker3
Copy link

I was able to confirm via an NVIDIA contact that this is indeed an nvcc bug and they've opened an internal issue for it.

@cebtenzzre
Copy link

The takes_ref_wrap and takes_const_ref_wrap tests in test_builtin_casters.cpp fails to compile with the workaround applied:

include/pybind11/detail/../cast.h:47:12: error: invalid initialization of reference of type ‘pybind11::detail::type_caster<ConstRefCasted>::cast_op_type<ConstRefCasted&>’ {aka ‘ConstRefCasted&’} from expression of type ‘pybind11::detail::make_caster<ConstRefCasted&>’ {aka ‘pybind11::detail::type_caster<ConstRefCasted>’}
   47 |     return caster;
      |            ^~~~~~

They also fail to compile with an explicit cast:

include/pybind11/detail/../cast.h:46:12: error: conversion from ‘pybind11::detail::make_caster<const ConstRefCasted&>’ {aka ‘pybind11::detail::type_caster<ConstRefCasted>’} to ‘pybind11::detail::type_caster<ConstRefCasted>::cast_op_type<const ConstRefCasted&>’ {aka ‘const ConstRefCasted&’} is ambiguous
  46 |     return (typename make_caster<T>::template cast_op_type<T>)caster;
     |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

jakirkham added a commit to regro-cf-autotick-bot/pp-sketchlib-feedstock that referenced this issue Jun 27, 2023
The combination of pybind11 + GCC 12 + nvcc 12 runs into compilation
errors. This is documented in a pybind11 issue. To workaround this,
configure the CUDA 12 migrator to use GCC 11, which shouldn't have this
issue.

xref: pybind/pybind11#4606
jakirkham added a commit to regro-cf-autotick-bot/cyrsoxs-feedstock that referenced this issue Jun 27, 2023
The combination of pybind11 + GCC 12 + nvcc 12 runs into compilation
errors. This is documented in a pybind11 issue. To workaround this,
configure the CUDA 12 migrator to use GCC 11, which shouldn't have this
issue.

xref: pybind/pybind11#4606
jakirkham added a commit to regro-cf-autotick-bot/pp-sketchlib-feedstock that referenced this issue Jun 27, 2023
The combination of pybind11 + GCC 12 + nvcc 12 runs into compilation
errors. This is documented in a pybind11 issue. To workaround this,
configure the CUDA 12 migrator to use GCC 11, which shouldn't have this
issue.

xref: pybind/pybind11#4606
johnlees pushed a commit to conda-forge/pp-sketchlib-feedstock that referenced this issue Jun 28, 2023
* Rebuild for CUDA 12

The transition to CUDA 12 SDK includes new packages for all CUDA libraries and
build tools. Notably, the cudatoolkit package no longer exists, and packages
should depend directly on the specific CUDA libraries (libblas, libcusolver,
etc) as needed. For an in-depth overview of the changes and to report problems
[see this issue]( conda-forge/conda-forge.github.io#1963 ).
Please feel free to raise any issues encountered there. Thank you! 🙏

* MNT: Re-rendered with conda-build 3.25.0, conda-smithy 3.23.1, and conda-forge-pinning 2023.06.08.00.22.40

* Use GCC 11 in CUDA 12 migrator

The combination of pybind11 + GCC 12 + nvcc 12 runs into compilation
errors. This is documented in a pybind11 issue. To workaround this,
configure the CUDA 12 migrator to use GCC 11, which shouldn't have this
issue.

xref: pybind/pybind11#4606

* MNT: Re-rendered with conda-build 3.24.0, conda-smithy 3.23.1, and conda-forge-pinning 2023.06.27.16.55.53

Now that GCC 11 is configured for use with CUDA 12 in the migrator,
re-render to propagate that changes to the variants and CI.

* Use LLVM 14 on macOS

As build issues are being encountered with LLVM 15 on macOS, pin to LLVM
14 in this feedstock to workaround those build issues. To ensure
`llvm-openmp` matches pin it as well. Also, as the new `libcxx` will
introduce this problem even with the older compiler toolchain, add
`libcxx` as an explicit dependency in `build` & `host` along with
pinning it.

These build issues still need to be fixed upstream. However, this
workaround should just allow this feedstock to continue to build on
macOS.

* MNT: Re-rendered with conda-build 3.24.0, conda-smithy 3.23.1, and conda-forge-pinning 2023.06.27.16.55.53

Now that the LLVM 14 toolchain is pinned on macOS, re-render to update
the variants with these constraints.

---------

Co-authored-by: jakirkham <jakirkham@gmail.com>
@thwalker3
Copy link

I haven't had a chance to test yet, but NVIDIA says that this has been fixed in the recently released 12.2.

@hubutui
Copy link

hubutui commented Jul 11, 2023

Cool, I could confirm that I could build https://github.com/NVIDIA/apex on ArchLinux with cuda 12.2.0, gcc 13.1.1, pybind11 2.10.4.

jakirkham added a commit to regro-cf-autotick-bot/cyrsoxs-feedstock that referenced this issue Aug 24, 2023
The combination of pybind11 + GCC 12 + nvcc 12 runs into compilation
errors. This is documented in a pybind11 issue. To workaround this,
configure the CUDA 12 migrator to use GCC 11, which shouldn't have this
issue.

xref: pybind/pybind11#4606
jakirkham added a commit to regro-cf-autotick-bot/pp-sketchlib-feedstock that referenced this issue Aug 24, 2023
The combination of pybind11 + GCC 12 + nvcc 12 runs into compilation
errors. This is documented in a pybind11 issue. To workaround this,
configure the CUDA 12 migrator to use GCC 11, which shouldn't have this
issue.

xref: pybind/pybind11#4606
johnlees pushed a commit to conda-forge/pp-sketchlib-feedstock that referenced this issue Aug 29, 2023
* Rebuild for CUDA 12 w/arch support

The transition to CUDA 12 SDK includes new packages for all CUDA libraries and
build tools. Notably, the cudatoolkit package no longer exists, and packages
should depend directly on the specific CUDA libraries (libcublas, libcusolver,
etc) as needed. For an in-depth overview of the changes and to report problems
[see this issue]( conda-forge/conda-forge.github.io#1963 ).
Please feel free to raise any issues encountered there. Thank you! 🙏

* MNT: Re-rendered with conda-build 3.26.1, conda-smithy 3.24.1, and conda-forge-pinning 2023.08.23.22.00.02

* Use GCC 11 in CUDA 12 migrator

The combination of pybind11 + GCC 12 + nvcc 12 runs into compilation
errors. This is documented in a pybind11 issue. To workaround this,
configure the CUDA 12 migrator to use GCC 11, which shouldn't have this
issue.

xref: pybind/pybind11#4606

* MNT: Re-rendered with conda-build 3.24.0, conda-smithy 3.24.1, and conda-forge-pinning 2023.08.24.19.16.55

---------

Co-authored-by: jakirkham <jakirkham@gmail.com>
Flamefire added a commit to Flamefire/pybind11 that referenced this issue Oct 20, 2023
There is a bug in some CUDA versions (observed in CUDA 12.1 and 11.7 w/ GCC 12.2),
that makes `cast_op` fail to compile:
  `cast.h:45:120: error: expected template-name before ‘<’ token`

Defining the nested type as an alias and using it allows this to work
without any change in semantics.

Fixes pybind#4606
rwgk pushed a commit that referenced this issue Oct 21, 2023
* Workaround NVCC parse failure in `cast_op`

There is a bug in some CUDA versions (observed in CUDA 12.1 and 11.7 w/ GCC 12.2),
that makes `cast_op` fail to compile:
  `cast.h:45:120: error: expected template-name before ‘<’ token`

Defining the nested type as an alias and using it allows this to work
without any change in semantics.

Fixes #4606

* style: pre-commit fixes

* Add comments to result_t referencing PR

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Tobias-Fischer added a commit to regro-cf-autotick-bot/pytorch_scatter-feedstock that referenced this issue Nov 8, 2023
The combination of pybind11 + GCC 12 + nvcc 12 runs into compilation
errors. This is documented in a pybind11 issue. To workaround this,
configure the CUDA 12 migrator to use GCC 11, which shouldn't have this
issue.

xref: pybind/pybind11#4606
xref: conda-forge/pp-sketchlib-feedstock@68d36e6
Tobias-Fischer added a commit to regro-cf-autotick-bot/theseus-ai-feedstock that referenced this issue Nov 9, 2023
The combination of pybind11 + GCC 12 + nvcc 12 runs into compilation
errors. This is documented in a pybind11 issue. To workaround this,
configure the CUDA 12 migrator to use GCC 11, which shouldn't have this
issue.

xref: pybind/pybind11#4606
xref: conda-forge/pp-sketchlib-feedstock@68d36e6
@serby2000
Copy link

I can build https://github.com/NVIDIA/apex with no issue on Debian 12 Bookworm with cuda 12.1.r12.1 and gcc 11.3.0

jakirkham added a commit to regro-cf-autotick-bot/pp-sketchlib-feedstock that referenced this issue Nov 27, 2023
The combination of pybind11 + GCC 12 + nvcc 12 runs into compilation
errors. This is documented in a pybind11 issue. To workaround this,
configure the CUDA 12 migrator to use GCC 11, which shouldn't have this
issue.

xref: pybind/pybind11#4606
basnijholt added a commit to regro-cf-autotick-bot/qsimcirq-feedstock that referenced this issue Dec 8, 2023
Copying from @jakirkham from regro-cf-autotick-bot/pp-sketchlib-feedstock@da7a213

The combination of pybind11 + GCC 12 + nvcc 12 runs into compilation
errors. This is documented in a pybind11 issue. To workaround this,
configure the CUDA 12 migrator to use GCC 11, which shouldn't have this
issue.

xref: pybind/pybind11#4606
pstjohn added a commit to pstjohn/pytorch_cluster-feedstock that referenced this issue Dec 24, 2023
The combination of pybind11 + GCC 12 + nvcc 12 runs into compilation
errors. This is documented in a pybind11 issue. To workaround this,
configure the CUDA 12 migrator to use GCC 11, which shouldn't have this
issue.

xref: pybind/pybind11#4606
wshanks added a commit to wshanks/qiskit-aer-feedstock that referenced this issue Apr 5, 2024
The pybind11 issue (pybind/pybind11#4606)
requiring a deviation from the upstream migration in
conda-forge-pinning-feedstock should be fixed in the latest release
(2.12).
wshanks added a commit to conda-forge/qiskit-aer-feedstock that referenced this issue Apr 5, 2024
* Clean up C build dependencies (and bump Qiskit)

* Remove muparserx which is not needed as of version 0.13
* Patch out muparserx cmake configuration
* Ignore run exports from spdlog. Only its headers are used at build
  time.
* Make numpy a run dependency only. Qiskit Aer interfaces with numpy
  through the pybind11 headers and does not link directly to numpy.
* Make the nlohmann_json bounds consistent across environments instead
  of special for osx arm64.
* Increase qiskit minimum version
* Add missing psutil dependency
  - This was missed before and being pulled in by Qiskit (which recently
dropped it as a dependency).
* Increment build number
* Revert to the upstream CUDA 12 migration
  - The pybind11 issue (pybind/pybind11#4606)
    requiring a deviation from the upstream migration in
    conda-forge-pinning-feedstock should be fixed in the latest release
    (2.12).
* MNT: Re-rendered with conda-build 3.28.3, conda-smithy 3.34.1, and conda-forge-pinning 2024.04.05.13.18.18

---------

Co-authored-by: conda-forge-webservices[bot] <91080706+conda-forge-webservices[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants