mirror of
https://github.com/ollama/ollama.git
synced 2025-03-20 14:52:59 +01:00
93 lines
3.6 KiB
C
Vendored
93 lines
3.6 KiB
C
Vendored
/**
|
|
* llama.cpp - commit ba1cb19cdd0d92e012e0f6e009e0620f854b6afd - do not edit this file
|
|
*
|
|
* MIT License
|
|
*
|
|
* Copyright (c) 2023-2024 The ggml authors
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*/
|
|
|
|
// Note: this description is outdated
|
|
//
|
|
// An interface allowing to compute ggml_cgraph with Metal
|
|
//
|
|
// This is a fully functional interface that extends ggml with GPU support for Apple devices.
|
|
// A similar interface can be created for other GPU backends (e.g. Vulkan, CUDA, etc.)
|
|
//
|
|
// How it works?
|
|
//
|
|
// As long as your program can create and evaluate a ggml_cgraph on the CPU, you can use this
|
|
// interface to evaluate the same graph on the GPU. Instead of using ggml_graph_compute(), you
|
|
// use ggml_metal_graph_compute() (or ggml_vulkan_graph_compute(), etc.)
|
|
//
|
|
// You only need to make sure that all memory buffers that you used during the graph creation
|
|
// are mapped to the device memory with the ggml_metal_add_buffer() function. This mapping is
|
|
// used during the graph evaluation to determine the arguments of the compute kernels.
|
|
//
|
|
// Synchronization between device and host memory (for example for input and output tensors)
|
|
// is done with the ggml_metal_set_tensor() and ggml_metal_get_tensor() functions.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include "ggml.h"
|
|
#include "ggml-backend.h"
|
|
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
|
|
struct ggml_tensor;
|
|
struct ggml_cgraph;
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
//
|
|
// backend API
|
|
// user-code should use only these functions
|
|
//
|
|
|
|
GGML_BACKEND_API ggml_backend_t ggml_backend_metal_init(void);
|
|
|
|
GGML_BACKEND_API bool ggml_backend_is_metal(ggml_backend_t backend);
|
|
|
|
GGML_DEPRECATED(
|
|
GGML_BACKEND_API ggml_backend_buffer_t ggml_backend_metal_buffer_from_ptr(void * data, size_t size, size_t max_size),
|
|
"obsoleted by the new device interface - https://github.com/ggerganov/llama.cpp/pull/9713");
|
|
|
|
GGML_BACKEND_API void ggml_backend_metal_set_abort_callback(ggml_backend_t backend, ggml_abort_callback abort_callback, void * user_data);
|
|
|
|
GGML_BACKEND_API ggml_backend_buffer_type_t ggml_backend_metal_buffer_type(void);
|
|
|
|
// helper to check if the device supports a specific family
|
|
// ideally, the user code should be doing these checks
|
|
// ref: https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
|
|
GGML_BACKEND_API bool ggml_backend_metal_supports_family(ggml_backend_t backend, int family);
|
|
|
|
// capture all command buffers committed the next time `ggml_backend_graph_compute` is called
|
|
GGML_BACKEND_API void ggml_backend_metal_capture_next_compute(ggml_backend_t backend);
|
|
|
|
GGML_BACKEND_API ggml_backend_reg_t ggml_backend_metal_reg(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|