submission 780438
Kernel-Zhang · python · License unknown
Use it
Vendorable · source mirrored · license unknownView source →
No package. Vendor the mirrored source: 51 lines, June 9 Researcher Reciprocity License v1.0.
ref.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-prefixsum-v2-780438?include=source"interfacepython
Compatibility
measured onNVIDIA A100
declared hardwareNVIDIA A100
architecturessm_80
dtypesfp32
Benchmark evidence
1 measurement across 1 GPU, fastest first.
Operation / workload
Hardware
Latency
Rank
Observed
Reported · How evidence levels are derived →
Source and license
sourceavailable
revision digestsha256:81172be60124701c9623f970cf02a6eafb1bcd2b772de6d735fa79b90b6c1832
license declaredunknown
license concludedunknown
authorsKernel-Zhang
imported2026-08-15
Kernel source
ref.py51 lines
from utils import match_reference, DeterministicContext
import torch
from task import input_t, output_t
def custom_kernel(data: input_t) -> output_t:
data, output = data
output = torch.cumsum(data.to(torch.float64), dim=0).to(torch.float64)
return output
def ref_kernel(data: input_t) -> output_t:
"""
Reference implementation of inclusive prefix sum using PyTorch.
Args:
data: Input tensor to compute prefix sum on
Returns:
Tensor containing the inclusive prefix sum
"""
with DeterministicContext():
data, output = data
output = torch.cumsum(data.to(torch.float64), dim=0).to(torch.float64)
return output
def generate_input(size: int, seed: int) -> input_t:
"""
Generates random input tensor.
Returns:
Tensor to compute prefix sum on
"""
gen = torch.Generator(device="cuda")
gen.manual_seed(seed)
x = torch.randn(
size, device="cuda", dtype=torch.float32, generator=gen
).contiguous()
y = torch.empty(size, device="cuda", dtype=torch.float32).contiguous()
return x, y
# This algorithm is very sensitive to the tolerance and the error is magnified by the input size
# The tolerance is scaled by the square root of the input size
def check_implementation(data: input_t, output: output_t) -> str:
# Then get the size for scaling the tolerance
n = data[0].numel()
scale_factor = n ** 0.5 # Square root of input size
rtol = 1e-5 * scale_factor
atol = 1e-5 * scale_factor
return match_reference(data, output, reference=ref_kernel, rtol=rtol, atol=atol)
scrolls · 51 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