How to use numba in colaboratory

Has anyone tried using numba in Google Collaboration? I just can't figure out how to configure it in this environment. At the moment, I'm stuck in an error library nvvm not found.

+6
source share
3 answers

Copy this code into the cell. This 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)
+7
source

I did not need to install the packages suggested by @Algis, but the driver paths were different. So I had to do the following.

First determine the correct driver paths

!find / -iname 'libdevice'
!find / -iname 'libnvvm.so'

# Output:
# /usr/local/cuda-9.2/nvvm/lib64/libnvvm.so
# /usr/local/cuda-9.2/nvvm/libdevice

Then set the paths as described by @Algis

import os
os.environ['NUMBAPRO_LIBDEVICE'] = "/usr/local/cuda-9.2/nvvm/libdevice"
os.environ['NUMBAPRO_NVVM'] = "/usr/local/cuda-9.2/nvvm/lib64/libnvvm.so"
+2
source

You can do @Stan work at a time if you have this block at the beginning of your Colab notebook (it also automatically updates as CUDA updates)

import os
dev_lib_path = !find / -iname 'libdevice'
nvvm_lib_path = !find / -iname 'libnvvm.so'
assert len(dev_lib_path)>0, "Device Lib Missing"
assert len(nvvm_lib_path)>0, "NVVM Missing"
os.environ['NUMBAPRO_LIBDEVICE'] = dev_lib_path[0]
os.environ['NUMBAPRO_NVVM'] = nvvm_lib_path[0]
0
source

Source: https://habr.com/ru/post/1693698/


All Articles