Skip to content
KernelIndex
Search⌘K

submission 69352

Saint of the Famished · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

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

submission_triton.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-vectorsum-v2-69352?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
Vector sum reductionsuite of 6 cases
NVIDIA A100
141.0µs
#14 of 96
2025-11-10

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:094832b781e58afd87fcf3eb270c1f611dcb9786fa26199bd84675fb7fa48b6c
license declaredunknown
license concludedunknown
authorsSaint of the Famished
imported2026-08-15

Techniques

Extracted from the mirrored source by pattern, never inferred. Each row cites its line.

autotune@triton.autotune(
num-warps = 4triton.Config(kwargs={"BLOCK_SIZE": 2**7}, num_warps=4),

Kernel source

submission_triton.py64 lines
#!POPCORN leaderboard vectorsum_v2

import subprocess

import torch
import triton
import triton.language as tl
from task import input_t, output_t

GPU_TO_N_ELEMENTS = {"NVIDIA A100-SXM4-80GB": 52428800}
GPU_NAME = torch.cuda.get_device_name(0)


@triton.autotune(
    configs=[
        triton.Config(kwargs={"BLOCK_SIZE": 2**7}, num_warps=4),
        triton.Config(kwargs={"BLOCK_SIZE": 2**8}, num_warps=8),
        triton.Config(kwargs={"BLOCK_SIZE": 2**9}, num_warps=8),
        triton.Config(kwargs={"BLOCK_SIZE": 2**10}, num_warps=8),
        triton.Config(kwargs={"BLOCK_SIZE": 2**11}, num_warps=8),
        triton.Config(kwargs={"BLOCK_SIZE": 2**12}, num_warps=8),
    ],
    key=["n_elements"],
)
@triton.jit
def sum_kernel(x_ptr, output_ptr, n_elements, BLOCK_SIZE: tl.constexpr):
    pid = tl.program_id(0)
    block_start = pid * BLOCK_SIZE
    offsets = block_start + tl.arange(0, BLOCK_SIZE)
    mask = offsets < n_elements
    x = tl.load(x_ptr + offsets, mask=mask, other=0.0, eviction_policy="evict_first")
    block_sum = tl.sum(x, axis=0)
    tl.store(x_ptr + pid, block_sum)


def tune(n_elements: int = GPU_TO_N_ELEMENTS.get(GPU_NAME, 1024)):
    data = torch.randn(n_elements, device="cuda", dtype=torch.float32).contiguous()
    offset = (torch.rand(1, device="cuda") * 200 - 100).item()
    scale = (torch.rand(1, device="cuda") * 9.9 + 0.1).item()
    input_tensor = (data * scale + offset).contiguous()
    output_tensor = torch.empty(1, device="cuda", dtype=torch.float32)

    grid = lambda meta: (triton.cdiv(n_elements, meta["BLOCK_SIZE"]),)
    sum_kernel[grid](input_tensor, output_tensor, n_elements)


tune()


def custom_kernel(data: input_t) -> output_t:
    input, output = data
    n_elements = input.numel()
    if n_elements != GPU_TO_N_ELEMENTS.get(GPU_NAME, 1024):
        print(f"[WARN]: n_elements of {n_elements} is not tuned for.")
        tune(n_elements)

    grid = lambda meta: (triton.cdiv(n_elements, meta["BLOCK_SIZE"]),)
    sum_kernel[grid](input, output, n_elements)

    block_size = sum_kernel.best_config.all_kwargs()["BLOCK_SIZE"]
    n_blocks = triton.cdiv(n_elements, block_size)

    return input[:n_blocks].sum()
scrolls · 64 lines total

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

Changes from previous submission

Against this author's previous submission submission 66970.

#!POPCORN leaderboard vectorsum_v2
+ import subprocess
+
import torch
import triton
import triton.language as tl
from task import input_t, output_t
+ GPU_TO_N_ELEMENTS = {"NVIDIA A100-SXM4-80GB": 52428800}
+ GPU_NAME = torch.cuda.get_device_name(0)
+
+ @triton.autotune(
+ configs=[
+ triton.Config(kwargs={"BLOCK_SIZE": 2**7}, num_warps=4),
+ triton.Config(kwargs={"BLOCK_SIZE": 2**8}, num_warps=8),
+ triton.Config(kwargs={"BLOCK_SIZE": 2**9}, num_warps=8),
+ triton.Config(kwargs={"BLOCK_SIZE": 2**10}, num_warps=8),
+ triton.Config(kwargs={"BLOCK_SIZE": 2**11}, num_warps=8),
+ triton.Config(kwargs={"BLOCK_SIZE": 2**12}, num_warps=8),
+ ],
+ key=["n_elements"],
+ )
@triton.jit
- def sum_kernel(
- x_ptr,
- n_elements,
- BLOCK_SIZE: tl.constexpr,
- ):
+ def sum_kernel(x_ptr, output_ptr, n_elements, BLOCK_SIZE: tl.constexpr):
pid = tl.program_id(0)
block_start = pid * BLOCK_SIZE
offsets = block_start + tl.arange(0, BLOCK_SIZE)
⋯ 3 unchanged lines
tl.store(x_ptr + pid, block_sum)
+ def tune(n_elements: int = GPU_TO_N_ELEMENTS.get(GPU_NAME, 1024)):
+ data = torch.randn(n_elements, device="cuda", dtype=torch.float32).contiguous()
+ offset = (torch.rand(1, device="cuda") * 200 - 100).item()
+ scale = (torch.rand(1, device="cuda") * 9.9 + 0.1).item()
+ input_tensor = (data * scale + offset).contiguous()
+ output_tensor = torch.empty(1, device="cuda", dtype=torch.float32)
+
+ grid = lambda meta: (triton.cdiv(n_elements, meta["BLOCK_SIZE"]),)
+ sum_kernel[grid](input_tensor, output_tensor, n_elements)
+
+
+ tune()
+
+
def custom_kernel(data: input_t) -> output_t:
input, output = data
n_elements = input.numel()
+ if n_elements != GPU_TO_N_ELEMENTS.get(GPU_NAME, 1024):
+ print(f"[WARN]: n_elements of {n_elements} is not tuned for.")
+ tune(n_elements)
- if n_elements >= 10_000_000:
- BLOCK_SIZE = 8192
- elif n_elements >= 1_000_000:
- BLOCK_SIZE = 4096
- elif n_elements >= 100_000:
- BLOCK_SIZE = 2048
- elif n_elements >= 10_000:
- BLOCK_SIZE = 1024
- else:
- BLOCK_SIZE = 512
-
grid = lambda meta: (triton.cdiv(n_elements, meta["BLOCK_SIZE"]),)
+ sum_kernel[grid](input, output, n_elements)
- n_blocks = triton.cdiv(n_elements, BLOCK_SIZE)
- grid = (n_blocks,)
+ block_size = sum_kernel.best_config.all_kwargs()["BLOCK_SIZE"]
+ n_blocks = triton.cdiv(n_elements, block_size)
- sum_kernel[grid](input, n_elements, BLOCK_SIZE=BLOCK_SIZE)
-
return input[:n_blocks].sum()
scrolls · 81 diff lines total

Best evidence level for this revision: reported

JSON