提交 e3d9d1e0 编写于 作者: A A. Unique TensorFlower 提交者: TensorFlower Gardener

Eliminate never called function and unused data members.

PiperOrigin-RevId: 564748979
上级 d4e9abaf
......@@ -76,22 +76,18 @@ tsl::Status PluginRegistry::RegisterFactoryInternal(
}
(*factories)[plugin_id] = factory;
plugin_names_[plugin_id] = plugin_name;
return ::tsl::OkStatus();
}
template <typename FACTORY_TYPE>
tsl::StatusOr<FACTORY_TYPE> PluginRegistry::GetFactoryInternal(
PluginId plugin_id, const std::map<PluginId, FACTORY_TYPE>& factories,
const std::map<PluginId, FACTORY_TYPE>& generic_factories) const {
PluginId plugin_id,
const std::map<PluginId, FACTORY_TYPE>& factories) const {
auto iter = factories.find(plugin_id);
if (iter == factories.end()) {
iter = generic_factories.find(plugin_id);
if (iter == generic_factories.end()) {
return tsl::Status(
absl::StatusCode::kNotFound,
absl::StrFormat("Plugin ID %p not registered.", plugin_id));
}
return tsl::Status(
absl::StatusCode::kNotFound,
absl::StrFormat("Plugin ID %p not registered.", plugin_id));
}
return iter->second;
......@@ -162,60 +158,48 @@ bool PluginRegistry::HasFactory(Platform::Id platform_id,
}
}
return HasFactory(generic_factories_, plugin_kind, plugin_id);
return false;
}
// Explicit instantiations to support types exposed in user/public API.
#define EMIT_PLUGIN_SPECIALIZATIONS(FACTORY_TYPE, FACTORY_VAR, PLUGIN_STRING) \
template tsl::StatusOr<PluginRegistry::FACTORY_TYPE> \
PluginRegistry::GetFactoryInternal<PluginRegistry::FACTORY_TYPE>( \
PluginId plugin_id, \
const std::map<PluginId, PluginRegistry::FACTORY_TYPE>& factories, \
const std::map<PluginId, PluginRegistry::FACTORY_TYPE>& \
generic_factories) const; \
\
template tsl::Status \
PluginRegistry::RegisterFactoryInternal<PluginRegistry::FACTORY_TYPE>( \
PluginId plugin_id, const std::string& plugin_name, \
PluginRegistry::FACTORY_TYPE factory, \
std::map<PluginId, PluginRegistry::FACTORY_TYPE>* factories); \
\
template <> \
tsl::Status PluginRegistry::RegisterFactory<PluginRegistry::FACTORY_TYPE>( \
Platform::Id platform_id, PluginId plugin_id, const std::string& name, \
PluginRegistry::FACTORY_TYPE factory) { \
return RegisterFactoryInternal(plugin_id, name, factory, \
&factories_[platform_id].FACTORY_VAR); \
} \
\
template <> \
tsl::Status PluginRegistry::RegisterFactoryForAllPlatforms< \
PluginRegistry::FACTORY_TYPE>(PluginId plugin_id, \
const std::string& name, \
PluginRegistry::FACTORY_TYPE factory) { \
return RegisterFactoryInternal(plugin_id, name, factory, \
&generic_factories_.FACTORY_VAR); \
} \
\
template <> \
tsl::StatusOr<PluginRegistry::FACTORY_TYPE> PluginRegistry::GetFactory( \
Platform::Id platform_id, PluginId plugin_id) { \
if (plugin_id == PluginConfig::kDefault) { \
plugin_id = default_factories_[platform_id].FACTORY_VAR; \
\
if (plugin_id == kNullPlugin) { \
return tsl::Status( \
absl::StatusCode::kFailedPrecondition, \
"No suitable " PLUGIN_STRING \
" plugin registered. Have you linked in a " PLUGIN_STRING \
"-providing plugin?"); \
} else { \
VLOG(2) << "Selecting default " PLUGIN_STRING " plugin, " \
<< plugin_names_[plugin_id]; \
} \
} \
return GetFactoryInternal(plugin_id, factories_[platform_id].FACTORY_VAR, \
generic_factories_.FACTORY_VAR); \
#define EMIT_PLUGIN_SPECIALIZATIONS(FACTORY_TYPE, FACTORY_VAR, PLUGIN_STRING) \
template tsl::StatusOr<PluginRegistry::FACTORY_TYPE> \
PluginRegistry::GetFactoryInternal<PluginRegistry::FACTORY_TYPE>( \
PluginId plugin_id, \
const std::map<PluginId, PluginRegistry::FACTORY_TYPE>& factories) \
const; \
\
template tsl::Status \
PluginRegistry::RegisterFactoryInternal<PluginRegistry::FACTORY_TYPE>( \
PluginId plugin_id, const std::string& plugin_name, \
PluginRegistry::FACTORY_TYPE factory, \
std::map<PluginId, PluginRegistry::FACTORY_TYPE>* factories); \
\
template <> \
tsl::Status PluginRegistry::RegisterFactory<PluginRegistry::FACTORY_TYPE>( \
Platform::Id platform_id, PluginId plugin_id, const std::string& name, \
PluginRegistry::FACTORY_TYPE factory) { \
return RegisterFactoryInternal(plugin_id, name, factory, \
&factories_[platform_id].FACTORY_VAR); \
} \
\
template <> \
tsl::StatusOr<PluginRegistry::FACTORY_TYPE> PluginRegistry::GetFactory( \
Platform::Id platform_id, PluginId plugin_id) { \
if (plugin_id == PluginConfig::kDefault) { \
plugin_id = default_factories_[platform_id].FACTORY_VAR; \
\
if (plugin_id == kNullPlugin) { \
return tsl::Status( \
absl::StatusCode::kFailedPrecondition, \
"No suitable " PLUGIN_STRING \
" plugin registered. Have you linked in a " PLUGIN_STRING \
"-providing plugin?"); \
} else { \
VLOG(2) << "Selecting default " PLUGIN_STRING " plugin"; \
} \
} \
return GetFactoryInternal(plugin_id, factories_[platform_id].FACTORY_VAR); \
}
EMIT_PLUGIN_SPECIALIZATIONS(BlasFactory, blas, "BLAS");
......
......@@ -62,13 +62,6 @@ class PluginRegistry {
tsl::Status RegisterFactory(Platform::Id platform_id, PluginId plugin_id,
const std::string& name, FactoryT factory);
// Registers the specified factory as usable by _all_ platform types.
// Reports errors just as RegisterFactory.
template <typename FactoryT>
tsl::Status RegisterFactoryForAllPlatforms(PluginId plugin_id,
const std::string& name,
FactoryT factory);
// Potentially sets the plugin identified by plugin_id to be the default
// for the specified platform and plugin kind. If this routine is called
// multiple types for the same PluginKind, the PluginId given in the last call
......@@ -114,8 +107,7 @@ class PluginRegistry {
// Actually performs the work of factory retrieval.
template <typename FactoryT>
tsl::StatusOr<FactoryT> GetFactoryInternal(
PluginId plugin_id, const std::map<PluginId, FactoryT>& factories,
const std::map<PluginId, FactoryT>& generic_factories) const;
PluginId plugin_id, const std::map<PluginId, FactoryT>& factories) const;
// Returns true if the specified plugin has been registered with the specified
// platform factories. Unlike the other overload of this method, this does
......@@ -129,15 +121,9 @@ class PluginRegistry {
// The set of registered factories, keyed by platform ID.
std::map<Platform::Id, PluginFactories> factories_;
// Plugins supported for all platform kinds.
PluginFactories generic_factories_;
// The sets of default factories, keyed by platform ID.
std::map<Platform::Id, DefaultFactories> default_factories_;
// Lookup table for plugin names.
std::map<PluginId, std::string> plugin_names_;
SE_DISALLOW_COPY_AND_ASSIGN(PluginRegistry);
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册