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

Method eval_perf

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

Source from the content-addressed store, hash-verified

594 }
595
596 bool eval_perf(ggml_backend_t backend, const char * op_name) {
597 mode = MODE_PERF;
598
599 static const size_t graph_nodes = 8192;
600
601 ggml_init_params params = {
602 /* .mem_size = */ ggml_tensor_overhead()*128 + ggml_graph_overhead_custom(graph_nodes, false),
603 /* .mem_base = */ NULL,
604 /* .no_alloc = */ true,
605 };
606 ggml_context_ptr ctx(ggml_init(params)); // smart ptr
607 GGML_ASSERT(ctx);
608
609 ggml_tensor * out = build_graph(ctx.get());
610
611 if (op_name != nullptr && op_desc(out) != op_name) {
612 //printf(" %s: skipping\n", op_desc(out).c_str());
613 return true;
614 }
615
616 int len = printf(" %s(%s): ", op_desc(out).c_str(), vars().c_str());
617 fflush(stdout);
618
619 // check if backends support op
620 if (!ggml_backend_supports_op(backend, out)) {
621 printf("not supported\n");
622 return true;
623 }
624
625 // align while also leaving some margin for variations in parameters
626 int align = 8;
627 int last = (len + align - 1) / align * align;
628 if (last - len < 5) {
629 last += align;
630 }
631 printf("%*s", last - len, "");
632
633 // allocate
634 ggml_backend_buffer_ptr buf(ggml_backend_alloc_ctx_tensors(ctx.get(), backend)); // smart ptr
635
636 if (buf == NULL) {
637 printf("failed to allocate tensors\n");
638 return false;
639 }
640
641 // randomize tensors
642 initialize_tensors(ctx.get());
643
644 // build graph
645 ggml_cgraph * gf = ggml_new_graph_custom(ctx.get(), graph_nodes, false);
646 ggml_build_forward_expand(gf, out);
647
648 // warmup run
649 ggml_status status = ggml_backend_graph_compute(backend, gf);
650 if (status != GGML_STATUS_SUCCESS) {
651 fprintf(stderr, "%s: ggml_backend_graph_compute failed. status=%s \n", __func__, ggml_status_to_string(status));
652 return false;
653 }

Callers 1

test_backendFunction · 0.80

Calls 15

printfFunction · 0.85
fprintfFunction · 0.85
ggml_status_to_stringFunction · 0.85
ggml_backend_get_deviceFunction · 0.85
ggml_graph_sizeFunction · 0.85
ggml_graph_n_nodesFunction · 0.85
ggml_graph_add_nodeFunction · 0.85
ggml_graph_nodeFunction · 0.85
ggml_is_view_opFunction · 0.70
ggml_tensor_overheadFunction · 0.50

Tested by

no test coverage detected