Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/include/ggml-metal.h # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / include / ggml-metal.h` 61 lines ยท 2141 bytes Raw Blame History 1 // Note: this description is outdated 2 // 3 // An interface allowing to compute ggml_cgraph with Metal 4 // 5 // This is a fully functional interface that extends ggml with GPU support for Apple devices. 6 // A similar interface can be created for other GPU backends (e.g. Vulkan, CUDA, etc.) 7 // 8 // How it works? 9 // 10 // As long as your program can create and evaluate a ggml_cgraph on the CPU, you can use this 11 // interface to evaluate the same graph on the GPU. Instead of using ggml_graph_compute(), you 12 // use ggml_metal_graph_compute() (or ggml_vulkan_graph_compute(), etc.) 13 // 14 // You only need to make sure that all memory buffers that you used during the graph creation 15 // are mapped to the device memory with the ggml_metal_add_buffer() function. This mapping is 16 // used during the graph evaluation to determine the arguments of the compute kernels. 17 // 18 // Synchronization between device and host memory (for example for input and output tensors) 19 // is done with the ggml_metal_set_tensor() and ggml_metal_get_tensor() functions. 20 // 21 22 #pragma once 23 24 #include "ggml.h" 25 #include "ggml-backend.h" 26 27 #include 28 #include 29 30 struct ggml_tensor; 31 struct ggml_cgraph; 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 // 38 // backend API 39 // user-code should use only these functions 40 // 41 42 // TODO: remove in the future 43 GGML_BACKEND_API ggml_backend_t ggml_backend_metal_init(void); 44 45 GGML_BACKEND_API bool ggml_backend_is_metal(ggml_backend_t backend); 46 47 GGML_BACKEND_API void ggml_backend_metal_set_abort_callback(ggml_backend_t backend, ggml_abort_callback abort_callback, void * user_data); 48 49 // helper to check if the device supports a specific family 50 // ideally, the user code should be doing these checks 51 // ref: https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf 52 GGML_BACKEND_API bool ggml_backend_metal_supports_family(ggml_backend_t backend, int family); 53 54 // capture all command buffers committed the next time `ggml_backend_graph_compute` is called 55 GGML_BACKEND_API void ggml_backend_metal_capture_next_compute(ggml_backend_t backend); 56 57 GGML_BACKEND_API ggml_backend_reg_t ggml_backend_metal_reg(void); 58 59 #ifdef __cplusplus 60 } 61 #endif