Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions ggml/src/ggml-webgpu/ggml-webgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3713,11 +3713,18 @@ static void ggml_backend_webgpu_buffer_get_tensor(ggml_backend_buffer_t buffer,

size_t total_offset = ggml_webgpu_tensor_offset(tensor) + offset;

size_t final_size = size;
if (size % 4 != 0) {
size_t local_offset = total_offset % 4;
if (local_offset != 0) {
// If offset is not a multiple of 4, we need to round it down to the previous
// multiple of 4
total_offset -= local_offset;
}

size_t final_size = size + local_offset;
if (final_size % 4 != 0) {
// If size is not a multiple of 4, we need to round it up to the next
// multiple of 4
final_size = size + (4 - (size % 4));
final_size += 4 - (final_size % 4);
}

std::lock_guard<std::recursive_mutex> lock(buf_ctx->global_ctx->mutex);
Expand Down Expand Up @@ -3748,7 +3755,7 @@ static void ggml_backend_webgpu_buffer_get_tensor(ggml_backend_buffer_t buffer,
const void * mapped_range = buf_ctx->global_ctx->get_tensor_staging_buf.GetConstMappedRange(0, final_size);

// Copy the data from the mapped range to the output buffer
std::memcpy(data, mapped_range, size);
std::memcpy(data, (const void *) ((const char *) mapped_range + local_offset), size);
buf_ctx->global_ctx->get_tensor_staging_buf.Unmap();
WEBGPU_CPU_PROFILE_TOTAL_END(get_tensor, buf_ctx->global_ctx);
}
Expand Down
Loading