Skip to content

Instantly share code, notes, and snippets.

@c200chromebook
Created February 21, 2020 15:16
Show Gist options
  • Save c200chromebook/d131322c918b142f14f40c9b3583cc6d to your computer and use it in GitHub Desktop.
Save c200chromebook/d131322c918b142f14f40c9b3583cc6d to your computer and use it in GitHub Desktop.
working one
import numpy as np
import numba
from numba import cuda
import math
@cuda.jit(argtypes=[numba.int32[:]], debug=True)
def kernel(arr):
def expensive(x):
return math.pow(x, 1.001)
def cheap(x):
return math.sqrt(x)
def calc(x):
s1 = expensive(x)
q = cheap(s1)
return q + 1
def threadid():
return cuda.blockDim.x * cuda.blockIdx.x + cuda.threadIdx.x
for i in range(1000):
arr[threadid()] = calc(arr[threadid()])
def main():
print("SUP")
z = np.array(range(0, 5000))
print(z)
kernel[5000//128+1, 128](z)
print(z)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment