Skip to content
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6468cae
kokkos 5.0 and support amdgpu
josephleekl Dec 16, 2025
360437d
Auto update version from '0.44.0-dev21' to '0.44.0-dev22'
ringo-but-quantum Dec 16, 2025
e1b8a4a
hip shared memory issue
josephleekl Dec 16, 2025
c78777e
Update
maliasadi Dec 16, 2025
c11b7b5
trigger ci
maliasadi Dec 16, 2025
0074965
Update
maliasadi Jan 8, 2026
7d02917
Auto update version from '0.45.0-dev0' to '0.45.0-dev1'
ringo-but-quantum Jan 8, 2026
e267553
Merge branch 'master' into kokkos-5.0
josephleekl Feb 5, 2026
4517446
Auto update version from '0.45.0-dev14' to '0.45.0-dev15'
ringo-but-quantum Feb 5, 2026
a1e3eca
update
josephleekl Feb 5, 2026
b95af13
Update doc/lightning_kokkos/installation_hpc.rst
josephleekl Feb 5, 2026
3dc24d0
Update .github/CHANGELOG.md
josephleekl Feb 5, 2026
52ad1ce
Update .github/CHANGELOG.md
josephleekl Feb 5, 2026
22bc978
trigger CI
josephleekl Feb 5, 2026
1124218
Merge branch 'master' into kokkos-5.0
josephleekl Feb 5, 2026
b709a13
Auto update version from '0.45.0-dev15' to '0.45.0-dev16'
ringo-but-quantum Feb 5, 2026
31fa097
update workflows and doc
josephleekl Feb 6, 2026
02879a8
Merge branch 'master' into kokkos-5.0
josephleekl Feb 10, 2026
db95ad8
Auto update version from '0.45.0-dev16' to '0.45.0-dev17'
ringo-but-quantum Feb 10, 2026
20d3e6d
Merge branch 'master' into kokkos-5.0
josephleekl Mar 6, 2026
b177d42
Auto update version from '0.45.0-dev23' to '0.45.0-dev24'
ringo-but-quantum Mar 6, 2026
0abe49f
Merge branch 'master' into kokkos-5.0
josephleekl Mar 17, 2026
a32b4eb
Auto update version from '0.45.0-dev28' to '0.45.0-dev29'
ringo-but-quantum Mar 17, 2026
189d4af
trigger CI
josephleekl Mar 17, 2026
d2dd3c5
trigger CI
josephleekl Mar 17, 2026
f2bee43
update dockerfile
josephleekl Mar 17, 2026
8e7febb
missing nanobind include
josephleekl Mar 17, 2026
2e4ee2c
add patch for stable 4.5.0
josephleekl Mar 17, 2026
885cd78
Apply suggestions from code review
josephleekl Mar 23, 2026
2d54a43
format
josephleekl Mar 23, 2026
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
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

<h3>Internal changes ⚙️</h3>

- Upgraded Kokkos from v4.5.0 to v5.0.0.
[(#1308)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1308)

- Upgrade CIs to use CUDA 12.9.
[(#1353)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1353)
[(#1354)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1354)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_and_cache_Kokkos_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
kokkos_version:
required: false
type: string
default: 4.5.00
default: 5.0.0
outputs:
exec_model:
description: "The execution model for Kokkos."
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/set_wheel_build_matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:

- name: Kokkos version
id: kokkos_version
run: echo "kokkos_version=[\"4.5.00\"]" >> $GITHUB_OUTPUT
run: echo "kokkos_version=[\"5.0.0\"]" >> $GITHUB_OUTPUT

outputs:
python_version: ${{ steps.pyver.outputs.python_version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_lkcpu_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
uses: ./.github/workflows/build_and_cache_Kokkos_linux.yml
with:
os: ubuntu-24.04
kokkos_version: "4.5.00"
kokkos_version: "5.0.0"

build_lightning_kokkos_wheels:
needs: [build_and_cache_Kokkos]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests_lkcuda_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
max-parallel: 1
matrix:
os: [ubuntu-22.04]
kokkos_version: ["4.5.00"]
kokkos_version: ["5.0.0"]
exec_model: ["CUDA"]
cuda_version_maj: ["12"]
cuda_version_min: ["9"]
Expand Down Expand Up @@ -110,7 +110,7 @@ jobs:
matrix:
os: [ubuntu-22.04]
pl_backend: ["lightning_kokkos"]
kokkos_version: ["4.5.00"]
kokkos_version: ["5.0.0"]
exec_model: ["CUDA"]
cuda_version_maj: ["12"]
cuda_version_min: ["9"]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests_lkcuda_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
max-parallel: 1
matrix:
os: [ubuntu-22.04]
kokkos_version: ["4.5.00"]
kokkos_version: ["5.0.0"]
exec_model: ["CUDA"]
cuda_version_maj: ["12"]
cuda_version_min: ["9"]
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
matrix:
os: [ubuntu-22.04]
pl_backend: ["lightning_kokkos", "all"]
kokkos_version: ["4.5.00"]
kokkos_version: ["5.0.0"]
exec_model: ["CUDA"]
cuda_version_maj: ["12"]
cuda_version_min: ["9"]
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests_lkmpi_cuda_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
max-parallel: 1
matrix:
mpilib: ["openmpi"]
kokkos_version: ["4.5.00"]
kokkos_version: ["5.0.0"]
exec_model: ["CUDA"]
cuda_version_maj: ["12"]
cuda_version_min: ["9"]
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
# Adding venv name as an output for subsequent steps to reference if needed
echo "venv_name=${{ env.VENV_NAME }}" >> $GITHUB_OUTPUT
echo "Python_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
echo "Python3_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
echo "Python3_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV

- name: Display Python-Path
id: python_path
Expand All @@ -121,7 +121,7 @@ jobs:

- name: Install required packages
run: |
python -m pip install --upgrade pip # Upgrade pip
python -m pip install --upgrade pip # Upgrade pip
python -m pip install --group tests
python -m pip install cmake scipy

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_lkmpi_cuda_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
max-parallel: 1
matrix:
mpilib: ["openmpi"]
kokkos_version: ["4.5.00"]
kokkos_version: ["5.0.0"]
exec_model: ["CUDA"]
cuda_version_maj: ["12"]
cuda_version_min: ["9"]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_windows_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:

- name: Kokkos version
id: kokkos_version
run: echo "kokkos_version=[\"4.5.00\"]" >> $GITHUB_OUTPUT
run: echo "kokkos_version=[\"5.0.0\"]" >> $GITHUB_OUTPUT

outputs:
exec_model: ${{ steps.exec_model.outputs.exec_model }}
Expand Down
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
7 changes: 2 additions & 5 deletions doc/lightning_amdgpu/installation.rst
Copy link
Member

Choose a reason for hiding this comment

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

Kokkos 5.0 mandates C++20. This raises the minimum compiler requirements for anyone building from source:
• GCC ≥ 10.4
• Clang ≥ 14.0 (CPU) / 15.0 (CUDA)
• NVCC ≥ 12.2
• MSVC ≥ 19.30

Could you please check and update CMakes and docs accordingly?

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The installation instruction here is specifically for AMD MI300 GPU (GFX942); fo

.. note::

Lightning-Kokkos and Lightning-AMDGPU are tested with Kokkos version 4.5.00
Lightning-Kokkos and Lightning-AMDGPU is tested with Kokkos version 5.0.0


Install Lightning-AMDGPU
Expand All @@ -33,10 +33,7 @@ Install Lightning-AMDGPU

# Install Lightning-AMDGPU
PL_BACKEND="lightning_amdgpu" python scripts/configure_pyproject_toml.py
export CMAKE_ARGS="-DCMAKE_CXX_COMPILER=hipcc \
-DKokkos_ENABLE_HIP=ON \
-DKokkos_ARCH_AMD_GFX942=ON \
-DCMAKE_PREFIX_PATH=/opt/rocm"
export CMAKE_ARGS="-DCMAKE_CXX_COMPILER=hipcc -DKokkos_ENABLE_HIP=ON -DKokkos_ARCH_AMD_GFX942=ON"
python -m pip install . -vv


Expand Down
14 changes: 7 additions & 7 deletions doc/lightning_kokkos/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Install Kokkos (Optional)

.. note::

Lightning-Kokkos is tested with Kokkos version 4.5.00
Lightning-Kokkos is tested with Kokkos version 5.0.0

We suggest first installing Kokkos with the wanted configuration following the instructions found in the `Kokkos documentation <https://kokkos.github.io/kokkos-core-wiki/building.html>`_.
For example, the following will build Kokkos for NVIDIA A100 cards:
Expand All @@ -29,16 +29,16 @@ Download the `Kokkos code <https://github.com/kokkos/kokkos/releases>`_.
.. code-block:: bash

# Replace x, y, and z by the correct version
wget https://github.com/kokkos/kokkos/archive/refs/tags/4.x.yz.tar.gz
tar -xvf 4.x.y.z.tar.gz
cd kokkos-4.x.y.z
wget https://github.com/kokkos/kokkos/archive/refs/tags/5.0.0.tar.gz
tar -xvf 5.0.0.tar.gz
cd kokkos-5.0.0

Build Kokkos for NVIDIA A100 cards (``SM80`` architecture), and append the install location to ``CMAKE_PREFIX_PATH``.

.. code-block:: bash

# Replace <install-path> with the path to install Kokkos
# e.g. $HOME/kokkos-install/4.5.0/AMPERE80
# e.g. $HOME/kokkos-install/5.0.0/AMPERE80
export KOKKOS_INSTALL_PATH=<install-path>
mkdir -p ${KOKKOS_INSTALL_PATH}

Expand Down Expand Up @@ -113,7 +113,7 @@ Install Lightning-Kokkos with MPI

.. note::

Building Lightning-Kokkos with MPI requires an MPI library and ``mpi4py``.
Building Lightning-Kokkos with MPI requires an MPI library and ``mpi4py``.
If building for GPU, please ensure that MPI is built with GPU support - for example, see the guide to
build OpenMPI with `CUDA <https://docs.open-mpi.org/en/v5.0.x/tuning-apps/networking/cuda.html>`_
and `ROCm <https://docs.open-mpi.org/en/v5.0.x/tuning-apps/networking/rocm.html>`_ support.
Expand All @@ -130,7 +130,7 @@ Then Lightning-Kokkos with MPI support can be installed in the *editable* mode b
python -m pip install --group base
pip install git+https://github.com/PennyLaneAI/pennylane.git@main

# Lightning-Qubit needs to be 'installed' by pip before Lightning-Kokkos
# Lightning-Qubit needs to be 'installed' by pip before Lightning-Kokkos
# (compilation is not necessary)
PL_BACKEND="lightning_qubit" python scripts/configure_pyproject_toml.py
SKIP_COMPILATION=True pip install -e . --config-settings editable_mode=compat
Expand Down
12 changes: 6 additions & 6 deletions doc/lightning_kokkos/installation_hpc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Install Kokkos (Recommended)

.. note::

Lightning-Kokkos is tested with Kokkos version 4.5.00
Lightning-Kokkos is tested with Kokkos version 5.0.0

We suggest first installing Kokkos with the desired configuration, following the instructions found in the Kokkos documentation.
For example, the following instructions demonstrate building Kokkos for AMD MI210/250/250X GPUs:
Expand All @@ -38,9 +38,9 @@ Download the `Kokkos code <https://github.com/kokkos/kokkos/releases>`_.
.. code-block:: bash

# Replace x, y, and z by the correct version
wget https://github.com/kokkos/kokkos/archive/refs/tags/4.x.yz.tar.gz
tar -xvf 4.x.y.z.tar.gz
cd kokkos-4.x.y.z
wget https://github.com/kokkos/kokkos/archive/refs/tags/5.0.0.tar.gz
tar -xvf 5.0.0.tar.gz
cd kokkos-5.0.0/

Build Kokkos for AMD GPU (``GFX90A`` architecture), and append the install location to ``CMAKE_PREFIX_PATH``.

Expand Down Expand Up @@ -80,7 +80,7 @@ It can be installed from source as follows:
python -m pip install --group base
pip install git+https://github.com/PennyLaneAI/pennylane.git@main
PL_BACKEND="lightning_qubit" python scripts/configure_pyproject_toml.py
CMAKE_ARGS="-DCMAKE_CXX_COMPILER=CC" pip install .
CMAKE_ARGS="-DCMAKE_CXX_COMPILER=CC" pip install . -vv

Then to install Lightning-Kokkos with MPI support:

Expand All @@ -95,7 +95,7 @@ Then to install Lightning-Kokkos with MPI support:
export CMAKE_ARGS="-DENABLE_MPI=ON -DCMAKE_CXX_COMPILER=hipcc"

PL_BACKEND="lightning_kokkos" python scripts/configure_pyproject_toml.py
python -m pip install .
python -m pip install . -vv

.. note::

Expand Down
6 changes: 3 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ARG PENNYLANE_VERSION=master
ARG LIGHTNING_VERSION=master
ARG GCC_VERSION=13
ARG CUDA_INSTALLER=https://developer.download.nvidia.com/compute/cuda/12.5.1/local_installers/cuda_12.5.1_555.42.06_linux.run
ARG CUDA_INSTALLER=https://developer.download.nvidia.com/compute/cuda/12.9.1/local_installers/cuda_12.9.1_575.57.08_linux.run
ARG ROCM_INSTALLER=https://repo.radeon.com/amdgpu-install/7.0.3/ubuntu/jammy/amdgpu-install_7.0.3.70003-1_all.deb
ARG AMD_ARCH=AMD_GFX942
ARG CUDA_ARCH=AMPERE80
Expand Down Expand Up @@ -115,7 +115,7 @@
RUN chmod a+x cuda-install.run
RUN ./cuda-install.run --silent --toolkit --toolkitpath=/usr/local/cuda-$(echo ${CUDA_INSTALLER} | grep -o -P '/cuda/.{0,4}' | cut -d / -f 3)
ENV PATH=/usr/local/cuda/bin:${PATH}
ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}

Check warning on line 118 in docker/Dockerfile

View workflow job for this annotation

GitHub Actions / docker::ubuntu-24.04::lightning-gpu::kokkos-5.0

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$LD_LIBRARY_PATH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/

Check warning on line 118 in docker/Dockerfile

View workflow job for this annotation

GitHub Actions / docker::ubuntu-24.04::lightning-kokkos-cuda::kokkos-5.0

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$LD_LIBRARY_PATH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/

# Download Lightning release and build lightning-kokkos backend with Kokkos-CUDA
FROM base-build-cuda AS build-wheel-lightning-kokkos-cuda
Expand All @@ -133,7 +133,7 @@

# Install python3 and setup runtime virtual env in CUDA-12-runtime image (includes CUDA runtime and math libraries)
# Install lightning-kokkos CUDA backend
FROM nvidia/cuda:12.5.1-base-ubuntu24.04 AS wheel-lightning-kokkos-cuda
FROM nvidia/cuda:12.9.1-base-ubuntu24.04 AS wheel-lightning-kokkos-cuda
ARG PENNYLANE_VERSION
ARG GCC_VERSION
ENV DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -168,7 +168,7 @@

# Install python3 and setup runtime virtual env in CUDA-12-runtime image (includes CUDA runtime and math libraries)
# Install lightning-kokkos CUDA backend
FROM nvidia/cuda:12.5.1-runtime-ubuntu24.04 AS wheel-lightning-gpu
FROM nvidia/cuda:12.9.1-runtime-ubuntu24.04 AS wheel-lightning-gpu
ARG PENNYLANE_VERSION
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
Expand Down Expand Up @@ -209,7 +209,7 @@
FROM base-build-rocm AS build-wheel-lightning-kokkos-rocm
ARG AMD_ARCH
WORKDIR /opt/pennylane-lightning
ENV CMAKE_PREFIX_PATH=/opt/rocm:$CMAKE_PREFIX_PATH

Check warning on line 212 in docker/Dockerfile

View workflow job for this annotation

GitHub Actions / docker::ubuntu-24.04::lightning-kokkos-rocm::kokkos-5.0

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$CMAKE_PREFIX_PATH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/
ENV CXX=hipcc
ENV PL_BACKEND=lightning_amdgpu
RUN pip uninstall -y pennylane-lightning
Expand All @@ -236,7 +236,7 @@
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
ENV LD_LIBRARY_PATH="/usr/lib/llvm-14/lib:$LD_LIBRARY_PATH"

Check warning on line 239 in docker/Dockerfile

View workflow job for this annotation

GitHub Actions / docker::ubuntu-24.04::lightning-kokkos-rocm::kokkos-5.0

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$LD_LIBRARY_PATH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/
COPY --from=build-wheel-lightning-kokkos-rocm /opt/pennylane-lightning/dist/ /
COPY --from=build-wheel-lightning-qubit /opt/pennylane-lightning/dist/ /
RUN pip install --force-reinstall --no-cache-dir pennylane_lightning*.whl && rm pennylane_lightning*.whl
Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Copy link
Member

Choose a reason for hiding this comment

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

Don't forget to update the changelog :)

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-dev28"
__version__ = "0.45.0-dev29"
1 change: 1 addition & 0 deletions pennylane_lightning/core/bindings/BindingsCudaUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "cuda_helpers.hpp"

#include <nanobind/nanobind.h>
#include <nanobind/stl/pair.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this will help with an issue seen sometimes for ARM CUDA wheels CIs:
e.g.
https://github.com/PennyLaneAI/pennylane-lightning/actions/runs/23185381696/job/67367515707
https://github.com/PennyLaneAI/pennylane-lightning/actions/runs/23167693870/job/67311848768

This is indeterministic with some CI runs, possibly due to GPU runner environment issues. The error of the missing pair include masks the real error, so this will help with that.


/// @cond DEV
namespace {
Expand Down
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)
Copy link
Member

Choose a reason for hiding this comment

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

could you replace all these Kokkos::Experimental::popcount_builtin with std::popcount?

? 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(
Copy link
Member

Choose a reason for hiding this comment

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

We should be safe to use std::popcount in C++20 I suppose 🤔

Suggested change
1 - 2 * int(Kokkos::Experimental::popcount_builtin(
1 - 2 * int(std::popcount(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maliasadi but this is to execute on the device, not on the host, and std::popcount is just on the host. Kokkos popcount is more appropriate in this case

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(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
1 - 2 * int(Kokkos::Experimental::popcount_builtin(
1 - 2 * int(std::popcount(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but actually maybe i should use Kokkos::popcountinstead. let me try it

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
Loading