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

Function run_single_benchmark

examples/benchmark.cpp:198–296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196// ── Run a single benchmark (shared logic) ──────────────────────────────────
197
198static BenchWire run_single_benchmark(const std::string & model_path,
199 bool use_gpu,
200 const std::string & video_path,
201 int n_frames,
202 float px, float py,
203 int n_threads,
204 int encode_img_size) {
205 BenchWire wire = {};
206
207 auto fail = [&](const char * msg) {
208 wire.ok = 0;
209 snprintf(wire.error, sizeof(wire.error), "%s", msg);
210 };
211
212 // Decode frames
213 std::vector<sam3_image> frames(n_frames);
214 for (int f = 0; f < n_frames; f++) {
215 frames[f] = sam3_decode_video_frame(video_path, f);
216 if (frames[f].data.empty()) { fail("decode frame failed"); return wire; }
217 }
218
219 // Load model
220 int64_t t0 = ggml_time_us();
221
222 sam3_params params;
223 params.model_path = model_path;
224 params.use_gpu = use_gpu;
225 params.n_threads = n_threads;
226 params.encode_img_size = encode_img_size;
227
228 auto model = sam3_load_model(params);
229 if (!model) { fail("load failed"); return wire; }
230
231 auto state = sam3_create_state(*model, params);
232 if (!state) { fail("state failed"); return wire; }
233
234 bool visual_only = sam3_is_visual_only(*model);
235 sam3_tracker_ptr tracker;
236
237 if (visual_only) {
238 sam3_visual_track_params vtp;
239 vtp.max_keep_alive = 100;
240 vtp.recondition_every = 16;
241 tracker = sam3_create_visual_tracker(*model, vtp);
242 } else {
243 sam3_video_params vp;
244 vp.hotstart_delay = 0;
245 vp.max_keep_alive = 100;
246 tracker = sam3_create_tracker(*model, vp);
247 }
248 if (!tracker) { fail("tracker failed"); return wire; }
249
250 wire.t_load_ms = (ggml_time_us() - t0) / 1000.0;
251
252 // Frame 0: encode + add instance
253 t0 = ggml_time_us();
254
255 if (!sam3_encode_image(*state, *model, frames[0])) {

Callers 2

child_benchmarkFunction · 0.85
run_benchmark_isolatedFunction · 0.85

Calls 10

sam3_decode_video_frameFunction · 0.85
sam3_load_modelFunction · 0.85
sam3_create_stateFunction · 0.85
sam3_is_visual_onlyFunction · 0.85
sam3_create_trackerFunction · 0.85
sam3_encode_imageFunction · 0.85
sam3_propagate_frameFunction · 0.85
sam3_track_frameFunction · 0.85

Tested by

no test coverage detected