Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions bench_info/blur.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"benchmark": {
"name": "blur",
"short_name": "blur",
"relative_path": "image_processing/blur",
"module_name": "blur",
"func_name": "blur",
"kind": "microbench",
"domain": "Image Processing",
"dwarf": "dense_linear_algebra",
"parameters": {
"S": { },
"M": { },
"L": { },
"paper": { }
},
"init": {
"func_name": "initialize",
"input_args": [],
"output_args": ["image", "output"]
},
"input_args": ["image", "output"],
"array_args": ["image", "output"],
"output_args": ["output"]
}
}
26 changes: 26 additions & 0 deletions bench_info/hist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"benchmark": {
"name": "hist",
"short_name": "hist",
"relative_path": "image_processing/hist",
"module_name": "hist",
"func_name": "hist",
"kind": "microbench",
"domain": "Image Processing",
"dwarf": "dense_linear_algebra",
"parameters": {
"S": { },
"M": { },
"L": { },
"paper": { }
},
"init": {
"func_name": "initialize",
"input_args": [],
"output_args": ["image", "output"]
},
"input_args": ["image", "output"],
"array_args": ["image", "output"],
"output_args": ["output"]
}
}
26 changes: 26 additions & 0 deletions bench_info/iir_blur.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"benchmark": {
"name": "iir_blur",
"short_name": "iir_blur",
"relative_path": "image_processing/iir_blur",
"module_name": "iir_blur",
"func_name": "iir_blur",
"kind": "microbench",
"domain": "Image Processing",
"dwarf": "dense_linear_algebra",
"parameters": {
"S": { },
"M": { },
"L": { },
"paper": { }
},
"init": {
"func_name": "initialize",
"input_args": [],
"output_args": ["image", "output"]
},
"input_args": ["image", "output"],
"array_args": ["image", "output"],
"output_args": ["output"]
}
}
Binary file added data/image_processing/gray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/image_processing/rgb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions npbench/benchmarks/image_processing/blur/blur.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2021 ETH Zurich and the NPBench authors. All rights reserved.
import numpy as np

from PIL import Image
from pathlib import Path

def initialize():
image_path = Path(__file__).parent.parent.parent.parent.parent / "data/image_processing" / "gray.png"
image = np.array(Image.open(image_path), dtype=np.uint8)
output = np.empty((image.shape[0] - 2, image.shape[1] - 2), dtype=np.uint8)

return image, output
16 changes: 16 additions & 0 deletions npbench/benchmarks/image_processing/blur/blur_cupy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import cupy as np

def blur(image, output):
image = image.astype(np.float32)
blur_x = np.empty((image.shape[0], image.shape[1] - 2), dtype=np.float32)
blur_y = np.empty(output.shape, dtype=np.float32)

filter = np.array([1.0, 1.0, 1.0], dtype=np.float32) / 3.0

for y in range(blur_x.shape[0]):
blur_x[y, :] = np.convolve(image[y, :], filter, mode='valid')

for x in range(blur_y.shape[1]):
blur_y[:, x] = np.convolve(blur_x[:, x], filter, mode='valid')

output[:,:] = np.clip(blur_y, 0.0, 255.0).astype(np.uint8)
20 changes: 20 additions & 0 deletions npbench/benchmarks/image_processing/blur/blur_dace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import numpy as np
import dace as dc

@dc.program
def blur(image: dc.uint8[2560, 1536], output: dc.uint8[2558, 1534]):
imagef = image.astype(np.float32)
blur_x = np.empty((imagef.shape[0], imagef.shape[1] - 2), dtype=np.float32)
blur_y = np.empty(output.shape, dtype=np.float32)

for y in range(blur_x.shape[0]):
for x in range(blur_x.shape[1]):
blur_x[y, x] = (imagef[y, x] + imagef[y, x + 1] + imagef[y, x + 2]) / 3.0

for y in range(blur_y.shape[0]):
for x in range(blur_y.shape[1]):
blur_y[y, x] = (blur_x[y, x] + blur_x[y + 1, x] + blur_x[y + 2, x]) / 3.0

blur_y[blur_y < 0.0] = 0.0
blur_y[blur_y > 255.0] = 255.0
output[:,:] = blur_y.astype(np.uint8)
18 changes: 18 additions & 0 deletions npbench/benchmarks/image_processing/blur/blur_numba_n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import numpy as np
import numba as nb

@nb.jit(nopython=True, parallel=False, fastmath=True)
def blur(image, output):
image = image.astype(np.float32)
blur_x = np.empty((image.shape[0], image.shape[1] - 2), dtype=np.float32)
blur_y = np.empty(output.shape, dtype=np.float32)

filter = np.array([1.0, 1.0, 1.0], dtype=np.float32) / 3.0

for y in range(blur_x.shape[0]):
blur_x[y, :] = np.convolve(image[y, :], filter)[2:-2]

