Skip to content
KernelIndex
Search⌘K

submission 513371

JordanNanos · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

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

submission.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-vectorsum-v2-513371?include=source"
interfacepython
Compatibility
measured onNVIDIA H100
declared hardwareNVIDIA H100
architecturessm_90
dtypesfp32

Benchmark evidence

1 measurement across 1 GPU, fastest first.

Operation / workload
Hardware
Latency
Rank
Observed
Vector sum reductionsuite of 6 cases
NVIDIA H100
83.4µs
#12 of 37
2026-03-06

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:beb3be0596a7adf84dae46f025ed8efe754c02b79830253db51b85f6da1cb054
license declaredunknown
license concludedunknown
authorsJordanNanos
imported2026-08-15

Techniques

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

num-warps = 16NUM_WARPS = 16

Kernel source

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

BLOCK_SIZE = 4096
NUM_WARPS = 16
BLOCK2 = 512  # enough for all benchmark sizes: max_blocks = ceil(52428800/4096) = 12800... need larger

# Actually for BLOCK_SIZE=4096: ceil(52428800/4096) = 12800, need BLOCK2 >= 12800 -> 16384
# For BLOCK_SIZE=16384: ceil(52428800/16384) = 3200, BLOCK2 = 4096
BLOCK_SIZE = 16384
NUM_WARPS = 32
BLOCK2 = 4096  # 2^12 >= 3200

@triton.jit
def reduction_pass1(input_ptr, partial_ptr, N, BLOCK_SIZE: tl.constexpr):
    pid = tl.program_id(0)
    offsets = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
    mask = offsets < N
    x = tl.load(input_ptr + offsets, mask=mask, other=0.0).to(tl.float64)
    tl.store(partial_ptr + pid, tl.sum(x, axis=0))


@triton.jit
def reduction_pass2(partial_ptr, output_ptr, M, BLOCK2: tl.constexpr):
    offsets = tl.arange(0, BLOCK2)
    mask = offsets < M
    x = tl.load(partial_ptr + offsets, mask=mask, other=0.0)
    tl.store(output_ptr, tl.sum(x, axis=0).to(tl.float32))


_partial_buf = None
_warmed_up = False

def _ensure_buf(n_blocks):
    global _partial_buf
    max_needed = 4096  # enough for BLOCK_SIZE=16384 up to 52M elements
    if _partial_buf is None:
        _partial_buf = torch.empty(max_needed, device='cuda', dtype=torch.float64)


def _warmup():
    global _warmed_up
    if _warmed_up:
        return
    _ensure_buf(4096)
    # Warmup pass1
    dummy_in = torch.zeros(BLOCK_SIZE, device='cuda', dtype=torch.float32)
    dummy_out = torch.zeros(1, device='cuda', dtype=torch.float32)
    reduction_pass1[(1,)](dummy_in, _partial_buf, BLOCK_SIZE, BLOCK_SIZE=BLOCK_SIZE, num_warps=NUM_WARPS)
    reduction_pass2[(1,)](_partial_buf, dummy_out, 1, BLOCK2=BLOCK2, num_warps=16)
    torch.cuda.synchronize()
    _warmed_up = True


_warmup()


def custom_kernel(data: input_t) -> output_t:
    input_tensor, output_tensor = data
    N = input_tensor.numel()
    num_blocks = triton.cdiv(N, BLOCK_SIZE)
    
    _ensure_buf(num_blocks)
    partial = _partial_buf[:num_blocks]
    
    reduction_pass1[(num_blocks,)](
        input_tensor, partial, N,
        BLOCK_SIZE=BLOCK_SIZE,
        num_warps=NUM_WARPS,
    )
    
    reduction_pass2[(1,)](
        partial, output_tensor, num_blocks,
        BLOCK2=BLOCK2,
        num_warps=16,
    )
    
    return output_tensor[0]
scrolls · 80 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 512883.

