Read tensor data from backend into a float buffer, handling F32, F16, and quantized types. n = number of float elements to produce.
| 1067 | // Read tensor data from backend into a float buffer, handling F32, F16, and |
| 1068 | // quantized types. n = number of float elements to produce. |
| 1069 | static void sam3_read_f32(struct ggml_tensor* t, float* dst, int64_t n) { |
| 1070 | if (t->type == GGML_TYPE_F32) { |
| 1071 | ggml_backend_tensor_get(t, dst, 0, n * sizeof(float)); |
| 1072 | } else if (t->type == GGML_TYPE_F16) { |
| 1073 | std::vector<ggml_fp16_t> tmp(n); |
| 1074 | ggml_backend_tensor_get(t, tmp.data(), 0, n * sizeof(ggml_fp16_t)); |
| 1075 | ggml_fp16_to_fp32_row(tmp.data(), dst, (int)n); |
| 1076 | } else if (ggml_is_quantized(t->type)) { |
| 1077 | const size_t nbytes = ggml_nbytes(t); |
| 1078 | std::vector<uint8_t> raw(nbytes); |
| 1079 | ggml_backend_tensor_get(t, raw.data(), 0, nbytes); |
| 1080 | const auto * traits = ggml_get_type_traits(t->type); |
| 1081 | traits->to_float(raw.data(), dst, n); |
| 1082 | } else { |
| 1083 | fprintf(stderr, "%s: unsupported tensor type %d\n", __func__, (int)t->type); |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | static struct ggml_tensor* sam3_conv_transpose_weight(struct ggml_context* ctx, |
| 1088 | struct ggml_tensor* w) { |
no outgoing calls
no test coverage detected