Skip to content

Commit 7c58961

Browse files
Add kernel argument trait
1 parent 24b63f5 commit 7c58961

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

oneapi-rs/src/buffer.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use std::{
1515
task::{Context, Poll},
1616
};
1717

18+
use bytemuck::Pod;
1819
use pin_project::pin_project;
1920

2021
use crate::{
21-
event::{Event, EventFuture},
22-
usm::UsmAlloc,
22+
event::{Event, EventFuture}, kernel_bundle::KernelArgument, usm::UsmAlloc,
2323
};
2424

2525
/// The Buffer struct defines a shared array of one, two or three dimensions that can be used
@@ -138,3 +138,14 @@ impl<T, A: UsmAlloc> IntoFuture for EnqueuedBuffer<T, A> {
138138
}
139139
}
140140
}
141+
142+
unsafe impl<T: Pod, A: UsmAlloc> KernelArgument for Buffer<T, A> {
143+
unsafe fn as_raw_arg(&self) -> &[u8] {
144+
unsafe {
145+
slice::from_raw_parts(
146+
self.data.as_ptr() as *mut u8,
147+
std::mem::size_of::<*mut u8>()
148+
)
149+
}
150+
}
151+
}

oneapi-rs/src/kernel_bundle.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// SPDX-License-Identifier: MIT OR Apache-2.0
77
//
88

9+
use bytemuck::Pod;
910
use oneapi_rs_sys::{kernel_bundle::ffi, types};
1011

1112
pub struct SourceKernelBundle(pub(crate) cxx::UniquePtr<types::ffi::SourceKernelBundle>);
@@ -29,3 +30,13 @@ impl From<cxx::UniquePtr<types::ffi::ExecutableKernelBundle>> for ExecutableKern
2930
Self(value)
3031
}
3132
}
33+
34+
pub unsafe trait KernelArgument {
35+
unsafe fn as_raw_arg(&self) -> &[u8];
36+
}
37+
38+
unsafe impl<T: Pod> KernelArgument for T {
39+
unsafe fn as_raw_arg(&self) -> &[u8] {
40+
bytemuck::bytes_of(self)
41+
}
42+
}

0 commit comments

Comments
 (0)