From aebf10659681ce0729ed0d9721fb4d6961a0dde5 Mon Sep 17 00:00:00 2001 From: Guillaume Lagrange Date: Wed, 28 Aug 2024 12:51:55 -0400 Subject: [PATCH] Handle empty tensors (must bind at minimum 4 bytes on wgpu) (#86) --- crates/cubecl-wgpu/src/compute/server.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/cubecl-wgpu/src/compute/server.rs b/crates/cubecl-wgpu/src/compute/server.rs index fa8a87a6d..a5373b4fc 100644 --- a/crates/cubecl-wgpu/src/compute/server.rs +++ b/crates/cubecl-wgpu/src/compute/server.rs @@ -207,9 +207,13 @@ where .copied() .chain(self.copy_handles_used.iter().map(|x| x.0)) .collect::>(); - let memory = self.memory_management.reserve(data.len(), &total_handles); + let num_bytes = data.len(); - if let Some(len) = NonZero::new(data.len() as u64) { + // Handle empty tensors (must bind at minimum 4 bytes) + let reserve_size = core::cmp::max(num_bytes, 4); + let memory = self.memory_management.reserve(reserve_size, &total_handles); + + if let Some(len) = NonZero::new(num_bytes as u64) { let resource_handle = self.memory_management.get(memory.clone().binding()); // Dont re-use this handle for writing until the queue is flushed. All writes