Skip to content

Commit 8b6c3b8

Browse files
committed
Cargo fmt
1 parent 7d6627e commit 8b6c3b8

File tree

40 files changed

+498
-548
lines changed

40 files changed

+498
-548
lines changed

tests/difftests/tests/arch/atomic_ops/atomic_ops-rust/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ pub fn main_cs(
1414
const SEMANTICS: u32 = Semantics::NONE.bits();
1515

1616
let tid = global_id.x;
17-
17+
1818
// All threads participate in atomic operations
1919
// Each thread adds 1 to the first counter
2020
unsafe { atomic_i_add::<_, SCOPE, SEMANTICS>(&mut counters[0], 1) };
21-
22-
// Each thread subtracts 1 from the second counter
21+
22+
// Each thread subtracts 1 from the second counter
2323
unsafe { atomic_i_sub::<_, SCOPE, SEMANTICS>(&mut counters[1], 1) };
24-
24+
2525
// Each thread tries to set minimum with their thread ID
2626
unsafe { atomic_u_min::<_, SCOPE, SEMANTICS>(&mut counters[2], tid) };
27-
27+
2828
// Each thread tries to set maximum with their thread ID
2929
unsafe { atomic_u_max::<_, SCOPE, SEMANTICS>(&mut counters[3], tid) };
30-
30+
3131
// Thread 0 stores the final values after all operations complete
3232
if tid == 0 {
3333
// Use atomic loads to ensure we read the final values

tests/difftests/tests/arch/memory_barriers/memory_barriers-rust/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![no_std]
22

3-
use spirv_std::spirv;
43
use spirv_std::arch::workgroup_memory_barrier_with_group_sync;
4+
use spirv_std::spirv;
55

66
#[spirv(compute(threads(64)))]
77
pub fn main_cs(
@@ -13,19 +13,19 @@ pub fn main_cs(
1313
) {
1414
let tid = global_id.x as usize;
1515
let lid = local_id.x as usize;
16-
16+
1717
if tid < input.len() && tid < output.len() && lid < 64 {
1818
// Load data into shared memory
1919
shared[lid] = input[tid];
20-
20+
2121
// Workgroup barrier to ensure all threads have loaded their data
2222
unsafe {
2323
workgroup_memory_barrier_with_group_sync();
2424
}
25-
25+
2626
// Perform operations on shared memory
2727
let mut result = shared[lid];
28-
28+
2929
// Different threads perform different operations
3030
if lid % 4 == 0 {
3131
// Read from neighboring thread's data
@@ -46,21 +46,21 @@ pub fn main_cs(
4646
// XOR with wrapped neighbor
4747
result ^= shared[(lid + 32) % 64];
4848
}
49-
49+
5050
// Another barrier before writing back
5151
unsafe {
5252
workgroup_memory_barrier_with_group_sync();
5353
}
54-
54+
5555
// Write result back to shared memory
5656
shared[lid] = result;
57-
57+
5858
// Memory barrier to ensure writes are visible
5959
unsafe {
6060
workgroup_memory_barrier_with_group_sync();
6161
}
62-
62+
6363
// Final read and output
6464
output[tid] = shared[lid];
6565
}
66-
}
66+
}
Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
use difftest::config::Config;
2-
use difftest::scaffold::compute::{RustComputeShader, WgpuComputeTestMultiBuffer, BufferConfig, BufferUsage};
2+
use difftest::scaffold::compute::{
3+
BufferConfig, BufferUsage, RustComputeShader, WgpuComputeTestMultiBuffer,
4+
};
35

46
fn main() {
57
let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap();
6-
8+
79
let buffer_size = 256;
810
let initial_data: Vec<u32> = (0..64).collect();
9-
let initial_bytes: Vec<u8> = initial_data.iter()
10-
.flat_map(|&x| x.to_ne_bytes())
11-
.collect();
12-
13-
let test = WgpuComputeTestMultiBuffer::new(
14-
RustComputeShader::default(),
15-
[1, 1, 1],
16-
vec![
17-
BufferConfig {
18-
size: buffer_size,
19-
usage: BufferUsage::StorageReadOnly,
20-
initial_data: Some(initial_bytes),
21-
},
22-
BufferConfig {
23-
size: buffer_size,
24-
usage: BufferUsage::Storage,
25-
initial_data: None,
26-
},
27-
],
28-
);
29-
11+
let initial_bytes: Vec<u8> = initial_data.iter().flat_map(|&x| x.to_ne_bytes()).collect();
12+
13+
let test = WgpuComputeTestMultiBuffer::new(RustComputeShader::default(), [1, 1, 1], vec![
14+
BufferConfig {
15+
size: buffer_size,
16+
usage: BufferUsage::StorageReadOnly,
17+
initial_data: Some(initial_bytes),
18+
},
19+
BufferConfig {
20+
size: buffer_size,
21+
usage: BufferUsage::Storage,
22+
initial_data: None,
23+
},
24+
]);
25+
3026
test.run_test(&config).unwrap();
31-
}
27+
}
Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
use difftest::config::Config;
2-
use difftest::scaffold::compute::{WgslComputeShader, WgpuComputeTestMultiBuffer, BufferConfig, BufferUsage};
2+
use difftest::scaffold::compute::{
3+
BufferConfig, BufferUsage, WgpuComputeTestMultiBuffer, WgslComputeShader,
4+
};
35

46
fn main() {
57
let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap();
6-
8+
79
let buffer_size = 256;
810
let initial_data: Vec<u32> = (0..64).collect();
9-
let initial_bytes: Vec<u8> = initial_data.iter()
10-
.flat_map(|&x| x.to_ne_bytes())
11-
.collect();
12-
13-
let test = WgpuComputeTestMultiBuffer::new(
14-
WgslComputeShader::default(),
15-
[1, 1, 1],
16-
vec![
17-
BufferConfig {
18-
size: buffer_size,
19-
usage: BufferUsage::StorageReadOnly,
20-
initial_data: Some(initial_bytes),
21-
},
22-
BufferConfig {
23-
size: buffer_size,
24-
usage: BufferUsage::Storage,
25-
initial_data: None,
26-
},
27-
],
28-
);
29-
11+
let initial_bytes: Vec<u8> = initial_data.iter().flat_map(|&x| x.to_ne_bytes()).collect();
12+
13+
let test = WgpuComputeTestMultiBuffer::new(WgslComputeShader::default(), [1, 1, 1], vec![
14+
BufferConfig {
15+
size: buffer_size,
16+
usage: BufferUsage::StorageReadOnly,
17+
initial_data: Some(initial_bytes),
18+
},
19+
BufferConfig {
20+
size: buffer_size,
21+
usage: BufferUsage::Storage,
22+
initial_data: None,
23+
},
24+
]);
25+
3026
test.run_test(&config).unwrap();
31-
}
27+
}
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![no_std]
22

3-
use spirv_std::spirv;
43
#[allow(unused_imports)]
54
use spirv_std::num_traits::Float;
5+
use spirv_std::spirv;
66

77
#[repr(C)]
88
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
@@ -22,62 +22,62 @@ pub fn main_cs(
2222
) {
2323
let tid = global_id.x as usize;
2424
let count = push_constants.count as usize;
25-
25+
2626
if tid < input.len() && tid < output.len() && tid < count {
2727
let value = input[tid];
28-
28+
2929
// Apply different operations based on flags
3030
let result = match push_constants.flags {
3131
0 => {
3232
// Linear transformation
3333
value * push_constants.multiplier + push_constants.offset
34-
},
34+
}
3535
1 => {
3636
// Quadratic transformation
3737
value * value * push_constants.multiplier + push_constants.offset
38-
},
38+
}
3939
2 => {
4040
// Sine wave modulation
4141
(value * push_constants.multiplier).sin() + push_constants.offset
42-
},
42+
}
4343
3 => {
4444
// Exponential transformation
4545
(value * push_constants.multiplier).exp() + push_constants.offset
46-
},
46+
}
4747
4 => {
4848
// Logarithmic transformation (with protection against negative values)
4949
if value > 0.0 {
5050
(value * push_constants.multiplier).ln() + push_constants.offset
5151
} else {
5252
push_constants.offset
5353
}
54-
},
54+
}
5555
5 => {
5656
// Reciprocal transformation (with protection against division by zero)
5757
if value.abs() > 0.001 {
5858
push_constants.multiplier / value + push_constants.offset
5959
} else {
6060
push_constants.offset
6161
}
62-
},
62+
}
6363
6 => {
6464
// Power transformation
6565
value.powf(push_constants.multiplier) + push_constants.offset
66-
},
66+
}
6767
7 => {
6868
// Modulo operation (treating multiplier as divisor)
6969
if push_constants.multiplier > 0.0 {
7070
(value % push_constants.multiplier) + push_constants.offset
7171
} else {
7272
push_constants.offset
7373
}
74-
},
74+
}
7575
_ => {
7676
// Default: just add offset
7777
value + push_constants.offset
7878
}
7979
};
80-
80+
8181
output[tid] = result;
8282
}
83-
}
83+
}

