Skip to content

Make DeviceSlice a newtype around [()] #44

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

Merged
merged 4 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
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
14 changes: 11 additions & 3 deletions crates/cust/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ Notable changes to this project will be documented in this file.

## Unreleased

- Add `memory::memcpy_dtoh` to allow copying from device to host.
- Add support in `memory` for pitched malloc and 2D memcpy between device and host.
- `Stream::add_callback` now internally uses `cuStreamAddCallback` again, since there are no current plans to remove it (https://stackoverflow.com/a/58173486). As a result, the function again takes a device status as a parameter and *does* execute on context error.
- Add `memory::memcpy_dtoh` to allow copying from device to host.
- `DeviceSlice` is represented as a slice again, but as `[()]` instead of `[T]`.
- Reimplemented `Index` and `IndexMut` for `DeviceSlice` and removed `DeviceSlice::index`.
- Methods that returned `DeviceSlice` by value now return references:
- `DeviceSlice::from_raw_parts`
- `DeviceSlice::from_raw_parts_mut`
- `DeviceSliceIndex::index`
- `DeviceSliceIndex::get_unchecked`
- Added `DeviceSliceIndex::index_mut` and `DeviceSliceIndex::get_unchecked_mut`.
- Add support in `memory` for pitched malloc and 2D memcpy between device and host.
- `Stream::add_callback` now internally uses `cuStreamAddCallback` again, since there are no current plans to remove it (https://stackoverflow.com/a/58173486). As a result, the function again takes a device status as a parameter and *does* execute on context error.

## 0.3.2 - 2/16/22

Expand Down
4 changes: 2 additions & 2 deletions crates/cust/src/memory/device/device_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,13 @@ impl<T: DeviceCopy> Deref for DeviceBuffer<T> {
type Target = DeviceSlice<T>;

fn deref(&self) -> &DeviceSlice<T> {
unsafe { &*(self as *const _ as *const DeviceSlice<T>) }
unsafe { DeviceSlice::from_raw_parts(self.buf, self.len) }
}
}

impl<T: DeviceCopy> DerefMut for DeviceBuffer<T> {
fn deref_mut(&mut self) -> &mut DeviceSlice<T> {
unsafe { &mut *(self as *mut _ as *mut DeviceSlice<T>) }
unsafe { DeviceSlice::from_raw_parts_mut(self.buf, self.len) }
}
}

Expand Down
Loading
Loading