submission 66559
Saulane · python · License unknown
Use it
Vendorable · source mirrored · license unknownView source →
No package. Vendor the mirrored source: 71 lines, June 9 Researcher Reciprocity License v1.0.
submission5.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-vectoradd-v2-66559?include=source"interfacepython
Compatibility
measured onNVIDIA H100
declared hardwareNVIDIA H100
architecturessm_90
dtypesfp16
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:f764df7a31adaac5f1913e100b6498a23c6e9b44e48e69898c52d463e57d39d3
license declaredunknown
license concludedunknown
authorsSaulane
imported2026-08-15
Techniques
Extracted from the mirrored source by pattern, never inferred. Each row cites its line.
autotune
@triton.autotune(num-warps = 4
triton.Config({'BLOCK_SIZE': 256, 'VEC': 8}, num_warps=4, num_stages=2),stages = 2
triton.Config({'BLOCK_SIZE': 256, 'VEC': 8}, num_warps=4, num_stages=2),Kernel source
submission5.py71 lines
import torch
import triton
import triton.language as tl
from task import input_t, output_t
DEVICE = triton.runtime.driver.active.get_active_torch_device()
# ---- Autotuned, vectorized kernel ------------------------------------------
@triton.autotune(
configs=[
# Good starting points across Ampere/Ada/Hopper; feel free to extend.
triton.Config({'BLOCK_SIZE': 256, 'VEC': 8}, num_warps=4, num_stages=2),
triton.Config({'BLOCK_SIZE': 512, 'VEC': 8}, num_warps=8, num_stages=2),
triton.Config({'BLOCK_SIZE': 1024, 'VEC': 4}, num_warps=8, num_stages=2),
triton.Config({'BLOCK_SIZE': 2048, 'VEC': 2}, num_warps=8, num_stages=2),
triton.Config({'BLOCK_SIZE': 4096, 'VEC': 1}, num_warps=8, num_stages=2),
],
key=['n_elements'], # autotune choice depends mainly on problem size
)
@triton.jit
def add_kernel(x_ptr, y_ptr, out_ptr, n_elements,
BLOCK_SIZE: tl.constexpr, VEC: tl.constexpr):
pid = tl.program_id(axis=0)
# vectorized block start; each program handles BLOCK_SIZE * VEC elements
block_start = pid * BLOCK_SIZE * VEC
# 2D tile: [BLOCK_SIZE, VEC] so compiler emits wider loads/stores
offs = block_start + tl.arange(0, BLOCK_SIZE)[:, None] * VEC + tl.arange(0, VEC)[None, :]
mask = offs < n_elements
# Optional: tell compiler about alignment/contiguity (safe for contiguous tensors)
tl.multiple_of(block_start, VEC)
x = tl.load(x_ptr + offs, mask=mask, other=0.0)
y = tl.load(y_ptr + offs, mask=mask, other=0.0)
z = x + y
tl.store(out_ptr + offs, z, mask=mask)
def add_into(x: torch.Tensor, y: torch.Tensor, out: torch.Tensor):
# Preconditions
assert x.device == DEVICE and y.device == DEVICE and out.device == DEVICE
assert x.is_contiguous() and y.is_contiguous() and out.is_contiguous()
assert x.shape == y.shape == out.shape
# (Your task already restricts to fp16, which is great for bandwidth.)
assert x.dtype == torch.float16 and y.dtype == torch.float16 and out.dtype == torch.float16
n_elements = out.numel()
# Each program covers BLOCK_SIZE * VEC elements (meta values chosen by autotune).
grid = lambda meta: (triton.cdiv(n_elements, meta['BLOCK_SIZE'] * meta['VEC']),)
add_kernel[grid](x, y, out, n_elements) # meta-params picked by autotune
def custom_kernel(data: input_t) -> output_t:
"""
Custom implementation of vector addition using Triton (optimized).
Args:
inputs: triple (A, B, output)
Returns:
output (element-wise sum)
"""
A, B, output = data
assert A.is_cuda and B.is_cuda and output.is_cuda, "Tensors must be on GPU"
assert A.shape == B.shape == output.shape, "All shapes must match"
assert A.dtype == torch.float16 and B.dtype == torch.float16 and output.dtype == torch.float16, \
"All tensors must be float16"
add_into(A, B, output)
return output
scrolls · 71 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