Skip to content
KernelIndex
Search⌘K

submission 837945

alazarr.m · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

No package. Vendor the mirrored source: 39 lines, June 9 Researcher Reciprocity License v1.0.

submission.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-eigh-837945?include=source"
interfacepython
Compatibility
measured onNVIDIA B200
declared hardwareNVIDIA B200
architecturessm_100
dtypesfp32

Benchmark evidence

1 measurement across 1 GPU, fastest first.

Operation / workload
Hardware
Latency
Rank
Observed
NVIDIA B200
57.6ms
#275 of 286
2026-06-26

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:633e578eeda4781d27d2277164996c75c4b685f7d0557582a02f2083de4848a1
license declaredunknown
license concludedunknown
authorsalazarr.m
imported2026-08-26

Kernel source

submission.py39 lines
"""impl8 — cheap diagonal detection + fast fill + cuSOLVER dense.

Leaderboard: gpumode `eigh` (LB 775), target GPU B200.

Same structure as the diagonal-fast-path variants, but the diagonal *detection*
is made an order of magnitude cheaper. A matrix is exactly diagonal iff all of
its nonzeros lie on the diagonal, i.e. count_nonzero(A) == count_nonzero(diag(A)).
That's a single pass over A plus a trivial diagonal count -- no `diag_embed`
allocation and no full `A - diag` subtraction (which cost ~4-5 extra passes over
the whole batch). On the n=4096 diagonal benchmark this is the dominant cost, so
shrinking it pulls the (log-sensitive) geomean down noticeably.

Dense solve stays on default cuSOLVER (`torch.linalg.eigh`).
"""
import torch

from task import input_t, output_t


def _is_exact_diagonal(data: torch.Tensor) -> bool:
    diag = torch.diagonal(data, dim1=-2, dim2=-1)
    return torch.count_nonzero(data).item() == torch.count_nonzero(diag).item()


def _diagonal_eigh(data: torch.Tensor) -> output_t:
    batch, n, _ = data.shape
    values, perm = torch.diagonal(data, dim1=-2, dim2=-1).sort(dim=-1)
    vectors = torch.zeros((batch, n, n), device=data.device, dtype=data.dtype)
    vectors.scatter_(1, perm.unsqueeze(1), 1.0)
    return vectors, values.contiguous()


def custom_kernel(data: input_t) -> output_t:
    if data.shape[-1] > 1 and _is_exact_diagonal(data):
        return _diagonal_eigh(data)

    values, vectors = torch.linalg.eigh(data)
    return vectors, values
scrolls · 39 lines total

Source code from GPU Mode and the KernelBot dataset · June 9 Researcher Reciprocity License v1.0

Best evidence level for this revision: reported

JSON