Skip to content

NEODAAS/Porting-Python-code-to-GPUs

Repository files navigation

Porting Python code to GPUs

Training material

The getting_started_with_numba_and_cupy.ipynb Jupyter notebook was created as a training resource as part of a National Centre for Earth Observation (NCEO) project investigating the advantages of different tools designed for running code on GPUs. Examples of code were obtained from NCEO scientists and the applications were ported to GPUs on the NEODAAS MAGEO system. Using Numba and CuPy, accelerations of between x700 and x1800 were achieved. The notebook provides a gentle introduction to Numba and CuPy using some simple examples to demonstrate the basic methods. It also shows how the methods might be applied to real life problems and how Numba and CuPy can be used together. Timings are compared for CPU and GPU to demonstrate the benefits of the methods. Recommended resources for further learning are included at the end of the notebook.

This resource may be used by researchers looking for an introduction to Numba and CuPy. It has been designed to run on MAGEOHub. It can be run on any machine with access to a CUDA-enabled NVIDIA GPU but may need some additional setting up outside of MAGEOHub.

MAGEOHub is operated by the NERC Earth Observation Data Acquisition and Analysis Service (NEODAAS) and access is available to researchers eligible for NERC funding. For information on how to access and information on other services NEODAAS provides please see: https://www.neodaas.ac.uk/

Running the notebook on MAGEOHub

To run the notebook you can log onto MAGEOHub and open a terminal window, then clone this repository:

git clone https://github.com/NEODAAS/Porting-Python-code-to-GPUs.git

You should now have a folder called 'Porting-Python-code-to-GPUs' and within the folder the notebook 'getting_started_with_numba_and_cupy.ipynb', which you can open by clicking on it. You will also find another notebook in this folder called 'nanpercentile_functions.ipynb'. This notebook is not designed to be run directly, but instead is imported within the main getting started notebook.

You can use the default Python 3 environment to run the notebook. It will take about an hour to work through all the examples. The notebook starts with some simple introductory examples and then moves on to some more advanced examples. You may wish to skip the final example, 'Accelerating Numpy's nanpercentile function', which is more advanced.

NCEO example code

Examples from the NCEO project can be found in the NCEO_example_code folder. This folder contains Python code for reprojecting a Landsat 8 scene and code for implementing self-organising maps. The folder contains the original Python scripts (provided by Niall McCarroll, University of Reading), along with Jupyter notebooks exploring how GPU libraries may be used to accelerate the code.

If you're interested in learning more about self-organising maps, check out Niall McCarroll's som GitHub repository that contains his Python implementation of self-organising maps, including code to run on a GPU: https://github.com/niallmcc/som

CC BY-NC 4.0
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

About

Training material developed for NCEO GPU project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published