File size: 1,450 Bytes
3e697eb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | """Task kb1_004_matrix_vector_multiplication (KernelBench Level 1 #4, split=train, category=matmul, dtype=fp32, variant=base)."""
PROBLEM_ID = "kb1_004_matrix_vector_multiplication"
SOURCE_KB_ID = 4
CATEGORY = "matmul"
SPLIT = "train"
DTYPE = "fp32"
VARIANT = "base"
import torch
import torch.nn as nn
class Model(nn.Module):
"""
Simple model that performs matrix-vector multiplication (C = A * B).
"""
def __init__(self):
super(Model, self).__init__()
def forward(self, A: torch.Tensor, B: torch.Tensor) -> torch.Tensor:
"""
Performs matrix-vector multiplication.
Args:
A: Input matrix of shape (M, K).
B: Input vector of shape (K, 1).
Returns:
Output vector of shape (M, 1).
"""
return torch.matmul(A, B)
M = 256 * 8 # 2048
K = 131072 * 8 # 1048576
# --- Task shape configuration (4GB-safe laptop envelope) ---
M = 1024
K = 16384
def get_inputs():
A = torch.rand(M, K)
B = torch.rand(K, 1)
return [A, B]
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)
|