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