MLX
Loading...
Searching...
No Matches
fence.h
Go to the documentation of this file.
1
// Copyright © 2024 Apple Inc.
2
3
#include "
mlx/backend/metal/device.h
"
4
5
namespace
mlx::core
{
6
7
/* A fence to be used for synchronizing work between the CPU and GPU
8
*
9
* Calls to `update_gpu` should be paired with calls to `wait`. This ensures
10
* that the array passed to `update_gpu` is computed and visible to the CPU
11
* after the call to `wait` returns.
12
*
13
* Calls to `update` should be paired with calls to `wait_gpu`. This ensures
14
* that the array passed to `wait_gpu` will not be read by the GPU until the CPU
15
* has called `update`.
16
*
17
* The fence supports slow (default) and fast mode. Fast mode requires setting
18
* the environment variable `MLX_METAL_FAST_SYNCH=1`. Fast mode also requires
19
* Metal 3.2+ (macOS 15+, iOS 18+).
20
*/
21
class
Fence
{
22
public
:
23
Fence
(
const
Stream
& stream);
24
25
void
update_gpu
(
const
array
& x);
26
void
wait_gpu
(
array
& x);
27
28
void
wait
();
29
void
update
();
30
31
private
:
32
Stream
stream_;
33
std::shared_ptr<void> fence_;
34
uint32_t cpu_count_{0};
35
uint32_t gpu_count_{0};
36
bool
use_fast_;
37
std::atomic_uint* cpu_value();
38
};
39
40
}
// namespace mlx::core
device.h
mlx::core::Fence::wait
void wait()
mlx::core::Fence::Fence
Fence(const Stream &stream)
mlx::core::Fence::update
void update()
mlx::core::Fence::update_gpu
void update_gpu(const array &x)
mlx::core::Fence::wait_gpu
void wait_gpu(array &x)
mlx::core::array
Definition
array.h:24
mlx::core
Definition
allocator.h:7
mlx::core::Stream
Definition
stream.h:9
mlx
backend
metal
fence.h
Generated by
1.13.2