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
10namespace mlx::core::metal {
11
12/* Check if the Metal backend 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 * */
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 * */
28
29/* Reset the peak memory to zero.
30 * */
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 * */
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 * */
51size_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 * */
62size_t set_cache_limit(size_t limit);
63
64/* Clear the memory 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 * */
78size_t set_wired_limit(size_t limit);
79
81void start_capture(std::string path = "");
83
85std::unordered_map<std::string, std::variant<std::string, size_t>>
87
88} // namespace mlx::core::metal
Definition allocator.h:13
size_t set_wired_limit(size_t limit)
size_t set_memory_limit(size_t limit, bool relaxed=true)
size_t get_cache_memory()
size_t get_peak_memory()
std::unordered_map< std::string, std::variant< std::string, size_t > > device_info()
Get information about the GPU and system settings.
size_t get_active_memory()
void start_capture(std::string path="")
Capture a GPU trace, saving it to an absolute file path
size_t set_cache_limit(size_t limit)
void reset_peak_memory()