Skip to content
Open
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
19 changes: 16 additions & 3 deletions crates/khal/src/backend/any_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,12 @@ impl<'b, T: DeviceValue> crate::ShaderArgs<'b> for GpuBuffer<T> {
}
#[cfg(feature = "cuda")]
(GpuBuffer::Cuda(buffer), GpuDispatch::Cuda(dispatch)) => {
dispatch.set_arg(binding, buffer.device_ptr_raw(), buffer.byte_len());
// cuda-oxide `&[T]` slice ABI wants an ELEMENT count, but byte_len is bytes;
// push element count so kernel `slice.len()` is correct (off-by-size_of
// otherwise -> OOB reads, e.g. gpu_init_sort_dispatch / lbvh). Arrays,
// scalars and uniforms ignore this value, so they are unaffected.
let elem_count = buffer.byte_len() / std::mem::size_of::<T>() as u64;
dispatch.set_arg(binding, buffer.device_ptr_raw(), elem_count);
Ok(())
}
#[cfg(feature = "metal")]
Expand Down Expand Up @@ -1336,7 +1341,11 @@ impl<'b, T: DeviceValue> crate::ShaderArgs<'b> for GpuBufferSlice<'_, T> {
}
#[cfg(feature = "cuda")]
(GpuBufferSlice::Cuda(slice), GpuDispatch::Cuda(dispatch)) => {
dispatch.set_arg(binding, slice.offset_ptr(), slice.byte_len);
dispatch.set_arg(
binding,
slice.offset_ptr(),
slice.byte_len / std::mem::size_of::<T>() as u64,
);
Ok(())
}
#[cfg(feature = "metal")]
Expand Down Expand Up @@ -1373,7 +1382,11 @@ impl<'b, T: DeviceValue> crate::ShaderArgs<'b> for GpuBufferSliceMut<'_, T> {
}
#[cfg(feature = "cuda")]
(GpuBufferSliceMut::Cuda(slice), GpuDispatch::Cuda(dispatch)) => {
dispatch.set_arg(binding, slice.offset_ptr(), slice.byte_len);
dispatch.set_arg(
binding,
slice.offset_ptr(),
slice.byte_len / std::mem::size_of::<T>() as u64,
);
Ok(())
}
#[cfg(feature = "metal")]
Expand Down
Loading