| 1470 | } |
| 1471 | |
| 1472 | bool eval_perf(ggml_backend_t backend, const char * op_names_filter, printer * output_printer) { |
| 1473 | mode = MODE_PERF; |
| 1474 | |
| 1475 | static const size_t graph_nodes = 8192; |
| 1476 | |
| 1477 | ggml_init_params params = { |
| 1478 | /* .mem_size = */ ggml_tensor_overhead()*128 + ggml_graph_overhead_custom(graph_nodes, false), |
| 1479 | /* .mem_base = */ NULL, |
| 1480 | /* .no_alloc = */ true, |
| 1481 | }; |
| 1482 | ggml_context_ptr ctx(ggml_init(params)); // smart ptr |
| 1483 | GGML_ASSERT(ctx); |
| 1484 | |
| 1485 | ggml_tensor * out = build_graph(ctx.get()); |
| 1486 | current_op_name = op_desc(out); |
| 1487 | if (!matches_filter(out, op_names_filter)) { |
| 1488 | //printf(" %s: skipping\n", op_desc(out).c_str()); |
| 1489 | return true; |
| 1490 | } |
| 1491 | |
| 1492 | if (!ggml_backend_supports_op(backend, out)) { |
| 1493 | // Create test result for unsupported performance test |
| 1494 | test_result result(ggml_backend_name(backend), current_op_name, vars(), "perf", false, false, |
| 1495 | "not supported"); |
| 1496 | |
| 1497 | output_printer->print_test_result(result); |
| 1498 | |
| 1499 | return true; |
| 1500 | } |
| 1501 | |
| 1502 | // allocate |
| 1503 | ggml_backend_buffer_ptr buf(ggml_backend_alloc_ctx_tensors(ctx.get(), backend)); // smart ptr |
| 1504 | |
| 1505 | if (buf == NULL) { |
| 1506 | printf("failed to allocate tensors\n"); |
| 1507 | return false; |
| 1508 | } |
| 1509 | |
| 1510 | // randomize tensors |
| 1511 | initialize_tensors(ctx.get()); |
| 1512 | |
| 1513 | // build graph |
| 1514 | ggml_cgraph * gf = ggml_new_graph_custom(ctx.get(), graph_nodes, false); |
| 1515 | ggml_build_forward_expand(gf, out); |
| 1516 | |
| 1517 | // warmup run |
| 1518 | ggml_status status = ggml_backend_graph_compute(backend, gf); |
| 1519 | if (status != GGML_STATUS_SUCCESS) { |
| 1520 | fprintf(stderr, "%s: ggml_backend_graph_compute failed. status=%s \n", __func__, ggml_status_to_string(status)); |
| 1521 | return false; |
| 1522 | } |
| 1523 | |
| 1524 | // determine number of runs |
| 1525 | int n_runs; |
| 1526 | bool is_cpu = ggml_backend_dev_type(ggml_backend_get_device(backend)) == GGML_BACKEND_DEVICE_TYPE_CPU; |
| 1527 | if (op_flops(out) > 0) { |
| 1528 | // based on flops |
| 1529 | const uint64_t GFLOP = 1000 * 1000 * 1000; |
no test coverage detected