Skip to content
KernelIndex
Search⌘K

submission 68217

koshibat · 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.

triton.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-vectorsum-v2-68217?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
156.5µs
#64 of 96
2025-11-08

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:f170814773671beda3ff3e64892614aa8352c02a4b4736cb7e0669fd7d1c453e
license declaredunknown
license concludedunknown
authorskoshibat
imported2026-08-15

Kernel source

triton.py39 lines
import torch
import triton
import triton.language as tl

@triton.jit
def sum_kernel_stage1(
    input_ptr,
    partial_sums_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
    
    data = tl.load(input_ptr + offsets, mask=mask, other=0.0)
    block_sum = tl.sum(data)
    tl.store(partial_sums_ptr + pid, block_sum)

def custom_kernel(data):
    input_tensor, output_tensor = data
    n_elements = input_tensor.numel()
    
    BLOCK_SIZE = 1024
    n_blocks = triton.cdiv(n_elements, BLOCK_SIZE)
    
    partial_sums = torch.empty(n_blocks, device='cuda', dtype=torch.float32)
    
    sum_kernel_stage1[(n_blocks,)](
        input_tensor,
        partial_sums,
        n_elements,
        BLOCK_SIZE=BLOCK_SIZE,
    )
    
    # float64で精度を保つ
    result = partial_sums.to(torch.float64).sum().to(torch.float32)
    return result
scrolls · 39 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 68216.

import torch
+ import triton
+ import triton.language as tl
+ @triton.jit
+ def sum_kernel_stage1(
+ input_ptr,
+ partial_sums_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
+
+ data = tl.load(input_ptr + offsets, mask=mask, other=0.0)
+ block_sum = tl.sum(data)
+ tl.store(partial_sums_ptr + pid, block_sum)
+
def custom_kernel(data):
input_tensor, output_tensor = data
- # 単純にrefと同じことをする
- result = input_tensor.to(torch.float64).sum().to(torch.float32)
- return result # output_tensorではなく、計算結果を直接返す
No newline at end of file
+ n_elements = input_tensor.numel()
+
+ BLOCK_SIZE = 1024
+ n_blocks = triton.cdiv(n_elements, BLOCK_SIZE)
+
+ partial_sums = torch.empty(n_blocks, device='cuda', dtype=torch.float32)
+
+ sum_kernel_stage1[(n_blocks,)](
+ input_tensor,
+ partial_sums,
+ n_elements,
+ BLOCK_SIZE=BLOCK_SIZE,
+ )
+
+ # float64で精度を保つ
+ result = partial_sums.to(torch.float64).sum().to(torch.float32)
+ return result
No newline at end of file
scrolls · 44 diff lines total

Best evidence level for this revision: reported

JSON