From 9297cc575411fae18d716cc18e7cbdb2172a311b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Fri, 26 Nov 2021 18:12:39 +0100 Subject: [PATCH] Implement DeviceCopy for UnitComplex, UnitQuaternion, and Unit instead of using a blanket impl --- src/base/unit.rs | 19 +++++++++++++++---- src/geometry/quaternion.rs | 3 +++ src/geometry/unit_complex.rs | 3 +++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/base/unit.rs b/src/base/unit.rs index 22af401a..60281b8f 100644 --- a/src/base/unit.rs +++ b/src/base/unit.rs @@ -26,10 +26,10 @@ use crate::{Dim, Matrix, OMatrix, RealField, Scalar, SimdComplexField, SimdRealF /// in their documentation, read their dedicated pages directly. #[repr(transparent)] #[derive(Clone, Hash, Copy)] -#[cfg_attr( - all(not(target_os = "cuda"), feature = "cuda"), - derive(cust::DeviceCopy) -)] +// #[cfg_attr( +// all(not(target_os = "cuda"), feature = "cuda"), +// derive(cust::DeviceCopy) +// )] pub struct Unit { pub(crate) value: T, } @@ -122,6 +122,17 @@ mod rkyv_impl { } } +#[cfg(all(not(target_os = "cuda"), feature = "cuda"))] +unsafe impl cust::memory::DeviceCopy + for Unit> +where + T: Scalar, + R: Dim, + C: Dim, + S: RawStorage + Copy, +{ +} + impl PartialEq for Unit> where T: Scalar + PartialEq, diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 05b73334..cae06251 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -1068,6 +1068,9 @@ impl fmt::Display for Quaternion { /// A unit quaternions. May be used to represent a rotation. pub type UnitQuaternion = Unit>; +#[cfg(all(not(target_os = "cuda"), feature = "cuda"))] +unsafe impl cust::memory::DeviceCopy for UnitQuaternion {} + impl PartialEq for UnitQuaternion { #[inline] fn eq(&self, rhs: &Self) -> bool { diff --git a/src/geometry/unit_complex.rs b/src/geometry/unit_complex.rs index 63cf251c..48405dd4 100755 --- a/src/geometry/unit_complex.rs +++ b/src/geometry/unit_complex.rs @@ -31,6 +31,9 @@ use std::cmp::{Eq, PartialEq}; /// * [Conversion to a matrix `to_rotation_matrix`, `to_homogeneous`…](#conversion-to-a-matrix) pub type UnitComplex = Unit>; +#[cfg(all(not(target_os = "cuda"), feature = "cuda"))] +unsafe impl cust::memory::DeviceCopy for UnitComplex {} + impl PartialEq for UnitComplex { #[inline] fn eq(&self, rhs: &Self) -> bool {