Created
December 9, 2018 17:00
-
-
Save wpjunior/f147e2533094bb7fa89d851e05a5f5ab to your computer and use it in GitHub Desktop.
multiply-by-2-full using numba and cuda
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 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