⋯ 2 unchanged lines
import triton.language as tl
from task import input_t, output_t
+ BLOCK_SIZE = 4096
+ NUM_WARPS = 16
+ BLOCK2 = 512 # enough for all benchmark sizes: max_blocks = ceil(52428800/4096) = 12800... need larger
+ # Actually for BLOCK_SIZE=4096: ceil(52428800/4096) = 12800, need BLOCK2 >= 12800 -> 16384
+ # For BLOCK_SIZE=16384: ceil(52428800/16384) = 3200, BLOCK2 = 4096
+ BLOCK_SIZE = 16384
+ NUM_WARPS = 32
+ BLOCK2 = 4096 # 2^12 >= 3200
+
@triton.jit
- def reduce_kernel(
- x_ptr,
- output_ptr,
- N,
- BLOCK_SIZE: tl.constexpr,
- NUM_BLOCKS: tl.constexpr,
- ):
+ def reduction_pass1(input_ptr, partial_ptr, N, BLOCK_SIZE: tl.constexpr):
pid = tl.program_id(0)
- acc = tl.zeros([BLOCK_SIZE], dtype=tl.float64)
- num_chunks = tl.cdiv(N, BLOCK_SIZE)
+ offsets = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
+ mask = offsets < N
+ x = tl.load(input_ptr + offsets, mask=mask, other=0.0).to(tl.float64)
+ tl.store(partial_ptr + pid, tl.sum(x, axis=0))
- chunk = pid
- while chunk < num_chunks:
- offsets = chunk * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
- mask = offsets < N
- x = tl.load(x_ptr + offsets, mask=mask, other=0.0).to(tl.float64)
- acc = acc + x
- chunk += NUM_BLOCKS
- local_sum = tl.sum(acc, axis=0).to(tl.float32)
- tl.atomic_add(output_ptr, local_sum)
+ @triton.jit
+ def reduction_pass2(partial_ptr, output_ptr, M, BLOCK2: tl.constexpr):
+ offsets = tl.arange(0, BLOCK2)
+ mask = offsets < M
+ x = tl.load(partial_ptr + offsets, mask=mask, other=0.0)
+ tl.store(output_ptr, tl.sum(x, axis=0).to(tl.float32))
- def custom_kernel(data: input_t) -> output_t:
- x, output = data
- N = x.numel()
+ _partial_buf = None
+ _warmed_up = False
- if N <= 4096:
- output[0] = x.to(torch.float64).sum().to(torch.float32)
- return output[0]
+ def _ensure_buf(n_blocks):
+ global _partial_buf
+ max_needed = 4096 # enough for BLOCK_SIZE=16384 up to 52M elements
+ if _partial_buf is None:
+ _partial_buf = torch.empty(max_needed, device='cuda', dtype=torch.float64)
- output.zero_()
- NUM_BLOCKS = 512
- BLOCK_SIZE = 4096
+ def _warmup():
+ global _warmed_up
+ if _warmed_up:
+ return
+ _ensure_buf(4096)
+ # Warmup pass1
+ dummy_in = torch.zeros(BLOCK_SIZE, device='cuda', dtype=torch.float32)
+ dummy_out = torch.zeros(1, device='cuda', dtype=torch.float32)
+ reduction_pass1[(1,)](dummy_in, _partial_buf, BLOCK_SIZE, BLOCK_SIZE=BLOCK_SIZE, num_warps=NUM_WARPS)
+ reduction_pass2[(1,)](_partial_buf, dummy_out, 1, BLOCK2=BLOCK2, num_warps=16)
+ torch.cuda.synchronize()
+ _warmed_up = True
- reduce_kernel[(NUM_BLOCKS,)](
- x, output, N,
+
+ _warmup()
+
+
+ def custom_kernel(data: input_t) -> output_t:
+ input_tensor, output_tensor = data
+ N = input_tensor.numel()
+ num_blocks = triton.cdiv(N, BLOCK_SIZE)
+
+ _ensure_buf(num_blocks)
+ partial = _partial_buf[:num_blocks]
+
+ reduction_pass1[(num_blocks,)](
+ input_tensor, partial, N,
BLOCK_SIZE=BLOCK_SIZE,
- NUM_BLOCKS=NUM_BLOCKS,
+ num_warps=NUM_WARPS,
+ )
+
+ reduction_pass2[(1,)](
+ partial, output_tensor, num_blocks,
+ BLOCK2=BLOCK2,
num_warps=16,
)
-
- return output[0]
+
+ return output_tensor[0]
No newline at end of file
scrolls · 112 diff lines total

Best evidence level for this revision: reported

JSON