Home

Numba and Cuda on Windows (using pip)

Updated:
Created:

How to install numba to run with a nvidia card on windows.

The basic outline is described here: http://numba.pydata.org/numba-doc/latest/user/installing.html#installing-using-pip-on-x86-x86-64-platforms

  1. Install the cuda sdk
  2. pip install numba
  3. set the environment variables
  4. nothing works???

Now one environment variable needs to be set:

CUDA_HOME=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2

Doesn't matter how you set it, e.g. system environment var, or in your IDE,...

With this I can run example code like this one:

from numba import cuda
import numpy as np
import numba

numba.cuda.profile_stop()

@cuda.jit
def max_example(result, values):
    """Find the maximum value in values and store in result[0]"""
    tid = cuda.threadIdx.x
    bid = cuda.blockIdx.x
    bdim = cuda.blockDim.x
    i = (bid * bdim) + tid
    cuda.atomic.max(result, 0, values[i])


arr = np.random.rand(16384)
result = np.zeros(1, dtype=np.float64)

max_example[256,64](result, arr)
print(result[0]) # Found using cuda.atomic.max
print(max(arr))  # Print max(arr) for comparision (should be equal!)

(Taken from http://numba.pydata.org/numba-doc/0.25.0/cuda/intrinsics.html)