Skip to content

Commit

Permalink
feat: remove cuda support
Browse files Browse the repository at this point in the history
  • Loading branch information
sebcrozet committed Apr 28, 2024
1 parent e1708be commit fe8f38a
Show file tree
Hide file tree
Showing 51 changed files with 207 additions and 1,658 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Change Log

## Unreleased

### Modified

- Remove CUDA support to break free from the toolchain restriction required by cust.
- Rework internal edges resolution using normal cones. This implies the modification of the
`SimdCompositeShape::map_part_at`, `TypedSimdCompositeShape::map_typed_part`, and
`TypedSimdCompositeShape::map_untyped_part` trait functions so that the closure argument takes
an extra argument for the (optional) normal constraints. This argument can be safely ignored
by user code unless applying the normal collection is relevant to your use-case.
- Contact manifolds will now retain all contacts (including the ones further than the specified `prediction`
distance) whenever any contact is actually closer than this `prediction` distance.
- Typo fix: renamed `TopologyError::BadAdjascentTrianglesOrientation` to `BadAdjacentTrianglesOrientation`.

### Fixed

- Fix contacts between convex shapes being occasionally ignored due to some rounding errors.
- Remove crash when entering unreachable code in non-linear TOI calculation.
- Fix accuracy issue in triangle-mesh center-of-mass calculation when the mesh isn’t manifold.

### Added

- Add `SdpMatrix2::inverse_and_get_determinant_unchecked`. This is useful for computing the
inverse in a AoSoA SIMD setting.
- Add `Aabb::intersects_moving_aabb` to perform a swept test between two moving aabbs.

## v0.13.8
### Added

Expand Down
4 changes: 0 additions & 4 deletions crates/parry2d-f64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ bytemuck-serialize = ["bytemuck", "nalgebra/convert-bytemuck"]
simd-stable = ["simba/wide", "simd-is-enabled"]
simd-nightly = ["simba/packed_simd", "simd-is-enabled"]
enhanced-determinism = ["simba/libm_force", "indexmap"]
cuda = ["cust_core", "cust", "nalgebra/cuda"]
parallel = ["rayon"]

# Do not enable this feature directly. It is automatically
Expand Down Expand Up @@ -62,9 +61,6 @@ rayon = { version = "1", optional = true }
bytemuck = { version = "1", features = ["derive"], optional = true }
log = "0.4"

[target.'cfg(not(target_os = "cuda"))'.dependencies]
cust = { version = "0.3", optional = true }

[dev-dependencies]
simba = { version = "0.8", default-features = false, features = ["partial_fixed_point_support"] }
oorandom = "11"
Expand Down
4 changes: 0 additions & 4 deletions crates/parry2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ bytemuck-serialize = ["bytemuck", "nalgebra/convert-bytemuck"]
simd-stable = ["simba/wide", "simd-is-enabled"]
simd-nightly = ["simba/packed_simd", "simd-is-enabled"]
enhanced-determinism = ["simba/libm_force", "indexmap"]
cuda = ["cust_core", "cust", "nalgebra/cuda"]
parallel = ["rayon"]

# Do not enable this feature directly. It is automatically
Expand Down Expand Up @@ -62,9 +61,6 @@ rayon = { version = "1", optional = true }
bytemuck = { version = "1", features = ["derive"], optional = true }
log = "0.4"

[target.'cfg(not(target_os = "cuda"))'.dependencies]
cust = { version = "0.3", optional = true }

[dev-dependencies]
simba = { version = "0.8", default-features = false, features = ["partial_fixed_point_support"] }
oorandom = "11"
Expand Down
4 changes: 0 additions & 4 deletions crates/parry3d-f64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ bytemuck-serialize = ["bytemuck", "nalgebra/convert-bytemuck"]
simd-stable = ["simba/wide", "simd-is-enabled"]
simd-nightly = ["simba/packed_simd", "simd-is-enabled"]
enhanced-determinism = ["simba/libm_force", "indexmap"]
cuda = ["cust_core", "cust", "nalgebra/cuda"]
parallel = ["rayon"]

