Skip to content

Commit

Permalink
feat(//core/plugins): Gating plugin logging based on global config
Browse files Browse the repository at this point in the history
Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
  • Loading branch information
narendasan committed May 13, 2021
1 parent 803eaf5 commit 1d5a088
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions core/plugins/register_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,37 @@ namespace impl {
class TRTorchPluginRegistry {
public:
TRTorchPluginRegistry() {
trtorch_logger.log(util::logging::LogLevel::kINFO, "Instatiated the TRTorch plugin registry class");
// register libNvInferPlugins and TRTorch plugins
// trtorch_logger logging level is set to kERROR and reset back to kDEBUG.
// This is because initLibNvInferPlugins initializes only a subset of plugins and logs them.
// Plugins outside this subset in TensorRT are not being logged in this. So temporarily we disable this to prevent
// multiple logging of same plugins. To provide a clear list of all plugins, we iterate through getPluginRegistry()
// where it prints the list of all the plugins registered in TensorRT with their namespaces.
trtorch_logger.set_reportable_log_level(util::logging::LogLevel::kERROR);
initLibNvInferPlugins(&trtorch_logger, "");
trtorch_logger.set_reportable_log_level(util::logging::LogLevel::kDEBUG);
plugin_logger.set_reportable_log_level(util::logging::LogLevel::kERROR);
initLibNvInferPlugins(&plugin_logger, "");
plugin_logger.set_reportable_log_level(util::logging::get_logger().get_reportable_log_level());

int numCreators = 0;
auto pluginsList = getPluginRegistry()->getPluginCreatorList(&numCreators);
for (int k = 0; k < numCreators; ++k) {
if (!pluginsList[k]) {
trtorch_logger.log(util::logging::LogLevel::kDEBUG, "Plugin creator for plugin " + str(k) + " is a nullptr");
plugin_logger.log(util::logging::LogLevel::kDEBUG, "Plugin creator for plugin " + str(k) + " is a nullptr");
continue;
}
std::string pluginNamespace = pluginsList[k]->getPluginNamespace();
trtorch_logger.log(
plugin_logger.log(
util::logging::LogLevel::kDEBUG,
"Registered plugin creator - " + std::string(pluginsList[k]->getPluginName()) +
", Namespace: " + pluginNamespace);
}
trtorch_logger.log(util::logging::LogLevel::kDEBUG, "Total number of plugins registered: " + str(numCreators));
plugin_logger.log(util::logging::LogLevel::kDEBUG, "Total number of plugins registered: " + str(numCreators));
}

public:
util::logging::TRTorchLogger trtorch_logger =
util::logging::TRTorchLogger("[TRTorch Plugins Context] - ", util::logging::LogLevel::kDEBUG, true);
util::logging::TRTorchLogger plugin_logger = util::logging::TRTorchLogger(
"[TRTorch Plugins Context] - ",
util::logging::get_logger().get_reportable_log_level(),
util::logging::get_logger().get_is_colored_output_on());
};

namespace {
Expand Down

0 comments on commit 1d5a088

Please sign in to comment.