Skip to content

Commit 7529b42

Browse files
Add basic Rust launch binding
1 parent 08f79ae commit 7529b42

4 files changed

Lines changed: 13 additions & 3 deletions

File tree

oneapi-rs-sys/src/queue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ std::unique_ptr<Event> barrier(std::unique_ptr<Queue> &queue,
5555

5656
void wait(std::unique_ptr<Queue> &queue) { queue->wait(); }
5757

58-
std::unique_ptr<Event> launch(std::unique_ptr<Queue> queue, Kernel const &kernel, rust::Slice<rust::slice<std::uint8_t const> const> args) {
58+
std::unique_ptr<Event> launch(std::unique_ptr<Queue> &queue, Kernel const &kernel, rust::Slice<rust::slice<std::uint8_t const> const> args) {
5959
return std::make_unique<Event>(queue->submit([&](sycl::handler &cgh) {
6060
for (std::size_t i = 0; i < args.size(); ++i)
6161
cgh.set_arg(i, syclexp::raw_kernel_arg(args[i].data(), args[i].size()));

oneapi-rs/src/buffer.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,11 @@ impl<T, A: UsmAlloc> IntoFuture for EnqueuedBuffer<T, A> {
141141

142142
unsafe impl<T: Pod, A: UsmAlloc> KernelArgument for Buffer<T, A> {
143143
unsafe fn as_raw_arg(&self) -> &[u8] {
144+
let data_ptr: *const NonNull<_> = &self.data;
145+
let cast_ptr = data_ptr as *const u8;
144146
unsafe {
145147
slice::from_raw_parts(
146-
self.data.as_ptr() as *mut u8,
148+
cast_ptr,
147149
std::mem::size_of::<*mut u8>()
148150
)
149151
}

oneapi-rs/src/kernel_bundle.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ unsafe impl<T: Pod> KernelArgument for T {
5454
bytemuck::bytes_of(self)
5555
}
5656
}
57+
58+
pub unsafe trait KernelArgumentList<const ARGC: usize> {
59+
unsafe fn as_raw_arg_list(&self) -> [&[u8]; ARGC];
60+
}

oneapi-rs/src/queue.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use bytemuck::Pod;
1010
use oneapi_rs_sys::{queue::ffi, types::ffi::EventPtr};
1111

1212
use crate::{
13-
buffer::{Buffer, EnqueuedBuffer}, context::Context, device::Device, event::Event, usm::{HostAllocator, SharedAllocator, UsmAlloc, UsmAllocator},
13+
buffer::{Buffer, EnqueuedBuffer}, context::Context, device::Device, event::Event, kernel_bundle::{Kernel, KernelArgumentList}, usm::{HostAllocator, SharedAllocator, UsmAlloc, UsmAllocator},
1414
};
1515

1616
/// The `Queue` connects a host program to a single device. Programs submit tasks to a device via the
@@ -127,6 +127,10 @@ impl Queue {
127127
pub fn wait(&mut self) {
128128
ffi::wait(&mut self.0);
129129
}
130+
131+
pub unsafe fn launch<const ARGC: usize>(&mut self, kernel: &Kernel, args: impl KernelArgumentList<ARGC>) -> Event {
132+
unsafe { ffi::launch(&mut self.0, &kernel.0, &args.as_raw_arg_list()) }.into()
133+
}
130134
}
131135

132136
impl From<&Device> for Queue {

0 commit comments

Comments
 (0)