@@ -6143,95 +6143,6 @@ static ggml_backend_buffer_type_t ggml_backend_metal_buffer_from_ptr_type(void)
6143
6143
return &ggml_backend_buffer_from_ptr_type_metal;
6144
6144
}
6145
6145
6146
- // TODO: obsoleted by ggml_backend_metal_device_buffer_from_ptr
6147
- ggml_backend_buffer_t ggml_backend_metal_buffer_from_ptr (void * data, size_t size, size_t max_size) {
6148
- struct ggml_backend_metal_buffer_context * ctx = calloc (1 , sizeof (struct ggml_backend_metal_buffer_context));
6149
-
6150
- ctx->all_data = data;
6151
- ctx->all_size = size;
6152
- ctx->owned = false ;
6153
- ctx->n_buffers = 0 ;
6154
-
6155
- const size_t size_page = sysconf (_SC_PAGESIZE);
6156
-
6157
- // page-align the data ptr
6158
- {
6159
- const uintptr_t offs = (uintptr_t ) data % size_page;
6160
- data = (void *) ((char *) data - offs);
6161
- size += offs;
6162
- }
6163
-
6164
- size_t size_aligned = size;
6165
- if ((size_aligned % size_page) != 0 ) {
6166
- size_aligned += (size_page - (size_aligned % size_page));
6167
- }
6168
-
6169
- struct ggml_backend_metal_device_context * ctx_dev = &g_ggml_ctx_dev_main;
6170
-
6171
- GGML_ASSERT (ctx_dev->mtl_device != nil );
6172
-
6173
- id <MTLDevice > device = ctx_dev->mtl_device ;
6174
-
6175
- // the buffer fits into the max buffer size allowed by the device
6176
- if (size_aligned <= device.maxBufferLength ) {
6177
- ctx->buffers [ctx->n_buffers].data = data;
6178
- ctx->buffers [ctx->n_buffers].size = size;
6179
- ctx->buffers [ctx->n_buffers].metal = nil ;
6180
-
6181
- if (size_aligned > 0 ) {
6182
- ctx->buffers [ctx->n_buffers].metal = [device newBufferWithBytesNoCopy: data length: size_aligned options: MTLResourceStorageModeShared deallocator: nil ];
6183
-
6184
- if (ctx->buffers [ctx->n_buffers].metal == nil ) {
6185
- GGML_LOG_ERROR (" %s : error: failed to allocate buffer, size = %8.2f MiB\n " , __func__, size_aligned / 1024.0 / 1024.0 );
6186
- return false ;
6187
- }
6188
- }
6189
-
6190
- ggml_backend_metal_log_allocated_size (device, size_aligned);
6191
-
6192
- ++ctx->n_buffers ;
6193
- } else {
6194
- // this overlap between the views will guarantee that the tensor with the maximum size will fully fit into
6195
- // one of the views
6196
- const size_t size_ovlp = ((max_size + size_page - 1 ) / size_page + 1 ) * size_page; // round-up 2 pages just in case
6197
- const size_t size_step = device.maxBufferLength - size_ovlp;
6198
- const size_t size_view = device.maxBufferLength ;
6199
-
6200
- for (size_t i = 0 ; i < size; i += size_step) {
6201
- const size_t size_step_aligned = (i + size_view <= size) ? size_view : (size_aligned - i);
6202
-
6203
- ctx->buffers [ctx->n_buffers].data = (void *) ((uint8_t *) data + i);
6204
- ctx->buffers [ctx->n_buffers].size = size_step_aligned;
6205
- ctx->buffers [ctx->n_buffers].metal = nil ;
6206
-
6207
- if (size_step_aligned > 0 ) {
6208
- ctx->buffers [ctx->n_buffers].metal = [device newBufferWithBytesNoCopy: (void *) ((uint8_t *) data + i) length: size_step_aligned options: MTLResourceStorageModeShared deallocator: nil ];
6209
-
6210
- if (ctx->buffers [ctx->n_buffers].metal == nil ) {
6211
- GGML_LOG_ERROR (" %s : error: failed to allocate buffer, size = %8.2f MiB\n " , __func__, size_step_aligned / 1024.0 / 1024.0 );
6212
- return false ;
6213
- }
6214
- }
6215
-
6216
- ggml_backend_metal_log_allocated_size (device, size_step_aligned);
6217
-
6218
- if (i + size_step < size) {
6219
- GGML_LOG_INFO (" \n " );
6220
- }
6221
-
6222
- ++ctx->n_buffers ;
6223
- }
6224
- }
6225
-
6226
- if (!ggml_backend_metal_buffer_rset_init (ctx, ctx_dev, device)) {
6227
- GGML_LOG_ERROR (" %s : error: failed to initialize residency set\n " , __func__);
6228
- free (ctx);
6229
- return NULL ;
6230
- }
6231
-
6232
- return ggml_backend_buffer_init (ggml_backend_metal_buffer_from_ptr_type (), ggml_backend_metal_buffer_i, ctx, size);
6233
- }
6234
-
6235
6146
// backend
6236
6147
6237
6148
static const char * ggml_backend_metal_name (ggml_backend_t backend) {
0 commit comments