|
6 | 6 | // SPDX-License-Identifier: MIT OR Apache-2.0 |
7 | 7 | // |
8 | 8 |
|
| 9 | +use std::marker::PhantomData; |
| 10 | + |
9 | 11 | use bytemuck::Pod; |
10 | 12 | use oneapi_rs_sys::{kernel_bundle::ffi, types}; |
11 | 13 |
|
| 14 | +use crate::{event::Event, queue::Queue}; |
| 15 | + |
12 | 16 | pub struct SourceKernelBundle(pub(crate) cxx::UniquePtr<types::ffi::SourceKernelBundle>); |
13 | 17 |
|
14 | 18 | impl From<cxx::UniquePtr<types::ffi::SourceKernelBundle>> for SourceKernelBundle { |
@@ -58,3 +62,80 @@ unsafe impl<T: Pod> KernelArgument for T { |
58 | 62 | pub unsafe trait KernelArgumentList<const ARGC: usize> { |
59 | 63 | unsafe fn as_raw_arg_list(&self) -> [&[u8]; ARGC]; |
60 | 64 | } |
| 65 | + |
| 66 | + |
| 67 | +pub type Range<const DIMENSIONS: usize = 1> = [u64; DIMENSIONS]; |
| 68 | + |
| 69 | +pub struct NdRange<const DIMENSIONS: usize = 1> { |
| 70 | + pub group_size: Range<DIMENSIONS>, |
| 71 | + pub local_size: Range<DIMENSIONS> |
| 72 | +} |
| 73 | + |
| 74 | +impl<const DIMENSIONS: usize> NdRange<DIMENSIONS> { |
| 75 | + pub fn new(group_size: Range<DIMENSIONS>, local_size: Range<DIMENSIONS>) -> Self { |
| 76 | + Self { |
| 77 | + group_size, |
| 78 | + local_size |
| 79 | + } |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +pub trait ValidDimension { |
| 84 | + unsafe fn launch<const ARGC: usize>(&self, queue: &mut Queue, kernel: &Kernel, args: impl KernelArgumentList<ARGC>) -> Event; |
| 85 | +} |
| 86 | + |
| 87 | +impl ValidDimension for NdRange<1> { |
| 88 | + unsafe fn launch<const ARGC: usize>(&self, queue: &mut Queue, kernel: &Kernel, args: impl KernelArgumentList<ARGC>) -> Event { |
| 89 | + unsafe { |
| 90 | + oneapi_rs_sys::queue::ffi::launch_1d( |
| 91 | + &mut queue.0, |
| 92 | + self.group_size[0], |
| 93 | + self.local_size[0], |
| 94 | + &kernel.0, |
| 95 | + &args.as_raw_arg_list() |
| 96 | + ) |
| 97 | + }.into() |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +impl ValidDimension for NdRange<2> { |
| 102 | + unsafe fn launch<const ARGC: usize>(&self, queue: &mut Queue, kernel: &Kernel, args: impl KernelArgumentList<ARGC>) -> Event { |
| 103 | + unsafe { |
| 104 | + oneapi_rs_sys::queue::ffi::launch_2d( |
| 105 | + &mut queue.0, |
| 106 | + types::ffi::Range2 { |
| 107 | + x: self.group_size[0], |
| 108 | + y: self.group_size[1], |
| 109 | + }, |
| 110 | + types::ffi::Range2 { |
| 111 | + x: self.local_size[0], |
| 112 | + y: self.local_size[1], |
| 113 | + }, |
| 114 | + &kernel.0, |
| 115 | + &args.as_raw_arg_list() |
| 116 | + ) |
| 117 | + }.into() |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +impl ValidDimension for NdRange<3> { |
| 122 | + unsafe fn launch<const ARGC: usize>(&self, queue: &mut Queue, kernel: &Kernel, args: impl KernelArgumentList<ARGC>) -> Event { |
| 123 | + unsafe { |
| 124 | + oneapi_rs_sys::queue::ffi::launch_3d( |
| 125 | + &mut queue.0, |
| 126 | + types::ffi::Range3 { |
| 127 | + x: self.group_size[0], |
| 128 | + y: self.group_size[1], |
| 129 | + z: self.group_size[2], |
| 130 | + }, |
| 131 | + types::ffi::Range3 { |
| 132 | + x: self.local_size[0], |
| 133 | + y: self.local_size[1], |
| 134 | + z: self.local_size[2], |
| 135 | + }, |
| 136 | + &kernel.0, |
| 137 | + &args.as_raw_arg_list() |
| 138 | + ) |
| 139 | + }.into() |
| 140 | + } |
| 141 | +} |
0 commit comments