Speeding up stencil computations on CPUs and GPUs
Project description
pystencils
Pystencils is a symbolic domain-specific language and metaprogramming toolkit for writing high-performance numerical stencil kernels for a variety of hardware targets.
[!note] This is the code of repository of pystencils 2.x, the near-complete rework of the pystencils package. The legacy package pystencils 1.4 is being supported at the
v1.xbranch of this repository.
Installation
Pystencils can be installed from PyPI using pip, e.g.:
pip install pystencils~=2.0
For more information on installing pystencils, refer to the Installation Guide.
Example
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)
Documentation
Here's an overview of our documentation ressources:
Contributing
Please refer to the contribution guide for instructions on how to start contributing to pystencils.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pystencils-2.0b1.tar.gz.
File metadata
- Download URL: pystencils-2.0b1.tar.gz
- Upload date:
- Size: 308.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79babf51f9b5364245e9c303a4f51b00b834b83ebc6f1b975f9767ec154c49a7
|
|
| MD5 |
8533ece8d0a7cd889721c198e4082fc8
|
|
| BLAKE2b-256 |
f8aafc4730ac354bf5af8078cce8d28fcefcb0373bab18b022ca8428e2e2ac11
|
File details
Details for the file pystencils-2.0b1-py3-none-any.whl.
File metadata
- Download URL: pystencils-2.0b1-py3-none-any.whl
- Upload date:
- Size: 377.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ad9318b7e2415c9eefe1933103eca0ee343ec392d81298b11eb03e0d5dc211c
|
|
| MD5 |
d85ba45c5635c16abe87482439358a1f
|
|
| BLAKE2b-256 |
66d9a7bdc58739a691e2e508109d806ea99b8fa164ba2c5fc399e2bfaf47f3af
|