Skip to content

Conversation

@KrxGu
Copy link
Contributor

@KrxGu KrxGu commented Dec 18, 2025

Fixes #5670

This PR migrates the CPU matmul kernel implementations to use the new UnsafePointer API, removing the deprecated LegacyUnsafePointer alias.

Changes

Updated 6 files in max/kernels/src/linalg/matmul/cpu/:

  • impl.mojo - Core matmul orchestration
  • apple_accelerate.mojo - Apple Accelerate BLAS wrapper
  • default.mojo - Default CPU microkernel
  • i8mm.mojo - ARM i8mm instruction microkernel
  • neon.mojo - ARM NEON microkernel
  • vnni.mojo - x86 VNNI microkernel

Implementation Notes

The new UnsafePointer API requires explicit mutability (mut=True/False) and origin tracking. Where needed for compatibility with unmigrated code (like _Accumulator) and FFI interfaces, we use rebind[] to convert between pointer types.

Testing

  • All matmul tests pass
  • Code formatted with bazelw run //bazel/lint:format

Updated 6 CPU matmul kernel files to use the new UnsafePointer API with
explicit mutability and origin tracking. The migration uses interop with
LegacyUnsafePointer where needed for compatibility with unmigrated code
like _Accumulator and FFI interfaces.

Fixes modular#5670
Copilot AI review requested due to automatic review settings December 18, 2025 18:12
@KrxGu KrxGu requested a review from a team as a code owner December 18, 2025 18:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates CPU matmul kernel implementations from the deprecated LegacyUnsafePointer alias to the new UnsafePointer API across 6 files in the matmul CPU kernel directory.

Key changes:

  • Updated imports to use LegacyUnsafePointer explicitly instead of aliasing it as UnsafePointer
  • Updated function signatures to use the new UnsafePointer API with explicit mutability and origin tracking
  • Added rebind conversions where needed for compatibility with unmigrated dependencies and FFI interfaces

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vnni.mojo Updated import statement and rebind operations to convert new UnsafePointer to LegacyUnsafePointer for _Accumulator compatibility
neon.mojo Updated import statement and rebind operations to convert new UnsafePointer to LegacyUnsafePointer for _Accumulator compatibility
impl.mojo Updated imports and function signature for _view_buffer_as to accept new UnsafePointer API; updated variable declarations
i8mm.mojo Added both imports, updated LoadStore_i8mm function signatures to new API, but contains incorrect rebind operations at call sites
default.mojo Updated import statement and rebind operations to convert new UnsafePointer to LegacyUnsafePointer for _Accumulator compatibility
apple_accelerate.mojo Removed UnsafePointer alias import, updated type definitions and rebind operations for FFI compatibility with CBLAS functions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

The c_ptr from LayoutTensor is already UnsafePointer, so no need to
convert to LegacyUnsafePointer at the call sites. The conversion happens
inside _store_c_tile where it's actually needed for partial_simd_store.
@KrxGu
Copy link
Contributor Author

KrxGu commented Dec 18, 2025

@NathanSWard Hi! I've updated the CPU matmul kernels to use the new UnsafePointer API as discussed in #5670.

The migration keeps _Accumulator using LegacyUnsafePointer for now and uses rebind[] at the interop points. All tests are passing.

CI all green. Good To Merge!!
Let me know if you'd prefer a different approach or if there's anything that needs adjustment. Happy to make changes!

@NathanSWard NathanSWard self-assigned this Dec 18, 2025
…versions

- Use free-standing alloc() instead of LegacyUnsafePointer.alloc()
- Remove LegacyUnsafePointer conversion in i8mm _store_c_tile
- Keep **_ origin syntax for proper type inference
- Keep rebind for neon.mojo since _Accumulator uses LegacyUnsafePointer
@NathanSWard
Copy link
Contributor

!sync

@modularbot modularbot added the imported-internally Signals that a given pull request has been imported internally. label Dec 19, 2025
@modularbot
Copy link
Collaborator

✅🟣 This contribution has been merged 🟣✅

Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the main branch during the next Mojo nightly release, typically within the next 24-48 hours.

We use Copybara to merge external contributions, click here to learn more.

@modularbot modularbot added the merged-internally Indicates that this pull request has been merged internally label Dec 19, 2025
@modularbot
Copy link
Collaborator

Landed in 32ae378! Thank you for your contribution 🎉

@modularbot modularbot added the merged-externally Merged externally in public mojo repo label Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

imported-internally Signals that a given pull request has been imported internally. merged-externally Merged externally in public mojo repo merged-internally Indicates that this pull request has been merged internally

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Migrate kernels/src/linagl/matmul/cpu off of LegacyUnsafePointer.

5 participants