Fixing fast radix
This commit is contained in:
+27
-15
@@ -47,6 +47,8 @@ pub struct RadixSorter
|
||||
|
||||
histogram_pass: ComputePipeline,
|
||||
prefix_sum_pass: ComputePipeline,
|
||||
total_prefix_sum_pass: ComputePipeline,
|
||||
scatter_pass: ComputePipeline,
|
||||
|
||||
timing_query_set: QuerySet,
|
||||
pub timing_buffer: Buffer,
|
||||
@@ -70,7 +72,7 @@ impl RadixSorter
|
||||
const WG_THREAD_COUNT: usize = 256;
|
||||
|
||||
// Elements managed per thread for histo build
|
||||
const WE_HISTO_ELEMENTS: usize = 16;
|
||||
const WE_HISTO_ELEMENTS: usize = 1;
|
||||
|
||||
// Elements managed per workgroup for histo build
|
||||
const WG_HISTO_ELEMENTS: usize = Self::WG_THREAD_COUNT * Self::WE_HISTO_ELEMENTS;
|
||||
@@ -222,7 +224,16 @@ impl RadixSorter
|
||||
cache: None,
|
||||
});
|
||||
|
||||
/*
|
||||
let total_prefix_sum_pass =
|
||||
device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
|
||||
label: Some("RadixSorter::total_prefix_sum_pass"),
|
||||
layout: Some(&pipelines_layout),
|
||||
module: &radix_sort_shader_module,
|
||||
entry_point: Some("total_prefix_sum_pass"),
|
||||
compilation_options: compilation_options.clone(),
|
||||
cache: None,
|
||||
});
|
||||
|
||||
let scatter_pass = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
|
||||
label: Some("RadixSorter::scatter_pass"),
|
||||
layout: Some(&pipelines_layout),
|
||||
@@ -232,17 +243,6 @@ impl RadixSorter
|
||||
cache: None,
|
||||
});
|
||||
|
||||
let indirect_count_pass =
|
||||
device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
|
||||
label: Some("RadixSorter::indirect_count_pass"),
|
||||
layout: Some(&pipelines_layout),
|
||||
module: &radix_sort_shader_module,
|
||||
entry_point: Some("indirect_count_pass"),
|
||||
compilation_options: compilation_options.clone(),
|
||||
cache: None,
|
||||
});
|
||||
*/
|
||||
|
||||
let timing_buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some("RadixSorter::timing_buffer"),
|
||||
size: (size_of::<u64>() * 2) as u64,
|
||||
@@ -271,6 +271,8 @@ impl RadixSorter
|
||||
|
||||
histogram_pass,
|
||||
prefix_sum_pass,
|
||||
total_prefix_sum_pass,
|
||||
scatter_pass,
|
||||
|
||||
timing_buffer,
|
||||
timing_query_set,
|
||||
@@ -288,7 +290,7 @@ impl RadixSorter
|
||||
{
|
||||
dbg!(self.histogram_count);
|
||||
let data_buffer_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
label: Some("RadixSorter::double_buffer_bind_group"),
|
||||
label: Some("RadixSorter::data_buffer_bind_group"),
|
||||
layout: &self.data_bind_group_layout,
|
||||
entries: &[
|
||||
// Keys
|
||||
@@ -314,7 +316,6 @@ impl RadixSorter
|
||||
end_of_pass_write_index: Some(1),
|
||||
}),
|
||||
});
|
||||
compute_pass.set_bind_group(0, &self.histograms_bind_group, &[]);
|
||||
|
||||
for i in 0..Self::PASS_COUNT
|
||||
{
|
||||
@@ -341,9 +342,20 @@ impl RadixSorter
|
||||
// ~~ Prefix sum pass
|
||||
compute_pass.set_pipeline(&self.prefix_sum_pass);
|
||||
compute_pass.set_immediates(0, bytes);
|
||||
compute_pass.dispatch_workgroups(Self::VALUE_COUNT as u32, 1, 1);
|
||||
|
||||
compute_pass.set_pipeline(&self.total_prefix_sum_pass);
|
||||
compute_pass.set_immediates(0, bytes);
|
||||
compute_pass.dispatch_workgroups(1, 1, 1);
|
||||
|
||||
//compute_pass.dispatch_workgroups_indirect(&self., 0);
|
||||
compute_pass.set_pipeline(&self.scatter_pass);
|
||||
compute_pass.set_immediates(0, bytes);
|
||||
compute_pass.dispatch_workgroups(
|
||||
self.max_size.div_ceil(Self::WG_THREAD_COUNT) as u32,
|
||||
1,
|
||||
1,
|
||||
);
|
||||
}
|
||||
|
||||
// Even number of passes => data is in the user buffer
|
||||
|
||||
+35
-33
@@ -198,11 +198,13 @@ impl State
|
||||
let mut encoder = device.create_command_encoder(&Default::default());
|
||||
|
||||
println!("Making elements");
|
||||
let elt_count = 1_000_000u32;
|
||||
let elt_count = (1 << 20) as u32;
|
||||
//let elt_count = 256 as u32;
|
||||
let org_big_value_buffer = (0..(elt_count as u32)).collect::<Vec<_>>();
|
||||
let org_big_key_buffer = org_big_value_buffer
|
||||
.iter()
|
||||
.map(|_| random::<u32>())
|
||||
//.map(|_| random::<u32>())
|
||||
.map(|_| random_range(1..256))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let sorted_values = org_big_key_buffer
|
||||
@@ -255,37 +257,37 @@ impl State
|
||||
},
|
||||
);
|
||||
|
||||
// wgpu::util::DownloadBuffer::read_buffer(
|
||||
// &device,
|
||||
// &queue,
|
||||
// &big_key_buffer.slice(..),
|
||||
// |clbk| {
|
||||
// let data_bytes = clbk.unwrap().to_vec();
|
||||
// let data = data_bytes
|
||||
// .chunks(4)
|
||||
// .map(|x| u32::from_ne_bytes([x[0], x[1], x[2], x[3]]))
|
||||
// .collect::<Vec<u32>>();
|
||||
// println!("{:?}", &data[0..512]);
|
||||
// },
|
||||
// );
|
||||
//
|
||||
// wgpu::util::DownloadBuffer::read_buffer(
|
||||
// &device,
|
||||
// &queue,
|
||||
// &big_value_buffer.slice(..),
|
||||
// move |clbk| {
|
||||
// let data_bytes = clbk.unwrap().to_vec();
|
||||
// let data = data_bytes
|
||||
// .chunks(4)
|
||||
// .map(|x| u32::from_ne_bytes([x[0], x[1], x[2], x[3]]))
|
||||
// .collect::<Vec<u32>>();
|
||||
// for (gpu_key, key) in data.iter().zip(sorted_values.iter())
|
||||
// {
|
||||
// assert_eq!(gpu_key, key, "FUCK YOU");
|
||||
// }
|
||||
// println!("Finished check !");
|
||||
// },
|
||||
// );
|
||||
wgpu::util::DownloadBuffer::read_buffer(
|
||||
&device,
|
||||
&queue,
|
||||
&big_key_buffer.slice(..),
|
||||
|clbk| {
|
||||
let data_bytes = clbk.unwrap().to_vec();
|
||||
let data = data_bytes
|
||||
.chunks(4)
|
||||
.map(|x| u32::from_ne_bytes([x[0], x[1], x[2], x[3]]))
|
||||
.collect::<Vec<u32>>();
|
||||
println!("{:?}", &data[0..256]);
|
||||
},
|
||||
);
|
||||
|
||||
wgpu::util::DownloadBuffer::read_buffer(
|
||||
&device,
|
||||
&queue,
|
||||
&big_value_buffer.slice(..),
|
||||
move |clbk| {
|
||||
let data_bytes = clbk.unwrap().to_vec();
|
||||
let data = data_bytes
|
||||
.chunks(4)
|
||||
.map(|x| u32::from_ne_bytes([x[0], x[1], x[2], x[3]]))
|
||||
.collect::<Vec<u32>>();
|
||||
for (gpu_key, key) in data.iter().zip(sorted_values.iter())
|
||||
{
|
||||
assert_eq!(gpu_key, key, "FUCK YOU");
|
||||
}
|
||||
println!("Finished check !");
|
||||
},
|
||||
);
|
||||
|
||||
device.poll(wgpu::wgt::PollType::Poll);
|
||||
panic!();
|
||||
|
||||
Reference in New Issue
Block a user