GPUs

Overview

Teaching: 35 min
Exercises: 25 min
Questions
  • What are GPUs and how do we access them?

  • How can we use a GPU with Numba?

  • How can we use a GPU in Pandas, Numpy or SciKit Learn?

Objectives
  • Understand what the difference between a GPU and CPU is and the performance implications

  • Apply Numba to use a GPU

  • Understand that there are GPU enabled replacements for many popular Python libraries

  • Recall that NVIDIA GPUs can be programmed in CUDA, but this is a very low level operation

What are GPUs and why should we use them?

How can you access a GPU if your PC doesn’t have one

Using GPUs

Using GPUs with Numba

The following will calculate the mean of 100,000,000 random numbers using Cupy.

import cupy as cp
a = cp.random.random(100_000_000)
%time cp.mean(a)

For comparison let’s do the same using numpy as see how long it takes.

import numpy as np
a = np.random.random(100_000_000)
%time np.mean(a)

Challenge

the challenge

Solution

the solution

Key Points

  • GPUs are Graphics Processing Units, they have large numbers of very simple processing cores and are suited to some parallel tasks like machine learning and array operations

  • Many laptops and desktops won’t have very powerful GPUs, instead we’ll want to use HPC or Cloud systems to access a GPU.

  • Google’s Colab provides free access to GPUs with a Jupyter notebooks interface.

  • Numba can use GPUs with minor modifications to the code.

  • NVIDIA have drop in replacements for Pandas, Numpy and SciKit learn that are GPU accelerated.