Skip to content

Instantly share code, notes, and snippets.

@wpjunior
Created December 9, 2018 17:00
Show Gist options
  • Save wpjunior/f147e2533094bb7fa89d851e05a5f5ab to your computer and use it in GitHub Desktop.
Save wpjunior/f147e2533094bb7fa89d851e05a5f5ab to your computer and use it in GitHub Desktop.
multiply-by-2-full using numba and cuda
import numpy as np
from numba import cuda
@cuda.jit
def multiply_by_2(array):
pos = cuda.grid(1)
array[pos] = array[pos] * 2
# criamos um vetor ordenado até 1000, [0, 1, 2]
an_array = np.arange(1000)
threadsperblock = 32
blockspergrid = (an_array.size + (threadsperblock - 1)) // threadsperblock
multiply_by_2[blockspergrid, threadsperblock](an_array)
print(an_array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment