Skip to content

[REFACTOR][GEMM] Merge standalone gemv into gemm and migrate gemv tests #242

@RMLYC

Description

@RMLYC

Problem

gemv and gemm are implemented and tested as separate operator stacks, even though GEMV is a shape-specialized GEMM case.

Affected files/functions:

  • tileops/ops/gemv.py (GemvOp) duplicates operator dispatch and lifecycle already present in tileops/ops/gemm.py (GemmOp).
  • tileops/ops/__init__.py exports both GemmOp and GemvOp, keeping two public APIs for one conceptual op family.
  • tests/ops/test_gemv.py and tests/ops/test_gemm.py are split, so GEMV coverage is disconnected from GEMM regression checks.

Problematic pattern today:

# tileops/ops/__init__.py
from .gemm import GemmOp
from .gemv import GemvOp

__all__ = [
    ...,
    "GemmOp",
    "GemvOp",
    ...,
]

And separate op entrypoints:

# tileops/ops/gemv.py
class GemvOp(Op):
    ...
    self.kernel = self.kernel_map["gemv_kernel"](n, k, self.dtype, tune=tune)

# tileops/ops/gemm.py
class GemmOp(Op):
    ...
    self.kernel = self.kernel_map["gemm_kernel"](
        m, n, k, self.dtype, tune=tune, trans_a=trans_a, trans_b=trans_b
    )

Proposed Fix

Unify GEMV into GEMM as a shape-specialized path and remove standalone GEMV ops/test entry.

Implementation plan:

  1. Remove standalone GEMV op exports and entrypoints (GemvOp, and related imports).
  2. Route GEMV workloads through GemmOp by expressing GEMV as GEMM shape mapping (e.g., M=1 / equivalent shape transform in the operator wrapper).
  3. Migrate all tests/ops/test_gemv.py coverage into tests/ops/test_gemm.py (or GEMM test matrix), preserving dtype/tuning/shape scenarios from current GEMV tests.

Target end-state sketch:

# only GEMM-facing public API
from .gemm import GemmOp

# GEMV cases executed through GEMM-compatible shapes
op = GemmOp(m=1, n=n, k=k, ...)
out = op(a_2d, b)

Next Steps

A follow-up PR will implement the refactor with:

  • API cleanup (remove standalone GEMV surface).
  • Kernel dispatch unification under GEMM.
  • Test migration table (old GEMV case -> new GEMM case) included in PR description.
  • Correctness verification for migrated cases and a brief performance sanity check on representative GEMV-shaped inputs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions