MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / as_host_vec

Method as_host_vec

crates/cust/src/memory/array.rs:840–855  ·  view source on GitHub ↗

Copy data from the array into a vec on the host. **This will not check if the formats match, it does however yield a correct vec**. Format mismatch and especially format size mismatch may yield incorrect (but not unsound!) behavior

(&self)

Source from the content-addressed store, hash-verified

838 /// however yield a correct vec**. Format mismatch and especially format size mismatch may yield incorrect (but not unsound!)
839 /// behavior
840 pub fn as_host_vec<T: ArrayPrimitive>(&self) -> CudaResult<Vec<T>> {
841 let desc = self.descriptor()?;
842 let self_size = desc.width()
843 * desc.height().max(1)
844 * desc.depth().max(1)
845 * desc.num_channels() as usize
846 * desc.format().mem_size();
847
848 let len = self_size / T::array_format().mem_size();
849 unsafe {
850 // SAFETY: anything ArrayPrimitive is a number and therefore zeroable.
851 let mut vec = vec![zeroed(); len];
852 self.copy_to(&mut vec)?;
853 Ok(vec)
854 }
855 }
856}
857
858impl std::fmt::Debug for ArrayObject {

Callers 1

mainFunction · 0.45

Calls 8

depthMethod · 0.80
num_channelsMethod · 0.80
mem_sizeMethod · 0.80
descriptorMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45
formatMethod · 0.45
copy_toMethod · 0.45

Tested by

no test coverage detected