Skip to content

Commit 02ef136

Browse files
Move ranges to range module
1 parent b9c1a63 commit 02ef136

5 files changed

Lines changed: 117 additions & 101 deletions

File tree

oneapi-rs/examples/kernel_launch.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
use oneapi_rs::{
1010
buffer::Buffer,
11-
kernel::{KernelArgument, KernelArgumentList, NdRange},
11+
kernel::{KernelArgument, KernelArgumentList},
1212
queue::Queue,
13+
range::NdRange,
1314
usm::{SharedAllocator, UsmAllocator},
1415
};
1516

oneapi-rs/src/kernel.rs

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
use bytemuck::Pod;
1010
use oneapi_rs_sys::{kernel_bundle::ffi, types};
1111

12-
use crate::{event::Event, queue::Queue};
13-
1412
pub struct SourceKernelBundle(pub(crate) cxx::UniquePtr<types::ffi::SourceKernelBundle>);
1513

1614
impl From<cxx::UniquePtr<types::ffi::SourceKernelBundle>> for SourceKernelBundle {
@@ -60,100 +58,3 @@ unsafe impl<T: Pod> KernelArgument for T {
6058
pub unsafe trait KernelArgumentList<const ARGC: usize> {
6159
unsafe fn as_raw_arg_list(&self) -> [&[u8]; ARGC];
6260
}
63-
64-
pub type Range<const DIMENSIONS: usize = 1> = [u64; DIMENSIONS];
65-
66-
pub struct NdRange<const DIMENSIONS: usize = 1> {
67-
pub group_size: Range<DIMENSIONS>,
68-
pub local_size: Range<DIMENSIONS>,
69-
}
70-
71-
impl<const DIMENSIONS: usize> NdRange<DIMENSIONS> {
72-
pub fn new(group_size: Range<DIMENSIONS>, local_size: Range<DIMENSIONS>) -> Self {
73-
Self {
74-
group_size,
75-
local_size,
76-
}
77-
}
78-
}
79-
80-
pub trait ValidDimension {
81-
unsafe fn launch<const ARGC: usize>(
82-
&self,
83-
queue: &mut Queue,
84-
kernel: &Kernel,
85-
args: impl KernelArgumentList<ARGC>,
86-
) -> Event;
87-
}
88-
89-
impl ValidDimension for NdRange<1> {
90-
unsafe fn launch<const ARGC: usize>(
91-
&self,
92-
queue: &mut Queue,
93-
kernel: &Kernel,
94-
args: impl KernelArgumentList<ARGC>,
95-
) -> Event {
96-
unsafe {
97-
oneapi_rs_sys::queue::ffi::launch_1d(
98-
&mut queue.0,
99-
types::ffi::Range1 {
100-
data: self.group_size,
101-
},
102-
types::ffi::Range1 {
103-
data: self.local_size,
104-
},
105-
&kernel.0,
106-
&args.as_raw_arg_list(),
107-
)
108-
}
109-
.into()
110-
}
111-
}
112-
113-
impl ValidDimension for NdRange<2> {
114-
unsafe fn launch<const ARGC: usize>(
115-
&self,
116-
queue: &mut Queue,
117-
kernel: &Kernel,
118-
args: impl KernelArgumentList<ARGC>,
119-
) -> Event {
120-
unsafe {
121-
oneapi_rs_sys::queue::ffi::launch_2d(
122-
&mut queue.0,
123-
types::ffi::Range2 {
124-
data: self.group_size,
125-
},
126-
types::ffi::Range2 {
127-
data: self.local_size,
128-
},
129-
&kernel.0,
130-
&args.as_raw_arg_list(),
131-
)
132-
}
133-
.into()
134-
}
135-
}
136-
137-
impl ValidDimension for NdRange<3> {
138-
unsafe fn launch<const ARGC: usize>(
139-
&self,
140-
queue: &mut Queue,
141-
kernel: &Kernel,
142-
args: impl KernelArgumentList<ARGC>,
143-
) -> Event {
144-
unsafe {
145-
oneapi_rs_sys::queue::ffi::launch_3d(
146-
&mut queue.0,
147-
types::ffi::Range3 {
148-
data: self.group_size,
149-
},
150-
types::ffi::Range3 {
151-
data: self.local_size,
152-
},
153-
&kernel.0,
154-
&args.as_raw_arg_list(),
155-
)
156-
}
157-
.into()
158-
}
159-
}

oneapi-rs/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ pub mod info;
1414
pub mod kernel;
1515
pub mod platform;
1616
pub mod queue;
17+
pub mod range;
1718
pub mod usm;

oneapi-rs/src/queue.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use crate::{
1414
context::Context,
1515
device::Device,
1616
event::Event,
17-
kernel::{Kernel, KernelArgumentList, NdRange, ValidDimension},
17+
kernel::{Kernel, KernelArgumentList},
18+
range::{NdRange, ValidDimension},
1819
usm::{HostAllocator, SharedAllocator, UsmAlloc, UsmAllocator},
1920
};
2021

oneapi-rs/src/range.rs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//
2+
// Copyright (C) 2026 Intel Corporation
3+
//
4+
// Under the MIT License or the Apache License v2.0.
5+
// See LICENSE-MIT and LICENSE-APACHE for license information.
6+
// SPDX-License-Identifier: MIT OR Apache-2.0
7+
//
8+
9+
use oneapi_rs_sys::types;
10+
11+
use crate::{
12+
event::Event,
13+
kernel::{Kernel, KernelArgumentList},
14+
queue::Queue,
15+
};
16+
17+
pub type Range<const DIMENSIONS: usize = 1> = [u64; DIMENSIONS];
18+
19+
pub struct NdRange<const DIMENSIONS: usize = 1> {
20+
pub group_size: Range<DIMENSIONS>,
21+
pub local_size: Range<DIMENSIONS>,
22+
}
23+
24+
impl<const DIMENSIONS: usize> NdRange<DIMENSIONS> {
25+
pub fn new(group_size: Range<DIMENSIONS>, local_size: Range<DIMENSIONS>) -> Self {
26+
Self {
27+
group_size,
28+
local_size,
29+
}
30+
}
31+
}
32+
33+
pub trait ValidDimension {
34+
unsafe fn launch<const ARGC: usize>(
35+
&self,
36+
queue: &mut Queue,
37+
kernel: &Kernel,
38+
args: impl KernelArgumentList<ARGC>,
39+
) -> Event;
40+
}
41+
42+
impl ValidDimension for NdRange<1> {
43+
unsafe fn launch<const ARGC: usize>(
44+
&self,
45+
queue: &mut Queue,
46+
kernel: &Kernel,
47+
args: impl KernelArgumentList<ARGC>,
48+
) -> Event {
49+
unsafe {
50+
oneapi_rs_sys::queue::ffi::launch_1d(
51+
&mut queue.0,
52+
types::ffi::Range1 {
53+
data: self.group_size,
54+
},
55+
types::ffi::Range1 {
56+
data: self.local_size,
57+
},
58+
&kernel.0,
59+
&args.as_raw_arg_list(),
60+
)
61+
}
62+
.into()
63+
}
64+
}
65+
66+
impl ValidDimension for NdRange<2> {
67+
unsafe fn launch<const ARGC: usize>(
68+
&self,
69+
queue: &mut Queue,
70+
kernel: &Kernel,
71+
args: impl KernelArgumentList<ARGC>,
72+
) -> Event {
73+
unsafe {
74+
oneapi_rs_sys::queue::ffi::launch_2d(
75+
&mut queue.0,
76+
types::ffi::Range2 {
77+
data: self.group_size,
78+
},
79+
types::ffi::Range2 {
80+
data: self.local_size,
81+
},
82+
&kernel.0,
83+
&args.as_raw_arg_list(),
84+
)
85+
}
86+
.into()
87+
}
88+
}
89+
90+
impl ValidDimension for NdRange<3> {
91+
unsafe fn launch<const ARGC: usize>(
92+
&self,
93+
queue: &mut Queue,
94+
kernel: &Kernel,
95+
args: impl KernelArgumentList<ARGC>,
96+
) -> Event {
97+
unsafe {
98+
oneapi_rs_sys::queue::ffi::launch_3d(
99+
&mut queue.0,
100+
types::ffi::Range3 {
101+
data: self.group_size,
102+
},
103+
types::ffi::Range3 {
104+
data: self.local_size,
105+
},
106+
&kernel.0,
107+
&args.as_raw_arg_list(),
108+
)
109+
}
110+
.into()
111+
}
112+
}

0 commit comments

Comments
 (0)