| 352 | |
| 353 | buf->iface.get_tensor(buf, tensor, data, offset, size); |
| 354 | } |
| 355 | |
| 356 | void ggml_backend_tensor_set_2d(struct ggml_tensor * tensor, const void * data, size_t offset, size_t size, |
| 357 | size_t n_copies, size_t stride_tensor, size_t stride_data) { |
| 358 | GGML_ASSERT(tensor); |
| 359 | ggml_backend_buffer_t buf = tensor->view_src ? tensor->view_src->buffer : tensor->buffer; |
| 360 | GGML_ASSERT(buf != NULL && "tensor buffer not set"); |
| 361 | |
| 362 | if (n_copies <= 1 || buf->iface.set_tensor_2d == NULL) { |
| 363 | for (size_t i = 0; i < n_copies; i++) { |
| 364 | ggml_backend_tensor_set(tensor, (const char *) data + i*stride_data, offset + i*stride_tensor, size); |
| 365 | } |
| 366 | return; |
| 367 | } |
| 368 | if (size == 0) { |
| 369 | return; |
| 370 | } |
| 371 | |
| 372 | GGML_ASSERT(tensor->data != NULL && "tensor not allocated"); |
| 373 | GGML_ASSERT(offset + (n_copies-1)*stride_tensor + size <= ggml_nbytes(tensor) && "tensor write out of bounds"); |
| 374 | |
| 375 | buf->iface.set_tensor_2d(buf, tensor, data, offset, size, n_copies, stride_tensor, stride_data); |
| 376 | } |
| 377 |
no test coverage detected