forked from kosipov/pp_122-mko-lab2
add numba example
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
from numba import cuda
|
||||||
|
|
||||||
|
@cuda.jit
|
||||||
|
def heat_step(u, v):
|
||||||
|
j, i = cuda.grid(2) # x → столбец j, y → строка i
|
||||||
|
if 1 <= i < u.shape[0] - 1 and 1 <= j < u.shape[1] - 1:
|
||||||
|
v[i, j] = 0.25 * (u[i - 1, j] + u[i + 1, j]
|
||||||
|
+ u[i, j - 1] + u[i, j + 1])
|
||||||
|
|
||||||
|
threads = (16, 16)
|
||||||
|
blocks = ((u.shape[1] + 15) // 16, (u.shape[0] + 15) // 16)
|
||||||
|
d_u = cuda.to_device(u)
|
||||||
|
d_v = cuda.to_device(u) # границы уже равны u
|
||||||
|
heat_step[blocks, threads](d_u, d_v)
|
||||||
|
cuda.synchronize()
|
||||||
Reference in New Issue
Block a user