1+ // Test CUDA atomic operations compile correctly
2+ // build-pass
3+
4+ use cuda_std:: kernel;
5+ use cuda_std:: atomic:: { AtomicF32 , AtomicF64 , BlockAtomicF32 , SystemAtomicF32 , BlockAtomicF64 , SystemAtomicF64 } ;
6+ use core:: sync:: atomic:: Ordering ;
7+
8+ #[ kernel]
9+ pub unsafe fn test_cuda_atomic_floats ( ) {
10+ // Device-scoped atomic float
11+ let atomic_f32 = AtomicF32 :: new ( 3.14 ) ;
12+ let _old = atomic_f32. fetch_add ( 1.0 , Ordering :: Relaxed ) ;
13+ let _val = atomic_f32. load ( Ordering :: Relaxed ) ;
14+ atomic_f32. store ( 2.718 , Ordering :: Relaxed ) ;
15+
16+ // Block-scoped atomic float
17+ let block_atomic = BlockAtomicF32 :: new ( 1.5 ) ;
18+ let _old = block_atomic. fetch_add ( 0.5 , Ordering :: Relaxed ) ;
19+
20+ // System-scoped atomic float
21+ let system_atomic = SystemAtomicF32 :: new ( 0.0 ) ;
22+ let _old = system_atomic. fetch_add ( 1.0 , Ordering :: Relaxed ) ;
23+
24+ // Test f64 as well
25+ let atomic_f64 = AtomicF64 :: new ( 3.14159 ) ;
26+ let _old = atomic_f64. fetch_add ( 1.0 , Ordering :: Relaxed ) ;
27+
28+ // Test block-scoped f64
29+ let block_f64 = BlockAtomicF64 :: new ( 2.718 ) ;
30+ let _old = block_f64. fetch_sub ( 0.5 , Ordering :: Relaxed ) ;
31+
32+ // Test bitwise operations on floats
33+ let _old = atomic_f32. fetch_and ( 3.14 , Ordering :: Relaxed ) ;
34+ let _old = atomic_f32. fetch_or ( 1.0 , Ordering :: Relaxed ) ;
35+ let _old = atomic_f32. fetch_xor ( 2.0 , Ordering :: Relaxed ) ;
36+ }
0 commit comments