Convert Figma logo to code with AI

kokkos logokokkos

Kokkos C++ Performance Portability Programming Ecosystem: The Programming Model - Parallel Execution and Memory Abstraction

1,850
421
1,850
441

Top Related Projects

4,907

[ARCHIVED] The C++ parallel algorithms library. See https://github.com/NVIDIA/cccl

3,683

HIP: C++ Heterogeneous-Compute Interface for Portability

1,541

A C++ GPU Computing Library for OpenCL

Quick Overview

Kokkos is a performance-portable programming model for parallel execution and memory abstraction. It aims to enable developers to write high-performance applications that can run efficiently on diverse hardware architectures, including multi-core CPUs, GPUs, and accelerators, without the need to rewrite code for each platform.

Pros

  • Performance portability across various hardware architectures
  • Simplified parallel programming model with a unified interface
  • Extensive support for different memory spaces and execution policies
  • Active development and maintenance by a dedicated community

Cons

  • Steep learning curve for developers new to parallel programming
  • Potential overhead in some cases compared to platform-specific optimizations
  • Limited support for certain specialized hardware or niche architectures
  • Requires careful design considerations to fully leverage its capabilities

Code Examples

  1. Basic parallel for loop:
#include <Kokkos_Core.hpp>

void example_parallel_for() {
  Kokkos::parallel_for(100, KOKKOS_LAMBDA(const int i) {
    // Perform operation on each index
    printf("Index: %d\n", i);
  });
}
  1. Reduction example:
#include <Kokkos_Core.hpp>

void example_reduction() {
  int sum = 0;
  Kokkos::parallel_reduce(100, KOKKOS_LAMBDA(const int i, int& local_sum) {
    local_sum += i;
  }, sum);
  printf("Sum: %d\n", sum);
}
  1. View creation and usage:
#include <Kokkos_Core.hpp>

void example_view() {
  Kokkos::View<double**> matrix("Matrix", 10, 10);
  Kokkos::parallel_for(10, KOKKOS_LAMBDA(const int i) {
    for (int j = 0; j < 10; ++j) {
      matrix(i, j) = i * j;
    }
  });
}

Getting Started

To get started with Kokkos:

  1. Clone the repository:

    git clone https://github.com/kokkos/kokkos.git
    
  2. Configure and build:

    cd kokkos
    mkdir build && cd build
    cmake ..
    make
    
  3. Include Kokkos in your project:

    #include <Kokkos_Core.hpp>
    
    int main(int argc, char* argv[]) {
      Kokkos::initialize(argc, argv);
      // Your Kokkos code here
      Kokkos::finalize();
      return 0;
    }
    
  4. Compile your project with Kokkos:

    g++ -std=c++14 -I/path/to/kokkos/include your_file.cpp -L/path/to/kokkos/lib -lkokkos
    

Competitor Comparisons

4,907

[ARCHIVED] The C++ parallel algorithms library. See https://github.com/NVIDIA/cccl

Pros of Thrust

  • Highly optimized for NVIDIA GPUs, offering excellent performance on CUDA-enabled devices
  • Extensive set of parallel algorithms and data structures out-of-the-box
  • Seamless integration with CUDA and C++ STL

Cons of Thrust

  • Limited portability across different hardware architectures
  • Less flexibility for custom memory spaces and execution policies
  • Steeper learning curve for developers not familiar with CUDA ecosystem

Code Comparison

Thrust:

thrust::device_vector<float> d_vec(1000);
thrust::fill(d_vec.begin(), d_vec.end(), 1.0f);
float sum = thrust::reduce(d_vec.begin(), d_vec.end());

Kokkos:

Kokkos::View<float*> d_vec("d_vec", 1000);
Kokkos::parallel_for(1000, KOKKOS_LAMBDA(const int i) {
  d_vec(i) = 1.0f;
});
float sum = Kokkos::parallel_reduce(1000, KOKKOS_LAMBDA(const int i, float& lsum) {
  lsum += d_vec(i);
}, sum);

Both Thrust and Kokkos aim to simplify parallel programming, but they have different strengths. Thrust excels in NVIDIA GPU environments, offering high performance and a rich set of algorithms. Kokkos provides better portability across various architectures and more flexibility in execution policies, making it suitable for a wider range of HPC applications.

3,683

HIP: C++ Heterogeneous-Compute Interface for Portability

Pros of HIP

  • Direct GPU programming model, closer to CUDA for easier porting
  • Supports both AMD and NVIDIA GPUs, offering broader hardware compatibility
  • Provides lower-level control over GPU resources

Cons of HIP

  • Less abstraction, requiring more hardware-specific knowledge
  • Steeper learning curve for developers new to GPU programming
  • Limited portability to non-GPU architectures

Code Comparison

HIP code example:

__global__ void vectorAdd(float *a, float *b, float *c, int n) {
    int i = blockDim.x * blockIdx.x + threadIdx.x;
    if (i < n) c[i] = a[i] + b[i];
}

Kokkos code example:

struct VectorAdd {
    KOKKOS_INLINE_FUNCTION
    void operator()(const int i) const {
        c(i) = a(i) + b(i);
    }
    // View declarations omitted for brevity
};

HIP offers a more CUDA-like syntax, while Kokkos provides a higher level of abstraction, potentially simplifying code across different architectures. Kokkos aims for better portability, whereas HIP focuses on GPU-specific optimizations and control.

1,541

A C++ GPU Computing Library for OpenCL

Pros of Compute

  • Part of the Boost ecosystem, benefiting from its extensive documentation and community support
  • Focuses specifically on GPU computing, offering a more specialized solution for GPU-related tasks
  • Provides a higher-level abstraction for GPGPU programming, potentially easier for beginners

Cons of Compute

  • Limited to GPU computing, while Kokkos offers a more versatile approach for various hardware architectures
  • Less active development and updates compared to Kokkos
  • Smaller community and fewer resources available for troubleshooting and support

Code Comparison

Compute example:

compute::vector<float> vec(1000);
compute::fill(vec.begin(), vec.end(), 42);
compute::transform(vec.begin(), vec.end(), vec.begin(), compute::_1 * 2);

Kokkos example:

Kokkos::View<float*> vec("vec", 1000);
Kokkos::parallel_for(1000, KOKKOS_LAMBDA(const int i) {
  vec(i) = 42;
});
Kokkos::parallel_for(1000, KOKKOS_LAMBDA(const int i) {
  vec(i) *= 2;
});

Both libraries aim to simplify parallel computing, but Kokkos provides a more general-purpose solution for various architectures, while Compute focuses on GPU-specific optimizations within the Boost framework.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Kokkos

Kokkos: Core Libraries

Kokkos Core implements a programming model in C++ for writing performance portable applications targeting all major HPC platforms. For that purpose it provides abstractions for both parallel execution of code and data management. Kokkos is designed to target complex node architectures with N-level memory hierarchies and multiple types of execution resources. It currently can use CUDA, HIP, SYCL, HPX, OpenMP and C++ threads as backend programming models with several other backends in development.

Kokkos Core is part of the Kokkos C++ Performance Portability Programming Ecosystem.

Kokkos is a Linux Foundation project.

Learning about Kokkos

To start learning about Kokkos:

Obtaining Kokkos

The latest release of Kokkos can be obtained from the GitHub releases page.

The current release is 4.4.00.

curl -OJ -L https://github.com/kokkos/kokkos/releases/download/4.4.00/kokkos-4.4.00.tar.gz
# Or with wget
wget https://github.com/kokkos/kokkos/releases/download/4.4.00/kokkos-4.4.00.tar.gz

To clone the latest development version of Kokkos from GitHub:

git clone -b develop  https://github.com/kokkos/kokkos.git

Building Kokkos

To build Kokkos, you will need to have a C++ compiler that supports C++17 or later. All requirements including minimum and primary tested compiler versions can be found here.

Building and installation instructions are described here.

You can also install Kokkos using Spack: spack install kokkos. Available configuration options can be displayed using spack info kokkos.

For the complete documentation: kokkos.org/kokkos-core-wiki/

Support

For questions find us on Slack: https://kokkosteam.slack.com or open a GitHub issue.

For non-public questions send an email to: crtrott(at)sandia.gov

Contributing

Please see this page for details on how to contribute.

Citing Kokkos

Please see the following page.

License

License

Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains certain rights in this software.

The full license statement used in all headers is available here or here.