-
Notifications
You must be signed in to change notification settings - Fork 110
runtimes: strided (pitched) buffer I/O + centralized stride helpers #879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
416ed9f
to
ef10850
Compare
5b24b30
to
ce5fd54
Compare
a1ba972
to
db1bd8f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code in general looks extremely clean, honestly one of the best PRs I've seen in a while. The describe
function also seems extremely useful for inferring the correct variant of LinearLayout
.
General comment, but I wonder if preferred_strides
should be a device property. I haven't benchmarked the wgpu copy, but it seems like it might be slower compared to CUDA where the striding is handled by specialized GPU hardware and incurs no meaningful performance penalty. That way, a caller could decide on the allocation type based on their needs (i.e. optimized for long-lived tensors like weights, but the runtime preferred value for immediate inputs like images for a recognition model).
1f9c499
to
0132fa8
Compare
Implemented device-level preference for allocation layout:
|
@ariawisp The merge conflicts would need to be solved. |
c050144
to
e111e07
Compare
Summary - WGPU pitched I/O (rank>=2 inner-contiguous rows) and pitched allocation for Optimized. - CPU pitched read/write parity and pitched allocation for Optimized. - Centralize stride logic with runtime helpers: contiguous_strides, is_contiguous, is_inner_contiguous_rows, row_pitch_elems; remove duplicates in STD. - Backend gating: WGPU/HIP now accept inner-contiguous rows; no change to CUDA logic. - Docs: update book examples to use runtime::stride; rename PR doc. Details - WGPU: stream.rs read/write uses row_pitch_elems; server.rs create uses pitched rows when Optimized. - CPU: compute/server.rs create/read/write implement pitched behavior. - Runtime: stride.rs adds InnerContiguousRows, is_inner_contiguous_rows, row_pitch_elems. - HIP/WGPU runtime.rs can_read_tensor accepts pitched rows. - STD: remove is_contiguous/compact_strides; adjust LinearLayout to use runtime is_contiguous. runtime(stride/io): add device-level default allocation preference for rank>1 (contiguous vs pitched). WGPU/CPU default to contiguous; CUDA/HIP to pitched. Use preference in empty_tensor and to_client_tensor. � Conflicts: � crates/cubecl-convolution/src/kernels/layered/algorithm/simple.rs � crates/cubecl-cpu/src/compute/server.rs � crates/cubecl-cpu/src/runtime.rs � crates/cubecl-cuda/src/compute/server.rs � crates/cubecl-cuda/src/runtime.rs � crates/cubecl-hip/src/compute/server.rs � crates/cubecl-hip/src/runtime.rs � crates/cubecl-runtime/src/server.rs � crates/cubecl-runtime/tests/dummy/compute.rs � crates/cubecl-wgpu/src/compute/server.rs � crates/cubecl-wgpu/src/compute/stream.rs � crates/cubecl-wgpu/src/runtime.rs
e111e07
to
0b326e3
Compare
Branch has been rebased on main (cf40b4e) and confirmed CI workflow passes on my fork. |
Scope
cubecl_runtime::stride
and adopts it across CPU/HIP/CUDA/STD; removes duplicate helpers in STD.Key Changes
InnerContiguousRows
,is_inner_contiguous_rows
, androw_pitch_elems
; keepcontiguous_strides
andis_contiguous
.AllocationKind::Optimized
and rank > 1, WGPU/CPU/HIP/CUDA allocate pitched rows (row pitch aligned to the backend’s alignment);Contiguous
unchanged.can_read_tensor
accept fully contiguous or inner‑contiguous rows.write_async
/write
helpers;to_client_tensor
picks preferred allocation; size preflight returnsIoError::InvalidSize
.pitched_rows_layout(..)
andpreferred_allocation_kind(..)
for consistent planning.Limits
UnsupportedStrides
.Notes
cubecl_runtime::stride::{contiguous_strides, is_contiguous, is_inner_contiguous_rows, row_pitch_elems}
.cubecl_std::tensor::{is_contiguous, compact_strides}
were removed.IoError::InvalidSize { expected, actual }
for create‑with‑data mismatches.PR has been validated with Burn — no compilation or test errors.