MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / eval

Method eval

smallthinker/tests/test-backend-ops.cpp:435–594  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

433 }
434
435 bool eval(ggml_backend_t backend1, ggml_backend_t backend2, const char * op_name) {
436 mode = MODE_TEST;
437
438 ggml_init_params params = {
439 /* .mem_size = */ ggml_tensor_overhead()*128 + ggml_graph_overhead(),
440 /* .mem_base = */ NULL,
441 /* .no_alloc = */ true,
442 };
443 ggml_context * ctx = ggml_init(params);
444 GGML_ASSERT(ctx);
445
446 gf = ggml_new_graph(ctx);
447
448 // pre-graph sentinel
449 add_sentinel(ctx);
450
451 ggml_tensor * out = build_graph(ctx);
452
453 if (op_name != nullptr && op_desc(out) != op_name) {
454 //printf(" %s: skipping\n", op_desc(out).c_str());
455 ggml_free(ctx);
456 return true;
457 }
458
459 printf(" %s(%s): ", op_desc(out).c_str(), vars().c_str());
460 fflush(stdout);
461
462 // check if the backends support the ops
463 bool supported = true;
464 for (ggml_backend_t backend : {backend1, backend2}) {
465 for (ggml_tensor * t = ggml_get_first_tensor(ctx); t != NULL; t = ggml_get_next_tensor(ctx, t)) {
466 if (!ggml_backend_supports_op(backend, t)) {
467 printf("not supported [%s] ", ggml_backend_name(backend));
468 supported = false;
469 break;
470 }
471 }
472 }
473 if (!supported) {
474 printf("\n");
475 ggml_free(ctx);
476 return true;
477 }
478
479 // post-graph sentinel
480 add_sentinel(ctx);
481
482 // allocate
483 ggml_backend_buffer_t buf = ggml_backend_alloc_ctx_tensors(ctx, backend1);
484
485 if (buf == NULL) {
486 printf("failed to allocate tensors [%s] ", ggml_backend_name(backend1));
487 ggml_free(ctx);
488 return false;
489 }
490
491 // build graph
492 ggml_build_forward_expand(gf, out);

Callers 1

test_backendFunction · 0.80

Calls 15

printfFunction · 0.85
ggml_graph_add_nodeFunction · 0.85
tensor_to_floatFunction · 0.85
ggml_op_descFunction · 0.85
isinf_or_maxFunction · 0.85
nmseFunction · 0.85
ggml_tensor_overheadFunction · 0.50
ggml_graph_overheadFunction · 0.50
ggml_initFunction · 0.50
ggml_new_graphFunction · 0.50

Tested by

no test coverage detected