| 90 | |
| 91 | template<typename T> |
| 92 | void benchmark_binary_elementwise_ops(TestUtils::TestRunner& runner, const BenchmarkConfig& config) { |
| 93 | const std::vector<std::pair<std::string, std::function<size_t(CactusGraph&, size_t, size_t)>>> ops = { |
| 94 | {"Add", [](CactusGraph& b, size_t a, size_t c) { return b.add(a, c); }}, |
| 95 | {"Subtract", [](CactusGraph& b, size_t a, size_t c) { return b.subtract(a, c); }}, |
| 96 | {"Multiply", [](CactusGraph& b, size_t a, size_t c) { return b.multiply(a, c); }}, |
| 97 | {"Divide", [](CactusGraph& b, size_t a, size_t c) { return b.divide(a, c); }} |
| 98 | }; |
| 99 | |
| 100 | Precision precision = TestUtils::default_precision<T>(); |
| 101 | std::string prec_str = precision_to_string(precision); |
| 102 | |
| 103 | for (const auto& [op_name, op_func] : ops) { |
| 104 | for (size_t dim : config.dimensions) { |
| 105 | size_t total_elements = dim * dim; |
| 106 | |
| 107 | TestUtils::TestFixture<T> fixture(op_name); |
| 108 | size_t input_a = fixture.create_input({dim, dim}, precision); |
| 109 | size_t input_b = fixture.create_input({dim, dim}, precision); |
| 110 | |
| 111 | std::vector<T> data_a(total_elements), data_b(total_elements); |
| 112 | setup_random_data(data_a); |
| 113 | setup_random_data(data_b); |
| 114 | |
| 115 | fixture.set_input_data(input_a, data_a, precision); |
| 116 | fixture.set_input_data(input_b, data_b, precision); |
| 117 | |
| 118 | op_func(fixture.graph(), input_a, input_b); |
| 119 | |
| 120 | double time_ms = time_operation<T>([&]() { |
| 121 | fixture.execute(); |
| 122 | }, config.iterations); |
| 123 | |
| 124 | double gflops = calculate_gflops(total_elements, time_ms); |
| 125 | |
| 126 | std::ostringstream details; |
| 127 | details << std::fixed << std::setprecision(3) << time_ms << "ms, " |
| 128 | << std::setprecision(2) << gflops << " GFLOPS"; |
| 129 | runner.log_performance(op_name + " " + std::to_string(dim) + "x" + std::to_string(dim), |
| 130 | details.str()); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | void benchmark_conv1d_ops(TestUtils::TestRunner& runner, const BenchmarkConfig& config) { |
| 136 | std::vector<std::tuple<size_t, size_t, size_t, size_t>> shapes = { |
nothing calls this directly
no test coverage detected