Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of color distance calculations by kernel fusion #809

Merged
merged 2 commits into from
Jan 10, 2025
Merged
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
48 changes: 48 additions & 0 deletions benchmarks/skimage/cucim_color_bench.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import math
import os
import pickle

Expand All @@ -25,6 +26,10 @@
"lab2xyz",
"rgba2rgb",
"label2rgb",
"deltaE_cie76",
"deltaE_ciede94",
"deltaE_ciede2000",
"deltaE_cmc",
]


Expand All @@ -40,6 +45,32 @@ def set_args(self, dtype):
self.args_gpu = (imaged,)


class DeltaEBench(ImageBench):
def set_args(self, dtype):
from skimage import color, data

# create synthetic lab image pair
rgb1 = data.astronaut()
lab1 = color.rgb2lab(rgb1)
lab2 = color.rgb2lab(np.roll(rgb1, (1, 1), axis=(0, 1)))

# change to desired dtype
lab1 = lab1.astype(dtype, copy=False)
lab2 = lab2.astype(dtype, copy=False)

# tile then crop as needed to get the expected size
n_tile0 = math.ceil(self.shape[0] / lab1.shape[0])
n_tile1 = math.ceil(self.shape[1] / lab1.shape[1])
lab1 = np.tile(lab1, (n_tile0, n_tile1, 1))
lab1 = lab1[: self.shape[0], : self.shape[1], :]
lab2 = np.tile(lab2, (n_tile0, n_tile1, 1))
lab2 = lab2[: self.shape[0], : self.shape[1], :]

print(f"{lab1.shape=}")
self.args_cpu = (lab1, lab2)
self.args_gpu = (cp.asarray(lab1), cp.asarray(lab2))


class RGBABench(ImageBench):
def set_args(self, dtype):
if self.shape[-1] != 4:
Expand Down Expand Up @@ -162,6 +193,23 @@ def main(args):
results = B.run_benchmark(duration=args.duration)
all_results = pd.concat([all_results, results["full"]])

elif function_name.startswith("deltaE"):
# only run these functions for floating point data types
float_dtypes = [t for t in dtypes if np.dtype(t).kind == "f"]

B = DeltaEBench(
function_name=function_name,
shape=shape + (3,),
dtypes=float_dtypes,
fixed_kwargs={},
var_kwargs={},
# index_str=f"{fromspace.lower()}2{tospace.lower()}",
module_cpu=skimage.color,
module_gpu=cucim.skimage.color,
run_cpu=run_cpu,
)
results = B.run_benchmark(duration=args.duration)
all_results = pd.concat([all_results, results["full"]])
elif function_name == "rgba2rgb":
B = RGBABench(
function_name="rgba2rgb",
Expand Down
11 changes: 11 additions & 0 deletions benchmarks/skimage/run-nv-bench-color.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ for shape in "${param_shape[@]}"; do
done
done
done

param_shape=(512,512 3840,2160)
param_filt=(deltaE_cie76 deltaE_ciede94 deltaE_ciede2000 deltaE_cmc)
param_dt=(float32, float64)
for shape in "${param_shape[@]}"; do
for filt in "${param_filt[@]}"; do
for dt in "${param_dt[@]}"; do
python cucim_color_bench.py -f $filt -i $shape -d $dt -t 10
done
done
done
Loading
Loading