Written and maintained by CASRAI Editorial Board
Published
On this page
Kokkos is an open-source C++ library for writing performance-portable parallel code: you write a loop or reduction once, and Kokkos maps it onto the CPU threads or GPU of the machine it is built for. It is developed as a Linux Foundation project, is licensed Apache-2.0 with an LLVM exception, and is built with CMake by choosing a backend such as OpenMP, CUDA, HIP or SYCL at configure time (GitHub README and Kokkos Core wiki, read 2026-11-13).
This guide covers what the library is for, how to build it from the official sources, a first program that initializes Kokkos and runs a reduction, the mistakes the documentation warns about, and how it compares with RAJA, the other library named in the same performance-portability role. The data table at the end lists the minimum compiler versions for Kokkos 3.x, 4.x and 5.x.
What Kokkos is used for in research
The Kokkos README describes the project as implementing "a programming model in C++ for writing performance portable applications," with abstractions for both parallel execution and data management. In research settings this matters where one simulation or analysis code has to run on a laptop, a CPU cluster and a GPU system without being rewritten for each. It is a C++ library and targets compiled scientific codes. Research software engineers (see the RSE role definition) typically maintain such codes, and the group that owns the code depends on the build recipe being recorded, which ties to computational reproducibility.
Two concepts carry most of the programming model, both from the Kokkos programming guide:
- Execution policy and parallel dispatch. An execution policy controls how a parallel operation runs. If you do not name one, the default execution space is used.
RangePolicysets the index range. - Views. A
Viewis Kokkos’s multidimensional array. Its memory space defaults to the default execution space’s default memory space, and its layout is chosen for parallel access on that space.
The repository lists these backends: CUDA, HIP, SYCL, HPX, OpenMP and C++ threads, with others in development. The docs wiki also points to companion projects: kokkos-kernels, kokkos-tools and pykokkos.
Install or access (official source only)
Kokkos is not a binary you download and run. The building-from-source page offers two routes, a release archive or a git checkout.
Option 1: release archive with checksum
The documentation’s example sets a version variable, downloads the archive from the project’s GitHub releases, and verifies it against the published SHA-256 file before unpacking:
export KOKKOS_VERSION=4.5.01
curl -sLO https://github.com/kokkos/kokkos/releases/download/${KOKKOS_VERSION}/kokkos-${KOKKOS_VERSION}.tar.gz
tar -xzvf kokkos-${KOKKOS_VERSION}.tar.gz
The wiki also publishes a checksum file named kokkos-${KOKKOS_VERSION}-SHA-256.txt and states that if the checksum does not match, the archive must not be used. Version 4.5.01 is the value in that example; the repository page showed 5.1.0 as the latest release when read on 2026-11-13, so replace the version with the release your project has chosen and record it.
Option 2: git
git clone https://github.com/kokkos/kokkos.git
cd kokkos
git checkout 4.5.01
The docs note that develop is the latest code and less stable than a tagged release.
Requirements before you configure
CMake 3.16 or newer is required (3.18 for Fortran linkage, 3.21.1 for NVC++). Compilers must meet the per-version minimums in the data table below. On HPC systems the compiler, CUDA or ROCm toolchain usually comes from the site’s module system or a package manager such as Spack, and GPU jobs are then requested through the scheduler, as in requesting a GPU in a Slurm batch job.
Step-by-step: build Kokkos, initialize it and run a reduction
Step 1. Configure an out-of-source build
The wiki requires an out-of-source build, using cmake -B builddir plus options. Its worked example for a CPU build with OpenMP is:
cmake -B builddir -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=Release -DKokkos_ENABLE_OPENMP=ON -DKokkos_ARCH_NATIVE=ON -DKokkos_ENABLE_DEPRECATED_CODE_4=OFF
Documented option behaviour: CMAKE_CXX_STANDARD defaults to 20; CMAKE_BUILD_TYPE accepts Debug, Release, RelWithDebInfo (the default) and MinSizeRel; and the wiki strongly recommends -DKokkos_ENABLE_DEPRECATION_WARNINGS=ON together with -DKokkos_ENABLE_DEPRECATED_CODE_4=OFF. For a GPU build, swap the backend flag and set the architecture explicitly, using the mapping below.
| Target | CMake flag (from the wiki) |
|---|---|
| CPU threads via OpenMP | Kokkos_ENABLE_OPENMP (or Kokkos_ENABLE_THREADS) |
| NVIDIA GPU | Kokkos_ENABLE_CUDA |
| AMD GPU | Kokkos_ENABLE_HIP |
| Intel GPU | Kokkos_ENABLE_SYCL |
| Host CPU architecture | Kokkos_ARCH_NATIVE |
| NVIDIA A100 | Kokkos_ARCH_AMPERE80 |
| AMD MI210X | Kokkos_ARCH_AMD_GFX90A |
| Intel Max 1550 | Kokkos_ARCH_INTEL_PVC |
On Windows, CUDA with MSVC additionally needs -DKokkos_ENABLE_COMPILE_AS_CMAKE_LANGUAGE=ON.
Step 2. Build, test and install
cmake --build builddir -j8
cmake --install builddir --prefix /path/to/kokkos-install
Always give an install prefix; omitting it installs to a default such as /usr/local, which the wiki says is not recommended. To run the test suite, configure with -DKokkos_ENABLE_TESTS=ON and then run ctest --test-dir builddir --output-on-failure. The wiki also notes the build tree can serve as an install tree through <builddir>/cmake_packages/.
Step 3. Initialize and finalize Kokkos in your program
From the initialization guide, the minimal skeleton is:
#include <Kokkos_Core.hpp>
int main(int argc, char* argv[]) {
Kokkos::initialize(argc, argv);
// Kokkos work goes here
Kokkos::finalize();
}
To set options in code instead of on the command line, create a Kokkos::InitializationSettings object, call setters such as set_num_threads(8) or set_device_id(1), and pass it to Kokkos::initialize(settings). The guide states Kokkos must be shut down with Kokkos::finalize() to free resources. If your code also uses MPI, initialize Kokkos right after MPI_Init, because the process binding masks are involved.
Step 4. Declare a View and run a parallel reduction
A View is declared with a label and its run-time extents, for example Kokkos::View<double*> x("x", N) for a one-dimensional array or Kokkos::View<double*[3]> b("another label", N) for N rows of three. Run-time dimensions must come before compile-time ones, so View<int*[3][8]> is valid and View<int[4]**> is not. The programming guide’s reduction example sums the entries:
const size_t N = /* problem size */;
View<double*> x("x", N);
double sum = 0.0;
parallel_reduce("Reduction", N,
KOKKOS_LAMBDA (const int i, double& update) { update += x(i); },
sum);
Fill x with your data before reducing. The same guide shows a functor form, parallel_reduce("Reduction", N, MaxPlus(x), result), where the functor’s operator() is declared KOKKOS_INLINE_FUNCTION void operator()(const size_type i, value_type& update) const.
Output and how to read it
The result of a reduction is the value written into the final argument, sum in the example above. Three points from the documentation help when reading results:
parallel_forgives no guarantee of loop order or concurrency, and may even run a small loop serially. Iterations must not wait on each other, so a result that depends on iteration order is a bug in the algorithm, not in Kokkos.- The string passed as the first argument of a View is a label Kokkos uses for debugging; different Views may share a label.
- Views are reference-counted: copying or assigning one is a shallow copy, and the memory can be deallocated once the count reaches zero.
For publication, record the Kokkos version, the backend and architecture flags, the compiler and the build type next to the results; those are the inputs that change what is built. The CuPy guide covers a separate, Python-side route to GPU arrays if your code is not C++.
Troubleshooting
| Symptom | What the documentation says |
|---|---|
| Checksum of the downloaded archive does not match | Do not use the archive; the wiki’s instruction is not to use it. |
| Configure in the source directory | The wiki requires an out-of-source build; use cmake -B builddir. |
| Configure or compile fails on an older compiler | The minimum compiler versions differ by Kokkos major version; see the data table. |
| Code built for the wrong GPU | The wiki says to set the architecture explicitly when possible, for example Kokkos_ARCH_AMPERE80 for an A100. |
| Lambda behaves unexpectedly or fails on GPU | Use KOKKOS_LAMBDA, which captures by value and expands specially on CUDA/HIP. Never capture by reference with [&]. |
| Crash at program exit | All View allocations must end before Kokkos::finalize; a View destroyed after finalize is incorrect usage. |
| Wrong thread or device binding under MPI | Call Kokkos::initialize immediately after MPI_Init. |
| Warnings about removed or old interfaces | Enable deprecation warnings and turn deprecated code off with Kokkos_ENABLE_DEPRECATED_CODE_4=OFF. |
The View page states that allocation and reference counting are turned off inside parallel_for, parallel_reduce and parallel_scan.
Free alternatives
RAJA is the other open-source C++ performance-portability library named in this role. The rows below contain only what each project’s own repository README states.
| Kokkos | RAJA | |
|---|---|---|
| Described as | A C++ programming model for performance portable applications | A library of C++ software abstractions, primarily developed at Lawrence Livermore National Laboratory, supporting portability for HPC applications |
| Licence | Apache-2.0 WITH LLVM-exception | BSD 3-Clause |
| Stewardship | Linux Foundation project | Developed by a core team at LLNL |
| C++ standard | CMake default CMAKE_CXX_STANDARD is 20 |
README states it relies on C++20 |
For job submission once either library is built, see srun vs sbatch vs salloc.
FAQ
What is Kokkos?
Kokkos is a C++ library and programming model for writing parallel code that runs efficiently on different CPU and GPU hardware. It is a Linux Foundation project under the Apache-2.0 licence with an LLVM exception.
Which compilers does Kokkos need?
It depends on the major version. For Kokkos 5.x the minimums include GCC 10.4.0, Clang 14.0.0 for CPU, NVCC 12.2 and MSVC 19.30; see the data table for 4.x and 3.x.
Does Kokkos run on GPUs?
Yes, through the CUDA (NVIDIA), HIP (AMD) and SYCL (Intel) backends, enabled with Kokkos_ENABLE_CUDA, Kokkos_ENABLE_HIP and Kokkos_ENABLE_SYCL.
Can I use Kokkos from Python?
The Kokkos documentation lists pykokkos among related projects; consult that project’s own documentation for its usage.
Sources
- Kokkos Core wiki, Building from source: kokkos.org/kokkos-core-wiki/get-started/building-from-source.html (read 2026-11-13)
- Kokkos Core wiki, Requirements: kokkos.org/kokkos-core-wiki/get-started/requirements.html (read 2026-11-13)
- Kokkos programming guide, Initialization, View and Parallel dispatch: Initialization, View, Parallel dispatch (read 2026-11-13)
- Kokkos repository README: github.com/kokkos/kokkos (read 2026-11-13)
- RAJA repository README: github.com/LLNL/RAJA (read 2026-11-13)
Data: Kokkos minimum compiler versions by major release (3.x, 4.x, 5.x)
Minimum supported compiler and toolchain versions for Kokkos 5.x, 4.x and 3.x, compiled from the Requirements page of the official Kokkos Core wiki and arranged by compiler so versions can be compared across major releases.
| Compiler | Kokkos 5.x minimum | Kokkos 4.x minimum | Kokkos 3.x minimum |
|---|---|---|---|
| GCC | 10.4.0 | 8.2.0 | 5.3.0 |
| Clang (CPU) | 14.0.0 | 8.0.0 | 4.0.0 |
| Clang (CUDA) | 15.0.0 with CUDA 11.8.0 | 10.0.0 | not listed |
| NVCC | 12.2 | 11.0 | 9.2.88 |
| IntelLLVM (SYCL) | 2024.2.1 | 2023.0.0 | not listed |
| ROCM | 6.2.0 | 5.2.0 | 4.5 |
| MSVC | 19.30 | 19.29 | 19.29 |
| NVC++ | 22.3 | 22.3 | 21.5 |
Sources
- Kokkos Core wiki: Requirements (accessed 2026-11-13)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







