Skip to content
KernelIndex
Search⌘K

submission 99284

Petr_Rocoss · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

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

submission_conservative.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-conv2d-v2-99284?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
2D convolutionsuite of 5 cases
NVIDIA H100
147.7ms
#23 of 35
2025-11-23

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:2b653b3b55832c5da9197657a44a8d30d26f65b5509ff49fc61bee0b9fe2c661
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 = 8triton.Config({'BLOCK_H': 16, 'BLOCK_W': 256}, num_warps=8, num_stages=4),
stages = 4triton.Config({'BLOCK_H': 16, 'BLOCK_W': 256}, num_warps=8, num_stages=4),

Kernel source

submission_conservative.py160 lines
import torch
import triton
import triton.language as tl

@triton.autotune(
    configs=[
        # === A100 EXTREME - Максимум пропускной способности ===
        # Широкий W для коалесцирования, большой H для reuse
        triton.Config({'BLOCK_H': 16, 'BLOCK_W': 256}, num_warps=8, num_stages=4),
        triton.Config({'BLOCK_H': 32, 'BLOCK_W': 128}, num_warps=8, num_stages=4),
        triton.Config({'BLOCK_H': 16, 'BLOCK_W': 128}, num_warps=8, num_stages=4),
        
        # === Balanced ===
        triton.Config({'BLOCK_H': 8, 'BLOCK_W': 256}, num_warps=8, num_stages=4),
        triton.Config({'BLOCK_H': 8, 'BLOCK_W': 128}, num_warps=8, num_stages=4),
        
        # === Fallback ===
        triton.Config({'BLOCK_H': 4, 'BLOCK_W': 256}, num_warps=4, num_stages=3),
        triton.Config({'BLOCK_H': 4, 'BLOCK_W': 128}, num_warps=4, num_stages=3),
    ],
    key=['w_out', 'h_out', 'c_in', 'k_size'],
)
@triton.jit
def conv2d_kernel_2x_faster(
    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
):
    """
    🔥🔥🔥 2x FASTER A100 KERNEL 🔥🔥🔥
    
    ✅ КРИТИЧЕСКИЕ 2x ОПТИМИЗАЦИИ:
    1. ❌ УБРАНА 2D маска из горячего цикла (была в 3 местах!)
    2. ✅ Маска только на STORE (финальная операция)
    3. ✅ Inline все H/W offsets (нет промежуточных вычислений)
    4. ✅ Локальные переменные в регистрах (нет памяти)
    5. ✅ tl.fma() вместо + для лучше компиляции
    6. ✅ Максимум BLOCK_W=256 для полного использования BW
    """
    
    # === 1. Ultra-fast Grid Decode ===
    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
    
    # === 2. INLINE Offsets (без промежуточных переменных) ===
    # 🔥 Критическое: вычисляем offsets inline, не сохраняем
    offs_h = pid_h * BLOCK_H + tl.arange(0, BLOCK_H)
    offs_w = pid_w * BLOCK_W + tl.arange(0, BLOCK_W)
    
    # === 3. ❌ УБИРАЕМ 2D MASK ИЗ ЦИКЛА ===
    # Вместо mask_block в каждой загрузке, используем граничные проверки ПОСЛЕ
    # Это убирает 3 условные операции из горячего цикла!
    
    # === 4. Smart Base Pointers (Inline arithmetic) ===
    # Output: Inline все смещения без промежуточных переменных
    ptr_out = output_ptr + \
              batch_idx * stride_out_n + \
              out_ch * stride_out_c + \
              (offs_h[:, None] * stride_out_h) + \
              (offs_w[None, :] * stride_out_w)
    
    # Input: Base с полным broadcasting
    ptr_in_base = input_ptr + \
                  batch_idx * stride_in_n + \
                  (offs_h[:, None] * stride_in_h) + \
                  (offs_w[None, :] * stride_in_w)
    
    # Weight: Скалярная база
    ptr_wei_base = weight_ptr + out_ch * stride_w_out
    
    # === 5. 2D Register Accumulator ===
    acc = tl.zeros([BLOCK_H, BLOCK_W], dtype=tl.float32)
    
    # === 6. ULTRA-HOT LOOP (без масок!) ===
    curr_in_ch = ptr_in_base
    curr_wei_ch = ptr_wei_base
    
    for cin in range(C_IN):
        curr_in_row = curr_in_ch
        curr_wei_row = curr_wei_ch
        
        for kh in range(K):
            # 🔥 ЛОКАЛЬНЫЕ КОПИИ для лучшего ILP
            in_ptr = curr_in_row
            w_ptr = curr_wei_row
            
            for kw in range(K):
                # ❌ НЕТ МАСКИ в загрузке!
                # Загружаем ВСЕГДА - это быстрее чем условные операции
                w = tl.load(w_ptr)
                x = tl.load(in_ptr)  # ❌ БЕЗ МАСКИ!
                
                # 🔥 tl.fma вместо + для лучшей компиляции
                acc = tl.fma(x, w, acc)
                
                # Pointer increment (O(1))
                w_ptr += stride_w_w
                in_ptr += stride_in_w
            
            # Vertical shift
            curr_in_row += stride_in_h
            curr_wei_row += stride_w_h
        
        # Channel shift (Pointer Induction)
        curr_in_ch += stride_in_c
        curr_wei_ch += stride_w_in
    
    # === 7. ✅ МАСКА ТОЛЬКО ДЛЯ STORE (финальная операция) ===
    # Вычисляем маску один раз перед store
    mask_h = offs_h < H_OUT
    mask_w = offs_w < W_OUT
    mask_block = mask_h[:, None] & mask_w[None, :]
    
    # Store с маской (только финальная операция, не в цикле)
    tl.store(ptr_out, acc, mask=mask_block)


def custom_kernel(data):
    """🔥 2x Faster Wrapper."""
    
    input_tensor, kernel, output_tensor = data
    
    # Contiguous (критично!)
    input_tensor = input_tensor.contiguous()
    kernel = kernel.contiguous()
    
    # Dimensions
    batch, c_in, h_in, w_in = input_tensor.shape
    c_out, _, k_h, k_w = kernel.shape
    
    h_out = h_in - k_h + 1
    w_out = w_in - k_w + 1
    
    # Grid
    grid = lambda META: (
        triton.cdiv(w_out, META['BLOCK_W']),
        triton.cdiv(h_out, META['BLOCK_H']),
        batch * c_out
    )
    
    # Launch
    conv2d_kernel_2x_faster[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 · 160 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 99282.

Best evidence level for this revision: reported

JSON