Lightning-Kokkos installation¶
On linux systems, lightning.kokkos
with the OpenMP backend can be installed by providing the optional [kokkos]
tag:
$ pip install pennylane-lightning[kokkos]
Install Lightning-Kokkos from source¶
As Kokkos enables support for many different HPC-targeted hardware platforms, lightning.kokkos
can be built to support any of these platforms when building from source.
We suggest first installing Kokkos with the wanted configuration following the instructions found in the Kokkos documentation. For example, the following will build Kokkos for NVIDIA A100 cards
cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=RelWithDebugInfo \
-DCMAKE_INSTALL_PREFIX=/opt/kokkos/4.1.00/AMPERE80 \
-DCMAKE_CXX_STANDARD=20 \
-DBUILD_SHARED_LIBS:BOOL=ON \
-DBUILD_TESTING:BOOL=OFF \
-DKokkos_ENABLE_SERIAL:BOOL=ON \
-DKokkos_ENABLE_CUDA:BOOL=ON \
-DKokkos_ARCH_AMPERE80:BOOL=ON \
-DKokkos_ENABLE_EXAMPLES:BOOL=OFF \
-DKokkos_ENABLE_TESTS:BOOL=OFF \
-DKokkos_ENABLE_LIBDL:BOOL=OFF
cmake --build build && cmake --install build
echo export CMAKE_PREFIX_PATH=/opt/kokkos/4.1.00/AMPERE80:\$CMAKE_PREFIX_PATH
Next, append the install location to CMAKE_PREFIX_PATH
.
Note that the C++20 standard is required (-DCMAKE_CXX_STANDARD=20
option), and hence CUDA v12 is required for the CUDA backend.
If an installation is not found, our builder will clone and install it during the build process.
The simplest way to install Lightning-Kokkos (OpenMP backend) through pip
.
CMAKE_ARGS="-DKokkos_ENABLE_OPENMP=ON" PL_BACKEND="lightning_kokkos" python -m pip install .
To build the plugin directly with CMake as above:
cmake -B build -DKokkos_ENABLE_OPENMP=ON -DPL_BACKEND=lightning_kokkos -G Ninja
cmake --build build
The supported backend options are SERIAL
, OPENMP
, THREADS
, HIP
and CUDA
and the corresponding build options are -DKokkos_ENABLE_XXX=ON
, where XXX
needs be replaced by the backend name, for instance OPENMP
.
One can activate simultaneously one serial, one parallel CPU host (e.g. OPENMP
, THREADS
) and one parallel GPU device backend (e.g. HIP
, CUDA
), but not two of any category at the same time.
For HIP
and CUDA
, the appropriate software stacks are required to enable compilation and subsequent use.
Similarly, the CMake option -DKokkos_ARCH_{...}=ON
must also be specified to target a given architecture.
A list of the architectures is found on the Kokkos wiki.
Note that THREADS
backend is not recommended since Kokkos does not guarantee its safety.