MLX
Loading...
Searching...
No Matches
mlx
backend
metal
metal.h
Go to the documentation of this file.
1
// Copyright © 2023-2024 Apple Inc.
2
3
#pragma once
4
5
#include <variant>
6
7
#include "
mlx/array.h
"
8
9
namespace
mlx::core::metal
{
10
11
/* Check if the Metal backend is available. */
12
bool
is_available
();
13
14
/* Get the actively used memory in bytes.
15
*
16
* Note, this will not always match memory use reported by the system because
17
* it does not include cached memory buffers.
18
* */
19
size_t
get_active_memory
();
20
21
/* Get the peak amount of used memory in bytes.
22
*
23
* The maximum memory used recorded from the beginning of the program
24
* execution or since the last call to reset_peak_memory.
25
* */
26
size_t
get_peak_memory
();
27
28
/* Reset the peak memory to zero.
29
* */
30
void
reset_peak_memory
();
31
32
/* Get the cache size in bytes.
33
*
34
* The cache includes memory not currently used that has not been returned
35
* to the system allocator.
36
* */
37
size_t
get_cache_memory
();
38
39
/* Set the memory limit.
40
* Calls to malloc will wait on scheduled tasks if the limit is exceeded. If
41
* there are no more scheduled tasks an error will be raised if relaxed
42
* is false or memory will be allocated (including the potential for
43
* swap) if relaxed is true.
44
*
45
* The memory limit defaults to 1.5 times the maximum recommended working set
46
* size reported by the device.
47
*
48
* Returns the previous memory limit.
49
* */
50
size_t
set_memory_limit
(
size_t
limit,
bool
relaxed =
true
);
51
52
/* Set the free cache limit.
53
* If using more than the given limit, free memory will be reclaimed
54
* from the cache on the next allocation. To disable the cache,
55
* set the limit to 0.
56
*
57
* The cache limit defaults to the memory limit.
58
*
59
* Returns the previous cache limit.
60
* */
61
size_t
set_cache_limit
(
size_t
limit);
62
63
/* Clear the memory cache. */
64
void
clear_cache
();
65
67
void
start_capture
(std::string path =
""
);
68
void
stop_capture
();
69
71
std::unordered_map<std::string, std::variant<std::string, size_t>>
72
device_info
();
73
74
}
// namespace mlx::core::metal
array.h
mlx::core::metal
Definition
allocator.h:12
mlx::core::metal::is_available
bool is_available()
mlx::core::metal::clear_cache
void clear_cache()
mlx::core::metal::set_memory_limit
size_t set_memory_limit(size_t limit, bool relaxed=true)
mlx::core::metal::get_cache_memory
size_t get_cache_memory()
mlx::core::metal::get_peak_memory
size_t get_peak_memory()
mlx::core::metal::device_info
std::unordered_map< std::string, std::variant< std::string, size_t > > device_info()
Get information about the GPU and system settings.
mlx::core::metal::get_active_memory
size_t get_active_memory()
mlx::core::metal::start_capture
void start_capture(std::string path="")
Capture a GPU trace, saving it to an absolute file path
mlx::core::metal::set_cache_limit
size_t set_cache_limit(size_t limit)
mlx::core::metal::stop_capture
void stop_capture()
mlx::core::metal::reset_peak_memory
void reset_peak_memory()
Generated by
1.12.0