# Do not enable this feature directly. It is automatically
Expand Down Expand Up @@ -62,9 +61,6 @@ rayon = { version = "1", optional = true }
bytemuck = { version = "1", features = ["derive"], optional = true }
log = "0.4"

[target.'cfg(not(target_os = "cuda"))'.dependencies]
cust = { version = "0.3", optional = true }

[dev-dependencies]
oorandom = "11"
ptree = "0.4.0"
Expand Down
4 changes: 0 additions & 4 deletions crates/parry3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ bytemuck-serialize = ["bytemuck", "nalgebra/convert-bytemuck"]
simd-stable = ["simba/wide", "simd-is-enabled"]
simd-nightly = ["simba/packed_simd", "simd-is-enabled"]
enhanced-determinism = ["simba/libm_force", "indexmap"]
cuda = ["cust_core", "cust", "nalgebra/cuda"]
parallel = ["rayon"]

# Do not enable this feature directly. It is automatically
Expand Down Expand Up @@ -63,9 +62,6 @@ rayon = { version = "1", optional = true }
bytemuck = { version = "1", features = ["derive"], optional = true }
log = "0.4"

[target.'cfg(not(target_os = "cuda"))'.dependencies]
cust = { version = "0.3", optional = true }

[dev-dependencies]
oorandom = "11"
ptree = "0.4.0"
Expand Down
1 change: 0 additions & 1 deletion src/bounding_volume/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use rkyv::{bytecheck, CheckBytes};
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize, CheckBytes),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[derive(Debug, PartialEq, Copy, Clone)]
#[repr(C)]
pub struct Aabb {
Expand Down
4 changes: 2 additions & 2 deletions src/bounding_volume/aabb_heightfield.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::bounding_volume::Aabb;
use crate::math::{Isometry, Real};
use crate::shape::{GenericHeightField, HeightFieldStorage};
use crate::shape::HeightField;

impl<Storage: HeightFieldStorage> GenericHeightField<Storage> {
impl HeightField {
/// Computes the world-space [`Aabb`] of this heightfield, transformed by `pos`.
#[inline]
pub fn aabb(&self, pos: &Isometry<Real>) -> Aabb {
Expand Down
4 changes: 2 additions & 2 deletions src/bounding_volume/bounding_sphere_heightfield.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::bounding_volume::BoundingSphere;
use crate::math::{Isometry, Real};
use crate::shape::{GenericHeightField, HeightFieldStorage};
use crate::shape::HeightField;

impl<Storage: HeightFieldStorage> GenericHeightField<Storage> {
impl HeightField {
/// Computes the world-space bounding sphere of this height-field, transformed by `pos`.
#[inline]
pub fn bounding_sphere(&self, pos: &Isometry<Real>) -> BoundingSphere {
Expand Down
1 change: 0 additions & 1 deletion src/bounding_volume/simd_aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use simba::simd::{SimdPartialOrd, SimdValue};
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(check_bytes)
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
pub struct SimdAabb {
/// The min coordinates of the Aabbs.
pub mins: Point<SimdReal>,
Expand Down
7 changes: 3 additions & 4 deletions src/partitioning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
#[cfg(feature = "std")]
pub use self::qbvh::{
CenterDataSplitter, QbvhDataGenerator, QbvhNonOverlappingDataSplitter, QbvhUpdateWorkspace,
};
pub use self::qbvh::{
GenericQbvh, IndexedData, NodeIndex, Qbvh, QbvhNode, QbvhProxy, QbvhStorage, SimdNodeIndex,
CenterDataSplitter, IndexedData, NodeIndex, Qbvh, QbvhDataGenerator, QbvhNode,
QbvhNonOverlappingDataSplitter, QbvhProxy, QbvhUpdateWorkspace, SimdNodeIndex,
};
#[cfg(feature = "parallel")]
pub use self::visitor::{ParallelSimdSimultaneousVisitor, ParallelSimdVisitor};
Expand All @@ -18,5 +16,6 @@ pub use self::visitor::{
#[deprecated(note = "Renamed to Qbvh")]
pub type SimdQbvh<T> = Qbvh<T>;

#[cfg(feature = "std")]
mod qbvh;
mod visitor;
10 changes: 1 addition & 9 deletions src/partitioning/qbvh/mod.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
#[cfg(feature = "std")]
pub use self::{
build::{CenterDataSplitter, QbvhDataGenerator, QbvhNonOverlappingDataSplitter},
update::QbvhUpdateWorkspace,
};

pub use self::qbvh::{
GenericQbvh, IndexedData, NodeIndex, Qbvh, QbvhNode, QbvhNodeFlags, QbvhProxy, SimdNodeIndex,
IndexedData, NodeIndex, Qbvh, QbvhNode, QbvhNodeFlags, QbvhProxy, SimdNodeIndex,
};
pub use self::storage::QbvhStorage;

mod qbvh;
mod storage;
mod utils;

#[cfg(feature = "std")]
mod build;
#[cfg(feature = "std")]
mod traversal;
#[cfg(not(feature = "std"))]
mod traversal_no_std;
#[cfg(feature = "std")]
mod update;
108 changes: 8 additions & 100 deletions src/partitioning/qbvh/qbvh.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
use crate::bounding_volume::{Aabb, SimdAabb};
use crate::math::{Real, Vector};
use crate::partitioning::qbvh::storage::QbvhStorage;
use crate::utils::DefaultStorage;
use bitflags::bitflags;

use na::SimdValue;

#[cfg(feature = "rkyv")]
use rkyv::{bytecheck, CheckBytes};
#[cfg(all(feature = "std", feature = "cuda"))]
use {crate::utils::CudaArray1, cust::error::CudaResult};
#[cfg(feature = "cuda")]
use {
crate::utils::{CudaStorage, CudaStoragePtr},
cust_core::DeviceCopy,
};

/// A data to which an index is associated.
pub trait IndexedData: Copy {
Expand Down Expand Up @@ -64,7 +55,6 @@ pub type SimdNodeIndex = u32;
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize, CheckBytes),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
/// The index of one specific node of a Qbvh.
pub struct NodeIndex {
/// The index of the SIMD node containing the addressed node.
Expand Down Expand Up @@ -97,7 +87,6 @@ bitflags! {
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(as = "Self")
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[derive(Default)]
/// The status of a QBVH node.
pub struct QbvhNodeFlags: u8 {
Expand All @@ -120,7 +109,6 @@ bitflags! {
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(check_bytes)
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
pub struct QbvhNode {
/// The Aabbs of the qbvh nodes represented by this node.
pub simd_aabb: SimdAabb,
Expand Down Expand Up @@ -194,7 +182,6 @@ impl QbvhNode {
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(check_bytes)
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
/// Combination of a leaf data and its associated node’s index.
pub struct QbvhProxy<LeafData> {
/// Index of the leaf node the leaf data is associated to.
Expand Down Expand Up @@ -235,86 +222,22 @@ impl<LeafData> QbvhProxy<LeafData> {
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(check_bytes)
)]
#[repr(C)] // Needed for Cuda.
#[derive(Debug)]
pub struct GenericQbvh<LeafData, Storage: QbvhStorage<LeafData>> {
#[repr(C)]
#[derive(Debug, Clone)]
pub struct Qbvh<LeafData> {
pub(super) root_aabb: Aabb,
pub(super) nodes: Storage::Nodes,
pub(super) dirty_nodes: Storage::ArrayU32,
pub(super) free_list: Storage::ArrayU32,
pub(super) proxies: Storage::ArrayProxies,
pub(super) nodes: Vec<QbvhNode>,
pub(super) dirty_nodes: Vec<u32>,
pub(super) free_list: Vec<u32>,
pub(super) proxies: Vec<QbvhProxy<LeafData>>,
}

/// A quaternary bounding-volume-hierarchy.
///
/// This is a bounding-volume-hierarchy where each node has either four children or none.
pub type Qbvh<LeafData> = GenericQbvh<LeafData, DefaultStorage>;
#[cfg(feature = "cuda")]
/// A Qbvh stored in CUDA memory.
pub type CudaQbvh<LeafData> = GenericQbvh<LeafData, CudaStorage>;
#[cfg(feature = "cuda")]
/// A Qbvh accessible from CUDA kernels.
pub type CudaQbvhPtr<LeafData> = GenericQbvh<LeafData, CudaStoragePtr>;

impl<LeafData, Storage> Clone for GenericQbvh<LeafData, Storage>
where
Storage: QbvhStorage<LeafData>,
Storage::Nodes: Clone,
Storage::ArrayU32: Clone,
Storage::ArrayProxies: Clone,
{
fn clone(&self) -> Self {
Self {
root_aabb: self.root_aabb,
nodes: self.nodes.clone(),
dirty_nodes: self.dirty_nodes.clone(),
free_list: self.free_list.clone(),
proxies: self.proxies.clone(),
}
}
}

impl<LeafData, Storage> Copy for GenericQbvh<LeafData, Storage>
where
Storage: QbvhStorage<LeafData>,
Storage::Nodes: Copy,
Storage::ArrayU32: Copy,
Storage::ArrayProxies: Copy,
{
}

#[cfg(feature = "cuda")]
unsafe impl<LeafData, Storage> DeviceCopy for GenericQbvh<LeafData, Storage>
where
Storage: QbvhStorage<LeafData>,
Storage::Nodes: DeviceCopy,
Storage::ArrayU32: DeviceCopy,
Storage::ArrayProxies: DeviceCopy,
{
}

#[cfg(all(feature = "std", feature = "cuda"))]
impl<LeafData: DeviceCopy> CudaQbvh<LeafData> {
/// Returns the qbvh usable from within a CUDA kernel.
pub fn as_device_ptr(&self) -> CudaQbvhPtr<LeafData> {
GenericQbvh {
root_aabb: self.root_aabb,
nodes: self.nodes.as_device_ptr(),
dirty_nodes: self.dirty_nodes.as_device_ptr(),
free_list: self.free_list.as_device_ptr(),
proxies: self.proxies.as_device_ptr(),
}
}
}

#[cfg(feature = "std")]
impl<LeafData: IndexedData> Default for Qbvh<LeafData> {
fn default() -> Self {
Self::new()
}
}

#[cfg(feature = "std")]
impl<LeafData: IndexedData> Qbvh<LeafData> {
/// Initialize an empty Qbvh.
pub fn new() -> Self {
Expand All @@ -327,21 +250,6 @@ impl<LeafData: IndexedData> Qbvh<LeafData> {
}
}

/// Converts this RAM-based qbvh to an qbvh based on CUDA memory.
#[cfg(feature = "cuda")]
pub fn to_cuda(&self) -> CudaResult<CudaQbvh<LeafData>>
where
LeafData: DeviceCopy,
{
Ok(CudaQbvh {
root_aabb: self.root_aabb,
nodes: CudaArray1::new(&self.nodes)?,
dirty_nodes: CudaArray1::new(&self.dirty_nodes)?,
free_list: CudaArray1::new(&self.free_list)?,
proxies: CudaArray1::new(&self.proxies)?,
})
}

/// Iterates mutably through all the leaf data in this Qbvh.
pub fn iter_data_mut(&mut self) -> impl Iterator<Item = (NodeIndex, &mut LeafData)> {
self.proxies.iter_mut().map(|p| (p.node, &mut p.data))
Expand Down Expand Up @@ -405,7 +313,7 @@ impl<LeafData: IndexedData> Qbvh<LeafData> {
}
}

impl<LeafData: IndexedData, Storage: QbvhStorage<LeafData>> GenericQbvh<LeafData, Storage> {
impl<LeafData: IndexedData> Qbvh<LeafData> {
/// The Aabb of the root of this tree.
pub fn root_aabb(&self) -> &Aabb {
&self.root_aabb
Expand Down
Loading

0 comments on commit fe8f38a

Please sign in to comment.