MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / set_backend_tensor_from_f32

Function set_backend_tensor_from_f32

src/framework/assets/tensor_source.cpp:202–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200 return bytes;
201}
202
203void set_tensor_bytes(ggml_tensor * tensor, const void * data, size_t bytes, std::string_view name) {
204 if (tensor == nullptr) {
205 throw std::runtime_error("cannot upload to a null backend tensor: " + std::string(name));
206 }
207 if (bytes != ggml_nbytes(tensor)) {
208 throw std::runtime_error("backend tensor byte size mismatch for " + std::string(name));
209 }
210 ggml_backend_tensor_set(tensor, data, 0, bytes);
211}
212
213std::vector<float> decode_tensor_data_f32(std::string_view name, const TensorData & tensor) {
214 if (tensor.type == GGML_TYPE_F32) {
215 if (tensor.bytes.size() != static_cast<size_t>(tensor.shape.num_elements()) * sizeof(float)) {
216 throw std::runtime_error("invalid F32 tensor byte size: " + std::string(name));
217 }
218 std::vector<float> values(static_cast<size_t>(tensor.shape.num_elements()));
219 std::memcpy(values.data(), tensor.bytes.data(), tensor.bytes.size());
220 return values;
221 }
222 if (tensor.type == GGML_TYPE_F16) {
223 if (tensor.bytes.size() != static_cast<size_t>(tensor.shape.num_elements()) * sizeof(ggml_fp16_t)) {
224 throw std::runtime_error("invalid F16 tensor byte size: " + std::string(name));
225 }
226 std::vector<float> values(static_cast<size_t>(tensor.shape.num_elements()));
227 ggml_fp16_to_fp32_row(

Callers 2

set_backend_tensorMethod · 0.85

Calls 6

set_tensor_bytesFunction · 0.85
f16_bytesFunction · 0.85
bf16_bytesFunction · 0.85
quantize_f32_rowsFunction · 0.85
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected