Skip to content

Conversation

@diehlpk
Copy link

@diehlpk diehlpk commented Jan 8, 2025

Summary

Compiling qiskit-aer with CUDA support and gcc 12/13 resulted in some internal compiler error, see #2227.

The error was resolved by removing the const expression in from of the lambda functions. The issue is that the above const declared variables are passed to the lambda function using & as the default capture of the lambda function. Passing a constant value by reference to a lambda function causes issues by gcc 12/13.

Details and comments

Removing the const expression allows the code to compile with gcc 12/13 using CUDA 12.4/12.5. I have not yet checked if the issue us specific to Grace Grace and Grace Hopper which is ARM.

@CLAassistant
Copy link

CLAassistant commented Jan 8, 2025

CLA assistant check
All committers have signed the CLA.

@diehlpk
Copy link
Author

diehlpk commented Mar 8, 2025

Is there any interest to get this merged? I need to patch newer releases with Grace Hopper support.

@garrison
Copy link
Member

I am curious: Does it work if, instead of removing const, you replace it with constexpr on each of the lines you touched?

@diehlpk
Copy link
Author

diehlpk commented Nov 23, 2025

I can try it next week.

@garrison
Copy link
Member

Thank you. If that does not work, let me know because I have another suggestion in mind.

@diehlpk
Copy link
Author

diehlpk commented Nov 24, 2025

@garrison I changed the first two ones and now I get

/vast/home/diehlpk/qiskit-aer-patrick/src/simulators/density_matrix/densitymatrix.hpp(481): error: expression must have a constant value
    constexpr uint_t mask_u = ~MASKS[x_max + 1];
                              ^
/vast/home/diehlpk/qiskit-aer-patrick/src/simulators/density_matrix/densitymatrix.hpp(481): note #2689-D: the value of variable "x_max" (declared at line 451) cannot be used as a constant
    constexpr uint_t mask_u = ~MASKS[x_max + 1];
                                     ^
          detected during:
            instantiation of "double AER::QV::DensityMatrix<data_t>::expval_pauli(const AER::QV::reg_t &, const std::string &, AER::complex_t) const [with data_t=double]" at line 528 of /vast/home/diehlpk/qiskit-aer-patrick/src/simulators/density_matrix/densitymatrix_state.hpp
            instantiation of "double AER::DensityMatrix::State<densmat_t>::expval_pauli(const AER::reg_t &, const std::string &) [with densmat_t=AER::QV::DensityMatrix<double>]" at line 98 of /vast/home/diehlpk/qiskit-aer-patrick/src/simulators/density_matrix/densitymatrix_state.hpp
            instantiation of class "AER::DensityMatrix::State<densmat_t> [with densmat_t=AER::QV::DensityMatrix<double>]" at line 98 of /vast/home/diehlpk/qiskit-aer-patrick/src/simulators/density_matrix/densitymatrix_state.hpp
            instantiation of "AER::DensityMatrix::State<densmat_t>::State() [with densmat_t=AER::QV::DensityMatrix<double>]" at line 148 of /vast/home/diehlpk/qiskit-aer-patrick/src/simulators/circuit_executor.hpp
            instantiation of "size_t AER::CircuitExecutor::Executor<state_t>::required_memory_mb(const AER::Config &, const AER::Circuit &, const AER::Noise::NoiseModel &) const [with state_t=AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>]" at line 266 of /vast/home/diehlpk/qiskit-aer-patrick/src/simulators/circuit_executor.hpp
            [ 5 instantiation contexts not shown ]
            instantiation of "std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args &&...) [with _Tp=AER::DensityMatrix::Executor<AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>>, _Alloc=std::allocator<void>, _Lp=__gnu_cxx::_S_atomic, _Args=<>]" at line 972 of /vast/projects/opt/rhel8/x86_64/gcc/13.2.0/include/c++/13.2.0/bits/shared_ptr_base.h
            instantiation of "std::__shared_count<_Lp>::__shared_count(_Tp *&, std::_Sp_alloc_shared_tag<_Alloc>, _Args &&...) [with _Lp=__gnu_cxx::_S_atomic, _Tp=AER::DensityMatrix::Executor<AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>>, _Alloc=std::allocator<void>, _Args=<>]" at line 1713 of /vast/projects/opt/rhel8/x86_64/gcc/13.2.0/include/c++/13.2.0/bits/shared_ptr_base.h
            instantiation of "std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Alloc>, _Args &&...) [with _Tp=AER::DensityMatrix::Executor<AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>>, _Lp=__gnu_cxx::_S_atomic, _Alloc=std::allocator<void>, _Args=<>]" at line 465 of /vast/projects/opt/rhel8/x86_64/gcc/13.2.0/include/c++/13.2.0/bits/shared_ptr.h
            instantiation of "std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Alloc>, _Args &&...) [with _Tp=AER::DensityMatrix::Executor<AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>>, _Alloc=std::allocator<void>, _Args=<>]" at line 1010 of /vast/projects/opt/rhel8/x86_64/gcc/13.2.0/include/c++/13.2.0/bits/shared_ptr.h
            instantiation of "std::shared_ptr<std::_NonArray<_Tp>> std::make_shared<_Tp,_Args...>(_Args &&...) [with _Tp=AER::DensityMatrix::Executor<AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>>, _Args=<>]" at line 654 of /vast/home/diehlpk/qiskit-aer-patrick/src/controllers/aer_controller.hpp

/vast/home/diehlpk/qiskit-aer-patrick/src/simulators/density_matrix/densitymatrix.hpp(482): error: expression must have a constant value
    constexpr uint_t mask_l = MASKS[x_max];
                              ^
/vast/home/diehlpk/qiskit-aer-patrick/src/simulators/density_matrix/densitymatrix.hpp(482): note #2689-D: the value of variable "x_max" (declared at line 451) cannot be used as a constant
    constexpr uint_t mask_l = MASKS[x_max];
                                    ^
          detected during:
            instantiation of "double AER::QV::DensityMatrix<data_t>::expval_pauli(const AER::QV::reg_t &, const std::string &, AER::complex_t) const [with data_t=double]" at line 528 of /vast/home/diehlpk/qiskit-aer-patrick/src/simulators/density_matrix/densitymatrix_state.hpp
            instantiation of "double AER::DensityMatrix::State<densmat_t>::expval_pauli(const AER::reg_t &, const std::string &) [with densmat_t=AER::QV::DensityMatrix<double>]" at line 98 of /vast/home/diehlpk/qiskit-aer-patrick/src/simulators/density_matrix/densitymatrix_state.hpp
            instantiation of class "AER::DensityMatrix::State<densmat_t> [with densmat_t=AER::QV::DensityMatrix<double>]" at line 98 of /vast/home/diehlpk/qiskit-aer-patrick/src/simulators/density_matrix/densitymatrix_state.hpp
            instantiation of "AER::DensityMatrix::State<densmat_t>::State() [with densmat_t=AER::QV::DensityMatrix<double>]" at line 148 of /vast/home/diehlpk/qiskit-aer-patrick/src/simulators/circuit_executor.hpp
            instantiation of "size_t AER::CircuitExecutor::Executor<state_t>::required_memory_mb(const AER::Config &, const AER::Circuit &, const AER::Noise::NoiseModel &) const [with state_t=AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>]" at line 266 of /vast/home/diehlpk/qiskit-aer-patrick/src/simulators/circuit_executor.hpp
            [ 5 instantiation contexts not shown ]
            instantiation of "std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args &&...) [with _Tp=AER::DensityMatrix::Executor<AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>>, _Alloc=std::allocator<void>, _Lp=__gnu_cxx::_S_atomic, _Args=<>]" at line 972 of /vast/projects/opt/rhel8/x86_64/gcc/13.2.0/include/c++/13.2.0/bits/shared_ptr_base.h
            instantiation of "std::__shared_count<_Lp>::__shared_count(_Tp *&, std::_Sp_alloc_shared_tag<_Alloc>, _Args &&...) [with _Lp=__gnu_cxx::_S_atomic, _Tp=AER::DensityMatrix::Executor<AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>>, _Alloc=std::allocator<void>, _Args=<>]" at line 1713 of /vast/projects/opt/rhel8/x86_64/gcc/13.2.0/include/c++/13.2.0/bits/shared_ptr_base.h
            instantiation of "std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Alloc>, _Args &&...) [with _Tp=AER::DensityMatrix::Executor<AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>>, _Lp=__gnu_cxx::_S_atomic, _Alloc=std::allocator<void>, _Args=<>]" at line 465 of /vast/projects/opt/rhel8/x86_64/gcc/13.2.0/include/c++/13.2.0/bits/shared_ptr.h
            instantiation of "std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Alloc>, _Args &&...) [with _Tp=AER::DensityMatrix::Executor<AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>>, _Alloc=std::allocator<void>, _Args=<>]" at line 1010 of /vast/projects/opt/rhel8/x86_64/gcc/13.2.0/include/c++/13.2.0/bits/shared_ptr.h
            instantiation of "std::shared_ptr<std::_NonArray<_Tp>> std::make_shared<_Tp,_Args...>(_Args &&...) [with _Tp=AER::DensityMatrix::Executor<AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>>, _Args=<>]" at line 654 of /vast/home/diehlpk/qiskit-aer-patrick/src/controllers/aer_controller.hpp

/vast/home/diehlpk/qiskit-aer-patrick/src/simulators/density_matrix/densitymatrix.hpp(488): error: no instance of overloaded function "std::real" matches the argument list
            argument types are: (<error-type>)
      auto val = 2 * std::real(phase * BaseVector::data_[idx_mat]);
                     ^
/vast/projects/opt/rhel8/x86_64/gcc/13.2.0/include/c++/13.2.0/complex(2443): note #3327-D: candidate function template "std::real(_Tp)" failed deduction
      real(_Tp __x)
      ^
/vast/projects/opt/rhel8/x86_64/gcc/13.2.0/include/c++/13.2.0/complex(572): note #3327-D: candidate function template "std::real(const std::complex<_Tp> &)" failed deduction
      real(const complex<_Tp>& __z)
      ^
          detected during:
            instantiation of "double AER::QV::DensityMatrix<data_t>::expval_pauli(const AER::QV::reg_t &, const std::string &, AER::complex_t) const [with data_t=double]" at line 528 of /vast/home/diehlpk/qiskit-aer-patrick/src/simulators/density_matrix/densitymatrix_state.hpp
            instantiation of "double AER::DensityMatrix::State<densmat_t>::expval_pauli(const AER::reg_t &, const std::string &) [with densmat_t=AER::QV::DensityMatrix<double>]" at line 98 of /vast/home/diehlpk/qiskit-aer-patrick/src/simulators/density_matrix/densitymatrix_state.hpp
            instantiation of class "AER::DensityMatrix::State<densmat_t> [with densmat_t=AER::QV::DensityMatrix<double>]" at line 98 of /vast/home/diehlpk/qiskit-aer-patrick/src/simulators/density_matrix/densitymatrix_state.hpp
            instantiation of "AER::DensityMatrix::State<densmat_t>::State() [with densmat_t=AER::QV::DensityMatrix<double>]" at line 148 of /vast/home/diehlpk/qiskit-aer-patrick/src/simulators/circuit_executor.hpp
            instantiation of "size_t AER::CircuitExecutor::Executor<state_t>::required_memory_mb(const AER::Config &, const AER::Circuit &, const AER::Noise::NoiseModel &) const [with state_t=AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>]" at line 266 of /vast/home/diehlpk/qiskit-aer-patrick/src/simulators/circuit_executor.hpp
            [ 5 instantiation contexts not shown ]
            instantiation of "std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args &&...) [with _Tp=AER::DensityMatrix::Executor<AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>>, _Alloc=std::allocator<void>, _Lp=__gnu_cxx::_S_atomic, _Args=<>]" at line 972 of /vast/projects/opt/rhel8/x86_64/gcc/13.2.0/include/c++/13.2.0/bits/shared_ptr_base.h
            instantiation of "std::__shared_count<_Lp>::__shared_count(_Tp *&, std::_Sp_alloc_shared_tag<_Alloc>, _Args &&...) [with _Lp=__gnu_cxx::_S_atomic, _Tp=AER::DensityMatrix::Executor<AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>>, _Alloc=std::allocator<void>, _Args=<>]" at line 1713 of /vast/projects/opt/rhel8/x86_64/gcc/13.2.0/include/c++/13.2.0/bits/shared_ptr_base.h
            instantiation of "std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Alloc>, _Args &&...) [with _Tp=AER::DensityMatrix::Executor<AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>>, _Lp=__gnu_cxx::_S_atomic, _Alloc=std::allocator<void>, _Args=<>]" at line 465 of /vast/projects/opt/rhel8/x86_64/gcc/13.2.0/include/c++/13.2.0/bits/shared_ptr.h
            instantiation of "std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Alloc>, _Args &&...) [with _Tp=AER::DensityMatrix::Executor<AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>>, _Alloc=std::allocator<void>, _Args=<>]" at line 1010 of /vast/projects/opt/rhel8/x86_64/gcc/13.2.0/include/c++/13.2.0/bits/shared_ptr.h
            instantiation of "std::shared_ptr<std::_NonArray<_Tp>> std::make_shared<_Tp,_Args...>(_Args &&...) [with _Tp=AER::DensityMatrix::Executor<AER::DensityMatrix::State<AER::QV::DensityMatrix<double>>>, _Args=<>]" at line 654 of /vast/home/diehlpk/qiskit-aer-patrick/src/controllers/aer_controller.hpp

Comment on lines -481 to 483

const uint_t mask_u = ~MASKS[x_max + 1];
const uint_t mask_l = MASKS[x_max];
uint_t mask_u = ~MASKS[x_max + 1];
uint_t mask_l = MASKS[x_max];
auto lambda = [&](const int_t i, double &val_re, double &val_im) -> void {
Copy link
Member

Choose a reason for hiding this comment

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

I want to see what happens if these three lines look like

  const uint_t mask_u = ~MASKS[x_max + 1];
  const uint_t mask_l = MASKS[x_max];
  auto lambda = [&, mask_u, mask_l](const int_t i, double &val_re, double &val_im) -> void {

i.e., the only change from the original is to add , mask_u, mask_l to the capture so that those are captured by value instead of reference. And likewise for the other places with the proposed change.

Comment on lines -243 to 244

const size_t N = qubits.size();
size_t N = qubits.size();
auto func = [&](const areg_t<2> &inds,
Copy link
Member

Choose a reason for hiding this comment

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

Here would be

  const size_t N = qubits.size();
  auto func = [&, N](const areg_t<2> &inds,

@garrison
Copy link
Member

I changed the first two ones and now I get

@diehlpk, thank you for trying that. I added a new suggestion above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants