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 <variant>
6
7#include "mlx/array.h"
8
9namespace mlx::core::metal {
10
11/* Check if the Metal backend 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 * */
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 * */
27
28/* Reset the peak memory to zero.
29 * */
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 * */
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 * */
50size_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 * */
61size_t set_cache_limit(size_t limit);
62
63/* Clear the memory cache. */
65
66/* Set the wired size limit.
67 *
68 * Note, this function is only useful for macOS 15.0 or higher.
69 *
70 * The wired limit is the total size in bytes of memory that will be kept
71 * resident. The default value is ``0``.
72 *
73 * Setting a wired limit larger than system wired limit is an error.
74 *
75 * Returns the previous wired limit.
76 * */
77size_t set_wired_limit(size_t limit);
78
80void start_capture(std::string path = "");
82
84std::unordered_map<std::string, std::variant<std::string, size_t>>
86
87} // 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()