Skip to content

Commit 3d80022

Browse files
Make DeviceSlice a newtype around [()] (#44)
Co-authored-by: DrMeepster <[email protected]> Co-authored-by: Christian Legnitto <[email protected]>
1 parent 3880313 commit 3d80022

File tree

3 files changed

+187
-127
lines changed

3 files changed

+187
-127
lines changed

crates/cust/CHANGELOG.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ Notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7-
- Add `memory::memcpy_dtoh` to allow copying from device to host.
8-
- Add support in `memory` for pitched malloc and 2D memcpy between device and host.
9-
- `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.
7+
- Add `memory::memcpy_dtoh` to allow copying from device to host.
8+
- `DeviceSlice` is represented as a slice again, but as `[()]` instead of `[T]`.
9+
- Reimplemented `Index` and `IndexMut` for `DeviceSlice` and removed `DeviceSlice::index`.
10+
- Methods that returned `DeviceSlice` by value now return references:
11+
- `DeviceSlice::from_raw_parts`
12+
- `DeviceSlice::from_raw_parts_mut`
13+
- `DeviceSliceIndex::index`
14+
- `DeviceSliceIndex::get_unchecked`
15+
- Added `DeviceSliceIndex::index_mut` and `DeviceSliceIndex::get_unchecked_mut`.
16+
- Add support in `memory` for pitched malloc and 2D memcpy between device and host.
17+
- `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.
1018

1119
## 0.3.2 - 2/16/22
1220

crates/cust/src/memory/device/device_buffer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,13 @@ impl<T: DeviceCopy> Deref for DeviceBuffer<T> {
406406
type Target = DeviceSlice<T>;
407407

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

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

0 commit comments

Comments
 (0)