Skip to content

Commit 26b56cc

Browse files
committed
Port some compiletests from rust-gpu
We needed more compiletests, rust-gpu had some. So I ported them with AI and confirmed they passed.
1 parent 816f383 commit 26b56cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+958
-17
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Test CUDA atomic operations compile correctly
2+
// build-pass
3+
4+
use core::sync::atomic::Ordering;
5+
use cuda_std::atomic::{
6+
AtomicF32, AtomicF64, BlockAtomicF32, BlockAtomicF64, SystemAtomicF32, SystemAtomicF64,
7+
};
8+
use cuda_std::kernel;
9+
10+
#[kernel]
11+
pub unsafe fn test_cuda_atomic_floats() {
12+
// Device-scoped atomic float
13+
let atomic_f32 = AtomicF32::new(3.14);
14+
let _old = atomic_f32.fetch_add(1.0, Ordering::Relaxed);
15+
let _val = atomic_f32.load(Ordering::Relaxed);
16+
atomic_f32.store(2.718, Ordering::Relaxed);
17+
18+
// Block-scoped atomic float
19+
let block_atomic = BlockAtomicF32::new(1.5);
20+
let _old = block_atomic.fetch_add(0.5, Ordering::Relaxed);
21+
22+
// System-scoped atomic float
23+
let system_atomic = SystemAtomicF32::new(0.0);
24+
let _old = system_atomic.fetch_add(1.0, Ordering::Relaxed);
25+
26+
// Test f64 as well
27+
let atomic_f64 = AtomicF64::new(3.14159);
28+
let _old = atomic_f64.fetch_add(1.0, Ordering::Relaxed);
29+
30+
// Test block-scoped f64
31+
let block_f64 = BlockAtomicF64::new(2.718);
32+
let _old = block_f64.fetch_sub(0.5, Ordering::Relaxed);
33+
34+
// Test bitwise operations on floats
35+
let _old = atomic_f32.fetch_and(3.14, Ordering::Relaxed);
36+
let _old = atomic_f32.fetch_or(1.0, Ordering::Relaxed);
37+
let _old = atomic_f32.fetch_xor(2.0, Ordering::Relaxed);
38+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Test CUDA float extension functions compile correctly
2+
// build-pass
3+
4+
use cuda_std::kernel;
5+
use cuda_std::FloatExt;
6+
7+
#[kernel]
8+
pub unsafe fn test_float_extensions() {
9+
let x = 3.14f32;
10+
11+
// Test various float extension methods
12+
let _cospi = x.cospi();
13+
let _erf = x.error_function();
14+
let _erfc = x.complementary_error_function();
15+
let _erfcx = x.scaled_complementary_error_function();
16+
17+
// Test frexp
18+
let (_frac, _exp) = x.frexp();
19+
let _exp = x.unbiased_exp();
20+
21+
// Test bessel functions
22+
let _j0 = x.j0();
23+
let _j1 = x.j1();
24+
let _jn = x.jn(2);
25+
26+
// Test other functions
27+
let _ldexp = x.ldexp(3);
28+
let _lgamma = x.log_gamma();
29+
let _log1p = x.log1p();
30+
31+
// Test normcdf functions
32+
let _normcdf = x.norm_cdf();
33+
let _normcdfinv = (0.5f32).inv_norm_cdf();
34+
35+
// Test sinpi
36+
let _sinpi = x.sinpi();
37+
38+
// Test f64 as well
39+
let y = 2.718f64;
40+
let _cospi_f64 = y.cospi();
41+
let _erf_f64 = y.error_function();
42+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Tests multiplying a `Mat3` by a `Vec3`.
2+
// build-pass
3+
4+
use cuda_std::glam;
5+
use cuda_std::kernel;
6+
7+
#[kernel]
8+
pub unsafe fn mat3_vec3_multiply(input: glam::Mat3, output: *mut glam::Vec3) {
9+
let vector = input * glam::Vec3::new(1.0, 2.0, 3.0);
10+
*output = vector;
11+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Test `&'static T` constants where the `T` values don't themselves contain
2+
// references, and where the `T` values aren't immediately loaded from.
3+
4+
// build-pass
5+
6+
use cuda_std::glam::{Mat2, Vec2};
7+
use cuda_std::kernel;
8+
9+
#[inline(never)]
10+
fn scalar_load(r: &'static u32) -> u32 {
11+
*r
12+
}
13+
14+
const ROT90: Mat2 = Mat2::from_cols_array_2d(&[[0.0, 1.0], [-1.0, 0.0]]);
15+
16+
#[kernel]
17+
pub unsafe fn test_shallow_ref(
18+
scalar_out: *mut u32,
19+
vec_in: Vec2,
20+
bool_out: *mut u32,
21+
vec_out: *mut Vec2,
22+
) {
23+
*scalar_out = scalar_load(&123);
24+
*bool_out = (vec_in == Vec2::ZERO) as u32;
25+
*vec_out = ROT90.transpose() * vec_in;
26+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// build-pass
2+
3+
use cuda_std::kernel;
4+
5+
#[kernel]
6+
pub unsafe fn test_for_range(i: u32) {
7+
for _ in 0..i {}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// build-pass
2+
3+
use cuda_std::kernel;
4+
5+
#[kernel]
6+
pub unsafe fn test_for_range_signed(i: i32) {
7+
for _ in 0..i {}
8+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// NOTE(eddyb) this tests `for` loop desugaring (with its call to `Iterator::next`
2+
// and matching on the resulting `Option`), without relying on a `Range` iterator.
3+
// More precisely, `Range` used to not compile, due to it using `mem::replace`,
4+
// which, before https://github.com/rust-lang/rust/pull/83022, used to just call
5+
// `mem::swap` (which has a block-wise optimization that can't work on SPIR-V).
6+
7+
// build-pass
8+
9+
use core::ops::Range;
10+
use cuda_std::kernel;
11+
use cuda_std::vek::num_traits::Num;
12+
13+
struct RangeIter<T>(Range<T>);
14+
15+
impl<T: Num + Ord + Copy> Iterator for RangeIter<T> {
16+
type Item = T;
17+
fn next(&mut self) -> Option<T> {
18+
let x = self.0.start;
19+
if x >= self.0.end {
20+
None
21+
} else {
22+
self.0.start = x + T::one();
23+
Some(x)
24+
}
25+
}
26+
}
27+
28+
#[kernel]
29+
pub unsafe fn test_custom_range_iter(i: i32) {
30+
for _ in RangeIter(0..i) {}
31+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// build-pass
2+
3+
use cuda_std::kernel;
4+
5+
#[kernel]
6+
pub unsafe fn test_if(i: i32) {
7+
if i > 0 {}
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// build-pass
2+
3+
use cuda_std::kernel;
4+
5+
#[kernel]
6+
pub unsafe fn test_if_else(i: i32) {
7+
if i > 0 {
8+
} else {
9+
}
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// build-pass
2+
3+
use cuda_std::kernel;
4+
5+
#[kernel]
6+
pub unsafe fn test_if_else_if_else(i: i32) {
7+
if i > 0 {
8+
} else if i < 0 {
9+
} else {
10+
}
11+
}

0 commit comments

Comments
 (0)