Skip to content

Commit

Permalink
fix: do not deref ScratchBuffer to slice
Browse files Browse the repository at this point in the history
(if I ever get that function working) automatically dereferencing the buffer to a slice is dangerous because it could be non-CPU-accessible device memory
  • Loading branch information
decahedron1 committed Mar 5, 2025
1 parent 51d9bf7 commit 743fee8
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/operator/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,12 @@ pub struct ScratchBuffer<T> {
size: usize
}

impl<T> Deref for ScratchBuffer<T> {
type Target = [T];

fn deref(&self) -> &Self::Target {
impl<T> ScratchBuffer<T> {
pub unsafe fn as_slice(&self) -> &[T] {
unsafe { slice::from_raw_parts(self.buffer.cast_const(), self.size) }
}
}
impl<T> DerefMut for ScratchBuffer<T> {
fn deref_mut(&mut self) -> &mut Self::Target {

pub unsafe fn as_mut_slice(&mut self) -> &mut [T] {
unsafe { slice::from_raw_parts_mut(self.buffer, self.size) }
}
}
Expand Down

0 comments on commit 743fee8

Please sign in to comment.