kernel-train-problems / problems /kb1_005_matrix_scalar_multiplication.py
K1ta141k's picture
Upload 140 train problems and 140 Verifier-v2-verified clean teacher traces
3e697eb verified
Raw History Blame Contribute Delete
1.39 kB
"""Task kb1_005_matrix_scalar_multiplication (KernelBench Level 1 #5, split=train, category=matmul, dtype=fp32, variant=base)."""
PROBLEM_ID = "kb1_005_matrix_scalar_multiplication"
SOURCE_KB_ID = 5
CATEGORY = "matmul"
SPLIT = "train"
DTYPE = "fp32"
VARIANT = "base"
import torch
import torch.nn as nn
class Model(nn.Module):
"""
Simple model that performs a matrix-scalar multiplication (C = A * s)
"""
def __init__(self):
super(Model, self).__init__()
def forward(self, A: torch.Tensor, s: float) -> torch.Tensor:
"""
Performs matrix-scalar multiplication.
Args:
A: Input matrix of shape (M, N)
s: Scalar value
Returns:
C: Resulting matrix of shape (M, N)
"""
return A * s
M = 16384 * 4
N = 4096 * 4
# --- Task shape configuration (4GB-safe laptop envelope) ---
M = 4096
N = 4096
def get_inputs():
A = torch.rand(M, N)
s = 3.14
return [A, s]
def get_init_inputs():
return [] # No special initialization inputs needed
if __name__ == "__main__":
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
from verifier import verify_kernel, format_result
res = verify_kernel(None, __file__, self_check=True)
print(format_result(res))
sys.exit(0 if res["status"] == "PASS" else 1)