Skip to content

Commit

Permalink
metal : page align the data ptr
Browse files Browse the repository at this point in the history
ggml-ci
  • Loading branch information
ggerganov committed Jan 10, 2024
1 parent 07a1b05 commit ec0859d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ggml-metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit ec0859d

Please sign in to comment.