diff options
author | kiltyj <kiltyj@gmail.com> | 2023-06-05 13:24:04 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-05 23:24:04 +0300 |
commit | 9d0693bce38013364b1042568d9083353bfff48f (patch) | |
tree | 8311cb168defca62e9b2689571c4b641ea7654b9 /ggml.c | |
parent | efe05076323f5c6bafece109e21cce046f5e4b07 (diff) |
metal : use shared buffers between CPU and GPU (#1696)
* Use MTLDevice.newBufferWithBytesNoCopy to share buffers between CPU and GPU
* Page-align buffers used by Metal
* Remove trailing whitespace
* Only import unistd.h for Metal builds
* metal : remove unnecessary copies
---------
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Diffstat (limited to 'ggml.c')
-rw-r--r-- | ggml.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -22,6 +22,10 @@ #include <float.h> #include <limits.h> +#ifdef GGML_USE_METAL +#include <unistd.h> +#endif + // if C99 - static_assert is noop // ref: https://stackoverflow.com/a/53923785/4039976 #ifndef static_assert @@ -122,7 +126,11 @@ typedef void* thread_ret_t; #else inline static void* ggml_aligned_malloc(size_t size) { void* aligned_memory = NULL; +#ifdef GGML_USE_METAL + int result = posix_memalign(&aligned_memory, getpagesize(), size); +#else int result = posix_memalign(&aligned_memory, GGML_MEM_ALIGN, size); +#endif if (result != 0) { // Handle allocation failure return NULL; |