🐍 Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
perf(filters): accelerate large CPU Gaussian blur and pyramids without oneDNN (#4641)
Dmytro Mishkin3a6a1e333a39
diff --git a/benchmarks/README.md b/benchmarks/README.mdindex 2c87d371f..8b787077a 100644--- a/benchmarks/README.md+++ b/benchmarks/README.md@@ -10,7 +10,7 @@ baselines. Goal: current, citable numbers with disclosed methodology — where k| --- | --- || [`augmentation/`](augmentation/) | Cross-library augmentation benchmarks — [`flagship.py`](augmentation/flagship.py) (class-API, parameter sampling included, vs torchvision v2/albumentations/OpenCV/PIL) plus pipeline/per-op scripts; see its [README](augmentation/README.md). || [`geometry/`](geometry/) | [`flagship.py`](geometry/flagship.py): core geometry ops vs OpenCV/torchvision v2. |-| [`filters/`](filters/) | [`flagship.py`](filters/flagship.py): core filters vs OpenCV/albumentations/torchvision v2/kornia-rs/PIL. |+| [`filters/`](filters/) | [`flagship.py`](filters/flagship.py): core filters vs OpenCV/albumentations/torchvision v2/kornia-rs/PIL. [`gaussian_cpu.py`](filters/gaussian_cpu.py): Gaussian blur and scale-pyramid base/branch timing and numerical comparisons; [report](filters/gaussian_cpu.md). || [`color/`](color/) | pytest-benchmark microbenchmarks for color conversions. || [`feature/`](feature/) | Local-feature detector benchmarks incl. quality (matching) metrics; [`laf_ops.py`](feature/laf_ops.py) microbenchmarks the shared LAF operations and [`ellipse_to_laf.py`](feature/ellipse_to_laf.py) drills into one of them (both base-revision A/B — no cross-library baseline exists). [`local_features.py`](feature/local_features.py) measures Oxford graf speed and homography corner error for SIFT, SIFT-AffNet-HardNet and KeyNet-HardNet on CPU, CUDA or MPS (`--device cpu --timing-pairs 2` times the representative 1–2 pair and still scores all five); results in [`graf_benchmark.md`](feature/graf_benchmark.md). [`sift_runtime.py`](feature/sift_runtime.py) and [`plot_sift_runtime.py`](feature/plot_sift_runtime.py) chart scale-space SIFT runtime across releases and batch sizes; results in [`sift_runtime.md`](feature/sift_runtime.md). || [`common.py`](common.py) | Shared methodology utilities — use these in every new benchmark. |diff --git a/benchmarks/filters/gaussian_cpu.md b/benchmarks/filters/gaussian_cpu.mdnew file mode 100644index 000000000..dee16243f--- /dev/null+++ b/benchmarks/filters/gaussian_cpu.md@@ -0,0 +1,67 @@+# CPU Gaussian blur and scale-pyramid comparison++The tensor slice implementation accelerates large eager inference calls to `gaussian_blur2d`, `GaussianBlur2d`, and `ScalePyramid` on CPU builds without oneDNN. It uses the same Gaussian coefficients, support, padding, and horizontal/vertical pass order. No approximate kernel, truncation change, or reduced precision is introduced.++The fast path requires contiguous CPU float32/float64 input, at least 65,536 pixels per channel and 131,072 total elements. Reverse-mode gradient tracking, autocast, graph capture/tracing, non-contiguous images, smaller inputs, other dtypes/devices, and oneDNN builds retain convolution. Tensor weights and out-of-place `addcmul` preserve forward-mode differentiation and vmap support. The generic scale pyramid reuses its cached kernels.++## Measured regime++Apple M1, macOS 26.5.1, Python 3.11.14, PyTorch 2.14.0, one CPU thread, fixed seed 0. Each cell is a warmed median from `common.time_us` with a one-second minimum and its IQR. The entire public call is timed, including Gaussian kernel generation and allocations; the two backward cases include backward. Pyramid cases use the default six levels per octave. These are base-versus-branch comparisons, not cross-library comparisons.++Base: `607869e2d0a179d8ee6d3890a702b04ba5517c11`. The changed implementation was measured from a working tree based on that commit; per-file SHA256 hashes in the raw JSON pin the exact implementation. Both runs use the same harness SHA256. The harness prints and checks the imported checkout and prints the Python interpreter.++Raw results: [before](gaussian_cpu_results/before-cpu.json), [after](gaussian_cpu_results/after-cpu.json). All measured cases, including losses and unchanged dispatch paths, are below. “Speedup” is the ratio of the two medians, not a guarantee across machines.++| Case | Base median ± IQR (ms) | Changed median ± IQR (ms) | Ratio | Max absolute output/gradient difference |+| --- | ---: | ---: | ---: | ---: |+| blur-128-c1-k7 | 0.132 ± 0.002 | 0.156 ± 0.001 | 0.84× | 0 |+| blur-256-c1-k7 | 0.419 ± 0.005 | 0.423 ± 0.054 | 0.99× | 0 |+| blur-256-c3-k3 | 0.408 ± 0.026 | 0.410 ± 0.064 | 1.00× | 1.8e-07 |+| blur-256-c3-k7 | 1.271 ± 0.125 | 0.732 ± 0.030 | 1.74× | 1.2e-07 |+| blur-256-c3-k15 | 2.704 ± 0.184 | 1.325 ± 0.097 | 2.04× | 1.8e-07 |+| blur-256-c3-k31 | 6.376 ± 0.283 | 2.447 ± 0.083 | 2.61× | 1.8e-07 |+| blur-512-c1-k3 | 0.830 ± 0.017 | 0.570 ± 0.030 | 1.45× | 1.8e-07 |+| blur-512-c1-k7 | 2.126 ± 0.210 | 0.970 ± 0.036 | 2.19× | 1.8e-07 |+| blur-512-c1-k15 | 5.577 ± 0.110 | 1.670 ± 0.093 | 3.34× | 1.8e-07 |+| blur-512-c1-k31 | 12.478 ± 0.998 | 3.099 ± 0.074 | 4.03× | 1.8e-07 |+| blur-batch | 17.681 ± 1.262 | 9.802 ± 3.145 | 1.80× | 1.8e-07 |+| blur-batched-sigma | 2.651 ± 0.470 | 1.699 ± 0.149 | 1.56× | 1.2e-07 |+| blur-float64 | 11.678 ± 0.867 | 4.987 ± 0.880 | 2.34× | 3.3e-16 |+| blur-channels-last | 1.460 ± 0.247 | 1.383 ± 0.503 | 1.06× | 0 |+| blur-strided | 1.123 ± 0.538 | 1.165 ± 0.588 | 0.96× | 0 |+| blur-input-backward | 4.272 ± 0.253 | 3.764 ± 0.266 | 1.14× | 0 |+| blur-sigma-backward | 5.387 ± 0.396 | 4.869 ± 0.257 | 1.11× | 0 |+| blur-signed | 3.008 ± 0.176 | 1.367 ± 0.146 | 2.20× | 8.9e-08 |+| blur-constant | 2.819 ± 0.244 | 1.363 ± 0.131 | 2.07× | 0 |+| blur-impulse | 2.793 ± 0.146 | 1.347 ± 0.143 | 2.07× | 0 |+| pyramid-gray | 46.209 ± 2.213 | 21.098 ± 2.357 | 2.19× | 1.8e-07 |+| pyramid-rgb | 24.444 ± 2.276 | 15.774 ± 1.595 | 1.55× | 1.8e-07 |+| pyramid-double | 46.491 ± 5.563 | 20.776 ± 1.966 | 2.24× | 1.8e-07 |+| pyramid-float64 | 96.687 ± 2.382 | 45.688 ± 4.029 | 2.12× | 3.3e-16 |++`blur-<size>-c<channels>-k<kernel>` uses batch one and square images/kernels. `blur-batch` is four RGB 256×256 images with a 15-tap kernel; `blur-batched-sigma` is two RGB 256×256 images with distinct sigma pairs and a 7-tap kernel. Backward cases are RGB 256×256, 7 taps. Pyramid inputs are 512×512 grayscale, 256×256 RGB, or 256×256 grayscale doubled internally. Full parameters live in each JSON row.++Large single-image blurs improve by 1.45–4.03×, except the 3-tap RGB case, which is effectively unchanged. Complete scale pyramids improve by 1.55–2.24×. Small, layout-fallback, and backward timings vary in both directions despite retaining convolution; for example, the unchanged 128×128 case is 0.84×. Do not interpret noise in these cells as an optimization. Some cases have wide IQRs (especially non-contiguous layouts and batched blur); reproduce on the target machine.++## Numerical agreement++The largest float32 output difference is 1.79e-7; the float64 maximum is 3.33e-16. These bounds include every repeated Gaussian level of the complete scale pyramids. Random [0,1], signed [-1,1], constant, and impulse inputs are included. Constant and impulse outputs were bitwise identical in this run. Reverse-mode outputs and gradients were bitwise identical because that path retains convolution. Raw `tensor_errors` also record mean absolute error, max error normalized by reference magnitude, and relative L2 error.++Independent tests cover anisotropic per-image sigma, all four padding modes, helper input/kernel gradients, public sigma forward-mode derivatives, vmap, and dispatch fallbacks. These measurements establish ordinary floating-point rounding differences for the tested values; they do not promise bitwise equality or bound downstream effects in discontinuous feature selection.++## Reproduction++Use the same Python environment for two disposable worktrees: base revision above and this PR branch. Copy `benchmarks/filters/gaussian_cpu.py` from the branch to the base worktree, where it is untracked. Run from each worktree root as a module so the local checkout shadows any editable install:++```bash+# In the base worktree; choose an absolute path in your task scratch directory.+"$task_python" -m benchmarks.filters.gaussian_cpu --device cpu \+ --json "$task_scratch/before-cpu.json" --save-reference "$task_scratch/cpu-reference.pt"+# In the changed worktree, using the same interpreter and scratch directory.+"$task_python" -m benchmarks.filters.gaussian_cpu --device cpu \+ --json "$task_scratch/after-cpu.json" --reference "$task_scratch/cpu-reference.pt"+```++The reference tensors are temporary local files, not committed artifacts. The JSON reports contain aggregate metadata and errors, not local paths. CUDA and MPS are supported by `--device` for regression measurements; CUDA timing synchronizes through `blocked_autorange`, MPS synchronizes explicitly, and MPS skips unsupported float64 cases. CUDA cuDNN TF32 is disabled for this comparison. Accelerator execution is unchanged by this optimization.++Intel/oneDNN performance, CUDA execution, larger batch/feature-map regimes, and end-to-end feature matching remain unverified here. The PR includes separate instructions for an opt-in Intel experiment that removes only the oneDNN guard while retaining the oneDNN convolution baseline. No automatic oneDNN fast path is enabled without that evidence.diff --git a/benchmarks/filters/gaussian_cpu.py b/benchmarks/filters/gaussian_cpu.pynew file mode 100644index 000000000..91e0b89bd--- /dev/null+++ b/benchmarks/filters/gaussian_cpu.py@@ -0,0 +1,209 @@+# LICENSE HEADER MANAGED BY add-license-header+#+# Copyright 2018 Kornia Team+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+#++"""Compare public Gaussian blur and scale-pyramid APIs across revisions.++Run identical commands from each checkout as a module (``python -m+benchmarks.filters.gaussian_cpu``), and verify the printed Kornia import path.+The baseline is the same public API on the base revision, not a replacement+implementation. CPU float tensors, fixed seed, eager execution, and one timed+thread; allocation, Gaussian kernel generation, and optional backward are timed.+CUDA/MPS runs check the unchanged accelerator path, with device synchronization.+Reports include medians/IQRs and losses alongside wins. Save reference tensors+outside the repository with --save-reference, then use --reference to quantify+output and gradient differences. Reference files must be locally generated.+"""++from __future__ import annotations++import argparse+import hashlib+import sys+from pathlib import Path+from typing import Any, Callable++import torch++sys.path.insert(0, str(Path(__file__).resolve().parents[1]))+from common import collect_load_metrics, run_metadata, save_json, time_us, versions_line++import kornia+from kornia.filters import gaussian_blur2d+from kornia.geometry.transform import ScalePyramid+++def cases() -> list[dict[str, Any]]:+ """Fixed workloads spanning accelerated and deliberately unchanged regimes."""+ rows = []+ for size, channels in ((128, 1), (256, 1), (256, 3), (512, 1)):+ for kernel in (7,) if size == 128 or (channels == 1 and size == 256) else (3, 7, 15, 31):+ rows.append(+ {"name": f"blur-{size}-c{channels}-k{kernel}", "size": size, "channels": channels, "kernel": kernel}+ )+ rows.extend(+ [+ {"name": "blur-batch", "batch": 4, "size": 256, "channels": 3, "kernel": 15},+ {"name": "blur-batched-sigma", "batch": 2, "size": 256, "channels": 3, "kernel": 7, "batched_sigma": True},+ {"name": "blur-float64", "size": 512, "channels": 1, "kernel": 15, "dtype": "float64"},+ {"name": "blur-channels-last", "size": 256, "channels": 3, "kernel": 7, "layout": "channels_last"},+ {"name": "blur-strided", "size": 256, "channels": 3, "kernel": 7, "layout": "strided"},+ {"name": "blur-input-backward", "size": 256, "channels": 3, "kernel": 7, "backward": "input"},+ {"name": "blur-sigma-backward", "size": 256, "channels": 3, "kernel": 7, "backward": "sigma"},+ {"name": "blur-signed", "size": 256, "channels": 3, "kernel": 15, "signal": "signed"},+ {"name": "blur-constant", "size": 256, "channels": 3, "kernel": 15, "signal": "constant"},+ {"name": "blur-impulse", "size": 256, "channels": 3, "kernel": 15, "signal": "impulse"},+ {"name": "pyramid-gray", "size": 512, "channels": 1, "op": "ScalePyramid"},+ {"name": "pyramid-rgb", "size": 256, "channels": 3, "op": "ScalePyramid"},+ {"name": "pyramid-double", "size": 256, "channels": 1, "op": "ScalePyramid", "double": True},+ {"name": "pyramid-float64", "size": 512, "channels": 1, "op": "ScalePyramid", "dtype": "float64"},+ ]+ )+ return rows+++def make_operation(case: dict[str, Any], device: torch.device) -> Callable[[], tuple[torch.Tensor, ...]]:+ """Construct inputs once; keep all public forward/backward work inside the callable."""+ torch.manual_seed(0)+ size = case["size"]+ shape = (case.get("batch", 1), case["channels"], size, size)+ dtype = getattr(torch, case.get("dtype", "float32"))+ value = torch.rand(shape, dtype=dtype, device=device)+ signal = case.get("signal")+ if signal == "signed":+ value = 2 * value - 1+ elif signal == "constant":+ value.fill_(1)+ elif signal == "impulse":+ value.zero_()+ value[..., size // 2, size // 2] = 1+ if case.get("layout") == "channels_last":+ value = value.contiguous(memory_format=torch.channels_last)+ elif case.get("layout") == "strided":+ value = torch.rand((*shape[:-1], 2 * size), dtype=dtype, device=device)[..., ::2]+ if case.get("op") == "ScalePyramid":+ pyramid = ScalePyramid(double_image=case.get("double", False)).to(device=device, dtype=dtype)++ def run_pyramid() -> tuple[torch.Tensor, ...]:+ levels, sigmas, distances = pyramid(value)+ return tuple(levels + sigmas + distances)++ return run_pyramid+ sigma = torch.tensor([[1.5, 2.1]], dtype=dtype, device=device)+ if case.get("batched_sigma"):+ sigma = torch.tensor([[1.5, 2.1], [0.8, 3.2]], dtype=dtype, device=device)+ backward = case.get("backward")+ value.requires_grad_(backward is not None)+ sigma.requires_grad_(backward == "sigma")+ loss_weights = torch.randn_like(value) if backward else None++ def run_blur() -> tuple[torch.Tensor, ...]:+ result = gaussian_blur2d(value, case["kernel"], sigma)+ if backward:+ arguments = (value, sigma) if backward == "sigma" else (value,)+ gradients = torch.autograd.grad(result, arguments, grad_outputs=loss_weights)+ return (result, *gradients)+ return (result,)++ return run_blur+++def differences(actual: tuple[torch.Tensor, ...], reference: tuple[torch.Tensor, ...]) -> dict[str, Any]:+ """Report absolute error and scale-normalized error, avoiding relative error near zero."""+ assert len(actual) == len(reference)+ stats = []+ for current, baseline in zip(actual, reference):+ assert current.shape == baseline.shape and current.dtype == baseline.dtype+ delta = (current.double() - baseline.double()).abs()+ scale = baseline.double().abs().max().item()+ norm = baseline.double().norm().item()+ stats.append(+ {+ "max_abs": delta.max().item(),+ "mean_abs": delta.mean().item(),+ "max_abs_over_reference_max": delta.max().item() / max(scale, 1e-300),+ "relative_l2": delta.norm().item() / max(norm, 1e-300),+ }+ )+ return {"tensor_errors": stats}+++def main() -> None:+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--json", type=Path, required=True)+ parser.add_argument("--device", choices=("cpu", "cuda", "mps"), default="cpu")+ parser.add_argument("--min-run-time", type=float, default=1.0)+ parser.add_argument("--save-reference", type=Path)+ parser.add_argument("--reference", type=Path)+ args = parser.parse_args()+ device = torch.device(args.device)+ torch.set_num_threads(1)+ # Keep the CUDA comparison independent of reduced-precision convolution defaults.+ torch.backends.cudnn.allow_tf32 = False+ root = Path.cwd().resolve()+ assert Path(kornia.__file__).resolve().is_relative_to(root), "Kornia must import from the measured checkout"+ print(f"Kornia: {kornia.__file__}; Python: {sys.executable}", flush=True)+ metadata = run_metadata(device)+ sources = ("kornia/filters/gaussian.py", "kornia/filters/filter.py", "kornia/geometry/transform/pyramid.py")+ metadata.update(+ seed=0,+ load=collect_load_metrics(),+ min_run_time=args.min_run_time,+ mkldnn_available=torch.backends.mkldnn.is_available(),+ cudnn_allow_tf32=torch.backends.cudnn.allow_tf32,+ implementation_sha256={name: hashlib.sha256((root / name).read_bytes()).hexdigest() for name in sources},+ harness_sha256=hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),+ timing="public forward including allocation/kernel generation; labelled backward; one CPU thread",+ )+ print(versions_line(metadata), flush=True)+ print(f"# commit {metadata['git_commit']}; {metadata['platform']}; {device}; one CPU thread", flush=True)+ reference = torch.load(args.reference, weights_only=True, map_location="cpu") if args.reference else {}+ saved = {}+ results = []+ for case in cases():+ if device.type == "mps" and case.get("dtype") == "float64":+ continue+ operation = make_operation(case, device)+ outputs = tuple(tensor.detach().cpu().clone() for tensor in operation())+ sync = torch.mps.synchronize if device.type == "mps" else None+ median, spread = time_us(operation, min_run_time=args.min_run_time, sync=sync)+ batch = case.get("batch", 1)+ row = {+ "op": case.get("op", "gaussian_blur2d"),+ "backend": "kornia (eager)",+ "case": case["name"],+ "batch": batch,+ "channels": case["channels"],+ "height": case["size"],+ "width": case["size"],+ "dtype": case.get("dtype", "float32"),+ "median_us": median,+ "iqr_us": spread,+ "throughput_per_s": batch * 1e6 / median,+ "parameters": case,+ }+ if reference:+ row.update(differences(outputs, reference[case["name"]]))+ results.append(row)+ saved[case["name"]] = outputs+ print(f"{case['name']:25s} {median:12.1f} us +/- IQR {spread:10.1f}", flush=True)+ save_json(args.json, metadata, results)+ if args.save_reference:+ torch.save(saved, args.save_reference)+++if __name__ == "__main__":+ main()diff --git a/benchmarks/filters/gaussian_cpu_results/after-cpu.json b/benchmarks/filters/gaussian_cpu_results/after-cpu.jsonnew file mode 100644index 000000000..3abc00328--- /dev/null+++ b/benchmarks/filters/gaussian_cpu_results/after-cpu.json@@ -0,0 +1,1109 @@+{+ "metadata": {+ "albumentations": null,+ "cudnn_allow_tf32": false,+ "device": "cpu",+ "git_commit": "607869e2d-dirty",+ "harness_sha256": "528354ef76e02087141be03f1cd3b3f899da72239ee38b42b37fcd7d82fa16a1",+ "implementation_sha256": {+ "kornia/filters/filter.py": "dc8cd1a6d1c28bad6e301108d56f92b1a9178b54bd535746677ffafc4411055a",+ "kornia/filters/gaussian.py": "fd4367e4bb4d6a06fbeb880d0af5b948637cd20cf57d9cec1be0e391a0a20382",+ "kornia/geometry/transform/pyramid.py": "814dcc2ce9b4d486b3983e44372d1d3b3c1ab569152c5b6562b6309d83c192c4"+ },+ "kornia": "0.9.0rc1",+ "kornia_rs": "0.1.14",+ "load": {+ "cpu_count": 8,+ "load_avg_15m": 2.2314453125,+ "load_avg_1m": 3.0966796875,+ "load_avg_5m": 2.7919921875,+ "mem_available_bytes": null,+ "mem_total_bytes": null+ },+ "machine": "arm64",+ "min_run_time": 1.0,+ "mkldnn_available": false,+ "numpy": "2.4.0",+ "opencv": null,+ "pillow": "12.3.0",+ "platform": "macOS-26.5.1-arm64-arm-64bit",+ "python": "3.11.14",+ "seed": 0,+ "timestamp_utc": "2026-09-17T16:46:24+00:00",+ "timing": "public forward including allocation/kernel generation; labelled backward; one CPU thread",+ "torch": "2.14.0",+ "torch_num_threads": 1,+ "torchvision": null+ },+ "results": [+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-128-c1-k7",+ "channels": 1,+ "dtype": "float32",+ "height": 128,+ "iqr_us": 1.0277285000484147,+ "median_us": 156.0467500021332,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 1,+ "kernel": 7,+ "name": "blur-128-c1-k7",+ "size": 128+ },+ "tensor_errors": [+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ }+ ],+ "throughput_per_s": 6408.335963333615,+ "width": 128+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-256-c1-k7",+ "channels": 1,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 54.03167007898445,+ "median_us": 423.4704200644046,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 1,+ "kernel": 7,+ "name": "blur-256-c1-k7",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ }+ ],+ "throughput_per_s": 2361.4400265499357,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-256-c3-k3",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 64.01458995242137,+ "median_us": 409.5512499770848,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 3,+ "name": "blur-256-c3-k3",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 1.7881393432617188e-07,+ "max_abs_over_reference_max": 1.9544391567454993e-07,+ "mean_abs": 1.5896982101063866e-08,+ "relative_l2": 5.496840334359116e-08+ }+ ],+ "throughput_per_s": 2441.6968573675504,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-256-c3-k7",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 30.028232522454285,+ "median_us": 731.5352100340533,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 7,+ "name": "blur-256-c3-k7",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 1.1920928955078125e-07,+ "max_abs_over_reference_max": 1.6442200485998562e-07,+ "mean_abs": 1.7513987889590982e-08,+ "relative_l2": 5.8910714380819646e-08+ }+ ],+ "throughput_per_s": 1366.988199998534,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-256-c3-k15",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 97.17500070109946,+ "median_us": 1324.9540999822784,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 15,+ "name": "blur-256-c3-k15",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 1.7881393432617188e-07,+ "max_abs_over_reference_max": 2.5463019547450846e-07,+ "mean_abs": 1.757355979255711e-08,+ "relative_l2": 5.916246838741678e-08+ }+ ],+ "throughput_per_s": 754.7431265833097,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-256-c3-k31",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 82.5667004392015,+ "median_us": 2446.9333002343774,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 31,+ "name": "blur-256-c3-k31",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 1.7881393432617188e-07,+ "max_abs_over_reference_max": 2.546408723385148e-07,+ "mean_abs": 1.766587350478706e-08,+ "relative_l2": 5.930713752814612e-08+ }+ ],+ "throughput_per_s": 408.67480936411954,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-512-c1-k3",+ "channels": 1,+ "dtype": "float32",+ "height": 512,+ "iqr_us": 29.817394988640334,+ "median_us": 570.3885450202506,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 1,+ "kernel": 3,+ "name": "blur-512-c1-k3",+ "size": 512+ },+ "tensor_errors": [+ {+ "max_abs": 1.7881393432617188e-07,+ "max_abs_over_reference_max": 2.0190546261286263e-07,+ "mean_abs": 1.5950575971146463e-08,+ "relative_l2": 5.51328414684889e-08+ }+ ],+ "throughput_per_s": 1753.1908884399086,+ "width": 512+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-512-c1-k7",+ "channels": 1,+ "dtype": "float32",+ "height": 512,+ "iqr_us": 35.96916500100641,+ "median_us": 970.1737499563023,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 1,+ "kernel": 7,+ "name": "blur-512-c1-k7",+ "size": 512+ },+ "tensor_errors": [+ {+ "max_abs": 1.7881393432617188e-07,+ "max_abs_over_reference_max": 2.408636406699863e-07,+ "mean_abs": 1.7493675841251388e-08,+ "relative_l2": 5.8971442965549606e-08+ }+ ],+ "throughput_per_s": 1030.7432045497428,+ "width": 512+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-512-c1-k15",+ "channels": 1,+ "dtype": "float32",+ "height": 512,+ "iqr_us": 93.49589963676404,+ "median_us": 1669.8041996278334,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 1,+ "kernel": 15,+ "name": "blur-512-c1-k15",+ "size": 512+ },+ "tensor_errors": [+ {+ "max_abs": 1.7881393432617188e-07,+ "max_abs_over_reference_max": 2.525761717113846e-07,+ "mean_abs": 1.7456159184803255e-08,+ "relative_l2": 5.893534888576247e-08+ }+ ],+ "throughput_per_s": 598.8726104670717,+ "width": 512+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-512-c1-k31",+ "channels": 1,+ "dtype": "float32",+ "height": 512,+ "iqr_us": 73.82090043392972,+ "median_us": 3099.383299559122,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 1,+ "kernel": 31,+ "name": "blur-512-c1-k31",+ "size": 512+ },+ "tensor_errors": [+ {+ "max_abs": 1.7881393432617188e-07,+ "max_abs_over_reference_max": 2.5260011826737535e-07,+ "mean_abs": 1.752187017700635e-08,+ "relative_l2": 5.907593007986859e-08+ }+ ],+ "throughput_per_s": 322.64483071269274,+ "width": 512+ },+ {+ "backend": "kornia (eager)",+ "batch": 4,+ "case": "blur-batch",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 3145.354003208922,+ "median_us": 9801.521002373192,+ "op": "gaussian_blur2d",+ "parameters": {+ "batch": 4,+ "channels": 3,+ "kernel": 15,+ "name": "blur-batch",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 1.7881393432617188e-07,+ "max_abs_over_reference_max": 2.497075716246632e-07,+ "mean_abs": 1.7515806878994528e-08,+ "relative_l2": 5.9030835666551843e-08+ }+ ],+ "throughput_per_s": 408.09992643299955,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 2,+ "case": "blur-batched-sigma",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 149.1020499088335,+ "median_us": 1699.0249998343643,+ "op": "gaussian_blur2d",+ "parameters": {+ "batch": 2,+ "batched_sigma": true,+ "channels": 3,+ "kernel": 7,+ "name": "blur-batched-sigma",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 1.1920928955078125e-07,+ "max_abs_over_reference_max": 1.5197283151296477e-07,+ "mean_abs": 1.7441986225700628e-08,+ "relative_l2": 5.874007343614899e-08+ }+ ],+ "throughput_per_s": 1177.1457160400685,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-float64",+ "channels": 1,+ "dtype": "float64",+ "height": 512,+ "iqr_us": 879.6791997156108,+ "median_us": 4987.479100236669,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 1,+ "dtype": "float64",+ "kernel": 15,+ "name": "blur-float64",+ "size": 512+ },+ "tensor_errors": [+ {+ "max_abs": 3.3306690738754696e-16,+ "max_abs_over_reference_max": 4.746908989715925e-16,+ "mean_abs": 3.278589253113539e-17,+ "relative_l2": 1.1016191066929582e-16+ }+ ],+ "throughput_per_s": 200.50209332256597,+ "width": 512+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-channels-last",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 503.36762487859204,+ "median_us": 1383.0708001478342,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 7,+ "layout": "channels_last",+ "name": "blur-channels-last",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ }+ ],+ "throughput_per_s": 723.0287848554908,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-strided",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 588.0520999198777,+ "median_us": 1165.341599698877,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 7,+ "layout": "strided",+ "name": "blur-strided",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ }+ ],+ "throughput_per_s": 858.1174826835315,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-input-backward",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 265.5103497090751,+ "median_us": 3763.583399995696,+ "op": "gaussian_blur2d",+ "parameters": {+ "backward": "input",+ "channels": 3,+ "kernel": 7,+ "name": "blur-input-backward",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ }+ ],+ "throughput_per_s": 265.7042222051313,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-sigma-backward",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 257.15829979162595,+ "median_us": 4869.237499951851,+ "op": "gaussian_blur2d",+ "parameters": {+ "backward": "sigma",+ "channels": 3,+ "kernel": 7,+ "name": "blur-sigma-backward",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ }+ ],+ "throughput_per_s": 205.37096414169332,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-signed",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 145.90420032618562,+ "median_us": 1366.5333004610147,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 15,+ "name": "blur-signed",+ "signal": "signed",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 8.940696716308594e-08,+ "max_abs_over_reference_max": 2.2103137068773322e-07,+ "mean_abs": 6.27547345541148e-09,+ "relative_l2": 9.643183023767994e-08+ }+ ],+ "throughput_per_s": 731.77872772119,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-constant",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 131.05942507536378,+ "median_us": 1363.345849676989,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 15,+ "name": "blur-constant",+ "signal": "constant",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ }+ ],+ "throughput_per_s": 733.4895985761244,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-impulse",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 143.2291501259897,+ "median_us": 1347.0416000927798,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 15,+ "name": "blur-impulse",+ "signal": "impulse",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ }+ ],+ "throughput_per_s": 742.3675704826958,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "pyramid-gray",+ "channels": 1,+ "dtype": "float32",+ "height": 512,+ "iqr_us": 2356.937500735512,+ "median_us": 21097.750002809335,+ "op": "ScalePyramid",+ "parameters": {+ "channels": 1,+ "name": "pyramid-gray",+ "op": "ScalePyramid",+ "size": 512+ },+ "tensor_errors": [+ {+ "max_abs": 1.7881393432617188e-07,+ "max_abs_over_reference_max": 2.374662728631538e-07,+ "mean_abs": 1.854444538669971e-08,+ "relative_l2": 6.138359605779723e-08+ },+ {+ "max_abs": 1.7881393432617188e-07,+ "max_abs_over_reference_max": 2.9420867868528735e-07,+ "mean_abs": 9.0825930480302e-09,+ "relative_l2": 4.2051730097533155e-08+ },+ {+ "max_abs": 1.1920928955078125e-07,+ "max_abs_over_reference_max": 2.149612838605671e-07,+ "mean_abs": 5.425439060976108e-09,+ "relative_l2": 3.198816848039568e-08+ },+ {+ "max_abs": 1.1920928955078125e-07,+ "max_abs_over_reference_max": 2.2700347020204898e-07,+ "mean_abs": 4.2806883963445825e-09,+ "relative_l2": 2.883243703846104e-08+ },+ {+ "max_abs": 1.1920928955078125e-07,+ "max_abs_over_reference_max": 2.33298564070668e-07,+ "mean_abs": 4.642060957849026e-09,+ "relative_l2": 3.03819630361661e-08+ },+ {+ "max_abs": 5.960464477539063e-08,+ "max_abs_over_reference_max": 1.1810230848677284e-07,+ "mean_abs": 3.5700698693593344e-09,+ "relative_l2": 2.7622771620194528e-08+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ }+ ],+ "throughput_per_s": 47.39841925640611,+ "width": 512+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "pyramid-rgb",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 1595.3539914335124,+ "median_us": 15773.500002978835,+ "op": "ScalePyramid",+ "parameters": {+ "channels": 3,+ "name": "pyramid-rgb",+ "op": "ScalePyramid",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 1.7881393432617188e-07,+ "max_abs_over_reference_max": 2.4297825247449053e-07,+ "mean_abs": 1.8623849326912833e-08,+ "relative_l2": 6.156594757819806e-08+ },+ {+ "max_abs": 1.1920928955078125e-07,+ "max_abs_over_reference_max": 1.8871294656677838e-07,+ "mean_abs": 9.022389551521176e-09,+ "relative_l2": 4.188108585946756e-08+ },+ {+ "max_abs": 1.1920928955078125e-07,+ "max_abs_over_reference_max": 2.1280181681679125e-07,+ "mean_abs": 4.96947905048728e-09,+ "relative_l2": 3.0790103528289026e-08+ },+ {+ "max_abs": 5.960464477539063e-08,+ "max_abs_over_reference_max": 1.1259658535091401e-07,+ "mean_abs": 3.4407195117738514e-09,+ "relative_l2": 2.5921644987637026e-08+ },+ {+ "max_abs": 8.940696716308594e-08,+ "max_abs_over_reference_max": 1.7520069239313634e-07,+ "mean_abs": 3.2854990826712713e-09,+ "relative_l2": 2.5436551891167603e-08+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ }+ ],+ "throughput_per_s": 63.39747042895676,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "pyramid-double",+ "channels": 1,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 1965.6875028886134,+ "median_us": 20776.104502147064,+ "op": "ScalePyramid",+ "parameters": {+ "channels": 1,+ "double": true,+ "name": "pyramid-double",+ "op": "ScalePyramid",+ "size": 256+ },+ "tensor_errors": [+ {+ "max_abs": 1.7881393432617188e-07,+ "max_abs_over_reference_max": 2.0525848988455373e-07,+ "mean_abs": 1.869881790147095e-08,+ "relative_l2": 6.15670680720105e-08+ },+ {+ "max_abs": 1.7881393432617188e-07,+ "max_abs_over_reference_max": 2.5840403124070283e-07,+ "mean_abs": 9.16490231854065e-09,+ "relative_l2": 4.218733201169144e-08+ },+ {+ "max_abs": 1.1920928955078125e-07,+ "max_abs_over_reference_max": 2.0006408052499214e-07,+ "mean_abs": 5.279919908692439e-09,+ "relative_l2": 3.165120457981202e-08+ },+ {+ "max_abs": 1.1920928955078125e-07,+ "max_abs_over_reference_max": 2.205426672871267e-07,+ "mean_abs": 3.756819448123376e-09,+ "relative_l2": 2.658025515704665e-08+ },+ {+ "max_abs": 5.960464477539063e-08,+ "max_abs_over_reference_max": 1.152694434768215e-07,+ "mean_abs": 2.1488328153888383e-09,+ "relative_l2": 1.9480715168804692e-08+ },+ {+ "max_abs": 5.960464477539063e-08,+ "max_abs_over_reference_max": 1.1770025934075143e-07,+ "mean_abs": 5.820766091346741e-10,+ "relative_l2": 9.119731469497265e-09+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ }+ ],+ "throughput_per_s": 48.13221842894836,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "pyramid-float64",+ "channels": 1,+ "dtype": "float64",+ "height": 512,+ "iqr_us": 4029.2499979841523,+ "median_us": 45688.33300436381,+ "op": "ScalePyramid",+ "parameters": {+ "channels": 1,+ "dtype": "float64",+ "name": "pyramid-float64",+ "op": "ScalePyramid",+ "size": 512+ },+ "tensor_errors": [+ {+ "max_abs": 3.3306690738754696e-16,+ "max_abs_over_reference_max": 4.616688081562461e-16,+ "mean_abs": 3.4595719595102076e-17,+ "relative_l2": 1.1439864928571349e-16+ },+ {+ "max_abs": 2.220446049250313e-16,+ "max_abs_over_reference_max": 3.7171395243388824e-16,+ "mean_abs": 1.6746406055849022e-17,+ "relative_l2": 7.794257926721392e-17+ },+ {+ "max_abs": 2.220446049250313e-16,+ "max_abs_over_reference_max": 4.0405124505433585e-16,+ "mean_abs": 9.526297213453364e-18,+ "relative_l2": 5.816252575786119e-17+ },+ {+ "max_abs": 1.1102230246251565e-16,+ "max_abs_over_reference_max": 2.1125676631546808e-16,+ "mean_abs": 7.008915294213583e-18,+ "relative_l2": 4.99538693545606e-17+ },+ {+ "max_abs": 1.1102230246251565e-16,+ "max_abs_over_reference_max": 2.171514339475662e-16,+ "mean_abs": 4.264528545109651e-18,+ "relative_l2": 3.8403756663282035e-17+ },+ {+ "max_abs": 1.1102230246251565e-16,+ "max_abs_over_reference_max": 2.1957631159080594e-16,+ "mean_abs": 5.7462715141731735e-18,+ "relative_l2": 4.677855702619876e-17+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ },+ {+ "max_abs": 0.0,+ "max_abs_over_reference_max": 0.0,+ "mean_abs": 0.0,+ "relative_l2": 0.0+ }+ ],+ "throughput_per_s": 21.88742583154626,+ "width": 512+ }+ ]+}diff --git a/benchmarks/filters/gaussian_cpu_results/before-cpu.json b/benchmarks/filters/gaussian_cpu_results/before-cpu.jsonnew file mode 100644index 000000000..442e320ad--- /dev/null+++ b/benchmarks/filters/gaussian_cpu_results/before-cpu.json@@ -0,0 +1,509 @@+{+ "metadata": {+ "albumentations": null,+ "cudnn_allow_tf32": false,+ "device": "cpu",+ "git_commit": "607869e2d",+ "harness_sha256": "528354ef76e02087141be03f1cd3b3f899da72239ee38b42b37fcd7d82fa16a1",+ "implementation_sha256": {+ "kornia/filters/filter.py": "dc8cd1a6d1c28bad6e301108d56f92b1a9178b54bd535746677ffafc4411055a",+ "kornia/filters/gaussian.py": "0c078e8f9951d483be21098adfe8340d7d4f81ff70dfffbc649c375725872aac",+ "kornia/geometry/transform/pyramid.py": "14b3b90b1b5d9d3c47d74ac8b353a8d667b51eea0e2e7afebbe8f0f52dc23179"+ },+ "kornia": "0.9.0rc1",+ "kornia_rs": "0.1.14",+ "load": {+ "cpu_count": 8,+ "load_avg_15m": 2.248046875,+ "load_avg_1m": 4.61279296875,+ "load_avg_5m": 2.94189453125,+ "mem_available_bytes": null,+ "mem_total_bytes": null+ },+ "machine": "arm64",+ "min_run_time": 1.0,+ "mkldnn_available": false,+ "numpy": "2.4.0",+ "opencv": null,+ "pillow": "12.3.0",+ "platform": "macOS-26.5.1-arm64-arm-64bit",+ "python": "3.11.14",+ "seed": 0,+ "timestamp_utc": "2026-09-17T16:45:33+00:00",+ "timing": "public forward including allocation/kernel generation; labelled backward; one CPU thread",+ "torch": "2.14.0",+ "torch_num_threads": 1,+ "torchvision": null+ },+ "results": [+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-128-c1-k7",+ "channels": 1,+ "dtype": "float32",+ "height": 128,+ "iqr_us": 1.7749582493706815,+ "median_us": 131.59287499729544,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 1,+ "kernel": 7,+ "name": "blur-128-c1-k7",+ "size": 128+ },+ "throughput_per_s": 7599.195625299261,+ "width": 128+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-256-c1-k7",+ "channels": 1,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 5.2072900507482505,+ "median_us": 418.76625000440987,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 1,+ "kernel": 7,+ "name": "blur-256-c1-k7",+ "size": 256+ },+ "throughput_per_s": 2387.9670340899474,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-256-c3-k3",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 25.970839997171428,+ "median_us": 408.013749984093,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 3,+ "name": "blur-256-c3-k3",+ "size": 256+ },+ "throughput_per_s": 2450.8977945938987,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-256-c3-k7",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 125.43754983198588,+ "median_us": 1270.616649708245,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 7,+ "name": "blur-256-c3-k7",+ "size": 256+ },+ "throughput_per_s": 787.0194367668777,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-256-c3-k15",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 183.95409933873435,+ "median_us": 2704.112499486655,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 15,+ "name": "blur-256-c3-k15",+ "size": 256+ },+ "throughput_per_s": 369.80709944199384,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-256-c3-k31",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 283.1843743479109,+ "median_us": 6376.362550145131,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 31,+ "name": "blur-256-c3-k31",+ "size": 256+ },+ "throughput_per_s": 156.82922546134697,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-512-c1-k3",+ "channels": 1,+ "dtype": "float32",+ "height": 512,+ "iqr_us": 16.976679980871232,+ "median_us": 829.702500050189,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 1,+ "kernel": 3,+ "name": "blur-512-c1-k3",+ "size": 512+ },+ "throughput_per_s": 1205.2512797532968,+ "width": 512+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-512-c1-k7",+ "channels": 1,+ "dtype": "float32",+ "height": 512,+ "iqr_us": 210.23125045758172,+ "median_us": 2125.745800003642,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 1,+ "kernel": 7,+ "name": "blur-512-c1-k7",+ "size": 512+ },+ "throughput_per_s": 470.42313337666553,+ "width": 512+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-512-c1-k15",+ "channels": 1,+ "dtype": "float32",+ "height": 512,+ "iqr_us": 110.0249748560607,+ "median_us": 5577.247949986486,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 1,+ "kernel": 15,+ "name": "blur-512-c1-k15",+ "size": 512+ },+ "throughput_per_s": 179.2999000523947,+ "width": 512+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-512-c1-k31",+ "channels": 1,+ "dtype": "float32",+ "height": 512,+ "iqr_us": 998.4587522922084,+ "median_us": 12478.396001824876,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 1,+ "kernel": 31,+ "name": "blur-512-c1-k31",+ "size": 512+ },+ "throughput_per_s": 80.13850496920895,+ "width": 512+ },+ {+ "backend": "kornia (eager)",+ "batch": 4,+ "case": "blur-batch",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 1262.167003005743,+ "median_us": 17680.541997833643,+ "op": "gaussian_blur2d",+ "parameters": {+ "batch": 4,+ "channels": 3,+ "kernel": 15,+ "name": "blur-batch",+ "size": 256+ },+ "throughput_per_s": 226.23740836056444,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 2,+ "case": "blur-batched-sigma",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 469.887549843406,+ "median_us": 2650.8417002332862,+ "op": "gaussian_blur2d",+ "parameters": {+ "batch": 2,+ "batched_sigma": true,+ "channels": 3,+ "kernel": 7,+ "name": "blur-batched-sigma",+ "size": 256+ },+ "throughput_per_s": 754.4773419793385,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-float64",+ "channels": 1,+ "dtype": "float64",+ "height": 512,+ "iqr_us": 866.6454941703705,+ "median_us": 11678.124996251427,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 1,+ "dtype": "float64",+ "kernel": 15,+ "name": "blur-float64",+ "size": 512+ },+ "throughput_per_s": 85.63018466757215,+ "width": 512+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-channels-last",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 246.80410024302546,+ "median_us": 1460.04170019296,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 7,+ "layout": "channels_last",+ "name": "blur-channels-last",+ "size": 256+ },+ "throughput_per_s": 684.9119445477752,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-strided",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 537.6281500502956,+ "median_us": 1122.9874999116873,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 7,+ "layout": "strided",+ "name": "blur-strided",+ "size": 256+ },+ "throughput_per_s": 890.4818620676017,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-input-backward",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 252.93645012425347,+ "median_us": 4271.908349983278,+ "op": "gaussian_blur2d",+ "parameters": {+ "backward": "input",+ "channels": 3,+ "kernel": 7,+ "name": "blur-input-backward",+ "size": 256+ },+ "throughput_per_s": 234.08741903461353,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-sigma-backward",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 396.30627543374345,+ "median_us": 5387.025000163703,+ "op": "gaussian_blur2d",+ "parameters": {+ "backward": "sigma",+ "channels": 3,+ "kernel": 7,+ "name": "blur-sigma-backward",+ "size": 256+ },+ "throughput_per_s": 185.63121573959867,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-signed",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 176.22289997234466,+ "median_us": 3008.077100093942,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 15,+ "name": "blur-signed",+ "signal": "signed",+ "size": 256+ },+ "throughput_per_s": 332.4382875587763,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-constant",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 244.4124991598075,+ "median_us": 2818.7791001982987,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 15,+ "name": "blur-constant",+ "signal": "constant",+ "size": 256+ },+ "throughput_per_s": 354.76352152946316,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "blur-impulse",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 145.5999501558834,+ "median_us": 2793.358349663322,+ "op": "gaussian_blur2d",+ "parameters": {+ "channels": 3,+ "kernel": 15,+ "name": "blur-impulse",+ "signal": "impulse",+ "size": 256+ },+ "throughput_per_s": 357.9920206516031,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "pyramid-gray",+ "channels": 1,+ "dtype": "float32",+ "height": 512,+ "iqr_us": 2212.656498159049,+ "median_us": 46209.29150041775,+ "op": "ScalePyramid",+ "parameters": {+ "channels": 1,+ "name": "pyramid-gray",+ "op": "ScalePyramid",+ "size": 512+ },+ "throughput_per_s": 21.64066938769143,+ "width": 512+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "pyramid-rgb",+ "channels": 3,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 2275.8340055588633,+ "median_us": 24443.916001473553,+ "op": "ScalePyramid",+ "parameters": {+ "channels": 3,+ "name": "pyramid-rgb",+ "op": "ScalePyramid",+ "size": 256+ },+ "throughput_per_s": 40.90997530590913,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "pyramid-double",+ "channels": 1,+ "dtype": "float32",+ "height": 256,+ "iqr_us": 5562.541999097448,+ "median_us": 46490.75000634184,+ "op": "ScalePyramid",+ "parameters": {+ "channels": 1,+ "double": true,+ "name": "pyramid-double",+ "op": "ScalePyramid",+ "size": 256+ },+ "throughput_per_s": 21.509655143519716,+ "width": 256+ },+ {+ "backend": "kornia (eager)",+ "batch": 1,+ "case": "pyramid-float64",+ "channels": 1,+ "dtype": "float64",+ "height": 512,+ "iqr_us": 2381.7500041332096,+ "median_us": 96687.37500032876,+ "op": "ScalePyramid",+ "parameters": {+ "channels": 1,+ "dtype": "float64",+ "name": "pyramid-float64",+ "op": "ScalePyramid",+ "size": 512+ },+ "throughput_per_s": 10.342611949042983,+ "width": 512+ }+ ]+}diff --git a/changelog.d/4641.fixed.md b/changelog.d/4641.fixed.mdnew file mode 100644index 000000000..98013f190--- /dev/null+++ b/changelog.d/4641.fixed.md@@ -0,0 +1 @@+Speed up large float32/float64 CPU Gaussian blurs and scale pyramids on builds without oneDNN while preserving tensor sigma gradients and existing autocast/export behavior.diff --git a/kornia/filters/gaussian.py b/kornia/filters/gaussian.pyindex 235a60bc6..23038988c 100644--- a/kornia/filters/gaussian.py+++ b/kornia/filters/gaussian.py@@ -20,16 +20,57 @@ from __future__ import annotationsfrom typing import Anyimport torch+import torch.nn.functional as Ffrom torch import nnfrom kornia.core._compat import deprecatedfrom kornia.core.check import KORNIA_CHECK, KORNIA_CHECK_IS_TENSOR, KORNIA_CHECK_SHAPE-from kornia.core.utils import is_compiling+from kornia.core.utils import is_autocast_enabled, is_compilingfrom .filter import filter2d, filter2d_separablefrom .kernels import _check_kernel_size, _unpack_2d_ks, get_gaussian_kernel1d, get_gaussian_kernel2d+def _gaussian_blur2d_cpu_eligible(input: torch.Tensor) -> bool:+ """Select large native-precision images without an accelerated CPU convolution backend."""+ # Preserve convolution's autocast and export behaviour, and leave oneDNN's+ # optimized CPU kernels alone. Small images are faster in one convolution;+ # convolution also avoids a long chain of slice-backward operations.+ return (+ not is_compiling()+ and not torch.jit.is_tracing()+ and input.device.type == "cpu"+ and input.dtype in (torch.float32, torch.float64)+ and not torch.backends.mkldnn.is_available()+ and not is_autocast_enabled()+ and not (torch.is_grad_enabled() and input.requires_grad)+ and input.is_contiguous()+ and input.shape[-2] * input.shape[-1] >= 256 * 256+ and input.numel() >= 128 * 1024+ )+++def _gaussian_blur2d_cpu(+ input: torch.Tensor, kernel_x: torch.Tensor, kernel_y: torch.Tensor, border_type: str+) -> torch.Tensor:+ """Accumulate separable Gaussian taps without materializing convolution's im2col buffer.++ Keep weights as tensors: scalar ``alpha`` values would lose derivatives with+ respect to sigma and break forward-mode automatic differentiation.+ """+ for axis, kernel in ((-1, kernel_x), (-2, kernel_y)):+ size = input.shape[axis]+ radius = kernel.shape[-1] // 2+ padding = (radius, radius, 0, 0) if axis == -1 else (0, 0, radius, radius)+ padded = F.pad(input, padding, mode=border_type)+ output = padded.narrow(axis, 0, size) * kernel[:, 0, None, None, None]+ for tap in range(1, kernel.shape[-1]):+ # The out-of-place operator also has a vmap batching rule.+ output = output.addcmul(padded.narrow(axis, tap, size), kernel[:, tap, None, None, None])+ input = output+ return input++def gaussian_blur2d(input: torch.Tensor,kernel_size: tuple[int, int] | int,@@ -113,7 +154,15 @@ def gaussian_blur2d(bs = sigma.shape[0]kernel_x = get_gaussian_kernel1d(kx, sigma[:, 1].view(bs, 1))kernel_y = get_gaussian_kernel1d(ky, sigma[:, 0].view(bs, 1))- out = filter2d_separable(input, kernel_x, kernel_y, border_type)+ if (+ _gaussian_blur2d_cpu_eligible(input)+ and not (torch.is_grad_enabled() and sigma.requires_grad)+ and bs in (1, input.shape[0])+ and border_type in ("constant", "reflect", "replicate", "circular")+ ):+ out = _gaussian_blur2d_cpu(input, kernel_x, kernel_y, border_type)+ else:+ out = filter2d_separable(input, kernel_x, kernel_y, border_type)else:kernel = get_gaussian_kernel2d(kernel_size, sigma)out = filter2d(input, kernel, border_type)diff --git a/kornia/geometry/transform/pyramid.py b/kornia/geometry/transform/pyramid.pyindex bb4169d0c..e55659573 100644--- a/kornia/geometry/transform/pyramid.py+++ b/kornia/geometry/transform/pyramid.py@@ -25,6 +25,7 @@ from torch import nnfrom kornia.core.check import KORNIA_CHECK, KORNIA_CHECK_SHAPEfrom kornia.filters import filter2d, gaussian_blur2d+from kornia.filters.gaussian import _gaussian_blur2d_cpu, _gaussian_blur2d_cpu_eligible__all__ = ["PyrDown", "PyrUp", "ScalePyramid", "build_laplacian_pyramid", "build_pyramid", "pyrdown", "pyrup"]@@ -270,6 +271,8 @@ class ScalePyramid(nn.Module):pad = ksize // 2_B, C, _H, _W = x.shapek = kernel.to(device=x.device, dtype=x.dtype)+ if _gaussian_blur2d_cpu_eligible(x) and not (torch.is_grad_enabled() and k.requires_grad):+ return _gaussian_blur2d_cpu(x, k.view(1, -1), k.view(1, -1), "reflect")# Depthwise separable: same kernel applied independently to every channel.k_h = k.view(1, 1, 1, ksize).expand(C, 1, 1, ksize).contiguous()tmp = F.conv2d(F.pad(x, (pad, pad, 0, 0), mode="reflect"), k_h, groups=C)diff --git a/tests/filters/test_gaussian_cpu.py b/tests/filters/test_gaussian_cpu.pynew file mode 100644index 000000000..68b5a2da5--- /dev/null+++ b/tests/filters/test_gaussian_cpu.py@@ -0,0 +1,277 @@+# LICENSE HEADER MANAGED BY add-license-header+#+# Copyright 2018 Kornia Team+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+#++import importlib+import io+import warnings++import pytest+import torch++from kornia.filters import GaussianBlur2d, gaussian_blur2d, get_gaussian_kernel1d+from kornia.filters.filter import filter2d_separable+from kornia.filters.gaussian import _gaussian_blur2d_cpu++from testing.base import BaseTester++gaussian_module = importlib.import_module("kornia.filters.gaussian")+++def _require_native_cpu(device: torch.device, dtype: torch.dtype) -> None:+ if device.type != "cpu" or dtype not in (torch.float32, torch.float64):+ pytest.skip("the CPU slice accumulation path supports native CPU float32 and float64 only")+++def _disable_mkldnn(monkeypatch: pytest.MonkeyPatch) -> None:+ # The production guard deliberately leaves oneDNN convolutions alone. Force+ # its unavailable branch so this suite exercises the native fallback on CI.+ monkeypatch.setattr(torch.backends.mkldnn, "is_available", lambda: False)+++def _cpu_tolerance(dtype: torch.dtype) -> float:+ return 5e-7 if dtype == torch.float32 else 1e-12+++class TestGaussianBlurCpu(BaseTester):+ @pytest.mark.parametrize("border_type", ("constant", "reflect", "replicate", "circular"))+ def test_helper_matches_separable_convolution_per_sample_kernels(self, border_type, device, dtype):+ _require_native_cpu(device, dtype)+ image = torch.rand(2, 2, 257, 256, device=device, dtype=dtype)+ sigma = torch.tensor([[0.6, 1.7], [1.4, 0.8]], device=device, dtype=dtype)+ kernel_x = get_gaussian_kernel1d(7, sigma[:, 1:])+ kernel_y = get_gaussian_kernel1d(5, sigma[:, :1])++ actual = _gaussian_blur2d_cpu(image, kernel_x, kernel_y, border_type)+ expected = filter2d_separable(image, kernel_x, kernel_y, border_type)++ tolerance = _cpu_tolerance(dtype)+ self.assert_close(actual, expected, rtol=tolerance, atol=tolerance)++ def test_helper_vmap_has_no_user_warning(self, device, dtype):+ _require_native_cpu(device, dtype)+ image = torch.rand(2, 1, 7, 9, device=device, dtype=dtype)+ kernel_x = torch.rand(2, 5, device=device, dtype=dtype)+ kernel_y = torch.rand(2, 3, device=device, dtype=dtype)++ with warnings.catch_warnings(record=True) as recorded:+ warnings.simplefilter("always")+ actual = torch.vmap(lambda x, kx, ky: _gaussian_blur2d_cpu(x[None], kx[None], ky[None], "reflect")[0])(+ image, kernel_x, kernel_y+ )+ assert not any(issubclass(warning.category, UserWarning) for warning in recorded)+ expected = filter2d_separable(image, kernel_x, kernel_y, "reflect")+ tolerance = _cpu_tolerance(dtype)+ self.assert_close(actual, expected, rtol=tolerance, atol=tolerance)++ def test_helper_gradcheck_small_input_and_kernels(self, device):+ if device.type != "cpu":+ pytest.skip("the helper is CPU-only")+ image = torch.rand(1, 1, 7, 9, device=device, dtype=torch.float64, requires_grad=True)+ kernel_x = torch.rand(1, 5, device=device, dtype=torch.float64, requires_grad=True)+ kernel_y = torch.rand(1, 3, device=device, dtype=torch.float64, requires_grad=True)++ self.gradcheck(_gaussian_blur2d_cpu, (image, kernel_x, kernel_y, "reflect"))++ def test_public_large_path_dispatches_without_reverse_mode_gradients(self, monkeypatch, device, dtype):+ _require_native_cpu(device, dtype)+ _disable_mkldnn(monkeypatch)+ image = torch.rand(2, 1, 256, 256, device=device, dtype=dtype)+ sigma = torch.tensor([[0.7, 1.8], [1.6, 0.9]], device=device, dtype=dtype)+ helper = gaussian_module._gaussian_blur2d_cpu+ calls = 0++ def counted_helper(*args, **kwargs):+ nonlocal calls+ calls += 1+ return helper(*args, **kwargs)++ monkeypatch.setattr(gaussian_module, "_gaussian_blur2d_cpu", counted_helper)++ actual = gaussian_blur2d(image, (5, 7), sigma, "reflect")+ kernel_x = get_gaussian_kernel1d(7, sigma[:, 1:])+ kernel_y = get_gaussian_kernel1d(5, sigma[:, :1])+ expected = filter2d_separable(image, kernel_x, kernel_y, "reflect")+ tolerance = _cpu_tolerance(dtype)+ self.assert_close(actual, expected, rtol=tolerance, atol=tolerance)+ assert calls == 1++ def test_public_reverse_mode_gradients_match_convolution(self, monkeypatch, device, dtype):+ _require_native_cpu(device, dtype)+ _disable_mkldnn(monkeypatch)++ def should_not_run(*args, **kwargs):+ raise AssertionError("reverse-mode gradients must use the convolution path")++ monkeypatch.setattr(gaussian_module, "_gaussian_blur2d_cpu", should_not_run)+ image = torch.rand(2, 1, 256, 256, device=device, dtype=dtype, requires_grad=True)+ sigma = torch.tensor([[0.7, 1.8], [1.6, 0.9]], device=device, dtype=dtype, requires_grad=True)+ actual = gaussian_blur2d(image, (5, 7), sigma, "reflect")+ kernel_x = get_gaussian_kernel1d(7, sigma[:, 1:])+ kernel_y = get_gaussian_kernel1d(5, sigma[:, :1])+ expected = filter2d_separable(image, kernel_x, kernel_y, "reflect")+ actual_grads = torch.autograd.grad(actual.square().mean(), (image, sigma), create_graph=True)+ expected_grads = torch.autograd.grad(expected.square().mean(), (image, sigma), create_graph=True)+ self.assert_close(actual_grads[0], expected_grads[0], rtol=3e-5, atol=3e-5)+ self.assert_close(actual_grads[1], expected_grads[1], rtol=3e-5, atol=3e-5)+ self.assert_close(+ torch.autograd.grad(actual_grads[1].sum(), sigma)[0],+ torch.autograd.grad(expected_grads[1].sum(), sigma)[0],+ rtol=4e-5,+ atol=4e-5,+ )++ def test_public_large_path_gradcheck_with_scalar_image_parameter(self, monkeypatch, device):+ if device.type != "cpu":+ pytest.skip("the optimized path is CPU-only")+ _disable_mkldnn(monkeypatch)+ base = torch.rand(1, 1, 256, 512, device=device, dtype=torch.float64)+ scale = torch.tensor(0.8, device=device, dtype=torch.float64, requires_grad=True)+ sigma = torch.tensor([[0.9, 1.3]], device=device, dtype=torch.float64, requires_grad=True)++ def op(image_scale, blur_sigma):+ return gaussian_blur2d(base * image_scale, (5, 7), blur_sigma, "reflect")[..., :2, :2]++ self.gradcheck(op, (scale, sigma))+ assert torch.autograd.gradgradcheck(op, (scale, sigma))++ def test_public_large_path_jvp_through_sigma(self, monkeypatch, device):+ if device.type != "cpu":+ pytest.skip("the optimized path is CPU-only")+ _disable_mkldnn(monkeypatch)+ image = torch.rand(1, 1, 256, 512, device=device, dtype=torch.float64)+ sigma = torch.tensor([[0.9, 1.3]], device=device, dtype=torch.float64)+ tangent = torch.tensor([[0.2, -0.3]], device=device, dtype=torch.float64)+ helper = gaussian_module._gaussian_blur2d_cpu+ calls = 0++ def counted_helper(*args, **kwargs):+ nonlocal calls+ calls += 1+ return helper(*args, **kwargs)++ monkeypatch.setattr(gaussian_module, "_gaussian_blur2d_cpu", counted_helper)++ def fast(blur_sigma):+ return gaussian_blur2d(image, (5, 7), blur_sigma, "replicate")++ def reference(blur_sigma):+ return filter2d_separable(+ image,+ get_gaussian_kernel1d(7, blur_sigma[:, 1:]),+ get_gaussian_kernel1d(5, blur_sigma[:, :1]),+ "replicate",+ )++ actual, actual_tangent = torch.func.jvp(fast, (sigma,), (tangent,))+ expected, expected_tangent = torch.func.jvp(reference, (sigma,), (tangent,))+ self.assert_close(actual, expected, rtol=2e-10, atol=2e-10)+ self.assert_close(actual_tangent, expected_tangent, rtol=3e-10, atol=3e-10)+ assert calls == 1++ def test_noncontiguous_and_small_inputs_fall_back_to_convolution(self, monkeypatch, device, dtype):+ _require_native_cpu(device, dtype)+ _disable_mkldnn(monkeypatch)++ def should_not_run(*args, **kwargs):+ raise AssertionError("the optimized CPU helper should not run")++ monkeypatch.setattr(gaussian_module, "_gaussian_blur2d_cpu", should_not_run)+ noncontiguous = torch.rand(1, 1, 512, 256, device=device, dtype=dtype).transpose(-1, -2)+ small = torch.rand(1, 1, 256, 256, device=device, dtype=dtype)+ for image in (noncontiguous, small):+ actual = gaussian_blur2d(image, (5, 7), (0.9, 1.3), "reflect")+ expected = filter2d_separable(+ image,+ get_gaussian_kernel1d(7, 1.3, device=device, dtype=dtype),+ get_gaussian_kernel1d(5, 0.9, device=device, dtype=dtype),+ "reflect",+ )+ self.assert_close(actual, expected)++ def test_onednn_available_falls_back_to_convolution(self, monkeypatch, device, dtype):+ _require_native_cpu(device, dtype)+ monkeypatch.setattr(torch.backends.mkldnn, "is_available", lambda: True)++ def should_not_run(*args, **kwargs):+ raise AssertionError("oneDNN hosts must keep their convolution implementation")++ monkeypatch.setattr(gaussian_module, "_gaussian_blur2d_cpu", should_not_run)+ image = torch.rand(1, 1, 256, 512, device=device, dtype=dtype)+ actual = gaussian_blur2d(image, (5, 7), (0.9, 1.3), "reflect")+ expected = filter2d_separable(+ image,+ get_gaussian_kernel1d(7, 1.3, device=device, dtype=dtype),+ get_gaussian_kernel1d(5, 0.9, device=device, dtype=dtype),+ "reflect",+ )+ self.assert_close(actual, expected)++ def test_autocast_falls_back_to_convolution(self, monkeypatch, device, dtype):+ if device.type != "cpu" or dtype != torch.float32:+ pytest.skip("CPU autocast is required")+ _disable_mkldnn(monkeypatch)++ def should_not_run(*args, **kwargs):+ raise AssertionError("the optimized CPU helper should not run")++ monkeypatch.setattr(gaussian_module, "_gaussian_blur2d_cpu", should_not_run)+ image = torch.rand(1, 1, 256, 512, device=device)+ with torch.autocast("cpu", dtype=torch.bfloat16):+ autocast_output = gaussian_blur2d(image, (5, 7), (0.9, 1.3), "reflect")+ autocast_reference = filter2d_separable(+ image,+ get_gaussian_kernel1d(7, 1.3, device=device),+ get_gaussian_kernel1d(5, 0.9, device=device),+ "reflect",+ )+ assert autocast_output.dtype == autocast_reference.dtype+ self.assert_close(autocast_output, autocast_reference)++ def test_dynamo_large_input_falls_back_to_convolution(self, monkeypatch, device, dtype, torch_optimizer):+ if device.type != "cpu" or dtype != torch.float32:+ pytest.skip("the Dynamo fallback is checked once on CPU float32")+ _disable_mkldnn(monkeypatch)++ def should_not_run(*args, **kwargs):+ raise AssertionError("the optimized CPU helper should not run while compiling")++ monkeypatch.setattr(gaussian_module, "_gaussian_blur2d_cpu", should_not_run)+ image = torch.rand(1, 1, 256, 512, device=device)+ compiled = torch_optimizer(lambda x: gaussian_blur2d(x, (5, 7), (0.9, 1.3), "reflect"))+ reference = filter2d_separable(+ image,+ get_gaussian_kernel1d(7, 1.3, device=device),+ get_gaussian_kernel1d(5, 0.9, device=device),+ "reflect",+ )+ self.assert_close(compiled(image), reference)++ def test_onnx_trace_large_input_falls_back_to_convolution(self, monkeypatch, device, dtype):+ if device.type != "cpu" or dtype != torch.float32:+ pytest.skip("the trace fallback is checked once on CPU float32")+ pytest.importorskip("onnx")+ _disable_mkldnn(monkeypatch)++ def should_not_run(*args, **kwargs):+ raise AssertionError("the optimized CPU helper should not run while tracing")++ monkeypatch.setattr(gaussian_module, "_gaussian_blur2d_cpu", should_not_run)+ buffer = io.BytesIO()+ with warnings.catch_warnings():+ warnings.simplefilter("ignore")+ torch.onnx.export(GaussianBlur2d((5, 7), (0.9, 1.3)), torch.rand(1, 1, 256, 512), buffer, dynamo=False)+ assert buffer.getbuffer().nbytes > 0diff --git a/tests/geometry/transform/test_pyramid_cpu.py b/tests/geometry/transform/test_pyramid_cpu.pynew file mode 100644index 000000000..0acb70d83--- /dev/null+++ b/tests/geometry/transform/test_pyramid_cpu.py@@ -0,0 +1,42 @@+# LICENSE HEADER MANAGED BY add-license-header+#+# Copyright 2018 Kornia Team+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+#++import pytest+import torch++from kornia.filters.filter import filter2d_separable+from kornia.geometry import ScalePyramid++from testing.base import BaseTester+++class TestScalePyramidCpu(BaseTester):+ def test_fast_blur_matches_separable_convolution(self, monkeypatch, device, dtype):+ if device.type != "cpu" or dtype not in (torch.float32, torch.float64):+ pytest.skip("the optimized scale-pyramid blur supports native CPU float32 and float64 only")+ # Exercise the generic ScalePyramid integration even on hosts where+ # oneDNN would normally keep the existing convolution implementation.+ monkeypatch.setattr(torch.backends.mkldnn, "is_available", lambda: False)+ pyramid = ScalePyramid(n_levels=2).to(device=device, dtype=dtype)+ image = torch.rand(2, 1, 256, 256, device=device, dtype=dtype)+ kernel = pyramid._gk_0++ actual = pyramid._blur_fast(image, kernel)+ expected = filter2d_separable(image, kernel.view(1, -1), kernel.view(1, -1), "reflect")++ tolerance = 5e-7 if dtype == torch.float32 else 1e-12+ self.assert_close(actual, expected, rtol=tolerance, atol=tolerance)