kernel-train-problems / problems /kb1_014_matmul_for_upper_triangular_matrices.py
K1ta141k's picture
Upload 140 train problems and 140 Verifier-v2-verified clean teacher traces
3e697eb verified
Raw History Blame Contribute Delete
1.81 kB
"""Task kb1_014_matmul_for_upper_triangular_matrices (KernelBench Level 1 #14, split=train, category=matmul, dtype=fp32, variant=base)."""
PROBLEM_ID = "kb1_014_matmul_for_upper_triangular_matrices"
SOURCE_KB_ID = 14
CATEGORY = "matmul"
SPLIT = "train"
DTYPE = "fp32"
VARIANT = "base"
import torch
import torch.nn as nn
class Model(nn.Module):
"""
Simple model that performs matrix multiplication (C = A * B) for upper triangular matrices.
"""
def __init__(self):
super(Model, self).__init__()
def forward(self, A, B):
"""
Performs matrix multiplication for upper triangular matrices.
Args:
A (torch.Tensor): Upper triangular matrix of shape (N, N).
B (torch.Tensor): Upper triangular matrix of shape (N, N).
Returns:
torch.Tensor: The product of A and B, also an upper triangular matrix of shape (N, N).
"""
return torch.triu(torch.matmul(A, B))
N = 4096
# --- Task shape configuration (4GB-safe laptop envelope) ---
N = 1024
def get_inputs():
"""
Generates upper triangular matrices for testing.
Returns:
list: A list containing two upper triangular matrices of shape (N, N).
"""
A = torch.triu(torch.rand(N, N))
B = torch.triu(torch.rand(N, N))
return [A, B]
def get_init_inputs():
"""
No specific initialization inputs are needed for this model.
Returns:
list: An empty list.
"""
return []
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)