Speeding up stencil computations on CPUs and GPUs
Project description
pystencils
Run blazingly fast stencil codes on numpy arrays.
pystencils uses sympy to define stencil operations, that can be executed on numpy arrays. Exploiting the stencil structure makes pystencils run faster than normal numpy code and even as Cython and numba, as demonstrated in this notebook.
Here is a code snippet that computes the average of neighboring cells:
import pystencils as ps
import numpy as np
f, g = ps.fields("f, g : [2D]")
stencil = ps.Assignment(g[0, 0],
(f[1, 0] + f[-1, 0] + f[0, 1] + f[0, -1]) / 4)
kernel = ps.create_kernel(stencil).compile()
f_arr = np.random.rand(1000, 1000)
g_arr = np.empty_like(f_arr)
kernel(f=f_arr, g=g_arr)
pystencils is mostly used for numerical simulations using finite difference or finite volume methods. It comes with automatic finite difference discretization for PDEs:
import pystencils as ps
import sympy as sp
c, v = ps.fields("c, v(2): [2D]")
adv_diff_pde = ps.fd.transient(c) - ps.fd.diffusion(c, sp.symbols("D")) + ps.fd.advection(c, v)
discretize = ps.fd.Discretization2ndOrder(dx=1, dt=0.01)
discretization = discretize(adv_diff_pde)
Installation
pip install pystencils[interactive]
Without [interactive]
you get a minimal version with very little dependencies.
All options:
gpu
: use this if an NVIDIA or AMD GPU is available and CUDA or ROCm is installedalltrafos
: pulls in additional dependencies for loop simplification e.g. libislbench_db
: functionality to store benchmark result in object databasesinteractive
: installs dependencies to work in Jupyter including image I/O, plotting etc.doc
: packages to build documentation
Options can be combined e.g.
pip install pystencils[interactive, gpu, doc]
pystencils is also fully compatible with Windows machines. If working with visual studio and cupy makes sure to run example files first to ensure that cupy can find the compiler's executable.
Documentation
Read the docs here and
check out the Jupyter notebooks in doc/notebooks
. The Changelog of pystencils can be found here.
Authors
Many thanks go to the contributors of pystencils.
Please cite us
If you use pystencils in a publication, please cite the following articles:
Overview:
- M. Bauer et al, Code Generation for Massively Parallel Phase-Field Simulations. Association for Computing Machinery, 2019. https://doi.org/10.1145/3295500.3356186
Performance Modelling:
- D. Ernst et al, Analytical performance estimation during code generation on modern GPUs. Journal of Parallel and Distributed Computing, 2023. https://doi.org/10.1016/j.jpdc.2022.11.003
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pystencils-1.3.7.tar.gz
.
File metadata
- Download URL: pystencils-1.3.7.tar.gz
- Upload date:
- Size: 311.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 964a0b2130ea7da23294f93b332f6c526589f5ee8118c6f8c52e3b01517ba734 |
|
MD5 | fd70201493b7ab52dc29350d11c8afd2 |
|
BLAKE2b-256 | ad29ced165ce19927046126dd3742dab9223b110c10c4d66f1f9fe5fb20f6a5c |
File details
Details for the file pystencils-1.3.7-py3-none-any.whl
.
File metadata
- Download URL: pystencils-1.3.7-py3-none-any.whl
- Upload date:
- Size: 273.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c952b678d6991980613fc581d1de8f766ba140bd8090e525ec9ab043edfb4519 |
|
MD5 | 9e23b026f84ab6c7473a92b92829f8ae |
|
BLAKE2b-256 | 585859c29a0c3600a1ffac369592bb5e2597c10944db9246809c883116fc2736 |