for x in range(blur_y.shape[1]):
blur_y[:, x] = np.convolve(blur_x[:, x], filter)[2:-2]

output[:,:] = np.clip(blur_y, 0.0, 255.0).astype(np.uint8)
18 changes: 18 additions & 0 deletions npbench/benchmarks/image_processing/blur/blur_numba_np.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import numpy as np
import numba as nb

@nb.jit(nopython=True, parallel=True, fastmath=True)
def blur(image, output):
image = image.astype(np.float32)
blur_x = np.empty((image.shape[0], image.shape[1] - 2), dtype=np.float32)
blur_y = np.empty(output.shape, dtype=np.float32)

filter = np.array([1.0, 1.0, 1.0], dtype=np.float32) / 3.0

for y in range(blur_x.shape[0]):
blur_x[y, :] = np.convolve(image[y, :], filter)[2:-2]

for x in range(blur_y.shape[1]):
blur_y[:, x] = np.convolve(blur_x[:, x], filter)[2:-2]

output[:,:] = np.clip(blur_y, 0.0, 255.0).astype(np.uint8)
18 changes: 18 additions & 0 deletions npbench/benchmarks/image_processing/blur/blur_numba_npr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import numpy as np
import numba as nb

@nb.jit(nopython=True, parallel=True, fastmath=True)
def blur(image, output):
image = image.astype(np.float32)
blur_x = np.empty((image.shape[0], image.shape[1] - 2), dtype=np.float32)
blur_y = np.empty(output.shape, dtype=np.float32)

filter = np.array([1.0, 1.0, 1.0], dtype=np.float32) / 3.0

for y in nb.prange(blur_x.shape[0]):
blur_x[y, :] = np.convolve(image[y, :], filter)[2:-2]

for x in nb.prange(blur_y.shape[1]):
blur_y[:, x] = np.convolve(blur_x[:, x], filter)[2:-2]

output[:,:] = np.clip(blur_y, 0.0, 255.0).astype(np.uint8)
18 changes: 18 additions & 0 deletions npbench/benchmarks/image_processing/blur/blur_numba_o.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import numpy as np
import numba as nb

@nb.jit(nopython=False, forceobj=True, parallel=False, fastmath=True)
def blur(image, output):
image = image.astype(np.float32)
blur_x = np.empty((image.shape[0], image.shape[1] - 2), dtype=np.float32)
blur_y = np.empty(output.shape, dtype=np.float32)

filter = np.array([1.0, 1.0, 1.0], dtype=np.float32) / 3.0

for y in range(blur_x.shape[0]):
blur_x[y, :] = np.convolve(image[y, :], filter, mode='valid')

for x in range(blur_y.shape[1]):
blur_y[:, x] = np.convolve(blur_x[:, x], filter, mode='valid')

output[:,:] = np.clip(blur_y, 0.0, 255.0).astype(np.uint8)
18 changes: 18 additions & 0 deletions npbench/benchmarks/image_processing/blur/blur_numba_op.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import numpy as np
import numba as nb

@nb.jit(nopython=False, forceobj=True, parallel=True, fastmath=True)
def blur(image, output):
image = image.astype(np.float32)
blur_x = np.empty((image.shape[0], image.shape[1] - 2), dtype=np.float32)
blur_y = np.empty(output.shape, dtype=np.float32)

filter = np.array([1.0, 1.0, 1.0], dtype=np.float32) / 3.0

for y in range(blur_x.shape[0]):
blur_x[y, :] = np.convolve(image[y, :], filter, mode='valid')

for x in range(blur_y.shape[1]):
blur_y[:, x] = np.convolve(blur_x[:, x], filter, mode='valid')

output[:,:] = np.clip(blur_y, 0.0, 255.0).astype(np.uint8)
18 changes: 18 additions & 0 deletions npbench/benchmarks/image_processing/blur/blur_numba_opr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import numpy as np
import numba as nb

@nb.jit(nopython=False, forceobj=True, parallel=True, fastmath=True)
def blur(image, output):
image = image.astype(np.float32)
blur_x = np.empty((image.shape[0], image.shape[1] - 2), dtype=np.float32)
blur_y = np.empty(output.shape, dtype=np.float32)

filter = np.array([1.0, 1.0, 1.0], dtype=np.float32) / 3.0

for y in nb.prange(blur_x.shape[0]):
blur_x[y, :] = np.convolve(image[y, :], filter, mode='valid')

for x in nb.prange(blur_y.shape[1]):
blur_y[:, x] = np.convolve(blur_x[:, x], filter, mode='valid')

output[:,:] = np.clip(blur_y, 0.0, 255.0).astype(np.uint8)
21 changes: 21 additions & 0 deletions npbench/benchmarks/image_processing/blur/blur_numpy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import numpy as np

# from PIL import Image

