Performance comparison of the 3D Laplacian stencil computation
The goal is to test multiple implementation of the Laplacian equation, for different programming languages and different libraries, with CPU and GPU, and various compilation options.
Currently, we implemented:
- Native C++ (CPU)
- C++ with the Kokkos library (CPU and GPU)
- Python with Numba (CPU)
- Python with Taichi (CPU and GPU)
The Laplacian operator is defined as the sum of second partial derivatives
In 1D, using a grid spacing h:
In 3D, for a regular cubic grid:
Clone the repository
git clone --recurse-submodules https://github.com/mianbreton/laplacian_challenge.gitThe C++ and Python tests are independent.
# Build native and Kokkos CPU executables
cd cpp/
mkdir -p build/openmp; cd build/openmp
cmake ../../ -DKokkos_ENABLE_OPENMP=ON
make -j $NCPU
# Build Kokkos GPU executables with CUDA
cd cpp/
mkdir -p build/cuda; cd build/cuda
cmake ../../ -DKokkos_ENABLE_OPENMP=ON -DKokkos_ENABLE_CUDA=ON
make -j $NCPUConfiguration options ( cmake -D arguments ) include :
# The following GPU backends are available
DKokkos_ENABLE_CUDA=ON/OFF
DKokkos_ENABLE_HIP=ON/OFF
DKokkos_ENABLE_SYCL=ON/OFF
# Debug, adds the -g compilation flag
-DDEBUG=ON/OFF
# Enable unit testing
-DENABLE_UNIT_TESTING=ON/OFFIf unit tests are enabled, run ctest in the build directory to test the build.
To install all the dependencies
cd python/
python -m pip install -e .
⚠️ Currently, it seems that Taichi does not support Python 3.11 and above
To test the installation, first install pytest and run the tests
python -m pip install pytest
# Then, in the python/ directory
pytestYou can run the C++ executables with
cd cpp/
./run_all.shTo run the Python implementations
cd python/
python run.py # Which by defaults runs as 'python run.py --ncells 32 64 128 256 --ncpus 1 2 4 8 16 --runs 10'Both runs will produce runtime files in ./timings/
If you with to contribute to this project with other implementations of the Laplacian equation, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.


