Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 676
Algis Avatar asked Feb 15 '18 15:02

Algis


People also ask

Where can I use Numba?

Numba is a just-in-time compiler for Python that works best on code that uses NumPy arrays and functions, and loops. The most common way to use Numba is through its collection of decorators that can be applied to your functions to instruct Numba to compile them.

Can Numba use GPU?

Numba supports CUDA GPU programming by directly compiling a restricted subset of Python code into CUDA kernels and device functions following the CUDA execution model. One feature that significantly simplifies writing GPU kernels is that Numba makes it appear that the kernel has direct access to NumPy arrays.

How do I set up Google Colaboratory?

To create your Google Colab file and get started with Google Colab, you can go to Google Drive and create a Google Drive account if you do not have one. Now, click on the “New” button at the top left corner of your Google Drive page, then click on More ▷ Google Colaboratory.


1 Answers

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)
like image 127
Algis Avatar answered Sep 21 '22 23:09

Algis