MCPcopy Create free account
hub / github.com/PABannier/sam3.cpp / sam3_read_f32

Function sam3_read_f32

sam3.cpp:1069–1085  ·  view source on GitHub ↗

Read tensor data from backend into a float buffer, handling F32, F16, and quantized types. n = number of float elements to produce.

Source from the content-addressed store, hash-verified

1067// Read tensor data from backend into a float buffer, handling F32, F16, and
1068// quantized types. n = number of float elements to produce.
1069static 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
1087static struct ggml_tensor* sam3_conv_transpose_weight(struct ggml_context* ctx,
1088 struct ggml_tensor* w) {

Callers 4

sam3_extract_obj_ptr_cpuFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected