CEMeNT at NUWEST¶
Python based Acceleration and Abstraction in Monte Carlo Dynamic Code with Numba
Center for Exascale Monte Carlo Neutron Transport Oregon State University
Objectives¶
Intro (10min)¶
Python Acceleration and Abstraction with Numba (30 min)¶
Beginner
- Compiling a python function using numba
nopython
mode* - Writing a function and using numba
threading
model* - Using NumPy functions in and Numba*
Advanced
- How a kernel gets compiled
- GPU compilations with Numba
MC/DC Time permitting (15-20 min)¶
- MC/DC's features for nuclear engineers
- Harmonize and what/how it works
- Running a problem and visualizing outputs*
*live demo in jupyter notebook
Feel free to:¶
- Ask questions (clarifying or in the weeds are welcome)
- Ask for a brief pause to implement what I am doing
- Chat with your neighbor for help!
Some Links¶
Other numba links and tutorials
- A ~5 minute guide to Numba
- The Life of a Numba Kernel: A Compilation Pipeline Taking User Defined Functions in Python to CUDA Kernels
- Software Carpentry Numba Guide
- CUDA by Numba Examples
- CFD implemented in Numba
MC/DC links
Basics of Numba (30min)¶
Environment Numba Dependencies¶
For you to follow along if you so desire! Feel free to use the colab sheet if you want a no fuss solution. Or try and set up an environment for your self on your machine (milage may vary)!
Google Colab¶
Pip users¶
git clone https://github.com/jpmorgan98/nuwest-mcdc-jpmorgan.git
cd nuwest-mcdc-jpmorgan
pip install numba numpy matplotlib jupyter
jupyter-notebook numba_live_demo.ipynb
Conda users¶
git clone https://github.com/jpmorgan98/nuwest-mcdc-jpmorgan.git
cd nuwest-mcdc-jpmorgan
conda create --name numba-demo numba numpy matplotlib jupyter
conda activate numba_live_demo.ipynb
Writing a Numba function¶
nopython
is the keyword to mean "compiled"- We have to be careful about typing
- Watch out for weird compiler issues!
Parallel operations in Numba¶
- Numba will try and automatically parallelize some operations
- We can explicitly est
- Using
OpenMP
ortbb
orworkqueues
- AVX acceleration
- Numba
ufuncs
andvectorized
flag - GPU offloading
Using NumPy functions in Numba¶
- Most NumPy functions are already either written in or linking to compiled code
- Numba can link to
- For some NumPy functions consider their threading configs (for LAPACK or BLAS)
Odds and ends¶
- Lots of other compiler commands to know (
cache
,fastmath
,nogil
,objectmode
) - Generation of intermediate representations
- Binding other scripts to Numba functions
Numba's limitations¶
- No true OpenMP type parallelism (save this branch)
- Dynamic typing is deeply flawed and really not recommended
- No GPU operability on AMD or Intel GPUs....yet (work ongoing)
- Profiling within Numba kernels is not supported
- Very vauge compiler errors
fastmath
only available for Intel- Can feel pretty hacky once you go past basic operability
Demo and Intro of MC/DC¶
Lets Push some particles¶
to the demo notebook!