Skip to content

Commit

Permalink
Some more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
juntyr committed Jan 11, 2024
1 parent b6dd445 commit 775094a
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 70 deletions.
7 changes: 3 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions necsim/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contracts = "0.6.3"
serde = { version = "1.0", default-features = false, features = ["derive"] }

[target.'cfg(target_os = "cuda")'.dependencies]
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "dd9507d", features = ["derive"], optional = true }
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "5e1534c", features = ["derive"], optional = true }

[target.'cfg(not(target_os = "cuda"))'.dependencies]
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "dd9507d", features = ["derive", "host"], optional = true }
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "5e1534c", features = ["derive", "host"], optional = true }
22 changes: 12 additions & 10 deletions necsim/core/src/landscape/extent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use necsim_core_bond::OffByOneU32;
use super::Location;

#[allow(clippy::module_name_repetitions, clippy::unsafe_derive_deserialize)]
#[derive(PartialEq, Eq, Copy, Clone, Debug, serde::Deserialize, serde::Serialize, TypeLayout)]
#[derive(PartialEq, Eq, Clone, Debug, serde::Deserialize, serde::Serialize, TypeLayout)]
#[cfg_attr(feature = "cuda", derive(rust_cuda::lend::LendRustToCuda))]
#[repr(C)]
#[cfg_attr(feature = "cuda", cuda(ignore))]
#[serde(rename = "Extent")]
#[serde(deny_unknown_fields)]
#[repr(C)]
pub struct LandscapeExtent {
x: u32,
y: u32,
Expand Down Expand Up @@ -58,7 +60,7 @@ impl LandscapeExtent {
LocationIterator {
x: self.x,
y: self.y,
extent: *self,
extent: self.clone(),
first_y: true,
}
}
Expand Down Expand Up @@ -186,7 +188,7 @@ mod tests {
LocationIterator {
x: 0,
y: 0,
extent,
extent: extent.clone(),
first_y: true,
}
);
Expand All @@ -200,7 +202,7 @@ mod tests {
LocationIterator {
x: 0,
y: 0,
extent,
extent: extent.clone(),
first_y: false,
}
);
Expand Down Expand Up @@ -230,7 +232,7 @@ mod tests {
LocationIterator {
x: 1386,
y: 6812,
extent,
extent: extent.clone(),
first_y: true,
}
);
Expand All @@ -242,7 +244,7 @@ mod tests {
LocationIterator {
x: 0,
y: 6812,
extent,
extent: extent.clone(),
first_y: true,
}
);
Expand All @@ -255,7 +257,7 @@ mod tests {
LocationIterator {
x: 1386,
y: 6813,
extent,
extent: extent.clone(),
first_y: false,
}
);
Expand All @@ -269,7 +271,7 @@ mod tests {
LocationIterator {
x: 1386,
y: 0,
extent,
extent: extent.clone(),
first_y: false,
}
);
Expand All @@ -283,7 +285,7 @@ mod tests {
LocationIterator {
x: 1386,
y: 6812,
extent,
extent: extent.clone(),
first_y: false,
}
);
Expand Down
4 changes: 2 additions & 2 deletions necsim/impls/cuda/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contracts = "0.6.3"
serde = { version = "1.0", default-features = false, features = ["derive"] }

[target.'cfg(target_os = "cuda")'.dependencies]
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "dd9507d", features = ["derive"] }
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "5e1534c", features = ["derive"] }

[target.'cfg(not(target_os = "cuda"))'.dependencies]
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "dd9507d", features = ["derive", "host"] }
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "5e1534c", features = ["derive", "host"] }
51 changes: 28 additions & 23 deletions necsim/impls/cuda/src/cogs/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use core::marker::PhantomData;
use necsim_core::cogs::{MathsCore, PrimeableRng, RngCore};

use const_type_layout::TypeGraphLayout;
use rust_cuda::safety::{PortableBitSemantics, StackOnly};
use rust_cuda::{
safety::{PortableBitSemantics, StackOnly},
utils::adapter::RustToCudaWithPortableBitCloneSemantics,
};

use serde::{Deserialize, Deserializer, Serialize, Serializer};

Expand All @@ -12,46 +15,53 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[cuda(free = "M", free = "R")]
pub struct CudaRng<M: MathsCore, R>
where
R: RngCore<M> + Copy + StackOnly + PortableBitSemantics + TypeGraphLayout,
R: RngCore<M> + StackOnly + PortableBitSemantics + TypeGraphLayout,
{
inner: R,
#[cuda(embed)]
inner: RustToCudaWithPortableBitCloneSemantics<R>,
marker: PhantomData<M>,
}

impl<M: MathsCore, R: RngCore<M> + Copy + StackOnly + PortableBitSemantics + TypeGraphLayout> Clone
impl<M: MathsCore, R: RngCore<M> + StackOnly + PortableBitSemantics + TypeGraphLayout + Copy> Copy
for CudaRng<M, R>
{
}

