MCPcopy Create free account
hub / github.com/evilsocket/cake / into_tensor

Method into_tensor

cake-core/src/cake/sharding/proto/message.rs:132–141  ·  view source on GitHub ↗

Consume self and create a Tensor, avoiding a copy on CPU by reusing the data buffer.

(self, device: &Device)

Source from the content-addressed store, hash-verified

130
131 /// Consume self and create a Tensor, avoiding a copy on CPU by reusing the data buffer.
132 pub fn into_tensor(self, device: &Device) -> Result<Tensor> {
133 let dtype = u8_to_dtype(self.dtype)?;
134 if matches!(device, Device::Cpu) {
135 // Reinterpret owned Vec<u8> directly as typed storage — avoids memcpy.
136 Self::vec_u8_to_tensor(self.data, dtype, &self.shape)
137 } else {
138 // GPU path must copy to device memory regardless.
139 Ok(Tensor::from_raw_buffer(&self.data, dtype, &self.shape, device)?)
140 }
141 }
142
143 /// Zero-copy conversion of Vec<u8> → CPU Tensor by reinterpreting bytes.
144 fn vec_u8_to_tensor(data: Vec<u8>, dtype: DType, shape: &[usize]) -> Result<Tensor> {

Callers 2

handle_master_clientMethod · 0.80
forward_requestMethod · 0.80

Calls 1

u8_to_dtypeFunction · 0.85

Tested by

no test coverage detected