Skip to content

Add Metal support#525

Merged
jw1912 merged 40 commits into
jw1912:mainfrom
tcheran-chess:metal-cleanup
Jun 15, 2026
Merged

Add Metal support#525
jw1912 merged 40 commits into
jw1912:mainfrom
tcheran-chess:metal-cleanup

Conversation

@jgilchrist

@jgilchrist jgilchrist commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Used Blightwidow's attempt as a starting point, but have:

  • Ported to objc2 and replaced the ad-hoc bindings to MPS with objc2-metal-performance-shaders
  • Refactored significantly to try and move as much metal-specific logic into metal.rs or Dialect among other cleanups and simplifications

I've left the commit history untouched (since the objc2 port which I posted about in the linked issue) to give an idea of the changes, but will squash if things look ok.

There's a much larger potential refactoring (splitting all the Metal stuff into bullet-metal and the common code into bullet-compiler as @jw1912 said in #500) which I haven't tackled, but let me know if you feel like this is a pre-requisite for merging.

Fixes #500

Comment thread crates/bullet_lib/src/nn.rs Outdated
this is more similar to what is already done for IR transform steps
among other things

@jw1912 jw1912 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Looks good! I have some nitpicks - mostly about imports

Comment thread crates/gpu/src/runtime/bindings.rs Outdated
Comment thread crates/trainer/Cargo.toml Outdated
Comment thread crates/trainer/src/optimiser/clip.rs Outdated
Comment thread crates/trainer/src/optimiser/adam.rs Outdated
Comment thread crates/gpu/src/function.rs Outdated
Comment thread crates/gpu/src/runtime/cuda.rs Outdated
Comment thread crates/gpu/src/pointwise/ir.rs Outdated
Comment thread crates/gpu/src/pointwise/write.rs Outdated
Comment thread crates/trainer/src/optimiser/ranger.rs Outdated
Comment thread crates/gpu/src/function.rs
Comment thread crates/gpu/src/pointwise/write.rs
@jgilchrist

Copy link
Copy Markdown
Contributor Author

Do you want me to try adding a CI job for this? I don't think the macOS runners have Metal, but we still might be able to run check

@jw1912

jw1912 commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Do you want me to try adding a CI job for this? I don't think the macOS runners have Metal, but we still might be able to run check

Maybe in a separate PR?

@jw1912

jw1912 commented Jun 15, 2026

Copy link
Copy Markdown
Owner

If you fix that clippy error by using i instead of buf_index, the only thing left would be to add some basic directions to https://github.com/jw1912/bullet/blob/main/docs/2-getting-started.md

these were left over from the previous change's ad-hoc bindings and aren't necessary
@jgilchrist

Copy link
Copy Markdown
Contributor Author

If you fix that clippy error by using i instead of buf_index

Fixed that and the 'too many args' one, those functions were still there because of the original change having those ad-hoc bindings and could be inlined.

the only thing left would be to add some basic directions to https://github.com/jw1912/bullet/blob/main/docs/2-getting-started.md

There's not a lot to do as everything should 'just work' after enabling the feature. But I've added that step anyway (plus it's the only place the available backends are listed I believe.

@jw1912

jw1912 commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Nice! And just to confirm if you run cargo test --workspace --features metal all the tests pass?

@jgilchrist

Copy link
Copy Markdown
Contributor Author

@jw1912 Yep, all green!

@jw1912 jw1912 merged commit 3b73417 into jw1912:main Jun 15, 2026
3 checks passed
@jgilchrist jgilchrist deleted the metal-cleanup branch June 15, 2026 14:51
jgilchrist added a commit to tcheran-chess/tcheran that referenced this pull request Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metal Support

2 participants