Skip to content

Commit 54f476c

Browse files
authored
Fix some compilation errors and warnings (#152)
1 parent 34df9c7 commit 54f476c

21 files changed

+57
-148
lines changed

crates/cuda_std/src/float.rs

+33-33
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,25 @@ mod private {
5454

5555
macro_rules! f32_intrinsic {
5656
($self:expr, $func:ident($($param:expr),*)) => {{
57-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
57+
#[cfg(not(target_arch = "nvptx64"))]
5858
let val = $self.$func($($param),*);
59-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
59+
#[cfg(target_arch = "nvptx64")]
6060
let val = paste::paste! { unsafe { intrinsics::[<$func f>]($self, $($param),*)} };
6161
val
6262
}};
6363
}
6464

6565
macro_rules! f64_intrinsic {
6666
($self:expr, $func:ident($($param:expr),*)) => {{
67-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
67+
#[cfg(not(target_arch = "nvptx64"))]
6868
let val = $self.$func($($param),*);
69-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
69+
#[cfg(target_arch = "nvptx64")]
7070
let val = unsafe { intrinsics::$func($self, $($param),*)};
7171
val
7272
}};
7373
}
7474

75-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
75+
#[cfg(target_arch = "nvptx64")]
7676
use crate::intrinsics;
7777

7878
impl GpuFloat for f32 {
@@ -117,9 +117,9 @@ impl GpuFloat for f32 {
117117
#[must_use = "method returns a new number and does not mutate the original value"]
118118
#[inline]
119119
fn abs(self) -> f32 {
120-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
120+
#[cfg(not(target_arch = "nvptx64"))]
121121
let val = self.abs();
122-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
122+
#[cfg(target_arch = "nvptx64")]
123123
let val = { unsafe { intrinsics::fabsf(self) } };
124124
val
125125
}
@@ -161,9 +161,9 @@ impl GpuFloat for f32 {
161161
#[must_use = "method returns a new number and does not mutate the original value"]
162162
#[inline]
163163
fn mul_add(self, a: f32, b: f32) -> f32 {
164-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
164+
#[cfg(not(target_arch = "nvptx64"))]
165165
let val = self.mul_add(a, b);
166-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
166+
#[cfg(target_arch = "nvptx64")]
167167
let val = { unsafe { intrinsics::fmaf(self, a, b) } };
168168
val
169169
}
@@ -218,9 +218,9 @@ impl GpuFloat for f32 {
218218
#[must_use = "method returns a new number and does not mutate the original value"]
219219
#[inline]
220220
fn powf(self, n: f32) -> f32 {
221-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
221+
#[cfg(not(target_arch = "nvptx64"))]
222222
let val = self.powf(n);
223-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
223+
#[cfg(target_arch = "nvptx64")]
224224
let val = { unsafe { intrinsics::powf(self, n) } };
225225
val
226226
}
@@ -252,9 +252,9 @@ impl GpuFloat for f32 {
252252
#[must_use = "method returns a new number and does not mutate the original value"]
253253
#[inline]
254254
fn ln(self) -> f32 {
255-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
255+
#[cfg(not(target_arch = "nvptx64"))]
256256
let val = self.ln();
257-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
257+
#[cfg(target_arch = "nvptx64")]
258258
let val = { unsafe { intrinsics::logf(self) } };
259259
val
260260
}
@@ -362,9 +362,9 @@ impl GpuFloat for f32 {
362362
/// `(sin(x), cos(x))`.
363363
#[inline]
364364
fn sin_cos(self) -> (f32, f32) {
365-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
365+
#[cfg(not(target_arch = "nvptx64"))]
366366
let val = self.sin_cos();
367-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
367+
#[cfg(target_arch = "nvptx64")]
368368
let val = {
369369
let mut sptr = 0.0;
370370
let mut cptr = 0.0;
@@ -381,9 +381,9 @@ impl GpuFloat for f32 {
381381
#[must_use = "method returns a new number and does not mutate the original value"]
382382
#[inline]
383383
fn exp_m1(self) -> f32 {
384-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
384+
#[cfg(not(target_arch = "nvptx64"))]
385385
let val = self.exp_m1();
386-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
386+
#[cfg(target_arch = "nvptx64")]
387387
let val = { unsafe { intrinsics::expm1f(self) } };
388388
val
389389
}
@@ -393,9 +393,9 @@ impl GpuFloat for f32 {
393393
#[must_use = "method returns a new number and does not mutate the original value"]
394394
#[inline]
395395
fn ln_1p(self) -> f32 {
396-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
396+
#[cfg(not(target_arch = "nvptx64"))]
397397
let val = self.ln_1p();
398-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
398+
#[cfg(target_arch = "nvptx64")]
399399
let val = { unsafe { intrinsics::log1pf(self) } };
400400
val
401401
}
@@ -485,9 +485,9 @@ impl GpuFloat for f64 {
485485
#[must_use = "method returns a new number and does not mutate the original value"]
486486
#[inline]
487487
fn abs(self) -> f64 {
488-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
488+
#[cfg(not(target_arch = "nvptx64"))]
489489
let val = self.abs();
490-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
490+
#[cfg(target_arch = "nvptx64")]
491491
let val = { unsafe { intrinsics::fabs(self) } };
492492
val
493493
}
@@ -529,9 +529,9 @@ impl GpuFloat for f64 {
529529
#[must_use = "method returns a new number and does not mutate the original value"]
530530
#[inline]
531531
fn mul_add(self, a: f64, b: f64) -> f64 {
532-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
532+
#[cfg(not(target_arch = "nvptx64"))]
533533
let val = self.mul_add(a, b);
534-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
534+
#[cfg(target_arch = "nvptx64")]
535535
let val = { unsafe { intrinsics::fma(self, a, b) } };
536536
val
537537
}
@@ -586,9 +586,9 @@ impl GpuFloat for f64 {
586586
#[must_use = "method returns a new number and does not mutate the original value"]
587587
#[inline]
588588
fn powf(self, n: f64) -> f64 {
589-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
589+
#[cfg(not(target_arch = "nvptx64"))]
590590
let val = self.powf(n);
591-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
591+
#[cfg(target_arch = "nvptx64")]
592592
let val = { unsafe { intrinsics::pow(self, n) } };
593593
val
594594
}
@@ -620,9 +620,9 @@ impl GpuFloat for f64 {
620620
#[must_use = "method returns a new number and does not mutate the original value"]
621621
#[inline]
622622
fn ln(self) -> f64 {
623-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
623+
#[cfg(not(target_arch = "nvptx64"))]
624624
let val = self.ln();
625-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
625+
#[cfg(target_arch = "nvptx64")]
626626
let val = { unsafe { intrinsics::log(self) } };
627627
val
628628
}
@@ -730,9 +730,9 @@ impl GpuFloat for f64 {
730730
/// `(sin(x), cos(x))`.
731731
#[inline]
732732
fn sin_cos(self) -> (f64, f64) {
733-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
733+
#[cfg(not(target_arch = "nvptx64"))]
734734
let val = self.sin_cos();
735-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
735+
#[cfg(target_arch = "nvptx64")]
736736
let val = {
737737
let mut sptr = 0.0;
738738
let mut cptr = 0.0;
@@ -749,9 +749,9 @@ impl GpuFloat for f64 {
749749
#[must_use = "method returns a new number and does not mutate the original value"]
750750
#[inline]
751751
fn exp_m1(self) -> f64 {
752-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
752+
#[cfg(not(target_arch = "nvptx64"))]
753753
let val = self.exp_m1();
754-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
754+
#[cfg(target_arch = "nvptx64")]
755755
let val = { unsafe { intrinsics::expm1(self) } };
756756
val
757757
}
@@ -761,9 +761,9 @@ impl GpuFloat for f64 {
761761
#[must_use = "method returns a new number and does not mutate the original value"]
762762
#[inline]
763763
fn ln_1p(self) -> f64 {
764-
#[cfg(not(any(target_arch = "nvptx", target_arch = "nvptx64")))]
764+
#[cfg(not(target_arch = "nvptx64"))]
765765
let val = self.ln_1p();
766-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
766+
#[cfg(target_arch = "nvptx64")]
767767
let val = { unsafe { intrinsics::log1p(self) } };
768768
val
769769
}

crates/cuda_std/src/mem.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//! Support for allocating memory and using `alloc` using CUDA memory allocation system-calls.
22
33
use crate::gpu_only;
4-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
4+
#[cfg(target_arch = "nvptx64")]
55
use alloc::alloc::*;
6-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
6+
#[cfg(target_arch = "nvptx64")]
77
use core::ffi::c_void;
88

9-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
9+
#[cfg(target_arch = "nvptx64")]
1010
extern "C" {
1111
// implicitly defined by cuda.
1212
pub fn malloc(size: usize) -> *mut c_void;
@@ -16,7 +16,7 @@ extern "C" {
1616

1717
pub struct CUDAAllocator;
1818

19-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
19+
#[cfg(target_arch = "nvptx64")]
2020
unsafe impl GlobalAlloc for CUDAAllocator {
2121
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
2222
malloc(layout.size()) as *mut u8
@@ -26,7 +26,7 @@ unsafe impl GlobalAlloc for CUDAAllocator {
2626
}
2727
}
2828

29-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
29+
#[cfg(target_arch = "nvptx64")]
3030
#[global_allocator]
3131
pub static GLOBAL_ALLOCATOR: CUDAAllocator = CUDAAllocator;
3232

crates/cust/src/memory/device/device_buffer.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl<A: DeviceCopy + Pod> DeviceBuffer<A> {
314314
/// whole number of elements. Such as `3` x [`u16`] -> `1.5` x [`u32`].
315315
/// - If either type is a ZST (but not both).
316316
#[cfg_attr(docsrs, doc(cfg(feature = "bytemuck")))]
317-
pub fn try_cast<B: Pod + DeviceCopy>(mut self) -> Result<DeviceBuffer<B>, PodCastError> {
317+
pub fn try_cast<B: Pod + DeviceCopy>(self) -> Result<DeviceBuffer<B>, PodCastError> {
318318
if align_of::<B>() > align_of::<A>() && (self.buf.as_raw() as usize) % align_of::<B>() != 0
319319
{
320320
Err(PodCastError::TargetAlignmentGreaterAndInputNotAligned)
@@ -329,9 +329,7 @@ impl<A: DeviceCopy + Pod> DeviceBuffer<A> {
329329
buf: self.buf.cast(),
330330
len: new_len,
331331
});
332-
unsafe {
333-
std::mem::forget(self);
334-
}
332+
std::mem::forget(self);
335333
ret
336334
} else {
337335
Err(PodCastError::OutputSliceWouldHaveSlop)

crates/gpu_rand/src/default.rs

-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ impl RngCore for DefaultRand {
3737
fn fill_bytes(&mut self, dest: &mut [u8]) {
3838
self.inner.fill_bytes(dest)
3939
}
40-
41-
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> {
42-
self.inner.try_fill_bytes(dest)
43-
}
4440
}
4541

4642
impl SeedableRng for DefaultRand {

crates/gpu_rand/src/xoroshiro/common.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
macro_rules! from_splitmix {
33
($seed:expr) => {{
44
let mut rng = crate::xoroshiro::SplitMix64::seed_from_u64($seed);
5-
Self::from_rng(&mut rng).unwrap()
5+
Self::from_rng(&mut rng)
66
}};
77
}
88

@@ -327,3 +327,9 @@ impl AsMut<[u8]> for Seed512 {
327327
&mut self.0
328328
}
329329
}
330+
331+
impl AsRef<[u8]> for Seed512 {
332+
fn as_ref(&self) -> &[u8] {
333+
&self.0
334+
}
335+
}

crates/gpu_rand/src/xoroshiro/splitmix64.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rand_core::impls::fill_bytes_via_next;
22
use rand_core::le::read_u64_into;
3-
use rand_core::{Error, RngCore, SeedableRng};
3+
use rand_core::{RngCore, SeedableRng};
44

55
/// A splitmix64 random number generator.
66
///
@@ -49,12 +49,6 @@ impl RngCore for SplitMix64 {
4949
fn fill_bytes(&mut self, dest: &mut [u8]) {
5050
fill_bytes_via_next(self, dest);
5151
}
52-
53-
#[inline]
54-
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
55-
self.fill_bytes(dest);
56-
Ok(())
57-
}
5852
}
5953

6054
impl SeedableRng for SplitMix64 {

crates/gpu_rand/src/xoroshiro/xoroshiro128plus.rs

-6
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ impl RngCore for Xoroshiro128Plus {
7878
fn fill_bytes(&mut self, dest: &mut [u8]) {
7979
fill_bytes_via_next(self, dest);
8080
}
81-
82-
#[inline]
83-
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> {
84-
self.fill_bytes(dest);
85-
Ok(())
86-
}
8781
}
8882

8983
impl SeedableRng for Xoroshiro128Plus {

crates/gpu_rand/src/xoroshiro/xoroshiro128plusplus.rs

-6
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ impl RngCore for Xoroshiro128PlusPlus {
7575
fn fill_bytes(&mut self, dest: &mut [u8]) {
7676
fill_bytes_via_next(self, dest);
7777
}
78-
79-
#[inline]
80-
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> {
81-
self.fill_bytes(dest);
82-
Ok(())
83-
}
8478
}
8579

8680
impl SeedableRng for Xoroshiro128PlusPlus {

crates/gpu_rand/src/xoroshiro/xoroshiro128starstar.rs

-6
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ impl RngCore for Xoroshiro128StarStar {
7575
fn fill_bytes(&mut self, dest: &mut [u8]) {
7676
fill_bytes_via_next(self, dest);
7777
}
78-
79-
#[inline]
80-
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> {
81-
self.fill_bytes(dest);
82-
Ok(())
83-
}
8478
}
8579

8680
impl SeedableRng for Xoroshiro128StarStar {

crates/gpu_rand/src/xoroshiro/xoroshiro64star.rs

-6
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ impl RngCore for Xoroshiro64Star {
3838
fn fill_bytes(&mut self, dest: &mut [u8]) {
3939
fill_bytes_via_next(self, dest);
4040
}
41-
42-
#[inline]
43-
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> {
44-
self.fill_bytes(dest);
45-
Ok(())
46-
}
4741
}
4842

4943
impl SeedableRng for Xoroshiro64Star {

crates/gpu_rand/src/xoroshiro/xoroshiro64starstar.rs

-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ impl RngCore for Xoroshiro64StarStar {
3737
fn fill_bytes(&mut self, dest: &mut [u8]) {
3838
fill_bytes_via_next(self, dest);
3939
}
40-
41-
#[inline]
42-
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> {
43-
self.fill_bytes(dest);
44-
Ok(())
45-
}
4640
}
4741

4842
impl SeedableRng for Xoroshiro64StarStar {

crates/gpu_rand/src/xoroshiro/xoshiro128plus.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rand_core::impls::{fill_bytes_via_next, next_u64_via_u32};
22
use rand_core::le::read_u32_into;
3-
use rand_core::{Error, RngCore, SeedableRng};
3+
use rand_core::{RngCore, SeedableRng};
44

55
/// A xoshiro128+ random number generator.
66
///
@@ -84,12 +84,6 @@ impl RngCore for Xoshiro128Plus {
8484
fn fill_bytes(&mut self, dest: &mut [u8]) {
8585
fill_bytes_via_next(self, dest);
8686
}
87-
88-
#[inline]
89-
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
90-
self.fill_bytes(dest);
91-
Ok(())
92-
}
9387
}
9488

9589
#[cfg(test)]

0 commit comments

Comments
 (0)