@@ -44,35 +44,43 @@ use necsim_core::cogs::{
4444 IncoherentLineageStore , LineageReference ,
4545} ;
4646use necsim_core:: reporter:: NullReporter ;
47+ use necsim_core:: rng:: Rng ;
4748use necsim_core:: simulation:: Simulation ;
48- use necsim_impls_no_std:: rng:: wyrng :: WyRng ;
49+ use necsim_impls_no_std:: rng:: cuda :: CudaRng ;
4950use rust_cuda:: common:: RustToCuda ;
5051use rust_cuda:: device:: BorrowFromRust ;
5152use rustacuda_core:: DeviceCopy ;
5253
5354#[ no_mangle]
5455/// # Safety
5556/// This CUDA kernel is unsafe as it is called with raw pointers
56- pub unsafe extern "ptx-kernel" fn simulate ( c_void_ptr : * mut core:: ffi:: c_void ) {
57- use necsim_impls_no_std:: cogs:: active_lineage_sampler:: independent:: IndependentActiveLineageSampler ;
58- use necsim_impls_no_std:: cogs:: coalescence_sampler:: independent:: IndependentCoalescenceSampler ;
59- use necsim_impls_no_std:: cogs:: dispersal_sampler:: in_memory:: packed_alias:: InMemoryPackedAliasDispersalSampler ;
60- use necsim_impls_no_std:: cogs:: event_sampler:: independent:: IndependentEventSampler ;
61- use necsim_impls_no_std:: cogs:: habitat:: in_memory:: InMemoryHabitat ;
62- use necsim_impls_no_std:: cogs:: lineage_reference:: in_memory:: InMemoryLineageReference ;
63- use necsim_impls_no_std:: cogs:: lineage_store:: incoherent:: in_memory:: IncoherentInMemoryLineageStore ;
57+ pub unsafe extern "ptx-kernel" fn simulate (
58+ simulation_c_ptr : * mut core:: ffi:: c_void ,
59+ cuda_rng_c_ptr : * mut core:: ffi:: c_void ,
60+ max_steps : usize ,
61+ ) {
62+ use necsim_impls_no_std:: cogs:: active_lineage_sampler:: independent:: IndependentActiveLineageSampler as ActiveLineageSampler ;
63+ use necsim_impls_no_std:: cogs:: coalescence_sampler:: independent:: IndependentCoalescenceSampler as CoalescenceSampler ;
64+ use necsim_impls_no_std:: cogs:: dispersal_sampler:: in_memory:: packed_alias:: InMemoryPackedAliasDispersalSampler as DispersalSampler ;
65+ use necsim_impls_no_std:: cogs:: event_sampler:: independent:: IndependentEventSampler as EventSampler ;
66+ use necsim_impls_no_std:: cogs:: habitat:: in_memory:: InMemoryHabitat as Habitat ;
67+ use necsim_impls_no_std:: cogs:: lineage_reference:: in_memory:: InMemoryLineageReference as LineageReference ;
68+ use necsim_impls_no_std:: cogs:: lineage_store:: incoherent:: in_memory:: IncoherentInMemoryLineageStore as LineageStore ;
69+ use necsim_impls_no_std:: rng:: aes:: AesRng as Rng ;
6470
6571 simulate_generic (
66- c_void_ptr
72+ simulation_c_ptr
6773 as * mut <Simulation <
68- InMemoryHabitat ,
69- InMemoryPackedAliasDispersalSampler ,
70- InMemoryLineageReference ,
71- IncoherentInMemoryLineageStore < _ > ,
72- IndependentCoalescenceSampler < _ , _ , _ > ,
73- IndependentEventSampler < _ , _ , _ , _ > ,
74- IndependentActiveLineageSampler < _ , _ , _ , _ > ,
74+ Habitat ,
75+ DispersalSampler ,
76+ LineageReference ,
77+ LineageStore < _ > ,
78+ CoalescenceSampler < _ , _ , _ > ,
79+ EventSampler < _ , _ , _ , _ > ,
80+ ActiveLineageSampler < _ , _ , _ , _ > ,
7581 > as RustToCuda >:: CudaRepresentation ,
82+ cuda_rng_c_ptr as * mut <CudaRng < Rng > as RustToCuda >:: CudaRepresentation ,
83+ max_steps,
7684 )
7785}
7886
@@ -84,21 +92,21 @@ unsafe fn simulate_generic<
8492 C : CoalescenceSampler < H , R , S > + RustToCuda ,
8593 E : EventSampler < H , D , R , S , C > + RustToCuda ,
8694 A : ActiveLineageSampler < H , D , R , S , C , E > + RustToCuda ,
95+ G : Rng ,
8796> (
8897 simulation_ptr : * mut <Simulation < H , D , R , S , C , E , A > as RustToCuda >:: CudaRepresentation ,
98+ cuda_rng_ptr : * mut <CudaRng < G > as RustToCuda >:: CudaRepresentation ,
99+ max_steps : usize ,
89100) {
90101 Simulation :: with_borrow_from_rust_mut ( simulation_ptr, |simulation| {
91- let max_steps: usize = 100 ;
92- #[ allow( clippy:: cast_sign_loss) ]
93- let rng_seed: u64 = utils:: index ( ) as u64 ;
94-
95- let mut rng = WyRng :: from_seed ( rng_seed) ;
96- let mut reporter = NullReporter ;
102+ CudaRng :: with_borrow_from_rust_mut ( cuda_rng_ptr, |cuda_rng| {
103+ let mut reporter = NullReporter ;
97104
98- //println!("{:#?}", simulation);
105+ //println!("{:#?}", simulation);
99106
100- let ( time, steps) = simulation. simulate_incremental ( max_steps, & mut rng , & mut reporter) ;
107+ let ( time, steps) = simulation. simulate_incremental ( max_steps, cuda_rng , & mut reporter) ;
101108
102- println ! ( "time = {:?}, steps = {}" , F64 ( time) , steps) ;
109+ println ! ( "time = {:?}, steps = {}" , F64 ( time) , steps) ;
110+ } )
103111 } )
104112}
0 commit comments