Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
535d4e4
feat(distributed): sealed all-sum (two ranks; partials cross only as …
jonathan308 Oct 14, 2026
eb576eb
fix(metal): bound sorted quantized NAX tail loads
jonathan308 Oct 17, 2026
5e9bf54
Merge current JACCL base documentation into quantized-tail repair
jonathan308 Oct 17, 2026
635cb25
docs(fork): describe sealed all-sum source ownership
jonathan308 Oct 17, 2026
652399b
style(distributed): apply configured formatting to sealed all-sum
jonathan308 Oct 17, 2026
65eb14f
test(metal): exercise contiguous sorted quantized activation tiles
jonathan308 Oct 17, 2026
f7bbf7d
Give floating-point NAX loaders a distinct Metal symbol
jonathan308 Oct 17, 2026
1fb86d3
Separate incompatible quantized Metal loader implementations
jonathan308 Oct 18, 2026
adbc349
Fix legacy quantized partial-tile bounds
jonathan308 Oct 18, 2026
9e22e19
Enforce optional Metal backing caps and preserve CPU quantized sums
jonathan308 Oct 18, 2026
4d91320
Cover page-backed small buffers in detached Metal footprints
jonathan308 Oct 18, 2026
54975cd
Bound startup waits and preserve capped Metal backing ownership
jonathan308 Oct 19, 2026
3a17911
fix(metal): retry 512-thread kernels with explicit compiler capacity
jonathan308 Oct 19, 2026
61fd8a8
jaccl: 1 MiB RDMA frames; mesh pipeline from MESH_PIPELINE
jonathan308 Oct 20, 2026
f0db8cf
fix(metal): order the fast-synch GPU wait after pending passes; paral…
jonathan308 Oct 20, 2026
872fa01
[Metal] Batch per-primitive buffer retention into one handler per com…
jonathan308 Oct 20, 2026
5711fa5
[Metal] Cache generated custom-kernel source and library name per kernel
jonathan308 Oct 20, 2026
8c6f9e7
[distributed] Stream the sealed all-sum in 256 KiB pieces over a two-…
jonathan308 Oct 20, 2026
6034a78
[Metal] Opt-in fused coherent fence update for CPU-stream inputs
jonathan308 Oct 20, 2026
a7d4079
[Metal] Opt-in fenced inputs for custom kernels
jonathan308 Oct 20, 2026
7ebf8e1
[Metal] Small flat sets for per-dispatch encoder hazard tracking
jonathan308 Oct 20, 2026
9ec3dba
[Metal] Opt-in eager commit after a cross-device fence update
jonathan308 Oct 20, 2026
a94584b
[scheduler] Optional separate budget for CPU-stream tasks
jonathan308 Oct 20, 2026
7620956
[Metal] Cheaper custom-kernel launches and graph bookkeeping
jonathan308 Oct 20, 2026
b7434f7
Revert the NAX gather_qmm simdgroup skip (#4352) on this tree
jonathan308 Oct 10, 2026
0077571
fix(metal): bound sorted quantized NAX tail loads
jonathan308 Oct 17, 2026
6beeabd
test(metal): exercise contiguous sorted quantized activation tiles
jonathan308 Oct 17, 2026
e3799f2
Give floating-point NAX loaders a distinct Metal symbol
jonathan308 Oct 17, 2026
d02ac77
Separate incompatible quantized Metal loader implementations
jonathan308 Oct 18, 2026
9266fda
Fix legacy quantized partial-tile bounds
jonathan308 Oct 18, 2026
2a0c9bb
Enforce optional Metal backing caps and preserve CPU quantized sums
jonathan308 Oct 18, 2026
99dc5f4
Cover page-backed small buffers in detached Metal footprints
jonathan308 Oct 18, 2026
23164b8
Preserve capped Metal backing ownership and validate custom launch di…
jonathan308 Oct 19, 2026
2bba342
fix(metal): retry 512-thread kernels with explicit compiler capacity
jonathan308 Oct 19, 2026
4a35574
Revert "Cover page-backed small buffers in detached Metal footprints"
jonathan308 Oct 21, 2026
6ee3062
fork.yaml: keep describing docs/src/usage/unified_memory.rst
jonathan308 Oct 21, 2026
ad59668
Merge main into work/glm53-flash-release
jonathan308 Oct 21, 2026
98b84f6
Merge the single-Mac native core (mlx#37 ad596687) into the cluster core
jonathan308 Oct 21, 2026
39296f3
Revert "Cover page-backed small buffers in detached Metal footprints"
jonathan308 Oct 21, 2026
a1d7567
fork.yaml: describe the host cuts and the streamed sealed sum
jonathan308 Oct 21, 2026
79d2ebe
Merge origin/main (the squash of mlx#37) into the cluster branch
jonathan308 Oct 22, 2026
360d11b
distributed: sealed reduce-scatter and all-gather for two ranks
jonathan308 Oct 22, 2026
69c0a0f
Merge the refreshed JACCL branch (main f78f0fa9) into the cluster col…
jonathan308 Oct 26, 2026
95938c4
Format inherited native cluster sources for pinned CI
jonathan308 Oct 26, 2026
2b5253a
test(jaccl): pass the all-sum addend in the streamed-sum exchange test
jonathan308 Oct 26, 2026
a135f49
Keep sealed collective callbacks portable outside Apple platforms
jonathan308 Oct 23, 2026
424562b
Merge the refreshed JACCL guard branch (main 6bc9de5b) into the seale…
jonathan308 Oct 27, 2026
16af5ab
Merge the fork.yaml section for the NAX split attention fix
jonathan308 Oct 27, 2026
be4b55b
Keep fenced inputs in device memory; take fenced waits first; refuse …
davidtai Oct 27, 2026
7c99353
Merge the JACCL shared failure flag fix (#33, 10d25ed6) into the seal…
davidtai Oct 27, 2026
1da2c0d
Merge the #33 clang-format fix (28e32c79) into the sealed all-sum branch
davidtai Oct 27, 2026
169802f
Apply clang-format to the fenced-input check in write_signature
davidtai Oct 27, 2026
94baa02
Make the JACCL timing tests independent of the runner's scheduling delay
davidtai Oct 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/src/usage/environment_variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ Metal
Enable the faster Metal CPU/GPU synchronization path. The default is ``0``.
This requires Metal 3.2 or later (macOS 15 or later, or iOS 18 or later).

.. envvar:: MLX_METAL_FUSED_FENCE_UPDATE

With ``MLX_METAL_FAST_SYNCH=1``, make a GPU array visible to the CPU with
one dispatch instead of two: the coherent rewrite of the array and the
fence timestamp. The default is ``0``.

.. envvar:: MLX_METAL_FENCED_INPUTS

With ``MLX_METAL_FAST_SYNCH=1``, a custom kernel made with
``metal_kernel_with_fenced_inputs`` waits itself for a fenced input that a
CPU stream makes in the same evaluation, and MLX does not encode a separate
fence wait for that input. The default is ``0``.

.. envvar:: MLX_CONV_WINOGRAD

Allow the Winograd algorithm for 3x3 ``conv2d``. The default is ``1``. Set
Expand Down
105 changes: 105 additions & 0 deletions fork.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,13 @@ def:
queues). MLX's `jaccl.cpp` registers the release hook each time it wraps a new JACCL
group.

Startup readiness: a per-group one-shot budget of 1..900000 ms replaces the
idle limit until its fixed monotonic deadline. Progress never renews it. Begin/end
refuse running calls; callers drain queued work and serialize scheduling. End
restores the original idle policy and refuses expired or closed groups. A mesh gives
the budget to each of its wires. The MLX Group API forwards to JACCL only;
unsupported backends refuse without fallback.

Advertised GID: `Connection::info()` advertises the IPv4-mapped GID of the port, but
`queue_pair_rtr` sent from GID index 1 whatever the index of that GID. The connection
now remembers the index where the advertised GID was found and sends from it;
Expand All @@ -308,6 +315,13 @@ def:
- "mlx/distributed/jaccl/lib/jaccl/mesh.cpp"
- "mlx/distributed/jaccl/lib/jaccl/mesh_impl.h"
- "mlx/distributed/jaccl/lib/jaccl/progress_guard.h"
- "mlx/distributed/jaccl/lib/jaccl/startup_wait_budget.h"
- "mlx/distributed/jaccl/lib/jaccl/group.h"
- "mlx/distributed/jaccl/lib/jaccl/mesh.h"
- "mlx/distributed/jaccl/lib/jaccl/ring.h"
- "mlx/distributed/distributed.h"
- "mlx/distributed/distributed_impl.h"
- "mlx/distributed/distributed.cpp"
- "mlx/distributed/jaccl/lib/jaccl/rdma.cpp"
- "mlx/distributed/jaccl/lib/jaccl/rdma.h"
- "mlx/distributed/jaccl/lib/jaccl/ring.cpp"
Expand All @@ -318,6 +332,97 @@ def:
- "docs/src/usage/environment_variables.rst"
- "tests/jaccl/*"
- "tests/jaccl/fake_verbs/infiniband/verbs.h"
- title: "Two-rank sealed all-sum"
description: |
The embedding program installs an authenticated frame codec for a two-rank
floating-point all-sum. The CPU communication stream seals each partial,
gathers the frames, opens the peer frame and adds in rank order. Missing
codecs and authentication failures refuse evaluation without a plaintext
fallback. The distributed primitive retains its temporary arrays until
the queued work completes. On a two-rank JACCL mesh the sum streams in 256 KiB
pieces, each with its own AES-256-GCM tag, over `MeshImpl::exchange`: a piece is
sent as soon as it is sealed and opened and added as soon as it lands. Other
groups keep the seal-gather-open path. Non-Apple builds use synchronous
piece sealing and opening without Apple dispatch or QoS APIs, preserving
the authenticated wire format and rank-ordered arithmetic. Apple keeps
its existing parallel path.
globs:
- "mlx/distributed/CMakeLists.txt"
- "mlx/distributed/primitives.h"
- "mlx/distributed/sealed.cpp"
- "mlx/distributed/sealed.h"
- "mlx/distributed/sealed_stream.h"
- "tests/distributed_sealed_stream_tests.cpp"
- title: "Fused cross-device fence update"
description: |
Opt-in (`MLX_METAL_FUSED_FENCE_UPDATE=1`, fast synch only). A GPU array that the CPU
reads in the same eval is made coherent and its fence timestamp is written in one
dispatch (`fence_update_coherent`) instead of `input_coherent` then `fence_update`.
Every word is still rewritten with system-coherent stores before a system-scope fence.
The last threadgroup to finish writes the timestamp. The fence buffer carries an
arrival count that only increases, so an unfinished earlier dispatch can delay a
timestamp but cannot release it early. Synchronization only: results do not change.
globs:
- "mlx/backend/metal/fence.cpp"
- "mlx/backend/metal/kernels/fence.metal"
- "mlx/utils.h"
- "docs/src/usage/environment_variables.rst"
- title: "Fenced custom-kernel inputs"
description: |
Opt-in (`MLX_METAL_FENCED_INPUTS=1`, fast synch only). `metal_kernel_with_fenced_inputs`
declares inputs that can come from a CPU stream in the same eval, such as a CPU-stream
all-sum. The source calls `MLX_FENCED_INPUT_WAIT(name)` before it reads such an input.
MLX then gives the CPU fence and the value of the update it waits for to the kernel
instead of a `fence_wait` dispatch, and thread 0 of each threadgroup spins on it. The
kernel starts after every pass and kernel encoded before it (`wait_for_all_pending`
and a barrier), as the `fence_wait` pass does, so the CPU work it waits for never
waits for it. MLX keeps the separate wait when the input is copied first, when another
GPU stream feeds the CPU in the same eval, and while exporting. A fenced input is
always in the device address space, never `constant`, because the GPU may load a
small constant buffer before the kernel's wait. The kernel takes its waits before any
argument check can throw, so no wait is left for a later kernel. The declaration is not
part of the exported schema. Synchronization only: results do not change.

The `fence_wait` dispatch itself makes its pass wait for every pass in flight
(`wait_for_all_pending`), and a buffer barrier orders it after the earlier kernels of
the same pass. Upstream ([ml-explore/mlx#4689](https://github.com/ml-explore/mlx/pull/4689))
gets the same order with a pass of its own for each wait (`end_encoding()` before the
dispatch, `end_encoding(true)` after it). The fork keeps the wait in the current pass,
so a wait adds no encoder boundary; `end_encoding(true)` stays available and waits as
`wait_for_all_pending` does. Fence waits use the value that the producer's update
returned, as upstream does since
[ml-explore/mlx#4552](https://github.com/ml-explore/mlx/pull/4552).
globs:
- "mlx/fence.h"
- "mlx/transforms.cpp"
- "mlx/fast.h"
- "mlx/fast_primitives.h"
- "mlx/backend/common/metal_kernel.cpp"
- "mlx/backend/metal/custom_kernel.cpp"
- "mlx/backend/metal/fence.cpp"
- "mlx/backend/metal/fenced_input.h"
- "mlx/backend/metal/device.h"
- "mlx/backend/metal/device.cpp"
- "mlx/backend/no_gpu/fence.cpp"
- "mlx/backend/cuda/fence.cpp"
- "mlx/utils.h"
- "docs/src/usage/environment_variables.rst"
- title: "Cheaper custom-kernel launches and graph bookkeeping"
description: |
Host time only: generated sources, kernel names, buffers and dispatch order do not
change. Custom-kernel primitives share the cached generated source and resolve the
pipeline once per source; repeat launches skip rebuilding the name, template string
and cache key, and bind inputs directly when none needs a contiguous copy. Graph
teardown dedups node inputs with a small vector, `eval_impl`'s per-node map is a flat
open-addressing map, and allocation reads the device's maximum buffer length once.
globs:
- "mlx/array.cpp"
- "mlx/transforms.cpp"
- "mlx/fast_primitives.h"
- "mlx/backend/common/metal_kernel.cpp"
- "mlx/backend/metal/custom_kernel.cpp"
- "mlx/backend/metal/allocator.cpp"
- "mlx/backend/cuda/custom_kernel.cpp"
- title: "Quantized tile bounds and distinct loader symbols"
description: |
Sorted gathered matrix products use the remaining reduction width for a
Expand Down
43 changes: 38 additions & 5 deletions mlx/array.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright © 2023-2024 Apple Inc.
#include <functional>
#include <unordered_map>
#include <unordered_set>

#include "mlx/array.h"
#include "mlx/ops.h"
Expand Down Expand Up @@ -283,18 +284,50 @@ array::ArrayDesc::~ArrayDesc() {

std::vector<std::shared_ptr<ArrayDesc>> for_deletion;

// The distinct inputs (and their siblings) of `ad`, one reference each.
// A graph node has a few inputs, so a vector with a linear search does
// the work of a hash map without allocating a node per input; large
// input lists also get a hash index.
auto append_deletable_inputs = [&for_deletion](ArrayDesc& ad) {
std::unordered_map<std::uintptr_t, array> input_map;
constexpr size_t linear_max = 32;
// Ids are kept beside the arrays: a moved-out array has no id.
std::vector<std::pair<std::uintptr_t, array>> distinct;
std::unordered_set<std::uintptr_t> index;
auto contains = [&](std::uintptr_t id) {
if (distinct.size() <= linear_max) {
for (auto& x : distinct) {
if (x.first == id) {
return true;
}
}
return false;
}
return index.count(id) > 0;
};
auto insert = [&](const array& x) {
if (contains(x.id())) {
return;
}
distinct.emplace_back(x.id(), x);
if (distinct.size() == linear_max + 1) {
for (auto& y : distinct) {
index.insert(y.first);
}
} else if (distinct.size() > linear_max + 1) {
index.insert(x.id());
}
};
distinct.reserve(ad.inputs.size());
for (array& a : ad.inputs) {
if (a.array_desc_) {
input_map.insert({a.id(), a});
insert(a);
for (auto& s : a.siblings()) {
input_map.insert({s.id(), s});
insert(s);
}
}
}
ad.inputs.clear();
for (auto& [_, a] : input_map) {
for (auto& [_, a] : distinct) {
bool is_deletable =
(a.array_desc_.use_count() <= a.siblings().size() + 1);
// An array with siblings is deletable only if all of its siblings
Expand All @@ -303,7 +336,7 @@ array::ArrayDesc::~ArrayDesc() {
if (!is_deletable) {
break;
}
int is_input = (input_map.find(s.id()) != input_map.end());
int is_input = contains(s.id());
is_deletable &=
s.array_desc_.use_count() <= a.siblings().size() + is_input;
}
Expand Down
Loading
Loading