Skip to content

Commit

Permalink
Allow bench/models/benchmark to build and run on targets that don't a…
Browse files Browse the repository at this point in the history
…llow you to provide your own main() for benchmarks; instead, they provide a weakly-linked bottleneck for intercepting command-line flags that we must override.

PiperOrigin-RevId: 704771511
  • Loading branch information
xnnpack-bot committed Dec 10, 2024
1 parent 7440eee commit a536778
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions bench/models/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ BENCHMARK(QD8Attention)

BENCHMARK(QS8MobileNetV2)->Unit(benchmark::kMicrosecond)->UseRealTime();

int main(int argc, char** argv) {
::benchmark::Initialize(&argc, argv);
int ProcessArgs(int& argc, char**& argv) {
for (int i = 1; i < argc;) {
if (strncmp(argv[i], "--num_threads=", 14) == 0) {
FLAGS_num_threads = atoi(argv[i] + 14);
Expand All @@ -260,7 +259,23 @@ int main(int argc, char** argv) {
++i;
}
}
return 0;
}

#ifdef BENCHMARK_ARGS_BOTTLENECK
// We are provided with a main that will call this function
extern "C" {
int BenchmarkArgBottleneck(int& argc, char**& argv) {
return ProcessArgs(argc, argv);
}
}
#else
int main(int argc, char** argv) {
::benchmark::Initialize(&argc, argv);
int status = ProcessArgs(argc, argv);
if (status != 0) return status;
if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1;
::benchmark::RunSpecifiedBenchmarks();
}
#endif

0 comments on commit a536778

Please sign in to comment.