Skip to content

Commit 5b2c168

Browse files
whhonecopybara-github
authored andcommitted
[litertlm] fix a Windows JVM issue with absl::flat_hash_map
The solution here is switching to std::map. LiteRT-LM-PiperOrigin-RevId: 908915953
1 parent 07e9c4a commit 5b2c168

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

runtime/engine/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ cc_library(
4747
deps = [
4848
":engine_interface",
4949
":engine_settings",
50-
"@com_google_absl//absl/container:flat_hash_map",
5150
"@com_google_absl//absl/functional:any_invocable",
5251
"@com_google_absl//absl/log:absl_log",
5352
"@com_google_absl//absl/status",

runtime/engine/engine_factory.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
#include <cstddef>
1919
#include <memory>
2020
#include <string>
21+
#include <unordered_map>
2122
#include <utility>
2223
#include <vector>
2324

24-
#include "absl/container/flat_hash_map.h" // from @com_google_absl
2525
#include "absl/functional/any_invocable.h" // from @com_google_absl
2626
#include "absl/log/absl_log.h" // from @com_google_absl
2727
#include "absl/status/status.h" // from @com_google_absl
@@ -209,10 +209,17 @@ class EngineFactory {
209209
}},
210210
}) {}
211211

212-
absl::flat_hash_map<EngineType, Creator> registry_;
212+
// Use std::unordered_map instead of absl::flat_hash_map to avoid Windows
213+
// build/linker issues across DLL boundaries (see cl/403158423 and
214+
// b/508692203). std::unordered_map can also be faster when the number of
215+
// elements is low.
216+
std::unordered_map<EngineType, Creator> registry_;
217+
213218
// Map of preferred engine types for each backend. The first available
214219
// (registered) engine type in the list will be selected by CreateDefault().
215-
absl::flat_hash_map<Backend, std::vector<EngineType>> preferred_engines_;
220+
// Use std::unordered_map for consistency with registry_ and to avoid similar
221+
// Windows issues.
222+
std::unordered_map<Backend, std::vector<EngineType>> preferred_engines_;
216223
};
217224

218225
// Helper struct to register an engine type with the EngineFactory.

0 commit comments

Comments
 (0)