metal : page align the data ptr (#4854)

This commit is contained in:
Georgi Gerganov 2024-01-10 11:50:10 +02:00 committed by GitHub
parent 07a1b052e5
commit 3cd0cbb1b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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));