Skip to content

Instantly share code, notes, and snippets.

@Gcav66
Created October 20, 2021 18:24
Show Gist options
  • Save Gcav66/eaeb8002b473ef277d6cac2cdc30812b to your computer and use it in GitHub Desktop.
Save Gcav66/eaeb8002b473ef277d6cac2cdc30812b to your computer and use it in GitHub Desktop.
from numba import cuda
import numpy as np
import cupy
def gather_from_detector():
return cupy.random.random((1000, 1000), dtype="float32")
@cuda.jit
def smooth_gpu(x, out):
i, j = cuda.grid(2)
n, m = x.shape
if 1 <= i < n - 1 and 1 <= j < m - 1:
out[i, j] = (x[i - 1, j - 1] + x[i - 1, j] + x[i - 1, j + 1] +
x[i , j - 1] + x[i , j] + x[i , j + 1] +
x[i + 1, j - 1] + x[i + 1, j] + x[i + 1, j + 1]) // 9
def smooth(x):
out = cupy.empty_like(x)
smooth_gpu[2, 32](x, out)
return out
def save(x, filename):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment