Skip to content

Commit ccb3c7e

Browse files
authored
chore: update dependencies (#90)
Increases MSRV to 1.81 (due to the `home` crate)
1 parent c079907 commit ccb3c7e

File tree

6 files changed

+36
-42
lines changed

6 files changed

+36
-42
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77
homepage = "https://github.com/filecoin-project/rust-gpu-tools"
88
license = "MIT/Apache-2.0"
99
repository = "https://github.com/filecoin-project/rust-gpu-tools"
10-
rust-version = "1.70.0"
10+
rust-version = "1.81.0"
1111

1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313
[features]
@@ -18,11 +18,11 @@ cuda = ["rustacuda"]
1818
[dependencies]
1919
home = "0.5"
2020
sha2 = "0.10"
21-
thiserror = "1.0.10"
22-
log = "0.4.11"
21+
thiserror = "2.0.12"
22+
log = "0.4.26"
2323
hex = "0.4.3"
2424

25-
opencl3 = { version = "0.9.3", default-features = false, features = ["CL_VERSION_1_2"], optional = true }
25+
opencl3 = { version = "0.11.0", default-features = false, features = ["CL_VERSION_1_2"], optional = true }
2626
rustacuda = { package = "fil-rustacuda", version = "0.1.3", optional = true }
2727
once_cell = "1.8.0"
2828
temp-env = "0.3.3"

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.70.0
1+
1.81.0

src/cuda/mod.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//!
77
//! 1. RustaCUDA doesn't expose a higher level function to launch a kernel on the default stream
88
//! 2. There was a bug, when the default stream was used implicitly via RustaCUDA's synchronuous
9-
//! copy methods. To prevent such kind of bugs, be explicit which stream is used.
9+
//! copy methods. To prevent such kind of bugs, be explicit which stream is used.
1010
1111
pub(crate) mod utils;
1212

@@ -133,13 +133,11 @@ impl Program {
133133
pub fn from_binary(device: &Device, filename: &CStr) -> GPUResult<Program> {
134134
debug!("Creating CUDA program from binary file.");
135135
rustacuda::context::CurrentContext::set_current(&device.context)?;
136-
let module = rustacuda::module::Module::load_from_file(filename).map_err(|err| {
136+
let module = rustacuda::module::Module::load_from_file(filename).inspect_err(|_err| {
137137
Self::pop_context();
138-
err
139138
})?;
140-
let stream = Stream::new(StreamFlags::NON_BLOCKING, None).map_err(|err| {
139+
let stream = Stream::new(StreamFlags::NON_BLOCKING, None).inspect_err(|_err| {
141140
Self::pop_context();
142-
err
143141
})?;
144142
let prog = Program {
145143
module,
@@ -155,13 +153,11 @@ impl Program {
155153
pub fn from_bytes(device: &Device, bytes: &[u8]) -> GPUResult<Program> {
156154
debug!("Creating CUDA program from bytes.");
157155
rustacuda::context::CurrentContext::set_current(&device.context)?;
158-
let module = rustacuda::module::Module::load_from_bytes(bytes).map_err(|err| {
156+
let module = rustacuda::module::Module::load_from_bytes(bytes).inspect_err(|_err| {
159157
Self::pop_context();
160-
err
161158
})?;
162-
let stream = Stream::new(StreamFlags::NON_BLOCKING, None).map_err(|err| {
159+
let stream = Stream::new(StreamFlags::NON_BLOCKING, None).inspect_err(|_err| {
163160
Self::pop_context();
164-
err
165161
})?;
166162
let prog = Program {
167163
module,
@@ -203,9 +199,7 @@ impl Program {
203199
let bytes_len = mem::size_of_val(slice);
204200

205201
// Transmuting types is safe as long a sizes match.
206-
let bytes = unsafe {
207-
std::slice::from_raw_parts(slice.as_ptr() as *const T as *const u8, bytes_len)
208-
};
202+
let bytes = unsafe { std::slice::from_raw_parts(slice.as_ptr() as *const u8, bytes_len) };
209203

210204
// It is only unsafe as long as the buffer isn't initialized, but that's what we do next.
211205
let mut buffer = unsafe { DeviceBuffer::<u8>::uninitialized(bytes_len)? };
@@ -245,10 +239,7 @@ impl Program {
245239

246240
// Transmuting types is safe as long a sizes match.
247241
let bytes = unsafe {
248-
std::slice::from_raw_parts(
249-
data.as_ptr() as *const T as *const u8,
250-
mem::size_of_val(data),
251-
)
242+
std::slice::from_raw_parts(data.as_ptr() as *const u8, mem::size_of_val(data))
252243
};
253244

254245
// It is safe as we synchronize the stream after the call.
@@ -264,10 +255,7 @@ impl Program {
264255

265256
// Transmuting types is safe as long a sizes match.
266257
let bytes = unsafe {
267-
std::slice::from_raw_parts_mut(
268-
data.as_mut_ptr() as *mut T as *mut u8,
269-
mem::size_of_val(data),
270-
)
258+
std::slice::from_raw_parts_mut(data.as_mut_ptr() as *mut u8, mem::size_of_val(data))
271259
};
272260

273261
// It is safe as we synchronize the stream after the call.

src/cuda/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::error::{GPUError, GPUResult};
1111
// are never used directly, they are only accessed through [`cuda::Device`] which contains an
1212
// `UnownedContext`. A device cannot have an own context itself, as then it couldn't be cloned,
1313
// but that is needed for creating the kernels.
14-
pub(crate) struct CudaContexts(Vec<rustacuda::context::Context>);
14+
pub(crate) struct CudaContexts(#[allow(unused)] Vec<rustacuda::context::Context>);
1515
unsafe impl Sync for CudaContexts {}
1616
unsafe impl Send for CudaContexts {}
1717

src/error.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ use rustacuda::error::CudaError;
99
pub enum GPUError {
1010
/// Error from the underlying `opencl3` library, e.g. a memory allocation failure.
1111
#[cfg(feature = "opencl")]
12-
#[error("Opencl3 Error: {0}{}", match .1 {
12+
#[error("Opencl3 Error: {0}{}", match .message {
1313
Some(message) => format!(" {}", message),
1414
None => "".to_string(),
1515
})]
16-
Opencl3(ClError, Option<String>),
16+
Opencl3 {
17+
/// The error code.
18+
error: ClError,
19+
/// The error message.
20+
message: Option<String>,
21+
},
1722

1823
/// Error for OpenCL `clGetProgramInfo()` call failures.
1924
#[cfg(feature = "opencl")]
@@ -63,6 +68,9 @@ pub type GPUResult<T> = std::result::Result<T, GPUError>;
6368
#[cfg(feature = "opencl")]
6469
impl From<ClError> for GPUError {
6570
fn from(error: ClError) -> Self {
66-
GPUError::Opencl3(error, None)
71+
GPUError::Opencl3 {
72+
error,
73+
message: None,
74+
}
6775
}
6876
}

src/opencl/mod.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ impl Program {
152152
let mut program = opencl3::program::Program::create_from_source(&context, src)?;
153153
if let Err(build_error) = program.build(context.devices(), "") {
154154
let log = program.get_build_log(context.devices()[0])?;
155-
return Err(GPUError::Opencl3(build_error, Some(log)));
155+
return Err(GPUError::Opencl3 {
156+
error: build_error,
157+
message: Some(log),
158+
});
156159
}
157160
debug!(
158161
"Building kernel ({}) from source: done.",
@@ -191,7 +194,10 @@ impl Program {
191194
}?;
192195
if let Err(build_error) = program.build(context.devices(), "") {
193196
let log = program.get_build_log(context.devices()[0])?;
194-
return Err(GPUError::Opencl3(build_error, Some(log)));
197+
return Err(GPUError::Opencl3 {
198+
error: build_error,
199+
message: Some(log),
200+
});
195201
}
196202
let queue = CommandQueue::create_default(&context, 0)?;
197203
let kernels = opencl3::kernel::create_program_kernels(&program)?;
@@ -258,9 +264,7 @@ impl Program {
258264
)?
259265
};
260266
// Transmuting types is safe as long a sizes match.
261-
let bytes = unsafe {
262-
std::slice::from_raw_parts(slice.as_ptr() as *const T as *const u8, bytes_len)
263-
};
267+
let bytes = unsafe { std::slice::from_raw_parts(slice.as_ptr() as *const u8, bytes_len) };
264268
// Write some data right-away. This makes a significant performance different.
265269
unsafe {
266270
self.queue
@@ -314,10 +318,7 @@ impl Program {
314318

315319
// It is safe as long as the sizes match.
316320
let bytes = unsafe {
317-
std::slice::from_raw_parts(
318-
data.as_ptr() as *const T as *const u8,
319-
mem::size_of_val(data),
320-
)
321+
std::slice::from_raw_parts(data.as_ptr() as *const u8, mem::size_of_val(data))
321322
};
322323
unsafe {
323324
self.queue
@@ -332,10 +333,7 @@ impl Program {
332333

333334
// It is safe as long as the sizes match.
334335
let bytes = unsafe {
335-
std::slice::from_raw_parts_mut(
336-
data.as_mut_ptr() as *mut T as *mut u8,
337-
mem::size_of_val(data),
338-
)
336+
std::slice::from_raw_parts_mut(data.as_mut_ptr() as *mut u8, mem::size_of_val(data))
339337
};
340338
unsafe {
341339
self.queue

0 commit comments

Comments
 (0)