[][src]Trait rustacuda::memory::DeviceCopy

pub unsafe trait 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:

This example deliberately fails to compile
#[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 DeviceCopy for i64[src]

impl<T> DeviceCopy for [T; 1] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 13] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 22] where
    T: DeviceCopy
[src]

impl DeviceCopy for u16[src]

impl DeviceCopy for NonZeroU64[src]

impl DeviceCopy for u32[src]

impl DeviceCopy for bool[src]

impl DeviceCopy for u64[src]

impl DeviceCopy for i128[src]

impl<T> DeviceCopy for [T; 32] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 14] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 29] where
    T: DeviceCopy
[src]

impl DeviceCopy for i8[src]

impl<T> DeviceCopy for [T; 7] where
    T: DeviceCopy
[src]

impl DeviceCopy for i16[src]

impl<T> DeviceCopy for [T; 27] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 16] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 10] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for Option<T> where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 31] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 17] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 11] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 19] where
    T: DeviceCopy
[src]

impl<A, B, C, D, E> DeviceCopy for (A, B, C, D, E) where
    A: DeviceCopy,
    B: DeviceCopy,
    C: DeviceCopy,
    D: DeviceCopy,
    E: DeviceCopy
[src]

impl<T> DeviceCopy for PhantomData<T> where
    T: DeviceCopy + ?Sized
[src]

impl<T> DeviceCopy for [T; 4] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 2] where
    T: DeviceCopy
[src]

impl DeviceCopy for u128[src]

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
[src]

impl<A, B, C> DeviceCopy for (A, B, C) where
    A: DeviceCopy,
    B: DeviceCopy,
    C: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 3] where
    T: DeviceCopy
[src]

impl<A, B, C, D> DeviceCopy for (A, B, C, D) where
    A: DeviceCopy,
    B: DeviceCopy,
    C: DeviceCopy,
    D: DeviceCopy
[src]

impl DeviceCopy for char[src]

impl DeviceCopy for ()[src]

impl<T> DeviceCopy for [T; 21] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 8] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 6] where
    T: DeviceCopy
[src]

impl DeviceCopy for i32[src]

impl<T> DeviceCopy for [T; 30] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 12] where
    T: DeviceCopy
[src]

impl DeviceCopy for usize[src]

impl<A, B> DeviceCopy for (A, B) where
    A: DeviceCopy,
    B: DeviceCopy
[src]

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
[src]

impl<T> DeviceCopy for [T; 25] where
    T: DeviceCopy
[src]

impl DeviceCopy for u8[src]

impl<T> DeviceCopy for [T; 18] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for Wrapping<T> where
    T: DeviceCopy
[src]

impl DeviceCopy for NonZeroU8[src]

impl DeviceCopy for isize[src]

impl DeviceCopy for NonZeroU32[src]

impl DeviceCopy for f64[src]

impl<T> DeviceCopy for [T; 15] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 28] where
    T: DeviceCopy
[src]

impl DeviceCopy for NonZeroU16[src]

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
[src]

impl<T> DeviceCopy for [T; 9] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 26] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 24] where
    T: DeviceCopy
[src]

impl DeviceCopy for NonZeroU128[src]

impl<L, R> DeviceCopy for Result<L, R> where
    L: DeviceCopy,
    R: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 23] where
    T: DeviceCopy
[src]

impl<T> DeviceCopy for [T; 20] where
    T: DeviceCopy
[src]

impl DeviceCopy for f32[src]

impl<T> DeviceCopy for [T; 5] where
    T: DeviceCopy
[src]

Loading content...

Implementors

impl<T> DeviceCopy for DevicePointer<T>[src]

impl<T> DeviceCopy for UnifiedPointer<T> where
    T: DeviceCopy
[src]

Loading content...