Skip to content

[Refactor][GEMM] Unify GEMV into GemmOp#245

Open
RMLYC wants to merge 4 commits intotile-ai:mainfrom
RMLYC:refactor-gemm-unify-gemv-op-242
Open

[Refactor][GEMM] Unify GEMV into GemmOp#245
RMLYC wants to merge 4 commits intotile-ai:mainfrom
RMLYC:refactor-gemm-unify-gemv-op-242

Conversation

@RMLYC
Copy link
Collaborator

@RMLYC RMLYC commented Feb 28, 2026

Related to #242

Summary

  • merge GEMV logic into GemmOp and remove standalone gemv op entry
  • update GEMV kernel invocation paths used by GEMM/GEMV-shaped workloads
  • consolidate tests into tests/ops/test_gemm.py and delete redundant tests/ops/test_gemv.py

Test plan

  • pre-commit run --all-files
  • python tests/ops/test_gemm.py (13 passed)

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request streamlines the codebase by integrating General Matrix-Vector (GEMV) operations directly into the General Matrix-Matrix (GEMM) operator. This change eliminates a redundant standalone GEMV operator and its associated tests, consolidating functionality under a single, more versatile interface. The GemmOp is now capable of identifying and optimizing GEMV-shaped inputs by dispatching to a specialized kernel, leading to a more efficient and unified matrix multiplication framework.

Highlights

  • GEMV Unification: The General Matrix-Vector (GEMV) operation logic has been merged into the existing General Matrix-Matrix (GEMM) operator, removing the standalone GemvOp.
  • Kernel Dispatch: The GemmOp now intelligently detects GEMV-shaped inputs and dispatches to a specialized GemvKernel for optimized execution.
  • Test Consolidation: Dedicated GEMV tests have been removed, and new GEMV-like test cases were added to the test_gemm.py suite, with adjusted numerical precision checks for bfloat16.
  • Kernel Optimization: The _gemv_main kernel was refactored to improve efficiency through updated thread binding, shared memory utilization, and precise output handling.
  • Autotuning Enhancements: Autotuning configurations for GEMV kernels were expanded to cover a broader range of block_n values, aiming for better performance.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • tests/ops/test_gemm.py
    • Added new test parameters to GemmFixture.PARAMS to cover GEMV-like cases for float16 and bfloat16.
    • Adjusted atol and rtol values for float16 and bfloat16 in test_gemm for more accurate numerical checks.
  • tests/ops/test_gemv.py
    • Removed the entire test file dedicated to GemvOp.
  • tileops/kernels/gemv/gemv.py
    • Modified thread binding order and introduced row calculation in _gemv_main.
    • Implemented shared memory loading for a_local to optimize a tensor access.
    • Updated b_local loading with conditional checks for boundary conditions and zero casting.
    • Added T.sync_threads() calls for proper thread synchronization.
    • Modified the final output write to c buffer with conditional tk == 0 and row < n check.
    • Updated default_config for sm_version=90 by changing block_n and reduce_threads values.
    • Expanded autotune_configs to include a wider range of block_n values and additional configurations.
  • tileops/ops/init.py
    • Removed the import statement for GemvOp.
    • Removed GemvOp from the __all__ export list.
  • tileops/ops/gemm.py
    • Imported GemvKernel and get_sm_version.
    • Added trans_a and trans_b attributes to the __init__ method.
    • Implemented logic in __init__ to conditionally initialize self.kernel with GemvKernel for GEMV-shaped inputs.
    • Modified the forward method to reshape inputs and outputs appropriately when using the GemvKernel.
  • tileops/ops/gemv.py
    • Removed the entire file defining the standalone GemvOp.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request successfully unifies GEMV functionality into the GemmOp, removing the separate GemvOp. The changes correctly identify GEMV-shaped workloads within GemmOp and dispatch them to an optimized GemvKernel. The tests have also been consolidated appropriately. My review includes a few suggestions to improve the implementation's clarity and maintainability, including a refactoring of the kernel dispatch logic in GemmOp and a simplification of the test code.

@RMLYC RMLYC marked this pull request as draft February 28, 2026 08:37
@RMLYC RMLYC force-pushed the refactor-gemm-unify-gemv-op-242 branch from d95ddde to dda370f Compare February 28, 2026 09:46
@RMLYC RMLYC added the refactor Code restructuring without behavior change label Feb 28, 2026
@RMLYC RMLYC requested a review from superAngGao February 28, 2026 10:00
@RMLYC RMLYC marked this pull request as ready for review February 28, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code restructuring without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant