CEMeNT at NUWEST¶

Python based Acceleration and Abstraction in Monte Carlo Dynamic Code with Numba

Joanna Piper Morgan

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

  • MC/DC GitHub
  • MC/DC Release paper
  • How to Install MC/DC
  • Harmonize paper
  • Harmonize GitHub

Prerequisites¶

Intro¶

  • Some Python scripting experience
  • How to install packages
  • How to clone a git repo

To follow me into the weeds of Numba and GPUs¶

  • Compilers (specifically LLVM)
  • SIMT and CUDA v ROCm
  • Thread divergence

To follow me into MC/DC¶

  • Clone a repo
  • run an install script

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¶

No fuss pre-initialized env

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 or tbb or workqueues
  • AVX acceleration
  • Numba ufuncs and vectorized 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

Into the Weeds with Numba¶

Back to the powerpoint

LLVM Intro

for fun animations ᕙ(▀̿ĺ̯▀̿ ̿)ᕗ

Other Python Accelerators for CPUs and GPUs¶

The world of HPC Python is very exciting!!!!!!

  • PyKokkos
  • JAX compiler from Google
  • PyCUDA and PyOpenCL (you will have to write CUDA and OpenCL kernels)
  • CuPy

Demo and Intro of MC/DC¶

Back to the powerpoint (T⌓T)

Lets Push some particles¶

to the demo notebook!