Skip to content

Commit 32a1c5c

Browse files
rustfmt
1 parent 3818c67 commit 32a1c5c

12 files changed

Lines changed: 117 additions & 58 deletions

File tree

oneapi-rs-sys/build.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn get_compiler_path() -> Result<PathBuf, Error> {
6868
if let Ok(path) = std::env::var("CMPLR_ROOT") {
6969
let path = PathBuf::from(path).join("bin/icpx");
7070
if path.exists() {
71-
return Ok(path)
71+
return Ok(path);
7272
}
7373
}
7474
if let Ok(path) = which("icpx") {
@@ -81,5 +81,8 @@ fn get_compiler_path() -> Result<PathBuf, Error> {
8181
return Ok(path);
8282
}
8383

84-
Err(Error::new(std::io::ErrorKind::NotFound, "No DPC++ compiler found"))
84+
Err(Error::new(
85+
std::io::ErrorKind::NotFound,
86+
"No DPC++ compiler found",
87+
))
8588
}

oneapi-rs-sys/src/queue-sys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub mod ffi {
3333
ptr: *mut u8,
3434
value: i32,
3535
num_bytes: usize,
36-
dep_events: Vec<EventPtr>
36+
dep_events: Vec<EventPtr>,
3737
) -> UniquePtr<Event>;
3838
fn barrier(queue: &mut UniquePtr<Queue>, dep_events: Vec<EventPtr>) -> UniquePtr<Event>;
3939
fn wait(queue: &mut UniquePtr<Queue>);

oneapi-rs-sys/src/types-sys.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ pub mod ffi {
2929
// https://github.com/dtolnay/cxx/issues/774#issuecomment-808674945
3030
// We must use pointer wrapper structs instead.
3131
struct DevicePtr {
32-
ptr: UniquePtr<Device>
32+
ptr: UniquePtr<Device>,
3333
}
3434

3535
struct PlatformPtr {
36-
ptr: UniquePtr<Platform>
36+
ptr: UniquePtr<Platform>,
3737
}
38-
38+
3939
struct EventPtr {
40-
ptr: UniquePtr<Event>
40+
ptr: UniquePtr<Event>,
4141
}
4242

4343
#[derive(Debug)]
@@ -48,15 +48,15 @@ pub mod ffi {
4848
Custom,
4949
Automatic,
5050
All,
51-
Unimplemented
51+
Unimplemented,
5252
}
5353

5454
#[derive(Debug)]
5555
enum EventCommandStatus {
5656
Submitted,
5757
Running,
5858
Complete,
59-
Unknown
59+
Unknown,
6060
}
6161

6262
impl UniquePtr<Device> {}

oneapi-rs-sys/src/usm-sys.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,21 @@ pub mod ffi {
1515

1616
extern "C++" {
1717
include!("oneapi-rs-sys/include/usm.hpp");
18-
unsafe fn aligned_alloc_device(alignment: usize, num_bytes: usize, queue: &Queue) -> Result<*mut u8>;
19-
unsafe fn aligned_alloc_host(alignment: usize, num_bytes: usize, queue: &Queue) -> Result<*mut u8>;
20-
unsafe fn aligned_alloc_shared(alignment: usize, num_bytes: usize, queue: &Queue) -> Result<*mut u8>;
18+
unsafe fn aligned_alloc_device(
19+
alignment: usize,
20+
num_bytes: usize,
21+
queue: &Queue,
22+
) -> Result<*mut u8>;
23+
unsafe fn aligned_alloc_host(
24+
alignment: usize,
25+
num_bytes: usize,
26+
queue: &Queue,
27+
) -> Result<*mut u8>;
28+
unsafe fn aligned_alloc_shared(
29+
alignment: usize,
30+
num_bytes: usize,
31+
queue: &Queue,
32+
) -> Result<*mut u8>;
2133
unsafe fn free(ptr: *mut u8, queue: &Queue);
2234
}
2335
}

oneapi-rs/examples/alloc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
let mut queue = Queue::new();
1313
let mut buffer = queue.alloc_shared::<u32>(10).wait();
1414

15-
for e in buffer.iter() {
15+
for e in buffer.iter() {
1616
print!("{e} ")
1717
}
1818

@@ -22,7 +22,7 @@ fn main() {
2222
buffer[i] = i as u32;
2323
}
2424

25-
for e in buffer.iter() {
25+
for e in buffer.iter() {
2626
print!("{e} ")
2727
}
2828

oneapi-rs/examples/async.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async fn main() {
1313
let mut queue = Queue::new();
1414
let mut buffer = queue.alloc_shared::<u32>(10).await;
1515

16-
for e in buffer.iter() {
16+
for e in buffer.iter() {
1717
print!("{e} ")
1818
}
1919

@@ -23,7 +23,7 @@ async fn main() {
2323
buffer[i] = i as u32;
2424
}
2525

26-
for e in buffer.iter() {
26+
for e in buffer.iter() {
2727
print!("{e} ")
2828
}
2929

oneapi-rs/examples/sycl-ls.rs

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

9-
use oneapi_rs::platform::Platform;
109
use oneapi_rs::info;
10+
use oneapi_rs::platform::Platform;
1111

1212
fn main() {
1313
for platform in Platform::get_platforms() {
@@ -18,7 +18,9 @@ fn main() {
1818
let device_version = device.get_info::<info::device::Version>();
1919
let platform_version = platform.get_info::<info::platform::Version>();
2020

21-
println!("[{device_type:?}] {platform_name}, {device_name} {device_version} [{platform_version}]");
21+
println!(
22+
"[{device_type:?}] {platform_name}, {device_name} {device_version} [{platform_version}]"
23+
);
2224
}
2325
}
2426
}

oneapi-rs/src/buffer.rs

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

9-
use std::{alloc::{Layout, handle_alloc_error}, ops::{Deref, DerefMut}, pin::Pin, ptr::NonNull, slice, task::{Context, Poll}};
9+
use std::{
10+
alloc::{Layout, handle_alloc_error},
11+
ops::{Deref, DerefMut},
12+
pin::Pin,
13+
ptr::NonNull,
14+
slice,
15+
task::{Context, Poll},
16+
};
1017

1118
use pin_project::pin_project;
1219

13-
use crate::{event::{Event, EventFuture}, usm::UsmAlloc};
20+
use crate::{
21+
event::{Event, EventFuture},
22+
usm::UsmAlloc,
23+
};
1424

1525
/// The Buffer struct defines a shared array of one, two or three dimensions that can be used
1626
/// by the SYCL kernel. Buffers are templated on the type of their data, and the number of
@@ -38,7 +48,7 @@ impl<T, A: UsmAlloc> Buffer<T, A> {
3848
let layout = Layout::array::<T>(len).unwrap();
3949
let ptr = match allocator.allocate(layout.clone()) {
4050
Ok(ptr) => ptr,
41-
_ => handle_alloc_error(layout)
51+
_ => handle_alloc_error(layout),
4252
};
4353

4454
Self {
@@ -61,38 +71,33 @@ impl<T, A: UsmAlloc> Buffer<T, A> {
6171
impl<T, A: UsmAlloc> Deref for Buffer<T, A> {
6272
type Target = [T];
6373
fn deref(&self) -> &Self::Target {
64-
unsafe {
65-
slice::from_raw_parts(self.data.as_ptr(), self.len)
66-
}
74+
unsafe { slice::from_raw_parts(self.data.as_ptr(), self.len) }
6775
}
6876
}
6977

7078
impl<T, A: UsmAlloc> DerefMut for Buffer<T, A> {
7179
fn deref_mut(&mut self) -> &mut Self::Target {
72-
unsafe {
73-
slice::from_raw_parts_mut(self.data.as_ptr(), self.len)
74-
}
80+
unsafe { slice::from_raw_parts_mut(self.data.as_ptr(), self.len) }
7581
}
7682
}
7783

7884
impl<T, A: UsmAlloc> Drop for Buffer<T, A> {
7985
fn drop(&mut self) {
80-
unsafe { self.allocator.deallocate(self.data.cast(), self.layout); }
86+
unsafe {
87+
self.allocator.deallocate(self.data.cast(), self.layout);
88+
}
8189
}
8290
}
8391

8492
/// A [`Buffer`] whose initialization has been enqueued. You need to wait/await it.
8593
pub struct EnqueuedBuffer<T, A: UsmAlloc> {
8694
buffer: Buffer<T, A>,
87-
event: Event
95+
event: Event,
8896
}
8997

9098
impl<T, A: UsmAlloc> EnqueuedBuffer<T, A> {
9199
pub(crate) fn new(buffer: Buffer<T, A>, event: Event) -> Self {
92-
Self {
93-
buffer,
94-
event
95-
}
100+
Self { buffer, event }
96101
}
97102
}
98103

@@ -109,14 +114,16 @@ impl<T, A: UsmAlloc> EnqueuedBuffer<T, A> {
109114
pub struct BufferFuture<T, A: UsmAlloc> {
110115
buffer: Option<Buffer<T, A>>,
111116
#[pin]
112-
event_future: EventFuture
117+
event_future: EventFuture,
113118
}
114119

115120
impl<T, A: UsmAlloc> Future for BufferFuture<T, A> {
116121
type Output = Buffer<T, A>;
117122
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
118123
let this = self.project();
119-
this.event_future.poll(cx).map(|_| this.buffer.take().unwrap())
124+
this.event_future
125+
.poll(cx)
126+
.map(|_| this.buffer.take().unwrap())
120127
}
121128
}
122129

@@ -127,7 +134,7 @@ impl<T, A: UsmAlloc> IntoFuture for EnqueuedBuffer<T, A> {
127134
fn into_future(self) -> Self::IntoFuture {
128135
Self::IntoFuture {
129136
buffer: Some(self.buffer),
130-
event_future: self.event.into_future()
137+
event_future: self.event.into_future(),
131138
}
132139
}
133140
}

oneapi-rs/src/event.rs

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

9-
use std::{pin::Pin, task::{Context, Poll}};
9+
use std::{
10+
pin::Pin,
11+
task::{Context, Poll},
12+
};
1013

1114
use oneapi_rs_sys::event::ffi;
1215

1316
use pin_project::pin_project;
1417

15-
use crate::{info::{EventCommandStatus, event::{CommandExecutionStatus, EventInfo}}, queue::Queue};
18+
use crate::{
19+
info::{
20+
EventCommandStatus,
21+
event::{CommandExecutionStatus, EventInfo},
22+
},
23+
queue::Queue,
24+
};
1625

1726
pub struct Event(pub(crate) cxx::UniquePtr<ffi::Event>);
1827

@@ -51,8 +60,7 @@ impl Future for EventFuture {
5160
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
5261
if self.event.get_info::<CommandExecutionStatus>() == EventCommandStatus::Complete {
5362
Poll::Ready(())
54-
}
55-
else {
63+
} else {
5664
if self.set_callback == false {
5765
let this = self.project();
5866
*this.set_callback = true;
@@ -72,7 +80,7 @@ impl IntoFuture for Event {
7280
EventFuture {
7381
queue: Queue::new_immediate(),
7482
event: self,
75-
set_callback: false
83+
set_callback: false,
7684
}
7785
}
7886
}

oneapi-rs/src/lib.rs

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

9+
pub mod buffer;
10+
pub mod device;
11+
pub mod event;
912
pub mod info;
1013
pub mod platform;
11-
pub mod device;
1214
pub mod queue;
1315
pub mod usm;
14-
pub mod buffer;
15-
pub mod event;

0 commit comments

Comments
 (0)