Skip to content

Commit 29b098e

Browse files
committed
Some progress
1 parent ca0f10f commit 29b098e

File tree

21 files changed

+172
-402
lines changed

21 files changed

+172
-402
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

necsim/core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ contracts = "0.6.3"
2020
serde = { version = "1.0", default-features = false, features = ["derive"] }
2121

2222
[target.'cfg(target_os = "cuda")'.dependencies]
23-
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "fc18c79", features = ["derive"], optional = true }
23+
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "8dc0c6d", features = ["derive"], optional = true }
2424

2525
[target.'cfg(not(target_os = "cuda"))'.dependencies]
26-
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "fc18c79", features = ["derive", "host"], optional = true }
26+
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "8dc0c6d", features = ["derive", "host"], optional = true }

necsim/core/src/lineage.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@ impl From<Option<GlobalLineageReference>> for LineageInteraction {
9999
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, TypeLayout)]
100100
#[cfg_attr(feature = "cuda", derive(rust_cuda::lend::LendRustToCuda))]
101101
#[repr(C)]
102-
#[cuda(ignore)]
102+
#[cfg_attr(feature = "cuda", cuda(ignore))]
103103
#[serde(deny_unknown_fields)]
104104
pub struct Lineage {
105-
#[cuda(embed)]
106-
#[cuda(ignore)]
105+
#[cfg_attr(feature = "cuda", cuda(embed))]
106+
#[cfg_attr(feature = "cuda", cuda(ignore))]
107107
#[serde(alias = "id", alias = "ref")]
108108
pub global_reference: GlobalLineageReference,
109-
#[cuda(ignore)]
109+
#[cfg_attr(feature = "cuda", cuda(ignore))]
110110
#[serde(alias = "time")]
111111
pub last_event_time: NonNegativeF64,
112-
#[cuda(ignore)]
112+
#[cfg_attr(feature = "cuda", cuda(ignore))]
113113
#[serde(alias = "loc")]
114114
pub indexed_location: IndexedLocation,
115115
}

necsim/impls/cuda/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ contracts = "0.6.3"
1515
serde = { version = "1.0", default-features = false, features = ["derive"] }
1616

1717
[target.'cfg(target_os = "cuda")'.dependencies]
18-
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "fc18c79", features = ["derive"] }
18+
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "8dc0c6d", features = ["derive"] }
1919

2020
[target.'cfg(not(target_os = "cuda"))'.dependencies]
21-
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "fc18c79", features = ["derive", "host"] }
21+
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "8dc0c6d", features = ["derive", "host"] }

necsim/impls/no-std/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fnv = { version = "1.0", default-features = false, features = [] }
3030
rand_core = "0.6"
3131

3232
[target.'cfg(target_os = "cuda")'.dependencies]
33-
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "fc18c79", features = ["derive", "final"], optional = true }
33+
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "8dc0c6d", features = ["derive", "final"], optional = true }
3434

3535
[target.'cfg(not(target_os = "cuda"))'.dependencies]
36-
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "fc18c79", features = ["derive", "final", "host"], optional = true }
36+
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "8dc0c6d", features = ["derive", "final", "host"], optional = true }

necsim/impls/no-std/src/cogs/rng/seahash.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::marker::PhantomData;
22

3-
use necsim_core::cogs::{Backup, MathsCore, PrimeableRng, RngCore};
3+
use necsim_core::cogs::{MathsCore, PrimeableRng, RngCore};
44

55
use serde::{Deserialize, Serialize};
66

@@ -17,12 +17,7 @@ pub struct SeaHash<M: MathsCore> {
1717
marker: PhantomData<M>,
1818
}
1919

20-
#[contract_trait]
21-
impl<M: MathsCore> Backup for SeaHash<M> {
22-
unsafe fn backup_unchecked(&self) -> Self {
23-
self.clone()
24-
}
25-
}
20+
impl<M: MathsCore> Copy for SeaHash<M> {}
2621

2722
impl<M: MathsCore> RngCore<M> for SeaHash<M> {
2823
type Seed = [u8; 8];

necsim/impls/no-std/src/cogs/rng/wyhash.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::marker::PhantomData;
22

3-
use necsim_core::cogs::{Backup, MathsCore, PrimeableRng, RngCore};
3+
use necsim_core::cogs::{MathsCore, PrimeableRng, RngCore};
44

55
use serde::{Deserialize, Serialize};
66

@@ -23,12 +23,7 @@ pub struct WyHash<M: MathsCore> {
2323
marker: PhantomData<M>,
2424
}
2525

26-
#[contract_trait]
27-
impl<M: MathsCore> Backup for WyHash<M> {
28-
unsafe fn backup_unchecked(&self) -> Self {
29-
self.clone()
30-
}
31-
}
26+
impl<M: MathsCore> Copy for WyHash<M> {}
3227

3328
impl<M: MathsCore> RngCore<M> for WyHash<M> {
3429
type Seed = [u8; 8];

rustcoalescence/algorithms/cuda/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ thiserror = "1.0"
2323
serde = { version = "1.0", features = ["derive"] }
2424
serde_state = "0.4"
2525
serde_derive_state = "0.4"
26-
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "fc18c79", features = ["host"] }
26+
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "8dc0c6d", features = ["host"] }

