-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update to pick up mlx v0.16.0 #115
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,10 @@ let package = Package( | |
"mlx/mlx/distributed/mpi", | ||
"mlx/mlx/distributed/ops.cpp", | ||
"mlx/mlx/distributed/primitives.cpp", | ||
|
||
// the mlx-c side of distributed | ||
"include/mlx/c/distributed.cpp", | ||
"include/mlx/c/distributed_group.cpp", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now exposed on the mlx-c layer -- need to discuss how we expose this in swift and specifically how the build will work. |
||
], | ||
|
||
cSettings: [ | ||
|
Submodule mlx
updated
41 files
Submodule mlx-c
updated
43 files
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
namespace mlx::core::metal { | ||
|
||
const char* hadamard() { | ||
return R"preamble( | ||
|
||
using namespace metal; | ||
template <short R> | ||
METAL_FUNC void radix_func(thread float* x) { | ||
constexpr short logR = __builtin_ctz(R); | ||
short h = 1; | ||
#pragma clang loop unroll(full) | ||
for (short s = 0; s < logR; s++) { | ||
#pragma clang loop unroll(full) | ||
for (short i = 0; i < R / 2; i++) { | ||
short k = i & (h - 1); | ||
short j = ((i - k) << 1) + k; | ||
float a = x[j]; | ||
float b = x[j + h]; | ||
x[j] = a + b; | ||
x[j + h] = a - b; | ||
} | ||
h <<= 1; | ||
} | ||
} | ||
template <typename T, int N, int max_radix, int read_width> | ||
[[kernel]] void hadamard_n( | ||
const device T* in [[buffer(0)]], | ||
device T* out [[buffer(1)]], | ||
constant const float& scale, | ||
uint3 elem [[thread_position_in_grid]], | ||
uint3 grid [[threads_per_grid]]) { | ||
constexpr short num_threads = N / max_radix; | ||
constexpr short logN = __builtin_ctz(N); | ||
constexpr short logR = __builtin_ctz(max_radix); | ||
constexpr short num_steps = logN / logR; | ||
constexpr short logFinal = logN % logR; | ||
constexpr short final_radix = 1 << (logFinal); | ||
int batch_idx = elem.x * N; | ||
short i = elem.y; | ||
threadgroup T buf[N]; | ||
#pragma clang loop unroll(full) | ||
for (short j = 0; j < max_radix / read_width; j++) { | ||
short index = j * read_width * num_threads + i * read_width; | ||
#pragma clang loop unroll(full) | ||
for (short r = 0; r < read_width; r++) { | ||
buf[index + r] = in[batch_idx + index + r]; | ||
} | ||
} | ||
threadgroup_barrier(mem_flags::mem_threadgroup); | ||
float x[max_radix]; | ||
short h = 1; | ||
#pragma clang loop unroll(full) | ||
for (short s = 0; s < num_steps; s++) { | ||
short k = i & (h - 1); | ||
short j = ((i - k) << logR) + k; | ||
#pragma clang loop unroll(full) | ||
for (short r = 0; r < max_radix; r++) { | ||
x[r] = buf[j + h * r]; | ||
} | ||
radix_func<max_radix>(x); | ||
#pragma clang loop unroll(full) | ||
for (short r = 0; r < max_radix; r++) { | ||
buf[j + h * r] = x[r]; | ||
} | ||
h <<= logR; | ||
threadgroup_barrier(mem_flags::mem_threadgroup); | ||
} | ||
if (final_radix > 1) { | ||
#pragma clang loop unroll(full) | ||
for (int t = 0; t < max_radix / final_radix; t++) { | ||
short index = i + t * num_threads; | ||
short k = index & (h - 1); | ||
short j = ((index - k) << logFinal) + k; | ||
#pragma clang loop unroll(full) | ||
for (short r = 0; r < final_radix; r++) { | ||
x[r] = buf[j + h * r]; | ||
} | ||
radix_func<final_radix>(x); | ||
#pragma clang loop unroll(full) | ||
for (short r = 0; r < final_radix; r++) { | ||
buf[j + h * r] = x[r]; | ||
} | ||
} | ||
threadgroup_barrier(mem_flags::mem_threadgroup); | ||
} | ||
#pragma clang loop unroll(full) | ||
for (short j = 0; j < max_radix / read_width; j++) { | ||
short index = j * read_width * num_threads + i * read_width; | ||
#pragma clang loop unroll(full) | ||
for (short r = 0; r < read_width; r++) { | ||
out[batch_idx + index + r] = buf[index + r] * scale; | ||
} | ||
} | ||
} | ||
template <typename T, int N, int M, int read_width> | ||
[[kernel]] void hadamard_m( | ||
const device T* in [[buffer(0)]], | ||
device T* out [[buffer(1)]], | ||
constant const float& scale, | ||
uint3 elem [[thread_position_in_grid]], | ||
uint3 grid [[threads_per_grid]]) { | ||
int index = elem.x * grid.y + elem.y; | ||
short i = index % (N / read_width); | ||
int batch_idx = index / (N / read_width) * M * N; | ||
float x[read_width][M]; | ||
#pragma clang loop unroll(full) | ||
for (short c = 0; c < M; c++) { | ||
#pragma clang loop unroll(full) | ||
for (short r = 0; r < read_width; r++) { | ||
x[r][c] = in[batch_idx + c * N + i * read_width + r]; | ||
} | ||
} | ||
#pragma clang loop unroll(full) | ||
for (short r = 0; r < read_width; r++) { | ||
hadamard_radix_m(x[r]); | ||
} | ||
#pragma clang loop unroll(full) | ||
for (short c = 0; c < M; c++) { | ||
#pragma clang loop unroll(full) | ||
for (short r = 0; r < read_width; r++) { | ||
out[batch_idx + c * N + i * read_width + r] = x[r][c] * scale; | ||
} | ||
} | ||
} | ||
)preamble"; | ||
} | ||
|
||
} // namespace mlx::core::metal |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may have to add this back as mlx-c is for v0.15.2 but we need to build vs v0.16.0 for the Sequoia assert crashes