Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/support_kokkos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Include this file only once
include_guard()

set(KOKKOS_VERSION 4.5.00)
set(KOKKOS_VERSION 5.0.0)

# Macro to aid in finding Kokkos with 3 potential install options:
# 1. Fully integrated Kokkos packages and CMake module files
Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.45.0-dev0"
__version__ = "0.45.0-dev1"
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ using Pennylane::LightningKokkos::StateVectorKokkos;
using namespace Pennylane::LightningKokkos::Algorithms;

// explicit instantiation
#ifndef __HIP_DEVICE_COMPILE__
template class Pennylane::Algorithms::OpsData<StateVectorKokkos<float>>;
template class Pennylane::Algorithms::OpsData<StateVectorKokkos<double>>;

Expand All @@ -31,3 +32,4 @@ template class Pennylane::Algorithms::JacobianData<StateVectorKokkos<double>>;

template class Algorithms::AdjointJacobian<StateVectorKokkos<float>>;
template class Algorithms::AdjointJacobian<StateVectorKokkos<double>>;
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -1840,9 +1840,10 @@ template <typename PrecisionT> class applyMultiRZFunctor {
}

KOKKOS_FUNCTION void operator()(const std::size_t k) const {
arr(k) *= (Kokkos::Impl::bit_count(k & wires_parity) % 2 == 0)
? shift_0
: shift_1;
arr(k) *=
(Kokkos::Experimental::popcount_builtin(k & wires_parity) % 2 == 0)
? shift_0
: shift_1;
}
};

Expand Down Expand Up @@ -1880,10 +1881,12 @@ void applyNCMultiRZ(Kokkos::View<Kokkos::complex<PrecisionT> *> arr_,
Kokkos::View<Kokkos::complex<PrecisionT> *> arr, std::size_t i,
Kokkos::View<std::size_t *> indices, std::size_t offset) {
std::size_t index = indices(i);
arr(index + offset) *=
(Kokkos::Impl::bit_count((index + offset) & wires_parity) % 2 == 0)
? shift_0
: shift_1;
arr(index + offset) *= (Kokkos::Experimental::popcount_builtin(
(index + offset) & wires_parity) %
2 ==
0)
? shift_0
: shift_1;
};

applyNCNFunctor(ExecutionSpace{}, arr_, num_qubits, controlled_wires,
Expand Down Expand Up @@ -1932,8 +1935,10 @@ void applyPauliRot(Kokkos::View<Kokkos::complex<PrecisionT> *> arr_,
KOKKOS_LAMBDA(std::size_t i0) {
std::size_t i1 = i0 ^ mask_xy;
if (i0 <= i1) {
const auto count_y = Kokkos::Impl::bit_count(i0 & mask_y) * 2;
const auto count_z = Kokkos::Impl::bit_count(i0 & mask_z) * 2;
const auto count_y =
Kokkos::Experimental::popcount_builtin(i0 & mask_y) * 2;
const auto count_z =
Kokkos::Experimental::popcount_builtin(i0 & mask_z) * 2;
const auto sign_i0 = count_z + count_mask_y * 3 - count_y;
const auto sign_i1 = count_z + count_mask_y + count_y;
const ComplexT v0 = arr_(i0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ void applyGenMultiRZ(Kokkos::View<Kokkos::complex<PrecisionT> *> arr_,
Pennylane::Util::exp2(num_qubits)),
KOKKOS_LAMBDA(std::size_t k) {
arr_(k) *= static_cast<PrecisionT>(
1 - 2 * int(Kokkos::Impl::bit_count(k & wires_parity) % 2));
1 - 2 * int(Kokkos::Experimental::popcount_builtin(
k & wires_parity) %
2));
});
}

Expand Down Expand Up @@ -951,7 +953,9 @@ void applyNCGenMultiRZ(Kokkos::View<Kokkos::complex<PrecisionT> *> arr_,
KOKKOS_LAMBDA(std::size_t k) {
if (ctrls_mask == (ctrls_parity & k)) {
arr_(k) *= static_cast<PrecisionT>(
1 - 2 * int(Kokkos::Impl::bit_count(k & wires_parity) % 2));
1 - 2 * int(Kokkos::Experimental::popcount_builtin(
k & wires_parity) %
2));
} else {
arr_(k) = 0.0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/// @cond DEV
namespace {
using namespace Pennylane::Util;
using Kokkos::Experimental::swap;
using Kokkos::kokkos_swap;
using Pennylane::LightningKokkos::Util::controlBitPatterns;
using Pennylane::LightningKokkos::Util::generateBitPatterns;
using Pennylane::LightningKokkos::Util::one;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,18 +442,46 @@ auto probs_bitshift_generic(
d_probabilities);
break;
case 7UL:
Kokkos::parallel_reduce(
exp2(num_qubits - n_wires),
getProbsNQubitOpFunctor<PrecisionT, DeviceType, 7>(arr, num_qubits,
wires),
d_probabilities);
// Following conditions are here to prevent error for HIP out of shared
// memory error
#ifdef KOKKOS_ENABLE_HIP
if constexpr (std::is_same_v<DeviceType, Kokkos::HIP> &&
sizeof(PrecisionT) == 8) {
Kokkos::parallel_reduce(
Kokkos::RangePolicy<DeviceType, Kokkos::LaunchBounds<32>>(
0, exp2(num_qubits - n_wires)),
getProbsNQubitOpFunctor<PrecisionT, DeviceType, 7>(
arr, num_qubits, wires),
d_probabilities);
} else
#endif
{
Kokkos::parallel_reduce(
exp2(num_qubits - n_wires),
getProbsNQubitOpFunctor<PrecisionT, DeviceType, 7>(
arr, num_qubits, wires),
d_probabilities);
}
break;
case 8UL:
Kokkos::parallel_reduce(
exp2(num_qubits - n_wires),
getProbsNQubitOpFunctor<PrecisionT, DeviceType, 8>(arr, num_qubits,
wires),
d_probabilities);
#ifdef KOKKOS_ENABLE_HIP
if constexpr (std::is_same_v<DeviceType, Kokkos::HIP> &&
sizeof(PrecisionT) == 8) {
Kokkos::parallel_reduce(
Kokkos::RangePolicy<DeviceType, Kokkos::LaunchBounds<16>>(
0, exp2(num_qubits - n_wires)),
getProbsNQubitOpFunctor<PrecisionT, DeviceType, 8>(
arr, num_qubits, wires),
d_probabilities);
} else
#endif
{
Kokkos::parallel_reduce(
exp2(num_qubits - n_wires),
getProbsNQubitOpFunctor<PrecisionT, DeviceType, 8>(
arr, num_qubits, wires),
d_probabilities);
}
break;
default:
Kokkos::parallel_reduce(
Expand Down
Loading