Skip to content

Commit ecfce8d

Browse files
committed
float-weight: Work around Windows constexpr NaN bug
1 parent faa5a49 commit ecfce8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+674
-511
lines changed

openfst/benchmark/BUILD.bazel

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,36 @@
1616
#
1717
# Run with --config=benchmark.
1818

19-
load("@rules_cc//cc:defs.bzl", "cc_binary")
19+
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
2020

2121
package(default_visibility = ["//visibility:public"])
2222

23+
cc_library(
24+
name = "benchmark_main",
25+
srcs = ["benchmain_main.cc"],
26+
deps = [
27+
"//openfst/compat:init",
28+
"@com_google_absl//absl/flags:flag",
29+
"@com_google_absl//absl/log:flags",
30+
"@com_google_benchmark//:benchmark",
31+
],
32+
)
33+
2334
cc_binary(
2435
name = "symbol-table_test",
2536
testonly = True,
2637
srcs = ["symbol-table_test.cc"],
2738
linkstatic = True,
2839
deps = [
40+
":benchmark_main",
2941
"//openfst/compat:compat_memory",
30-
"//openfst/compat:init",
3142
"//openfst/lib:symbol-table",
3243
"@com_google_absl//absl/flags:flag",
33-
"@com_google_absl//absl/flags:usage",
3444
"@com_google_absl//absl/log:check",
3545
"@com_google_absl//absl/log:flags",
3646
"@com_google_absl//absl/memory",
3747
"@com_google_absl//absl/strings",
3848
"@com_google_benchmark//:benchmark",
39-
"@com_google_googletest//:gtest",
4049
],
4150
)
4251

