Skip to content

Commit d11b121

Browse files
committed
(ml5717) Fixed EventBuffer init
1 parent 0ea7c21 commit d11b121

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

necsim-cuda/src/lib.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ macro_rules! with_cuda {
3939
$inner
4040

4141
if let Err((_err, val)) = <$r#type>::drop($var) {
42-
//eprintln!("{:?}", err);
4342
std::mem::forget(val);
4443
}
4544
};
@@ -49,7 +48,6 @@ macro_rules! with_cuda {
4948
$inner
5049

5150
if let Err((_err, val)) = <$r#type>::drop($var) {
52-
//eprintln!("{:?}", err);
5351
std::mem::forget(val);
5452
}
5553
};
@@ -158,7 +156,7 @@ impl CudaSimulation {
158156
rng: G,
159157
reporter: &mut impl Reporter<InMemoryHabitat, InMemoryLineageReference>,
160158
) -> Result<(f64, usize)> {
161-
const SIMULATION_STEP_SLICE: usize = 1_000_usize;
159+
const SIMULATION_STEP_SLICE: usize = 100_usize;
162160

163161
let habitat = InMemoryHabitat::new(habitat.clone());
164162
let dispersal_sampler = InMemoryPackedAliasDispersalSampler::new(dispersal, &habitat)?;
@@ -167,7 +165,6 @@ impl CudaSimulation {
167165
let event_sampler = IndependentEventSampler::default();
168166
let active_lineage_sampler = IndependentActiveLineageSampler::default();
169167

170-
// TODO: Should we copy the heap contents back over?
171168
let mut simulation = Simulation::builder()
172169
.speciation_probability_per_generation(speciation_probability_per_generation)
173170
.habitat(habitat)
@@ -190,15 +187,8 @@ impl CudaSimulation {
190187
+ (total_individuals % cuda_block_length > 0) as u32
191188
});
192189

193-
let mut event_buffer: EventBufferHost<InMemoryHabitat, InMemoryLineageReference> =
194-
EventBufferHost::new(&cuda_block_size, &cuda_grid_size, SIMULATION_STEP_SLICE)?;
195-
196-
//let (time, steps) = simulation.simulate(rng, reporter);
197-
198190
let module_data = CString::new(include_str!(env!("KERNEL_PTX_PATH"))).unwrap();
199191

200-
//println!("{}", module_data.to_str().unwrap());
201-
202192
// Initialize the CUDA API
203193
rustacuda::init(CudaFlags::empty())?;
204194

@@ -221,6 +211,9 @@ impl CudaSimulation {
221211
print_context_resource_limits();
222212
print_kernel_function_attributes(&simulate_kernel);
223213

214+
let mut event_buffer: EventBufferHost<InMemoryHabitat, InMemoryLineageReference> =
215+
EventBufferHost::new(&cuda_block_size, &cuda_grid_size, SIMULATION_STEP_SLICE)?;
216+
224217
if let Err(err) = simulation.lend_to_cuda_mut(|simulation_mut_ptr| {
225218
let block_index_range = 0..(cuda_grid_size.x * cuda_grid_size.y * cuda_grid_size.z);
226219

necsim-impls-cuda/src/event_buffer/device.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ impl<H: Habitat + RustToCuda, R: LineageReference<H> + DeviceCopy> EventBufferDe
4040
let cuda_repr_ref: &mut super::common::EventBufferCudaRepresentation<H, R> =
4141
&mut *cuda_repr_ptr;
4242

43-
let buffer_len = cuda_repr_ref.block_size * cuda_repr_ref.grid_size;
43+
let buffer_len =
44+
cuda_repr_ref.block_size * cuda_repr_ref.grid_size * cuda_repr_ref.max_events;
4445

4546
let raw_slice: &mut [Option<Event<H, R>>] =
4647
core::slice::from_raw_parts_mut(cuda_repr_ref.device_buffer.as_raw_mut(), buffer_len);

0 commit comments

Comments
 (0)