def blur(image, output):
image = image.astype(np.float32)
blur_x = np.empty((image.shape[0], image.shape[1] - 2), dtype=np.float32)
blur_y = np.empty(output.shape, dtype=np.float32)

filter = np.array([1.0, 1.0, 1.0], dtype=np.float32) / 3.0

for y in range(blur_x.shape[0]):
blur_x[y, :] = np.convolve(image[y, :], filter, mode='valid')

for x in range(blur_y.shape[1]):
blur_y[:, x] = np.convolve(blur_x[:, x], filter, mode='valid')

output[:,:] = np.clip(blur_y, 0.0, 255.0).astype(np.uint8)

# img = Image.fromarray(output)
# img.save("blur_output.png")
12 changes: 12 additions & 0 deletions npbench/benchmarks/image_processing/hist/hist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2021 ETH Zurich and the NPBench authors. All rights reserved.
import numpy as np

from PIL import Image
from pathlib import Path

def initialize():
image_path = Path(__file__).parent.parent.parent.parent.parent / "data/image_processing" / "rgb.png"
image = np.array(Image.open(image_path), dtype=np.uint8)
output = np.empty((image.shape[0], image.shape[1], 3), dtype=np.uint8)

return image, output
36 changes: 36 additions & 0 deletions npbench/benchmarks/image_processing/hist/hist_cupy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import cupy as np

def hist(image, output):
image = image.astype(np.float32)
gray = 0.299 * image[:,:,0] + 0.587 * image[:,:,1] + 0.114 * image[:,:,2]

Cr = (image[:,:,0] - gray) * 0.713 + 128
Cb = (image[:,:,2] - gray) * 0.564 + 128

binned_gray = np.clip(gray, 0, 255).astype(np.uint8)

# [0, ..., 256] where 256 is the rightmost edge
hist, _ = np.histogram(binned_gray, bins=np.arange(257))

npixels = gray.shape[0] * gray.shape[1]
density = np.ndarray((256,), dtype=np.float32)
density[:] = hist / npixels

cdf = np.cumsum(density)

eq = cdf[binned_gray]
eq = eq * 255.0
eq = np.clip(eq, 0, 255)

red = eq + (Cr - 128.0) * 1.4
red = np.clip(red, 0, 255)

green = eq - 0.343 * (Cb - 128.0) - 0.711 * (Cr - 128.0)
green = np.clip(green, 0, 255)

blue = eq + 1.765 * (Cb - 128.0)
blue = np.clip(blue, 0, 255)

output[:,:,0] = red.astype(np.uint8)
output[:,:,1] = green.astype(np.uint8)
output[:,:,2] = blue.astype(np.uint8)
58 changes: 58 additions & 0 deletions npbench/benchmarks/image_processing/hist/hist_dace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import numpy as np
import dace

@dace.program
def hist(image: dace.uint8[2560, 1536, 3], output: dace.uint8[2560, 1536, 3]):
imagef = image.astype(np.float32)
gray = 0.299 * imagef[:,:,0] + 0.587 * imagef[:,:,1] + 0.114 * imagef[:,:,2]

Cr = (imagef[:,:,0] - gray) * 0.713 + 128
Cb = (imagef[:,:,2] - gray) * 0.564 + 128

gray[gray < 0] = 0
gray[gray > 255] = 255
binned_gray = gray.astype(np.uint8)

# histogram
hist = np.zeros((256,), dtype=np.uint32)
for y, x in dace.map[0:2560, 0:1536]:
with dace.tasklet:
p << binned_gray[y, x]
out >> hist(1, lambda x, y: x + y)[:]

out[p] = 1

npixels = gray.shape[0] * gray.shape[1]
density = np.ndarray((256,), dtype=np.float32)
density[:] = hist / npixels

# cumsum
cdf = np.ndarray((256,), dtype=np.float32)
sum: dace.float32 = 0.0
for i in range(256):
sum = sum + density[i]
cdf[i] = sum

eq = np.ndarray((2560, 1536), dtype=np.float32)
for y, x in dace.map[0:2560, 0:1536]:
eq[y, x] = cdf[binned_gray[y, x]]

eq = eq * 255.0
eq[eq < 0] = 0
eq[eq > 255] = 255

red = eq + (Cr - 128.0) * 1.4
red[red < 0.0] = 0.0
red[red > 255.0] = 255.0

green = eq - 0.343 * (Cb - 128.0) - 0.711 * (Cr - 128.0)
green[green < 0.0] = 0.0
green[green > 255.0] = 255.0

blue = eq + 1.765 * (Cb - 128.0)
blue[blue < 0.0] = 0.0
blue[blue > 255.0] = 255.0

output[:,:,0] = red.astype(np.uint8)
output[:,:,1] = green.astype(np.uint8)
output[:,:,2] = blue.astype(np.uint8)
Loading