#[allow(clippy::expl_impl_clone_on_copy)]
impl<M: MathsCore, R: RngCore<M> + StackOnly + PortableBitSemantics + TypeGraphLayout> Clone
for CudaRng<M, R>
{
fn clone(&self) -> Self {
Self {
inner: self.inner,
inner: self.inner.clone(),
marker: PhantomData::<M>,
}
}
}

impl<M: MathsCore, R: RngCore<M> + Copy + StackOnly + PortableBitSemantics + TypeGraphLayout>
From<R> for CudaRng<M, R>
impl<M: MathsCore, R: RngCore<M> + StackOnly + PortableBitSemantics + TypeGraphLayout> From<R>
for CudaRng<M, R>
{
#[must_use]
#[inline]
fn from(rng: R) -> Self {
Self {
inner: rng,
inner: rng.into(),
marker: PhantomData::<M>,
}
}
}

impl<M: MathsCore, R: RngCore<M> + Copy + StackOnly + PortableBitSemantics + TypeGraphLayout>
RngCore<M> for CudaRng<M, R>
impl<M: MathsCore, R: RngCore<M> + StackOnly + PortableBitSemantics + TypeGraphLayout> RngCore<M>
for CudaRng<M, R>
{
type Seed = <R as RngCore<M>>::Seed;

#[must_use]
#[inline]
fn from_seed(seed: Self::Seed) -> Self {
Self {
inner: R::from_seed(seed),
inner: R::from_seed(seed).into(),
marker: PhantomData::<M>,
}
}
Expand All @@ -63,33 +73,28 @@ impl<M: MathsCore, R: RngCore<M> + Copy + StackOnly + PortableBitSemantics + Typ
}
}

impl<
M: MathsCore,
R: PrimeableRng<M> + Copy + StackOnly + PortableBitSemantics + TypeGraphLayout,
> PrimeableRng<M> for CudaRng<M, R>
impl<M: MathsCore, R: PrimeableRng<M> + StackOnly + PortableBitSemantics + TypeGraphLayout>
PrimeableRng<M> for CudaRng<M, R>
{
#[inline]
fn prime_with(&mut self, location_index: u64, time_index: u64) {
self.inner.prime_with(location_index, time_index);
}
}

impl<M: MathsCore, R: RngCore<M> + Copy + StackOnly + PortableBitSemantics + TypeGraphLayout>
Serialize for CudaRng<M, R>
impl<M: MathsCore, R: RngCore<M> + StackOnly + PortableBitSemantics + TypeGraphLayout> Serialize
for CudaRng<M, R>
{
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.inner.serialize(serializer)
}
}

impl<
'de,
M: MathsCore,
R: RngCore<M> + Copy + StackOnly + PortableBitSemantics + TypeGraphLayout,
> Deserialize<'de> for CudaRng<M, R>
impl<'de, M: MathsCore, R: RngCore<M> + StackOnly + PortableBitSemantics + TypeGraphLayout>
Deserialize<'de> for CudaRng<M, R>
{
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let inner = R::deserialize(deserializer)?;
let inner = R::deserialize(deserializer)?.into();

Ok(Self {
inner,
Expand Down
4 changes: 2 additions & 2 deletions necsim/impls/no-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fnv = { version = "1.0", default-features = false, features = [] }
rand_core = "0.6"

[target.'cfg(target_os = "cuda")'.dependencies]
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "dd9507d", features = ["derive", "final"], optional = true }
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "5e1534c", features = ["derive", "final"], optional = true }

[target.'cfg(not(target_os = "cuda"))'.dependencies]
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "dd9507d", features = ["derive", "final", "host"], optional = true }
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "5e1534c", features = ["derive", "final", "host"], optional = true }
11 changes: 3 additions & 8 deletions necsim/impls/no-std/src/cogs/event_sampler/independent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ pub struct IndependentEventSampler<
T: TurnoverRate<M, H>,
N: SpeciationProbability<M, H>,
> {
#[cfg_attr(
feature = "cuda",
cuda(
embed = "Option<rust_cuda::utils::adapter::RustToCudaWithPortableBitCopySemantics<SpeciationSample>>"
)
)]
#[cfg_attr(feature = "cuda", cuda(embed))]
min_spec_sample: Option<SpeciationSample>,
marker: PhantomData<(M, H, G, X, D, T, N)>,
}
Expand Down Expand Up @@ -84,7 +79,7 @@ impl<
{
unsafe fn backup_unchecked(&self) -> Self {
Self {
min_spec_sample: self.min_spec_sample,
min_spec_sample: self.min_spec_sample.clone(),
marker: PhantomData::<(M, H, G, X, D, T, N)>,
}
}
Expand Down Expand Up @@ -254,7 +249,7 @@ impl<
) -> Option<SpeciationSample> {
// `core::mem::replace()` would be semantically better
// - but `clone()` does not spill to local memory
let old_value = self.min_spec_sample;
let old_value = self.min_spec_sample.clone();

self.min_spec_sample = new;

Expand Down
3 changes: 2 additions & 1 deletion necsim/impls/no-std/src/cogs/event_sampler/tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ pub trait MinSpeciationTrackingEventSampler<
-> Option<SpeciationSample>;
}

