MLX
 
Loading...
Searching...
No Matches
fence.h
Go to the documentation of this file.
1// Copyright © 2024 Apple Inc.
2
3#include <vector>
4
5#include "mlx/array.h"
6
7namespace mlx::core {
8
9/* A fence to be used for synchronizing work between streams.
10 *
11 * Calls to `wait` wait in the given stream until all previous calls to update
12 * are complete on their given stream.
13 *
14 * The array passed to `update` is computed and visible after the call to
15 * `wait` returns. The array passed to `wait` will not be read until all
16 * previous calls to `update` have completed.
17 *
18 * Note, calls to `update` should always from the same thread or explicitly
19 * synchronized so that they occur in sequence. Calls to `wait` can be on any
20 * thread.
21 *
22 * For the Metal back-end the fence supports slow (default) and fast mode.
23 * Fast mode requires setting the environment variable
24 * `MLX_METAL_FAST_SYNCH=1`. Fast mode also requires Metal 3.2+ (macOS 15+,
25 * iOS 18+).
26 */
27class Fence {
28 public:
29 Fence() {};
30 explicit Fence(Stream stream);
31
32 void update(Stream stream, const array& x);
33 void wait(Stream stream, const array& x);
34
35 private:
36 std::shared_ptr<void> fence_{nullptr};
37};
38
39} // namespace mlx::core
void update(Stream stream, const array &x)
Fence(Stream stream)
void wait(Stream stream, const array &x)
Fence()
Definition fence.h:29
Definition array.h:24
Definition allocator.h:7
Definition stream.h:9