MCPcopy Create free account
hub / github.com/cactus-compute/cactus / benchmark_binary_elementwise_ops

Function benchmark_binary_elementwise_ops

tests/test_performance.cpp:92–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90
91template<typename T>
92void 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
135void benchmark_conv1d_ops(TestUtils::TestRunner& runner, const BenchmarkConfig& config) {
136 std::vector<std::tuple<size_t, size_t, size_t, size_t>> shapes = {

Callers

nothing calls this directly

Calls 11

precision_to_stringFunction · 0.85
setup_random_dataFunction · 0.85
calculate_gflopsFunction · 0.85
create_inputMethod · 0.80
set_input_dataMethod · 0.80
log_performanceMethod · 0.80
addMethod · 0.45
subtractMethod · 0.45
multiplyMethod · 0.45
divideMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected