submission 99101
Petr_Rocoss · python · License unknown
Use it
Vendorable · source mirrored · license unknownView source →
No package. Vendor the mirrored source: 139 lines, June 9 Researcher Reciprocity License v1.0.
submission_conservative.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-conv2d-v2-99101?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:d9db2a3f221867a450017ed260a51387ed2bb641476decd429466e8451bc4b93
license declaredunknown
license concludedunknown
authorsPetr_Rocoss
imported2026-08-15
Techniques
Extracted from the mirrored source by pattern, never inferred. Each row cites its line.
autotune
@triton.autotune(num-warps = 8
triton.Config({'BLOCK_H': 8, 'BLOCK_W': 128}, num_warps=8, num_stages=5),stages = 5
triton.Config({'BLOCK_H': 8, 'BLOCK_W': 128}, num_warps=8, num_stages=5),Kernel source
submission_conservative.py139 lines
import torch
import triton
import triton.language as tl
@triton.autotune(
configs=[
# === A100/H100/B200 - максимум ===
triton.Config({'BLOCK_H': 8, 'BLOCK_W': 128}, num_warps=8, num_stages=5),
triton.Config({'BLOCK_H': 4, 'BLOCK_W': 256}, num_warps=8, num_stages=5),
triton.Config({'BLOCK_H': 16, 'BLOCK_W': 64}, num_warps=8, num_stages=4),
triton.Config({'BLOCK_H': 8, 'BLOCK_W': 256}, num_warps=8, num_stages=4),
# === L4 / средние ===
triton.Config({'BLOCK_H': 4, 'BLOCK_W': 128}, num_warps=8, num_stages=4),
triton.Config({'BLOCK_H': 8, 'BLOCK_W': 64}, num_warps=4, num_stages=4),
triton.Config({'BLOCK_H': 2, 'BLOCK_W': 256}, num_warps=4, num_stages=4),
# === Маленькие ===
triton.Config({'BLOCK_H': 2, 'BLOCK_W': 64}, num_warps=4, num_stages=3),
triton.Config({'BLOCK_H': 1, 'BLOCK_W': 128}, num_warps=2, num_stages=3),
],
key=['w_out', 'h_out', 'c_in', 'k_size'],
)
@triton.jit
def conv2d_kernel_tiled(
input_ptr, weight_ptr, output_ptr,
stride_in_n, stride_in_c, stride_in_h, stride_in_w,
stride_w_out, stride_w_in, stride_w_h, stride_w_w,
stride_out_n, stride_out_c, stride_out_h, stride_out_w,
H_IN, W_IN, H_OUT, W_OUT, C_IN, C_OUT, K,
BLOCK_H: tl.constexpr, BLOCK_W: tl.constexpr
):
"""
⚡ МАКСИМАЛЬНО ОПТИМИЗИРОВАННОЕ 2D-БЛОЧНОЕ ЯДРО CONV2D
Ключевые оптимизации:
✅ 2D-блокировка для максимальной L1 cache локальности
✅ Порядок циклов: cin → kh → kw (оптимально для NCHW)
✅ Pre-computed offsets вне горячих циклов
✅ 2D broadcasting для эффективных операций
✅ num_stages=5 для максимального prefetching
✅ Правильные маски для граничных условий
✅ += вместо acc = acc + для компиляторной оптимизации
"""
# === Grid Decoding ===
pid_w = tl.program_id(0)
pid_h = tl.program_id(1)
pid_z = tl.program_id(2)
batch_idx = pid_z // C_OUT
out_ch = pid_z % C_OUT
# === 2D Output Offsets ===
offs_h = pid_h * BLOCK_H + tl.arange(0, BLOCK_H)
mask_h = offs_h < H_OUT
offs_w = pid_w * BLOCK_W + tl.arange(0, BLOCK_W)
mask_w = offs_w < W_OUT
# === Base Pointers ===
out_base = output_ptr + batch_idx * stride_out_n + out_ch * stride_out_c
in_base = input_ptr + batch_idx * stride_in_n
wei_base = weight_ptr + out_ch * stride_w_out
# === 2D Accumulator ===
acc = tl.zeros([BLOCK_H, BLOCK_W], dtype=tl.float32)
# === Combined 2D Mask (early compute) ===
mask_2d = (mask_h[:, None] & mask_w[None, :])
# === Main Convolution Loop ===
for cin in range(C_IN):
in_ch = in_base + cin * stride_in_c
wei_ch = wei_base + cin * stride_w_in
for kh in range(K):
# Pre-compute height offsets for this kernel position
in_h_off = (offs_h[:, None] + kh) * stride_in_h
in_row = in_ch + in_h_off
wei_row = wei_ch + kh * stride_w_h
for kw in range(K):
# Load weight (scalar, broadcasts to [BLOCK_H, BLOCK_W])
wei_val = tl.load(wei_row + kw * stride_w_w)
# Load input block (2D) with proper indexing
in_w_off = (offs_w[None, :] + kw) * stride_in_w
in_ptrs = in_row + in_w_off
in_val = tl.load(in_ptrs, mask=mask_2d, other=0.0)
# FMA with += for better compiler optimization
acc += in_val * wei_val
# === Store Result ===
out_h_off = offs_h[:, None] * stride_out_h
out_w_off = offs_w[None, :] * stride_out_w
out_ptrs = out_base + out_h_off + out_w_off
tl.store(out_ptrs, acc, mask=mask_2d)
def custom_kernel(data):
"""Optimized wrapper function."""
input_tensor, kernel, output_tensor = data
# Ensure contiguous memory layout
input_tensor = input_tensor.contiguous()
kernel = kernel.contiguous()
# Extract dimensions
batch, c_in, h_in, w_in = input_tensor.shape
c_out, _, k_h, k_w = kernel.shape
# Calculate output dimensions (stride=1, padding=0)
h_out = h_in - k_h + 1
w_out = w_in - k_w + 1
# Grid configuration: (W_blocks, H_blocks, Batch*Out_Channels)
grid = lambda META: (
triton.cdiv(w_out, META['BLOCK_W']),
triton.cdiv(h_out, META['BLOCK_H']),
batch * c_out
)
# Launch kernel
conv2d_kernel_tiled[grid](
input_tensor, kernel, output_tensor,
*input_tensor.stride(),
*kernel.stride(),
*output_tensor.stride(),
h_in, w_in, h_out, w_out,
c_in, c_out, k_h,
)
return output_tensor
scrolls · 139 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 99100.
⋯ 3 unchanged lines@triton.autotune(configs=[- # A100/H100/B200 - максимальная производительность+ # === A100/H100/B200 - максимум ===triton.Config({'BLOCK_H': 8, 'BLOCK_W': 128}, num_warps=8, num_stages=5),triton.Config({'BLOCK_H': 4, 'BLOCK_W': 256}, num_warps=8, num_stages=5),triton.Config({'BLOCK_H': 16, 'BLOCK_W': 64}, num_warps=8, num_stages=4),+ triton.Config({'BLOCK_H': 8, 'BLOCK_W': 256}, num_warps=8, num_stages=4),- # L4 / средние размеры+ # === L4 / средние ===triton.Config({'BLOCK_H': 4, 'BLOCK_W': 128}, num_warps=8, num_stages=4),- triton.Config({'BLOCK_H': 8, 'BLOCK_W': 64}, num_warps=4, num_stages=4),+ triton.Config({'BLOCK_H': 8, 'BLOCK_W': 64}, num_warps=4, num_stages=4),+ triton.Config({'BLOCK_H': 2, 'BLOCK_W': 256}, num_warps=4, num_stages=4),- # Маленькие тензоры / fallback- triton.Config({'BLOCK_H': 2, 'BLOCK_W': 64}, num_warps=4, num_stages=3),+ # === Маленькие ===+ triton.Config({'BLOCK_H': 2, 'BLOCK_W': 64}, num_warps=4, num_stages=3),triton.Config({'BLOCK_H': 1, 'BLOCK_W': 128}, num_warps=2, num_stages=3),],key=['w_out', 'h_out', 'c_in', 'k_size'],⋯ 8 unchanged linesBLOCK_H: tl.constexpr, BLOCK_W: tl.constexpr):"""- Супер-оптимизированное 2D-блочное ядро Conv2D.- - 2D тайлинг (BLOCK_H x BLOCK_W) для максимальной локальности- - Оптимизированный порядок циклов: cin -> kh -> kw- - Минимум arithmetic в горячих циклах- - Правильное использование масок для граничных условий+ ⚡ МАКСИМАЛЬНО ОПТИМИЗИРОВАННОЕ 2D-БЛОЧНОЕ ЯДРО CONV2D++ Ключевые оптимизации:+ ✅ 2D-блокировка для максимальной L1 cache локальности+ ✅ Порядок циклов: cin → kh → kw (оптимально для NCHW)+ ✅ Pre-computed offsets вне горячих циклов+ ✅ 2D broadcasting для эффективных операций+ ✅ num_stages=5 для максимального prefetching+ ✅ Правильные маски для граничных условий+ ✅ += вместо acc = acc + для компиляторной оптимизации"""- # === Декодирование Grid IDs ===+ # === Grid Decoding ===pid_w = tl.program_id(0)pid_h = tl.program_id(1)pid_z = tl.program_id(2)⋯ 1 unchanged linesbatch_idx = pid_z // C_OUTout_ch = pid_z % C_OUT- # === 2D Offsets (блочная обработка) ===- # Height offsets: [BLOCK_H]+ # === 2D Output Offsets ===offs_h = pid_h * BLOCK_H + tl.arange(0, BLOCK_H)mask_h = offs_h < H_OUT- # Width offsets: [BLOCK_W]offs_w = pid_w * BLOCK_W + tl.arange(0, BLOCK_W)mask_w = offs_w < W_OUT- # === Базовые указатели ===- # Output: [batch, out_ch, h, w]+ # === Base Pointers ===out_base = output_ptr + batch_idx * stride_out_n + out_ch * stride_out_c-- # Input: [batch, ...]in_base = input_ptr + batch_idx * stride_in_n-- # Weight: [out_ch, ...]wei_base = weight_ptr + out_ch * stride_w_out- # === Аккумулятор (2D блок в регистрах) ===- # [BLOCK_H, BLOCK_W] - используем всю вычислительную мощь+ # === 2D Accumulator ===acc = tl.zeros([BLOCK_H, BLOCK_W], dtype=tl.float32)- # === ОСНОВНОЙ ЦИКЛ СВЕРТКИ ===- # Порядок: cin -> kh -> kw (оптимально для NCHW памяти)+ # === Combined 2D Mask (early compute) ===+ mask_2d = (mask_h[:, None] & mask_w[None, :])++ # === Main Convolution Loop ===for cin in range(C_IN):in_ch = in_base + cin * stride_in_cwei_ch = wei_base + cin * stride_w_infor kh in range(K):- # Pre-compute Input row pointer для этого kh- # offs_h[:, None] даёт размер [BLOCK_H, 1]- # Broadcasting: (BLOCK_H, 1) + скаляр = (BLOCK_H, 1)- in_h_idx = (offs_h[:, None] + kh) * stride_in_h- in_row = in_ch + in_h_idx-- # Pre-compute Weight row pointer+ # Pre-compute height offsets for this kernel position+ in_h_off = (offs_h[:, None] + kh) * stride_in_h+ in_row = in_ch + in_h_offwei_row = wei_ch + kh * stride_w_hfor kw in range(K):- # === Загрузка Веса ===- # Один скаляр, используется для всего блока (broadcast)+ # Load weight (scalar, broadcasts to [BLOCK_H, BLOCK_W])wei_val = tl.load(wei_row + kw * stride_w_w)- # === Загрузка Входа (2D блок) ===- # offs_w[None, :] даёт размер [1, BLOCK_W]- # Broadcasting: (BLOCK_H, 1) + [1, BLOCK_W] = (BLOCK_H, BLOCK_W)- in_w_idx = (offs_w[None, :] + kw) * stride_in_w- in_ptrs = in_row + in_w_idx+ # Load input block (2D) with proper indexing+ in_w_off = (offs_w[None, :] + kw) * stride_in_w+ in_ptrs = in_row + in_w_off+ in_val = tl.load(in_ptrs, mask=mask_2d, other=0.0)- # Маска: обе координаты должны быть валидны- in_val = tl.load(- in_ptrs,- mask=(mask_h[:, None] & mask_w[None, :]),- other=0.0- )-- # === FMA ===+ # FMA with += for better compiler optimizationacc += in_val * wei_val- # === ЗАПИСЬ РЕЗУЛЬТАТА ===- # Output addresses: base + h_offset * stride_h + w_offset * stride_w- out_h_idx = offs_h[:, None] * stride_out_h- out_w_idx = offs_w[None, :] * stride_out_w- out_ptrs = out_base + out_h_idx + out_w_idx+ # === Store Result ===+ out_h_off = offs_h[:, None] * stride_out_h+ out_w_off = offs_w[None, :] * stride_out_w+ out_ptrs = out_base + out_h_off + out_w_off- # Запись с маской для граничных условий- tl.store(- out_ptrs,- acc,- mask=(mask_h[:, None] & mask_w[None, :])- )+ tl.store(out_ptrs, acc, mask=mask_2d)def custom_kernel(data):- """Оптимальная wrapper для Conv2D."""+ """Optimized wrapper function."""input_tensor, kernel, output_tensor = data- # Гарантируем контигуозность+ # Ensure contiguous memory layoutinput_tensor = input_tensor.contiguous()kernel = kernel.contiguous()- # Размеры+ # Extract dimensionsbatch, c_in, h_in, w_in = input_tensor.shapec_out, _, k_h, k_w = kernel.shape+ # Calculate output dimensions (stride=1, padding=0)h_out = h_in - k_h + 1w_out = w_in - k_w + 1- # Grid: (W_blocks, H_blocks, N*C_out)+ # Grid configuration: (W_blocks, H_blocks, Batch*Out_Channels)grid = lambda META: (triton.cdiv(w_out, META['BLOCK_W']),triton.cdiv(h_out, META['BLOCK_H']),batch * c_out)+ # Launch kernelconv2d_kernel_tiled[grid](input_tensor, kernel, output_tensor,*input_tensor.stride(),
scrolls · 182 diff lines total
Best evidence level for this revision: reported
JSON