numbagoogle-colaboratorynumba-pro

How to use numba in Colaboratory


Anybody tried to use numba in google collaboratory? I just can not figure out how to set it up in this environment. At the moment, I'm stuck with the error library nvvm not found.


Solution

  • Copy this code into cell. It works for me.

    !apt-get install nvidia-cuda-toolkit
    !pip3 install numba
    
    import os
    os.environ['NUMBAPRO_LIBDEVICE'] = "/usr/lib/nvidia-cuda-toolkit/libdevice"
    os.environ['NUMBAPRO_NVVM'] = "/usr/lib/x86_64-linux-gnu/libnvvm.so"
    
    from numba import cuda
    import numpy as np
    import time
    
    @cuda.jit
    def hello(data):
        data[cuda.blockIdx.x, cuda.threadIdx.x] = cuda.blockIdx.x
    
    numBlocks = 5
    threadsPerBlock = 10
    
    data = np.ones((numBlocks, threadsPerBlock), dtype=np.uint8)
    
    hello[numBlocks, threadsPerBlock](data)
    
    print(data)