metal : page align the data ptr

ggml-ci
This commit is contained in:
Georgi Gerganov 2024-01-10 11:02:58 +02:00
parent 07a1b052e5
commit ec0859d85d
No known key found for this signature in database
GPG key ID: 449E073F9DC10735

View file

@ -2656,6 +2656,14 @@ ggml_backend_buffer_t ggml_backend_metal_buffer_from_ptr(void * data, size_t siz
ctx->n_buffers = 0;
const size_t size_page = sysconf(_SC_PAGESIZE);
// page-align the data ptr
{
const uintptr_t offs = (uintptr_t) data % size_page;
data = (void *) ((char *) data - offs);
size += offs;
}
size_t size_aligned = size;
if ((size_aligned % size_page) != 0) {
size_aligned += (size_page - (size_aligned % size_page));