Created
December 9, 2018 17:42
-
-
Save wpjunior/1b2ed82765f85b82e46fa8fbd5c296ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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