@@ -49,14 +58,12 @@ cc_binary(
4958
],
5059
linkstatic = True,
5160
deps = [
61+
":benchmark_main",
5262
"//openfst/compat:file_path",
53-
"//openfst/compat:init",
5463
"//openfst/extensions/ngram:ngram-fst",
5564
"//openfst/extensions/ngram:ngram-fst-file",
5665
"//openfst/lib",
5766
"@com_google_absl//absl/flags:flag",
58-
"@com_google_absl//absl/flags:usage",
59-
"@com_google_absl//absl/log",
6067
"@com_google_absl//absl/log:check",
6168
"@com_google_absl//absl/log:die_if_null",
6269
"@com_google_absl//absl/log:flags",
@@ -77,13 +84,12 @@ cc_binary(
7784
],
7885
linkstatic = True,
7986
deps = [
87+
":benchmark_main",
8088
"//openfst/compat:file_path",
81-
"//openfst/compat:init",
8289
"//openfst/extensions/ngram:ngram-fst",
8390
"//openfst/extensions/ngram:ngram-fst-file",
8491
"//openfst/lib",
8592
"@com_google_absl//absl/flags:flag",
86-
"@com_google_absl//absl/flags:usage",
8793
"@com_google_absl//absl/log",
8894
"@com_google_absl//absl/log:check",
8995
"@com_google_absl//absl/log:die_if_null",
@@ -106,13 +112,12 @@ cc_binary(
106112
],
107113
linkstatic = True,
108114
deps = [
115+
":benchmark_main",
109116
"//openfst/compat:file_path",
110-
"//openfst/compat:init",
111117
"//openfst/lib",
112118
"//openfst/lib:fst-decl",
113119
"@com_google_absl//absl/base",
114120
"@com_google_absl//absl/flags:flag",
115-
"@com_google_absl//absl/flags:usage",
116121
"@com_google_absl//absl/log",
117122
"@com_google_absl//absl/log:check",
118123
"@com_google_absl//absl/log:die_if_null",
@@ -132,12 +137,10 @@ cc_binary(
132137
],
133138
linkstatic = True,
134139
deps = [
140+
":benchmark_main",
135141
"//openfst/compat:file_path",
136-
"//openfst/compat:init",
137142
"//openfst/lib",
138143
"@com_google_absl//absl/flags:flag",
139-
"@com_google_absl//absl/flags:usage",
140-
"@com_google_absl//absl/log",
141144
"@com_google_absl//absl/log:die_if_null",
142145
"@com_google_absl//absl/log:flags",
143146
"@com_google_absl//absl/strings",
@@ -156,12 +159,10 @@ cc_binary(
156159
],
157160
linkstatic = True,
158161
deps = [
162+
":benchmark_main",
159163
"//openfst/compat:file_path",
160-
"//openfst/compat:init",
161164
"//openfst/lib",
162165
"@com_google_absl//absl/flags:flag",
163-
"@com_google_absl//absl/flags:usage",
164-
"@com_google_absl//absl/log",
165166
"@com_google_absl//absl/log:check",
166167
"@com_google_absl//absl/log:die_if_null",
167168
"@com_google_absl//absl/log:flags",
@@ -177,16 +178,13 @@ cc_binary(
177178
data = [],
178179
linkstatic = True,
179180
deps = [
180-
"//openfst/compat:init",
181+
":benchmark_main",
181182
"//openfst/lib",
182183
"@com_google_absl//absl/container:flat_hash_set",
183184
"@com_google_absl//absl/container:node_hash_set",
184185
"@com_google_absl//absl/flags:flag",
185-
"@com_google_absl//absl/flags:usage",
186-
"@com_google_absl//absl/log",
187186
"@com_google_absl//absl/log:flags",
188187
"@com_google_benchmark//:benchmark",
189-
"@com_google_googletest//:gtest",
190188
],
191189
)
192190

@@ -199,12 +197,10 @@ cc_binary(
199197
],
200198
linkstatic = True,
201199
deps = [
200+
":benchmark_main",
202201
"//openfst/compat:file_path",
203-
"//openfst/compat:init",
204202
"//openfst/lib",
205203
"@com_google_absl//absl/flags:flag",
206-
"@com_google_absl//absl/flags:usage",
207-
"@com_google_absl//absl/log",
208204
"@com_google_absl//absl/log:check",
209205
"@com_google_absl//absl/log:flags",
210206
"@com_google_benchmark//:benchmark",
@@ -222,12 +218,10 @@ cc_binary(
222218
],
223219
linkstatic = True,
224220
deps = [
221+
":benchmark_main",
225222
"//openfst/compat:file_path",
226-
"//openfst/compat:init",
227223
"//openfst/lib",
228224
"@com_google_absl//absl/flags:flag",
229-
"@com_google_absl//absl/flags:usage",
230-
"@com_google_absl//absl/log",
231225
"@com_google_absl//absl/log:check",
232226
"@com_google_absl//absl/log:die_if_null",
233227
"@com_google_absl//absl/log:flags",
@@ -243,12 +237,11 @@ cc_binary(
243237
data = ["testdata/serialize.fst"],
244238
linkstatic = True,
245239
deps = [
240+
":benchmark_main",
246241
"//openfst/compat:file_path",
247-
"//openfst/compat:init",
248242
"//openfst/lib",
249243
"//openfst/lib:symbol-table",
250244
"@com_google_absl//absl/flags:flag",
251-
"@com_google_absl//absl/flags:usage",
252245
"@com_google_absl//absl/log:die_if_null",
253246
"@com_google_absl//absl/log:flags",
254247
"@com_google_benchmark//:benchmark",
@@ -262,11 +255,9 @@ cc_binary(
262255
srcs = ["weight_test.cc"],
263256
linkstatic = True,
264257
deps = [
265-
"//openfst/compat:init",
258+
":benchmark_main",
266259
"//openfst/lib:weight",
267260
"@com_google_absl//absl/flags:flag",
268-
"@com_google_absl//absl/flags:usage",
269-
"@com_google_absl//absl/log",
270261
"@com_google_absl//absl/log:flags",
271262
"@com_google_benchmark//:benchmark",
272263
],

openfst/benchmark/CMakeLists.txt

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,21 @@ set(BENCHMARKS
3232
)
3333

3434
foreach(BENCHMARK_SRC ${BENCHMARKS})
35-
# CMake target names must be globally unique across the entire project.
36-
# Since many benchmarks share filenames with the tests in openfst/test
37-
# (e.g., compact_test.cc), we append a suffix to the target name.
35+
# CMake target names must be globally unique across the entire project. Since
36+
# many benchmarks share filenames with the tests in openfst/test (e.g.,
37+
# compact_test.cc), we append a suffix to the target name.
3838
set(BENCHMARK_TARGET "${BENCHMARK_SRC}_benchmark")
39-
add_executable(${BENCHMARK_TARGET} ${BENCHMARK_SRC}.cc)
39+
add_executable(${BENCHMARK_TARGET} ${BENCHMARK_SRC}.cc benchmain_main.cc)
4040

41-
# Set the output filename to match the source name (e.g., 'compact_test')
42-
# so the binary on disk does not have the suffix.
43-
set_target_properties(${BENCHMARK_TARGET} PROPERTIES OUTPUT_NAME ${BENCHMARK_SRC})
41+
# Set the output filename to match the source name (e.g., 'compact_test') so
42+
# the binary on disk does not have the suffix.
43+
set_target_properties(
44+
${BENCHMARK_TARGET}
45+
PROPERTIES OUTPUT_NAME ${BENCHMARK_SRC}
46+
)
4447

45-
target_include_directories(
46-
${BENCHMARK_TARGET} PRIVATE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
48+
target_include_directories(${BENCHMARK_TARGET}
49+
PRIVATE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
4750
)
4851

4952
target_link_libraries(
@@ -65,8 +68,13 @@ foreach(BENCHMARK_SRC ${BENCHMARKS})
6568
if(OPENFST_ENABLE_NGRAM_FSTS)
6669
target_link_libraries(${BENCHMARK_TARGET} PRIVATE fstngram)
6770
else()
68-
message(STATUS "NGram FSTs disabled, skipping benchmark ${BENCHMARK_TARGET}")
69-
set_target_properties(${BENCHMARK_TARGET} PROPERTIES EXCLUDE_FROM_ALL TRUE)
71+
message(
72+
STATUS "NGram FSTs disabled, skipping benchmark ${BENCHMARK_TARGET}"
73+
)
74+
set_target_properties(
75+
${BENCHMARK_TARGET}
76+
PROPERTIES EXCLUDE_FROM_ALL TRUE
77+
)
7078
endif()
7179
endif()
7280
endforeach()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2026 The OpenFst Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Main file for running OpenFst benchmarks.
16+
17+
#include "openfst/compat/init.h"
18+
#include "absl/flags/flag.h"
19+
#include "absl/log/flags.h"
20+
#include "benchmark/benchmark.h"
21+
22+
int main(int argc, char* argv[]) {
23+
// `MaybeReenterWithoutASLR` calls `execve`, so do it right away.
24+
benchmark::MaybeReenterWithoutASLR(argc, argv);
25+
26+
benchmark::Initialize(&argc, argv);
27+
fst::InitOpenFst(argv[0], &argc, &argv, true);
28+
29+
benchmark::RunSpecifiedBenchmarks();
30+
return 0;
31+
}

openfst/benchmark/compact_test.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222
#include <memory>
2323
#include <string>
2424

25-
#include "openfst/compat/init.h"
2625
#include "openfst/compat/file_path.h"
2726
#include "gtest/gtest.h"
2827
#include "absl/base/casts.h"
2928
#include "absl/flags/flag.h"
3029
#include "absl/log/check.h"
3130
#include "absl/log/die_if_null.h"
32-
#include "absl/log/flags.h"
3331
#include "absl/log/log.h"
3432
#include "benchmark/benchmark.h"
3533
#include "openfst/lib/accumulator.h"
@@ -203,9 +201,3 @@ BENCHMARK_TEMPLATE(BM_Copy, StdCompactUnweightedFst);
203201

204202
} // namespace
205203
} // namespace fst
206-
207-
int main(int argc, char** argv) {
208-
fst::InitOpenFst(argv[0], &argc, &argv, true);
209-
benchmark::RunSpecifiedBenchmarks();
210-
return 0;
211-
}

openfst/benchmark/compose_test.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323
#include <memory>
2424
#include <string>
2525

26-
#include "openfst/compat/init.h"
2726
#include "openfst/compat/file_path.h"
2827
#include "gtest/gtest.h"
2928
#include "absl/flags/flag.h"
3029
#include "absl/log/check.h"
3130
#include "absl/log/die_if_null.h"
32-
#include "absl/log/flags.h"
3331
#include "absl/log/log.h"
3432
#include "absl/strings/string_view.h"
3533
#include "benchmark/benchmark.h"
@@ -280,9 +278,3 @@ BENCHMARK(BM_LookAheadCompose<StdNGramFst>);
280278

281279
} // namespace
282280
} // namespace fst
283-
284-
int main(int argc, char** argv) {
285-
fst::InitOpenFst(argv[0], &argc, &argv, true);
286-
benchmark::RunSpecifiedBenchmarks();
287-
return 0;
288-
}

openfst/benchmark/connect_test.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@
2222
#include <memory>
2323
#include <string>
2424

25-
#include "openfst/compat/init.h"
2625
#include "openfst/compat/file_path.h"
2726
#include "gtest/gtest.h"
2827
#include "absl/flags/flag.h"
2928
#include "absl/log/die_if_null.h"
30-
#include "absl/log/flags.h"
3129
#include "absl/strings/string_view.h"
3230
#include "benchmark/benchmark.h"
3331
#include "openfst/lib/arc.h"
@@ -99,9 +97,3 @@ BENCHMARK(BM_CyclicConnect);
9997

10098
} // namespace
10199
} // namespace fst
102-
103-
int main(int argc, char** argv) {
104-
fst::InitOpenFst(argv[0], &argc, &argv, true);
105-
benchmark::RunSpecifiedBenchmarks();
106-
return 0;
107-
}

openfst/benchmark/determinize_test.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323
#include <memory>
2424
#include <string>
2525

26-
#include "openfst/compat/init.h"
2726
#include "openfst/compat/file_path.h"
2827
#include "gtest/gtest.h"
2928
#include "absl/flags/flag.h"
3029
#include "absl/log/check.h"
3130
#include "absl/log/die_if_null.h"
32-
#include "absl/log/flags.h"
3331
#include "benchmark/benchmark.h"
3432
#include "openfst/lib/arc.h"
3533
#include "openfst/lib/expanded-fst.h"
@@ -118,9 +116,3 @@ BENCHMARK(BM_DeterminizeFstTrans);
118116

119117
} // namespace
120118
} // namespace fst
121-
122-
int main(int argc, char** argv) {
123-
fst::InitOpenFst(argv[0], &argc, &argv, true);
124-
benchmark::RunSpecifiedBenchmarks();
125-
return 0;
126-
}

openfst/benchmark/fst_test.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323
#include <memory>
2424
#include <string>
2525

26-
#include "openfst/compat/init.h"
2726
#include "openfst/compat/file_path.h"
2827
#include "gtest/gtest.h"
2928
#include "absl/flags/flag.h"
3029
#include "absl/log/check.h"
3130
#include "absl/log/die_if_null.h"
32-
#include "absl/log/flags.h"
3331
#include "benchmark/benchmark.h"
3432
#include "openfst/extensions/ngram/ngram-fst.h"
3533
#include "openfst/lib/arc-map.h"
@@ -260,9 +258,3 @@ BENCHMARK_TEMPLATE(BM_Properties, StdConstFst);
260258

261259
} // namespace
262260
} // namespace fst
263-
264-
int main(int argc, char** argv) {
265-
fst::InitOpenFst(argv[0], &argc, &argv, true);
266-
benchmark::RunSpecifiedBenchmarks();
267-
return 0;
268-
}

0 commit comments

Comments
 (0)