rustcoalescence/algorithms/cuda/cpu-kernel/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ necsim-impls-no-std = { path = "../../../../necsim/impls/no-std", features = ["c
1414
necsim-impls-cuda = { path = "../../../../necsim/impls/cuda" }
1515
rustcoalescence-algorithms-cuda-gpu-kernel = { path = "../gpu-kernel" }
1616

17-
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "fc18c79", features = ["host"] }
17+
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "8dc0c6d", features = ["host"] }
Lines changed: 18 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![deny(clippy::pedantic)]
2-
#![allow(incomplete_features)]
3-
#![feature(specialization)]
2+
#![feature(c_str_literals)]
3+
#![feature(min_specialization)]
44
#![recursion_limit = "1024"]
55

66
use necsim_core::{
@@ -16,178 +16,25 @@ use necsim_impls_no_std::cogs::{
1616
event_sampler::tracking::MinSpeciationTrackingEventSampler,
1717
};
1818

19-
use rust_cuda::{
20-
common::RustToCuda,
21-
host::{CudaDropWrapper, LaunchConfig, LaunchPackage, Launcher, TypedKernel},
22-
rustacuda::{
23-
error::CudaResult,
24-
function::{BlockSize, Function, GridSize},
25-
stream::Stream,
26-
},
27-
};
28-
29-
use rustcoalescence_algorithms_cuda_gpu_kernel::SimulatableKernel;
19+
use rust_cuda::lend::RustToCuda;
3020

3121
mod link;
3222
mod patch;
3323

34-
pub type KernelCompilationCallback = dyn FnMut(&Function) -> CudaResult<()>;
35-
36-
#[allow(clippy::module_name_repetitions)]
37-
pub struct SimulationKernel<
38-
M: MathsCore,
39-
H: Habitat<M> + RustToCuda,
40-
G: PrimeableRng<M> + RustToCuda,
41-
S: LineageStore<M, H> + RustToCuda,
42-
X: EmigrationExit<M, H, G, S> + RustToCuda,
43-
D: DispersalSampler<M, H, G> + RustToCuda,
44-
C: CoalescenceSampler<M, H, S> + RustToCuda,
45-
T: TurnoverRate<M, H> + RustToCuda,
46-
N: SpeciationProbability<M, H> + RustToCuda,
47-
E: MinSpeciationTrackingEventSampler<M, H, G, S, X, D, C, T, N> + RustToCuda,
48-
I: ImmigrationEntry<M> + RustToCuda,
49-
A: SingularActiveLineageSampler<M, H, G, S, X, D, C, T, N, E, I> + RustToCuda,
24+
#[allow(clippy::type_complexity)]
25+
pub struct SimulationKernelPtx<
26+
M: MathsCore + Sync,
27+
H: Habitat<M> + RustToCuda + Sync,
28+
G: PrimeableRng<M> + RustToCuda + Sync,
29+
S: LineageStore<M, H> + RustToCuda + Sync,
30+
X: EmigrationExit<M, H, G, S> + RustToCuda + Sync,
31+
D: DispersalSampler<M, H, G> + RustToCuda + Sync,
32+
C: CoalescenceSampler<M, H, S> + RustToCuda + Sync,
33+
T: TurnoverRate<M, H> + RustToCuda + Sync,
34+
N: SpeciationProbability<M, H> + RustToCuda + Sync,
35+
E: MinSpeciationTrackingEventSampler<M, H, G, S, X, D, C, T, N> + RustToCuda + Sync,
36+
I: ImmigrationEntry<M> + RustToCuda + Sync,
37+
A: SingularActiveLineageSampler<M, H, G, S, X, D, C, T, N, E, I> + RustToCuda + Sync,
5038
ReportSpeciation: Boolean,
5139
ReportDispersal: Boolean,
52-
> {
53-
#[allow(clippy::type_complexity)]
54-
kernel: TypedKernel<
55-
dyn SimulatableKernel<
56-
M,
57-
H,
58-
G,
59-
S,
60-
X,
61-
D,
62-
C,
63-
T,
64-
N,
65-
E,
66-
I,
67-
A,
68-
ReportSpeciation,
69-
ReportDispersal,
70-
>,
71-
>,
72-
stream: CudaDropWrapper<Stream>,
73-
grid: GridSize,
74-
block: BlockSize,
75-
ptx_jit: bool,
76-
watcher: Box<KernelCompilationCallback>,
77-
}
78-
79-
impl<
80-
M: MathsCore,
81-
H: Habitat<M> + RustToCuda,
82-
G: PrimeableRng<M> + RustToCuda,
83-
S: LineageStore<M, H> + RustToCuda,
84-
X: EmigrationExit<M, H, G, S> + RustToCuda,
85-
D: DispersalSampler<M, H, G> + RustToCuda,
86-
C: CoalescenceSampler<M, H, S> + RustToCuda,
87-
T: TurnoverRate<M, H> + RustToCuda,
88-
N: SpeciationProbability<M, H> + RustToCuda,
89-
E: MinSpeciationTrackingEventSampler<M, H, G, S, X, D, C, T, N> + RustToCuda,
90-
I: ImmigrationEntry<M> + RustToCuda,
91-
A: SingularActiveLineageSampler<M, H, G, S, X, D, C, T, N, E, I> + RustToCuda,
92-
ReportSpeciation: Boolean,
93-
ReportDispersal: Boolean,
94-
> SimulationKernel<M, H, G, S, X, D, C, T, N, E, I, A, ReportSpeciation, ReportDispersal>
95-
{
96-
/// # Errors
97-
///
98-
/// Returns a `CudaError` if loading the CUDA kernel failed.
99-
pub fn try_new(
100-
stream: Stream,
101-
grid: GridSize,
102-
block: BlockSize,
103-
ptx_jit: bool,
104-
on_compile: Box<KernelCompilationCallback>,
105-
) -> CudaResult<Self>
106-
where
107-
Self: SimulatableKernel<
108-
M,
109-
H,
110-
G,
111-
S,
112-
X,
113-
D,
114-
C,
115-
T,
116-
N,
117-
E,
118-
I,
119-
A,
120-
ReportSpeciation,
121-
ReportDispersal,
122-
>,
123-
{
124-
let stream = CudaDropWrapper::from(stream);
125-
let kernel = Self::new_kernel()?;
126-
127-
Ok(Self {
128-
kernel,
129-
stream,
130-
grid,
131-
block,
132-
ptx_jit,
133-
watcher: on_compile,
134-
})
135-
}
136-
}
137-
138-
impl<
139-
M: MathsCore,
140-
H: Habitat<M> + RustToCuda,
141-
G: PrimeableRng<M> + RustToCuda,
142-
S: LineageStore<M, H> + RustToCuda,
143-
X: EmigrationExit<M, H, G, S> + RustToCuda,
144-
D: DispersalSampler<M, H, G> + RustToCuda,
145-
C: CoalescenceSampler<M, H, S> + RustToCuda,
146-
T: TurnoverRate<M, H> + RustToCuda,
147-
N: SpeciationProbability<M, H> + RustToCuda,
148-
E: MinSpeciationTrackingEventSampler<M, H, G, S, X, D, C, T, N> + RustToCuda,
149-
I: ImmigrationEntry<M> + RustToCuda,
150-
A: SingularActiveLineageSampler<M, H, G, S, X, D, C, T, N, E, I> + RustToCuda,
151-
ReportSpeciation: Boolean,
152-
ReportDispersal: Boolean,
153-
> Launcher
154-
for SimulationKernel<M, H, G, S, X, D, C, T, N, E, I, A, ReportSpeciation, ReportDispersal>
155-
{
156-
type CompilationWatcher = Box<KernelCompilationCallback>;
157-
type KernelTraitObject = dyn SimulatableKernel<
158-
M,
159-
H,
160-
G,
161-
S,
162-
X,
163-
D,
164-
C,
165-
T,
166-
N,
167-
E,
168-
I,
169-
A,
170-
ReportSpeciation,
171-
ReportDispersal,
172-
>;
173-
174-
fn get_launch_package(&mut self) -> LaunchPackage<Self> {
175-
LaunchPackage {
176-
config: LaunchConfig {
177-
grid: self.grid.clone(),
178-
block: self.block.clone(),
179-
shared_memory_size: 0_u32,
180-
ptx_jit: self.ptx_jit,
181-
},
182-
183-
kernel: &mut self.kernel,
184-
stream: &mut self.stream,
185-
186-
watcher: &mut self.watcher,
187-
}
188-
}
189-
190-
fn on_compile(kernel: &Function, watcher: &mut Self::CompilationWatcher) -> CudaResult<()> {
191-
(watcher)(kernel)
192-
}
193-
}
40+
>(std::marker::PhantomData<(M, H, G, S, X, D, C, T, N, E, I, A, ReportSpeciation, ReportDispersal)>);

0 commit comments

Comments
 (0)