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

Function sam3_profile_edgetam_encode

sam3.cpp:5096–5422  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5094}
5095
5096bool sam3_profile_edgetam_encode(const sam3_model& model,
5097 const sam3_image& image,
5098 int n_threads,
5099 int n_warmup,
5100 int n_iter) {
5101 const auto& hp = model.hparams;
5102 if (!hp.is_edgetam()) {
5103 fprintf(stderr, "%s: model is not EdgeTAM\n", __func__);
5104 return false;
5105 }
5106
5107 const int img_size = hp.img_size;
5108 fprintf(stderr, "%s: profiling EdgeTAM RepViT+FPN on %dx%d image\n",
5109 __func__, img_size, img_size);
5110 fprintf(stderr, " warmup=%d, iterations=%d, threads=%d\n",
5111 n_warmup, n_iter, n_threads);
5112 fprintf(stderr, " backend: %s\n", ggml_backend_name(model.backend));
5113
5114 // Stage config
5115 fprintf(stderr, " stages: [%d, %d, %d, %d] blocks, channels: [%d, %d, %d, %d]\n",
5116 hp.repvit_stages[0], hp.repvit_stages[1],
5117 hp.repvit_stages[2], hp.repvit_stages[3],
5118 hp.repvit_channels[0], hp.repvit_channels[1],
5119 hp.repvit_channels[2], hp.repvit_channels[3]);
5120
5121 // ── Preprocess image ────────────────────────────────────────────────
5122 auto img_data = sam2_preprocess_image(image, img_size);
5123
5124 // ════════════════════════════════════════════════════════════════════
5125 // PART 1: Full graph — op summary + total timing
5126 // ════════════════════════════════════════════════════════════════════
5127 fprintf(stderr, "\n=== FULL GRAPH (RepViT + FPN) ===\n");
5128 {
5129 const size_t buf_size = ggml_tensor_overhead() * 16384 + ggml_graph_overhead() * 2;
5130 struct ggml_init_params gp = {buf_size, nullptr, true};
5131 auto* ctx0 = ggml_init(gp);
5132
5133 auto* inp = ggml_new_tensor_4d(ctx0, GGML_TYPE_F32, img_size, img_size, 3, 1);
5134 ggml_set_name(inp, "input_image");
5135 ggml_set_input(inp);
5136
5137 struct ggml_tensor* stage_outs[4] = {};
5138 edgetam_build_repvit_graph(ctx0, inp, model, stage_outs);
5139
5140 struct ggml_tensor* fpn_outs[4] = {};
5141 edgetam_build_fpn_neck_graph(ctx0, stage_outs, model, fpn_outs);
5142
5143 int n_fpn = 4 - hp.scalp;
5144 auto* graph = ggml_new_graph_custom(ctx0, 32768, false);
5145 for (int i = 0; i < n_fpn; ++i) {
5146 char name[64];
5147 snprintf(name, sizeof(name), "fpn_out_%d", i);
5148 ggml_set_name(fpn_outs[i], name);
5149 ggml_set_output(fpn_outs[i]);
5150 ggml_build_forward_expand(graph, fpn_outs[i]);
5151 }
5152
5153 sam3_profile_print_op_summary(graph, "Full RepViT+FPN");

Callers 1

mainFunction · 0.85

Calls 11

sam2_preprocess_imageFunction · 0.85
edgetam_conv2d_biasFunction · 0.85
sam3_profile_op_countsFunction · 0.85
sam3_graph_computeFunction · 0.85
is_edgetamMethod · 0.80

Tested by

no test coverage detected