From d97589e8922cd0df36fbd287b906d32bb3795e13 Mon Sep 17 00:00:00 2001 From: elftausend <76885970+elftausend@users.noreply.github.com> Date: Sun, 8 Sep 2024 13:39:39 +0200 Subject: [PATCH] Fix some unused warnings --- src/buffer.rs | 16 +++++++--------- src/buffer/num.rs | 6 ++---- src/devices/cpu/cpu_ptr.rs | 24 +++++++++++------------- src/devices/cuda/cuda_ptr.rs | 6 ++---- src/devices/cuda/lazy.rs | 2 +- src/devices/cuda/ops.rs | 6 +++--- src/devices/nnapi/nnapi_device.rs | 11 ++++------- src/devices/stack_array.rs | 5 +---- src/devices/untyped/mod.rs | 18 +++++------------- src/devices/vulkan/ops.rs | 2 +- src/devices/wgsl/ops.rs | 2 +- src/exec_on_cpu.rs | 1 + src/lib.rs | 3 --- src/modules/autograd.rs | 8 ++++---- src/modules/autograd/tape.rs | 2 +- src/modules/autograd/wrapper.rs | 2 +- src/modules/lazy/lazy_graph.rs | 3 ++- src/modules/lazy/wrapper.rs | 2 +- tests/alloc.rs | 1 - tests/buffer.rs | 2 -- 20 files changed, 48 insertions(+), 74 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 2a58e02b..31638197 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -1,5 +1,4 @@ use core::{ - ffi::c_void, mem::ManuallyDrop, ops::{Deref, DerefMut}, }; @@ -11,9 +10,9 @@ use crate::cpu::{CPUPtr, CPU}; use crate::CPU; use crate::{ - flag::AllocFlag, shape::Shape, Alloc, Base, ClearBuf, CloneBuf, Device, - DevicelessAble, HasId, IsShapeIndep, OnDropBuffer, OnNewBuffer, PtrType, Read, ReplaceBuf, - ShallowCopy, Unit, WrappedData, WriteBuf, ZeroGrad, + flag::AllocFlag, shape::Shape, Alloc, Base, ClearBuf, CloneBuf, Device, DevicelessAble, HasId, + IsShapeIndep, OnDropBuffer, OnNewBuffer, PtrType, Read, ReplaceBuf, ShallowCopy, Unit, + WrappedData, WriteBuf, ZeroGrad, }; pub use self::num::Num; @@ -583,7 +582,7 @@ impl<'a, Mods: OnDropBuffer, T: Unit, S: Shape> Buffer<'a, T, CPU, S> { impl<'a, Mods: OnDropBuffer, T: Unit, S: Shape> Buffer<'a, T, crate::OpenCL, S> { /// Returns the OpenCL pointer of the `Buffer`. #[inline] - pub fn cl_ptr(&self) -> *mut c_void { + pub fn cl_ptr(&self) -> *mut core::ffi::c_void { assert!( !self.base().ptr.is_null(), "called cl_ptr() on an invalid OpenCL buffer" @@ -687,15 +686,14 @@ where T: Unit + Debug + Default + Clone + 'a, D: Read + Device + 'a, for<'b> >::Read<'b>: Debug, - D::Data: Debug, + D::Data: Debug, S: Shape, { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_struct("Buffer") - .field("ptr", self.data()); + f.debug_struct("Buffer").field("ptr", self.data()); writeln!(f, ",")?; - let data = self.read(); + let data = self.read(); writeln!(f, "data: {data:?}")?; writeln!(f, "len: {:?}", self.len())?; write!( diff --git a/src/buffer/num.rs b/src/buffer/num.rs index 556e052f..25957b30 100644 --- a/src/buffer/num.rs +++ b/src/buffer/num.rs @@ -1,13 +1,11 @@ use core::{ convert::Infallible, - ffi::c_void, ops::{Deref, DerefMut}, - ptr::null_mut, }; use crate::{ - flag::AllocFlag, Alloc, Buffer, CloneBuf, Device, HasId, OnDropBuffer, PtrType, - ShallowCopy, Unit, WrappedData, + flag::AllocFlag, Alloc, Buffer, CloneBuf, Device, HasId, OnDropBuffer, PtrType, ShallowCopy, + Unit, WrappedData, }; #[derive(Debug, Default)] diff --git a/src/devices/cpu/cpu_ptr.rs b/src/devices/cpu/cpu_ptr.rs index efed2306..e2a41801 100644 --- a/src/devices/cpu/cpu_ptr.rs +++ b/src/devices/cpu/cpu_ptr.rs @@ -99,11 +99,7 @@ impl CPUPtr { /// ``` #[inline] pub unsafe fn from_ptr(ptr: *mut T, len: usize, flag: AllocFlag) -> CPUPtr { - CPUPtr { - ptr, - len, - flag, - } + CPUPtr { ptr, len, flag } } pub fn from_vec(mut vec: Vec) -> CPUPtr { // CPUPtr only knows about the length, not the capacity -> deallocation happens with length, which may be less than the capacity @@ -246,7 +242,7 @@ impl ShallowCopy for CPUPtr { pub struct DeallocWithLayout { ptr: core::mem::ManuallyDrop>, - layout: Layout, + layout: Layout, } impl DeallocWithLayout { @@ -255,14 +251,18 @@ impl DeallocWithLayout { let (_, layout) = ptr.current_memory()?; let ptr = core::mem::ManuallyDrop::new(ptr); Some(Self { - ptr: core::mem::ManuallyDrop::new(CPUPtr { ptr: ptr.ptr as *mut u8, len: ptr.len, flag: ptr.flag }), - layout + ptr: core::mem::ManuallyDrop::new(CPUPtr { + ptr: ptr.ptr as *mut u8, + len: ptr.len, + flag: ptr.flag, + }), + layout, }) } - #[inline] + #[inline] pub fn layout(&self) -> &Layout { - &self.layout + &self.layout } } @@ -452,9 +452,7 @@ mod tests { #[test] fn test_dealloc_with_layout() { let data = CPUPtr::::new_initialized(10, crate::flag::AllocFlag::None); - let dealloc = unsafe { - DeallocWithLayout::new(data).unwrap() - }; + let dealloc = unsafe { DeallocWithLayout::new(data).unwrap() }; assert_eq!(dealloc.layout().size(), 40) } } diff --git a/src/devices/cuda/cuda_ptr.rs b/src/devices/cuda/cuda_ptr.rs index 8a5e4ddf..c5891183 100644 --- a/src/devices/cuda/cuda_ptr.rs +++ b/src/devices/cuda/cuda_ptr.rs @@ -1,8 +1,6 @@ -use core::{marker::PhantomData, ptr::null_mut}; - -use crate::{flag::AllocFlag, HasId, Id, PtrType, ShallowCopy}; - use super::api::{cu_read, cufree, cumalloc, CudaResult}; +use crate::{flag::AllocFlag, HasId, Id, PtrType, ShallowCopy}; +use core::marker::PhantomData; /// The pointer used for `CUDA` [`Buffer`](crate::Buffer)s #[derive(Debug, PartialEq, Eq)] diff --git a/src/devices/cuda/lazy.rs b/src/devices/cuda/lazy.rs index e61650be..ca036e3c 100644 --- a/src/devices/cuda/lazy.rs +++ b/src/devices/cuda/lazy.rs @@ -74,7 +74,7 @@ impl crate::LazySetup for CUDA { #[cfg(test)] mod tests { use crate::{ - AddOperation, ApplyFunction, AsNoId, Base, Buffer, Combiner, Device, HasId, Lazy, Retrieve, + AddOperation, ApplyFunction, Base, Buffer, Combiner, Device, HasId, Lazy, Retrieve, Retriever, Run, CUDA, }; diff --git a/src/devices/cuda/ops.rs b/src/devices/cuda/ops.rs index be0378f2..1eaa7eda 100644 --- a/src/devices/cuda/ops.rs +++ b/src/devices/cuda/ops.rs @@ -4,9 +4,9 @@ use crate::{ bounds_to_range, cuda::api::{cu_read_async, CUstreamCaptureStatus}, op_hint::unary, - pass_down_add_operation, pass_down_exec_now, AddOperation, ApplyFunction, - Buffer, CDatatype, ClearBuf, CopySlice, OnDropBuffer, Read, Resolve, Retrieve, Retriever, - SetOpHint, Shape, ToCLSource, ToMarker, UnaryGrad, Unit, WriteBuf, ZeroGrad, CUDA, + pass_down_add_operation, pass_down_exec_now, AddOperation, ApplyFunction, Buffer, CDatatype, + ClearBuf, CopySlice, OnDropBuffer, Read, Resolve, Retrieve, Retriever, SetOpHint, Shape, + ToCLSource, ToMarker, UnaryGrad, Unit, WriteBuf, ZeroGrad, CUDA, }; use super::{ diff --git a/src/devices/nnapi/nnapi_device.rs b/src/devices/nnapi/nnapi_device.rs index fe6d5dfe..7186e070 100644 --- a/src/devices/nnapi/nnapi_device.rs +++ b/src/devices/nnapi/nnapi_device.rs @@ -1,6 +1,7 @@ use crate::{ - cpu::{CPUPtr, DeallocWithLayout}, Alloc, AsOperandCode, Base, Buffer, Device, HasId, IsShapeIndep, Lazy, LazyRun, - LazySetup, Module, OnDropBuffer, PtrType, Retrieve, Retriever, Setup, Shape, Unit, WrappedData, + cpu::{CPUPtr, DeallocWithLayout}, + Alloc, AsOperandCode, Base, Buffer, Device, HasId, IsShapeIndep, Lazy, LazyRun, LazySetup, + Module, OnDropBuffer, PtrType, Retrieve, Retriever, Setup, Shape, Unit, WrappedData, }; use super::NnapiPtr; @@ -215,11 +216,7 @@ impl NnapiDevice { fn set_input_ptrs(&self, run: &mut Execution) -> crate::Result<()> { for (idx, (_id, input_ptr)) in self.input_ptrs.borrow().iter().enumerate() { unsafe { - run.set_input_raw( - idx as i32, - input_ptr.ptr.cast(), - input_ptr.layout().size() - ) + run.set_input_raw(idx as i32, input_ptr.ptr.cast(), input_ptr.layout().size()) }? } Ok(()) diff --git a/src/devices/stack_array.rs b/src/devices/stack_array.rs index a563544a..01ef5e8a 100644 --- a/src/devices/stack_array.rs +++ b/src/devices/stack_array.rs @@ -1,7 +1,4 @@ -use core::{ - ops::{Deref, DerefMut}, - ptr::null_mut, -}; +use core::ops::{Deref, DerefMut}; use crate::{shape::Shape, HasId, HostPtr, PtrType, ShallowCopy}; diff --git a/src/devices/untyped/mod.rs b/src/devices/untyped/mod.rs index a0a75243..e3f730db 100644 --- a/src/devices/untyped/mod.rs +++ b/src/devices/untyped/mod.rs @@ -27,7 +27,7 @@ impl<'a, T: Unit, S: crate::Shape> Buffer<'a, T, Untyped, S> { // Safety: An Untyped device buffer is shape and data type independent! // type Base = UntypedData; <- missing // type Data = UntypedData; <| - // storage type is also matched + // storage type is also matched Some(unsafe { std::mem::transmute(self) }) } @@ -47,9 +47,7 @@ impl<'a, T: Unit, S: crate::Shape> Buffer<'a, T, Untyped, S> { { self.data.matches_storage_type::().ok()?; - Some(unsafe { - &*(self as *const Self as *const Buffer) - }) + Some(unsafe { &*(self as *const Self as *const Buffer) }) } #[inline] @@ -59,9 +57,7 @@ impl<'a, T: Unit, S: crate::Shape> Buffer<'a, T, Untyped, S> { NS: crate::Shape, { self.data.matches_storage_type::().ok()?; - Some(unsafe { - &mut *(self as *mut Self as *mut Buffer) - }) + Some(unsafe { &mut *(self as *mut Self as *mut Buffer) }) } #[inline] @@ -69,9 +65,7 @@ impl<'a, T: Unit, S: crate::Shape> Buffer<'a, T, Untyped, S> { // Safety: An Untyped device buffer is shape and data type independent! // type Base = UntypedData; <- missing // type Data = UntypedData; <| - unsafe { - &*(self as *const Self as *const Buffer<(), Untyped, ()>) - } + unsafe { &*(self as *const Self as *const Buffer<(), Untyped, ()>) } } #[inline] @@ -79,9 +73,7 @@ impl<'a, T: Unit, S: crate::Shape> Buffer<'a, T, Untyped, S> { // Safety: An Untyped device buffer is shape and data type independent! // type Base = UntypedData; <- missing // type Data = UntypedData; <| - unsafe { - &mut *(self as *mut Self as *mut Buffer<(), Untyped, ()>) - } + unsafe { &mut *(self as *mut Self as *mut Buffer<(), Untyped, ()>) } } #[inline] diff --git a/src/devices/vulkan/ops.rs b/src/devices/vulkan/ops.rs index 851598d2..87eb35e5 100644 --- a/src/devices/vulkan/ops.rs +++ b/src/devices/vulkan/ops.rs @@ -2,7 +2,7 @@ use core::fmt::Debug; use crate::{ cpu_stack_ops::clear_slice, pass_down_add_operation, pass_down_exec_now, prelude::Number, - AddOperation, ApplyFunction, AsNoId, BufAsNoId, Buffer, CDatatype, ClearBuf, OnDropBuffer, + AddOperation, ApplyFunction, Buffer, CDatatype, ClearBuf, OnDropBuffer, Read, Resolve, Retrieve, Retriever, Shape, ToCLSource, ToMarker, ToWgslSource, UnaryGrad, Unit, UseGpuOrCpu, Vulkan, WriteBuf, ZeroGrad, }; diff --git a/src/devices/wgsl/ops.rs b/src/devices/wgsl/ops.rs index 655364a9..09f7353b 100644 --- a/src/devices/wgsl/ops.rs +++ b/src/devices/wgsl/ops.rs @@ -1,5 +1,5 @@ use crate::{ - op_hint::unary, AddOperation, Alloc, ApplyFunction, AsNoId, OnDropBuffer, Read, Retrieve, + op_hint::unary, AddOperation, Alloc, ApplyFunction, OnDropBuffer, Read, Retrieve, Retriever, SetOpHint, Shape, ToMarker, Unit, }; diff --git a/src/exec_on_cpu.rs b/src/exec_on_cpu.rs index a44dc0db..1bc37cc6 100644 --- a/src/exec_on_cpu.rs +++ b/src/exec_on_cpu.rs @@ -435,6 +435,7 @@ mod tests { } pub trait AddEw: crate::Device { + #[allow(dead_code)] fn add(&self, lhs: &crate::Buffer, rhs: &crate::Buffer) -> crate::Buffer; } diff --git a/src/lib.rs b/src/lib.rs index e9a0b072..a17e8ca0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,9 +56,6 @@ //! A lot more usage examples can be found in the [tests] and [examples] folder. //! //! [tests]: https://github.com/elftausend/custos/tree/main/tests -use core::ffi::c_void; - -//pub use libs::*; pub use buffer::*; pub use devices::*; diff --git a/src/modules/autograd.rs b/src/modules/autograd.rs index 7632865f..faceadbc 100644 --- a/src/modules/autograd.rs +++ b/src/modules/autograd.rs @@ -404,7 +404,7 @@ mod tests { Ok(()) }); - out.backward(); + out.backward().unwrap(); assert_eq!(&***buf.grad(), [5.; 10]); } @@ -443,7 +443,7 @@ mod tests { Ok(()) }); - out.backward(); + out.backward().unwrap(); assert_eq!(lhs.try_grad().unwrap().as_slice(), [4, 5, 6, 7]); } @@ -463,7 +463,7 @@ mod tests { panic!("should not be called"); }); - out.backward(); + out.backward().unwrap(); assert!(lhs.try_grad().is_none()); @@ -475,7 +475,7 @@ mod tests { Ok(()) }); - out.backward(); + out.backward().unwrap(); assert_eq!(lhs.try_grad().unwrap().as_slice(), [4, 5, 6, 7]); } diff --git a/src/modules/autograd/tape.rs b/src/modules/autograd/tape.rs index 2566045d..5dea6261 100644 --- a/src/modules/autograd/tape.rs +++ b/src/modules/autograd/tape.rs @@ -78,7 +78,7 @@ impl<'t> Tape<'t> { buf: &Buffer<'a, T, D, S>, seed: &[T], buffers: Option<&mut Buffers>>, - ) -> crate::Result<()> + ) -> crate::Result<()> where T: Unit + 'static, D: Alloc + ZeroGrad + WriteBuf + GradActions + AddOperation + 'static, diff --git a/src/modules/autograd/wrapper.rs b/src/modules/autograd/wrapper.rs index 347420ff..dbb4d25d 100644 --- a/src/modules/autograd/wrapper.rs +++ b/src/modules/autograd/wrapper.rs @@ -1,6 +1,6 @@ use core::marker::PhantomData; -use crate::{flag::AllocFlag, Autograd, HasId, PtrType, ShallowCopy, Shape, WrappedData}; +use crate::{flag::AllocFlag, Autograd, HasId, PtrType, ShallowCopy, WrappedData}; #[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] pub struct ReqGradWrapper { diff --git a/src/modules/lazy/lazy_graph.rs b/src/modules/lazy/lazy_graph.rs index 1d07b038..8b9b8b7f 100644 --- a/src/modules/lazy/lazy_graph.rs +++ b/src/modules/lazy/lazy_graph.rs @@ -1,5 +1,6 @@ use crate::{ - bounds_to_range, modules::lazy::exec_iter::ExecIter, op_hint::OpHint, AnyOp, BoxedShallowCopy, Buffers, Device, Downcast, Id, OperationFn, Parents + bounds_to_range, modules::lazy::exec_iter::ExecIter, op_hint::OpHint, AnyOp, BoxedShallowCopy, + Buffers, Device, Downcast, Id, OperationFn, Parents, }; use core::ops::RangeBounds; use std::collections::HashSet; diff --git a/src/modules/lazy/wrapper.rs b/src/modules/lazy/wrapper.rs index 3f4f72f6..ebf2e313 100644 --- a/src/modules/lazy/wrapper.rs +++ b/src/modules/lazy/wrapper.rs @@ -3,7 +3,7 @@ use core::{ ops::{Deref, DerefMut}, }; -use crate::{flag::AllocFlag, HasId, HostPtr, Id, Lazy, PtrType, ShallowCopy, Shape, WrappedData}; +use crate::{flag::AllocFlag, HasId, HostPtr, Id, Lazy, PtrType, ShallowCopy, WrappedData}; #[derive(Debug, Default)] pub struct LazyWrapper { diff --git a/tests/alloc.rs b/tests/alloc.rs index 9a008bbd..5f9f7d08 100644 --- a/tests/alloc.rs +++ b/tests/alloc.rs @@ -1,4 +1,3 @@ - #[cfg(feature = "wgpu")] use custos::prelude::*; #[cfg(feature = "wgpu")] diff --git a/tests/buffer.rs b/tests/buffer.rs index 4f0835cb..d7baa16c 100644 --- a/tests/buffer.rs +++ b/tests/buffer.rs @@ -1,6 +1,5 @@ use custos::prelude::*; - #[cfg(feature = "std")] pub fn read>(device: &D, buf: &Buffer) -> Vec where @@ -194,7 +193,6 @@ fn test_deviceless_buf() { Buffer::::deviceless(&device, 5) }; - for (idx, element) in buf.iter_mut().enumerate() { *element = idx as u8; }