#[derive(Clone, Copy, Debug, TypeLayout)]
#[derive(Clone, Debug, TypeLayout)]
#[cfg_attr(feature = "cuda", derive(rust_cuda::lend::LendRustToCuda))]
#[repr(C)]
pub struct SpeciationSample {
speciation_sample: ClosedOpenUnitF64,
Expand Down
3 changes: 2 additions & 1 deletion necsim/impls/no-std/src/cogs/habitat/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct InMemoryHabitat<M: MathsCore> {
habitat: Final<Box<[u32]>>,
#[cfg_attr(feature = "cuda", cuda(embed))]
u64_injection: Final<Box<[u64]>>,
#[cfg_attr(feature = "cuda", cuda(embed))]
extent: LandscapeExtent,
marker: PhantomData<M>,
}
Expand All @@ -31,7 +32,7 @@ impl<M: MathsCore> Backup for InMemoryHabitat<M> {
Self {
habitat: Final::new(self.habitat.clone()),
u64_injection: Final::new(self.u64_injection.clone()),
extent: self.extent,
extent: self.extent.clone(),
marker: PhantomData::<M>,
}
}
Expand Down
3 changes: 2 additions & 1 deletion necsim/impls/no-std/src/cogs/habitat/non_spatial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use necsim_core_bond::{OffByOneU32, OffByOneU64};
#[cfg_attr(feature = "cuda", derive(rust_cuda::lend::LendRustToCuda))]
#[cfg_attr(feature = "cuda", cuda(free = "M"))]
pub struct NonSpatialHabitat<M: MathsCore> {
#[cfg_attr(feature = "cuda", cuda(embed))]
extent: LandscapeExtent,
deme: NonZeroU32,
marker: PhantomData<M>,
Expand Down Expand Up @@ -58,7 +59,7 @@ impl<M: MathsCore> NonSpatialHabitat<M> {
impl<M: MathsCore> Backup for NonSpatialHabitat<M> {
unsafe fn backup_unchecked(&self) -> Self {
Self {
extent: self.extent,
extent: self.extent.clone(),
deme: self.deme,
marker: PhantomData::<M>,
}
Expand Down
2 changes: 0 additions & 2 deletions necsim/impls/no-std/src/cogs/rng/seahash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ pub struct SeaHash<M: MathsCore> {
marker: PhantomData<M>,
}

impl<M: MathsCore> Copy for SeaHash<M> {}

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

Expand Down
2 changes: 0 additions & 2 deletions necsim/impls/no-std/src/cogs/rng/wyhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ pub struct WyHash<M: MathsCore> {
marker: PhantomData<M>,
}

impl<M: MathsCore> Copy for WyHash<M> {}

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

Expand Down
2 changes: 1 addition & 1 deletion necsim/impls/no-std/src/decomposition/equal/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl<M: MathsCore, H: Habitat<M>> EqualDecomposition<M, H> {
/// Returns `Ok(Self)` iff the `habitat` can be partitioned into
/// `subdomain.size()` by area, otherwise returns `Err(Self)`.
pub fn area(habitat: &H, subdomain: Partition) -> Result<Self, Self> {
let extent = *habitat.get_extent();
let extent = habitat.get_extent().clone();

let mut indices = Vec::with_capacity(subdomain.size().get() as usize);

Expand Down
2 changes: 1 addition & 1 deletion necsim/impls/no-std/src/decomposition/equal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<M: MathsCore, H: Habitat<M>> Backup for EqualDecomposition<M, H> {
unsafe fn backup_unchecked(&self) -> Self {
Self {
subdomain: self.subdomain,
extent: self.extent,
extent: self.extent.clone(),
morton: self.morton,
indices: self.indices.clone(),
_marker: PhantomData::<(M, H)>,
Expand Down
2 changes: 1 addition & 1 deletion necsim/impls/no-std/src/decomposition/equal/weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl<M: MathsCore, H: Habitat<M>> EqualDecomposition<M, H> {
/// Returns `Ok(Self)` iff the `habitat` can be partitioned into
/// `subdomain.size()` by weight, otherwise returns `Err(Self)`.
pub fn weight(habitat: &H, subdomain: Partition) -> Result<Self, Self> {
let extent = *habitat.get_extent();
let extent = habitat.get_extent().clone();

let mut total_habitat = 0;
let mut indices = Vec::with_capacity(subdomain.size().get() as usize);
Expand Down
Loading

0 comments on commit 775094a

Please sign in to comment.