[−]Trait rustacuda::memory::DeviceCopy
Marker trait for types which can safely be copied to or from a CUDA device.
A type can be safely copied if its value can be duplicated simply by copying bits and if it does not contain a reference to memory which is not accessible to the device. Additionally, the DeviceCopy trait does not imply copy semantics as the Copy trait does.
How can I implement DeviceCopy?
There are two ways to implement DeviceCopy on your type. The simplest is to use derive
:
#[macro_use] extern crate rustacuda; #[derive(Clone, DeviceCopy)] struct MyStruct(u64);
This is safe because the DeviceCopy
derive macro will check that all fields of the struct,
enum or union implement DeviceCopy
. For example, this fails to compile, because Vec
cannot
be copied to the device:
#[derive(Clone, DeviceCopy)] struct MyStruct(Vec<u64>);
You can also implement DeviceCopy
unsafely:
use rustacuda::memory::DeviceCopy; #[derive(Clone)] struct MyStruct(u64); unsafe impl DeviceCopy for MyStruct { }
What is the difference between DeviceCopy
and Copy
?
DeviceCopy
is stricter than Copy
. DeviceCopy
must only be implemented for types which
do not contain references or raw pointers to non-device-accessible memory. DeviceCopy
also
does not imply copy semantics - that is, DeviceCopy
values are not implicitly copied on
assignment the way that Copy
values are. This is helpful, as it may be desirable to implement
DeviceCopy
for large structures that would be inefficient to copy for every assignment.
When can't my type be DeviceCopy
?
Some types cannot be safely copied to the device. For example, copying &T
would create an
invalid reference on the device which would segfault if dereferenced. Generalizing this, any
type implementing Drop
cannot be DeviceCopy
since it is responsible for some resource that
would not be available on the device.
Implementations on Foreign Types
impl<T> DeviceCopy for [T; 3] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for [T; 27] where
T: DeviceCopy,
T: DeviceCopy,
impl DeviceCopy for u8
impl<T> DeviceCopy for [T; 6] where
T: DeviceCopy,
T: DeviceCopy,
impl DeviceCopy for ()
impl DeviceCopy for NonZeroU8
impl<T> DeviceCopy for [T; 13] where
T: DeviceCopy,
T: DeviceCopy,
impl DeviceCopy for f64
impl DeviceCopy for u16
impl DeviceCopy for i128
impl DeviceCopy for i32
impl<T> DeviceCopy for [T; 7] where
T: DeviceCopy,
T: DeviceCopy,
impl<A, B, C, D, E> DeviceCopy for (A, B, C, D, E) where
A: DeviceCopy,
B: DeviceCopy,
C: DeviceCopy,
D: DeviceCopy,
E: DeviceCopy,
A: DeviceCopy,
B: DeviceCopy,
C: DeviceCopy,
D: DeviceCopy,
E: DeviceCopy,
impl<T> DeviceCopy for [T; 24] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for [T; 26] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for Option<T> where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for [T; 17] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for [T; 14] where
T: DeviceCopy,
T: DeviceCopy,
impl<A, B, C, D, E, F, G> DeviceCopy for (A, B, C, D, E, F, G) where
A: DeviceCopy,
B: DeviceCopy,
C: DeviceCopy,
D: DeviceCopy,
E: DeviceCopy,
F: DeviceCopy,
G: DeviceCopy,
A: DeviceCopy,
B: DeviceCopy,
C: DeviceCopy,
D: DeviceCopy,
E: DeviceCopy,
F: DeviceCopy,
G: DeviceCopy,
impl<T> DeviceCopy for [T; 28] where
T: DeviceCopy,
T: DeviceCopy,
impl<A, B, C, D> DeviceCopy for (A, B, C, D) where
A: DeviceCopy,
B: DeviceCopy,
C: DeviceCopy,
D: DeviceCopy,
A: DeviceCopy,
B: DeviceCopy,
C: DeviceCopy,
D: DeviceCopy,
impl DeviceCopy for i16
impl<T> DeviceCopy for [T; 25] where
T: DeviceCopy,
T: DeviceCopy,
impl DeviceCopy for bool
impl<T> DeviceCopy for [T; 1] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for [T; 8] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for Wrapping<T> where
T: DeviceCopy,
T: DeviceCopy,
impl DeviceCopy for f32
impl<T> DeviceCopy for [T; 22] where
T: DeviceCopy,
T: DeviceCopy,
impl<L, R> DeviceCopy for Result<L, R> where
L: DeviceCopy,
R: DeviceCopy,
L: DeviceCopy,
R: DeviceCopy,
impl DeviceCopy for u32
impl<A, B, C, D, E, F> DeviceCopy for (A, B, C, D, E, F) where
A: DeviceCopy,
B: DeviceCopy,
C: DeviceCopy,
D: DeviceCopy,
E: DeviceCopy,
F: DeviceCopy,
A: DeviceCopy,
B: DeviceCopy,
C: DeviceCopy,
D: DeviceCopy,
E: DeviceCopy,
F: DeviceCopy,
impl<A, B, C> DeviceCopy for (A, B, C) where
A: DeviceCopy,
B: DeviceCopy,
C: DeviceCopy,
A: DeviceCopy,
B: DeviceCopy,
C: DeviceCopy,
impl<T> DeviceCopy for [T; 23] where
T: DeviceCopy,
T: DeviceCopy,
impl DeviceCopy for char
impl<T> DeviceCopy for [T; 9] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for PhantomData<T> where
T: DeviceCopy + ?Sized,
T: DeviceCopy + ?Sized,
impl DeviceCopy for NonZeroU16
impl<T> DeviceCopy for [T; 4] where
T: DeviceCopy,
T: DeviceCopy,
impl DeviceCopy for u128
impl DeviceCopy for i64
impl<T> DeviceCopy for [T; 29] where
T: DeviceCopy,
T: DeviceCopy,
impl<A, B> DeviceCopy for (A, B) where
A: DeviceCopy,
B: DeviceCopy,
A: DeviceCopy,
B: DeviceCopy,
impl DeviceCopy for i8
impl DeviceCopy for NonZeroU32
impl DeviceCopy for NonZeroU128
impl<T> DeviceCopy for [T; 20] where
T: DeviceCopy,
T: DeviceCopy,
impl<A, B, C, D, E, F, G, H> DeviceCopy for (A, B, C, D, E, F, G, H) where
A: DeviceCopy,
B: DeviceCopy,
C: DeviceCopy,
D: DeviceCopy,
E: DeviceCopy,
F: DeviceCopy,
G: DeviceCopy,
H: DeviceCopy,
A: DeviceCopy,
B: DeviceCopy,
C: DeviceCopy,
D: DeviceCopy,
E: DeviceCopy,
F: DeviceCopy,
G: DeviceCopy,
H: DeviceCopy,
impl<T> DeviceCopy for [T; 2] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for [T; 18] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for [T; 19] where
T: DeviceCopy,
T: DeviceCopy,
impl DeviceCopy for u64
impl DeviceCopy for usize
impl<T> DeviceCopy for [T; 10] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for [T; 21] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for [T; 32] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for [T; 11] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for [T; 12] where
T: DeviceCopy,
T: DeviceCopy,
impl DeviceCopy for NonZeroU64
impl<T> DeviceCopy for [T; 16] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for [T; 15] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for [T; 31] where
T: DeviceCopy,
T: DeviceCopy,
impl<T> DeviceCopy for [T; 30] where
T: DeviceCopy,
T: DeviceCopy,
impl DeviceCopy for isize
impl<T> DeviceCopy for [T; 5] where
T: DeviceCopy,
Loading content...
T: DeviceCopy,
Implementors
impl<T> DeviceCopy for DevicePointer<T> where
T: ?Sized,
T: ?Sized,
impl<T> DeviceCopy for UnifiedPointer<T> where
T: DeviceCopy + ?Sized,
T: DeviceCopy + ?Sized,