Dispatch bf16 at run time when using the JIT#1584
Merged
Conversation
awni
commented
Nov 12, 2024
awni
commented
Nov 12, 2024
Comment on lines
+4
to
+16
| #define jit_if #if | ||
| #define jit_else #else | ||
| #define jit_endif #endif | ||
|
|
||
| jit_if (__METAL_VERSION__ >= 310) | ||
|
|
||
| #include "mlx/backend/metal/kernels/metal_3_1/bf16.h" | ||
|
|
||
| jit_else | ||
|
|
||
| #include "mlx/backend/metal/kernels/metal_3_0/bf16.h" | ||
|
|
||
| jit_endif // clang-format on |
Member
Author
There was a problem hiding this comment.
The purpose of this indirection is to keep the preprocessor dispatch directives inside the JIT source. Then they get evaluated by the metal run-time compiler.
angeloskath
approved these changes
Nov 15, 2024
Member
angeloskath
left a comment
There was a problem hiding this comment.
This is great! I left one tiny comment, I am not even sure it is an improvement. It's just that it is the only place that we do not have absolute includes and it can be confusing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This dispatches based on metal version at runtime when using the JIT.
The idea is to simplify distributing a single binary while supporting older OS yet getting newer features when available.
In general I think these are good guidelines to follow that give the most flexibility in terms of building applications with MLX:
MLX_METAL_JIT=True) so that we at least have this option.CC @davidkoski