Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wpjunior/1b2ed82765f85b82e46fa8fbd5c296ac to your computer and use it in GitHub Desktop.
Save wpjunior/1b2ed82765f85b82e46fa8fbd5c296ac to your computer and use it in GitHub Desktop.
import numpy as np
from numba import cuda
@cuda.jit
def add_2(array):
pos = cuda.grid(1)
array[pos] = array[pos] + 2
# criamos um vetor ordenado até 100000, [0, 1, 2, .. 999999] dentro da GPU
an_array = cuda.to_device(np.arange(100000))
threadsperblock = 32
blockspergrid = (an_array.size + (threadsperblock - 1)) // threadsperblock
for x in range(1000):
add_2[blockspergrid, threadsperblock](an_array)
print(an_array.copy_to_host())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment