Trait rust_cuda::safety::PortableBitSemantics
source · pub auto trait PortableBitSemantics { }
Expand description
Types whose in-memory bit representation on the CPU host is safe to copy to and read back on the GPU device while maintaining the same semantics, iff the type layout on the CPU matches the type layout on the GPU.
For a type to implement PortableBitSemantics
, it
-
should have the same memory layout on both the CPU and GPU, and
-
must not contain any references to data that are exposed as safely accessible on both ends but actually inaccessible on one.
For instance, a reference &u8
to host memory has the same well-defined
layout on both CPU and GPU (if their pointer sizes and alignments
match), but it is not portable since the host memory is generally
not accessible from the GPU.
This trait is automatically implemented when the compiler determines it’s appropriate.
Note that this trait is sealed, i.e. you cannot implement it on your own custom types.
Trait bounds usually combine PortableBitSemantics
with
TypeGraphLayout
to check that
the type layout is indeed the same on both the host CPU and the GPU
device.
Types that implement StackOnly
and
TypeGraphLayout
satisfy both
of the above criteria and thus also implement PortableBitSemantics
.