tests/difftests/tests/arch/push_constants/push_constants-rust/src/main.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use difftest::config::Config;
2-
use difftest::scaffold::compute::{RustComputeShader, WgpuComputeTestPushConstants, BufferConfig, BufferUsage};
2+
use difftest::scaffold::compute::{
3+
BufferConfig, BufferUsage, RustComputeShader, WgpuComputeTestPushConstants,
4+
};
35

46
#[repr(C)]
57
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
@@ -12,26 +14,22 @@ pub struct PushConstants {
1214

1315
fn main() {
1416
let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap();
15-
17+
1618
let num_elements = 256;
1719
let buffer_size = num_elements * 4; // 4 bytes per f32
18-
20+
1921
// Create input data
20-
let input_data: Vec<f32> = (0..num_elements)
21-
.map(|i| i as f32 * 0.1)
22-
.collect();
23-
let input_bytes: Vec<u8> = input_data.iter()
24-
.flat_map(|&x| x.to_ne_bytes())
25-
.collect();
26-
22+
let input_data: Vec<f32> = (0..num_elements).map(|i| i as f32 * 0.1).collect();
23+
let input_bytes: Vec<u8> = input_data.iter().flat_map(|&x| x.to_ne_bytes()).collect();
24+
2725
// Create push constants data
2826
let push_constants = PushConstants {
2927
multiplier: 2.5,
3028
offset: 1.0,
3129
flags: 0, // Linear transformation
3230
count: num_elements as u32,
3331
};
34-
32+
3533
let test = WgpuComputeTestPushConstants::new(
3634
RustComputeShader::default(),
3735
[4, 1, 1], // 256 / 64 = 4 workgroups
@@ -50,6 +48,6 @@ fn main() {
5048
std::mem::size_of::<PushConstants>() as u32,
5149
bytemuck::bytes_of(&push_constants).to_vec(),
5250
);
53-
51+
5452
test.run_test(&config).unwrap();
55-
}
53+
}

tests/difftests/tests/arch/push_constants/push_constants-wgsl/src/main.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use difftest::config::Config;
2-
use difftest::scaffold::compute::{WgslComputeShader, WgpuComputeTestPushConstants, BufferConfig, BufferUsage};
2+
use difftest::scaffold::compute::{
3+
BufferConfig, BufferUsage, WgpuComputeTestPushConstants, WgslComputeShader,
4+
};
35

46
#[repr(C)]
57
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
@@ -12,26 +14,22 @@ pub struct PushConstants {
1214

1315
fn main() {
1416
let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap();
15-
17+
1618
let num_elements = 256;
1719
let buffer_size = num_elements * 4; // 4 bytes per f32
18-
20+
1921
// Create input data
20-
let input_data: Vec<f32> = (0..num_elements)
21-
.map(|i| i as f32 * 0.1)
22-
.collect();
23-
let input_bytes: Vec<u8> = input_data.iter()
24-
.flat_map(|&x| x.to_ne_bytes())
25-
.collect();
26-
22+
let input_data: Vec<f32> = (0..num_elements).map(|i| i as f32 * 0.1).collect();
23+
let input_bytes: Vec<u8> = input_data.iter().flat_map(|&x| x.to_ne_bytes()).collect();
24+
2725
// Create push constants data
2826
let push_constants = PushConstants {
2927
multiplier: 2.5,
3028
offset: 1.0,
3129
flags: 0, // Linear transformation
3230
count: num_elements as u32,
3331
};
34-
32+
3533
let test = WgpuComputeTestPushConstants::new(
3634
WgslComputeShader::default(),
3735
[4, 1, 1], // 256 / 64 = 4 workgroups
@@ -50,6 +48,6 @@ fn main() {
5048
std::mem::size_of::<PushConstants>() as u32,
5149
bytemuck::bytes_of(&push_constants).to_vec(),
5250
);
53-
51+
5452
test.run_test(&config).unwrap();
55-
}
53+
}

0 commit comments

Comments
 (0)