Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions projects/hipdnn/backend/src/logging/ComponentFormatter.hpp

This file was deleted.

109 changes: 48 additions & 61 deletions projects/hipdnn/backend/src/logging/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: MIT

#include "Logging.hpp"
#include "ComponentFormatter.hpp"
#include "PlatformUtils.hpp"

#include <hipdnn_data_sdk/logging/CallbackTypes.h>
Expand Down Expand Up @@ -31,7 +30,16 @@ namespace
std::mutex s_loggingInitMutex; // NOLINT(readability-identifier-naming)
bool s_loggingInitialized = false; // NOLINT(readability-identifier-naming)
const std::string S_BACKEND_LOGGER_NAME = "hipdnn_backend";
const std::string S_CALLBACK_RECEIVER_LOGGER_NAME = "hipdnn_callback_receiver";

// Pattern string for the backend logger.
// Component name is already included in messages (e.g., "[hipdnn_backend] ..."),
// so the pattern includes timestamp, thread ID, and log level, but not a component name.
constexpr const char* BACKEND_LOGGER_PATTERN = "[%Y-%m-%d %H:%M:%S.%e] [tid %t] [%l] %v";

std::shared_ptr<spdlog::logger> getBackendLogger()
{
return spdlog::get(S_BACKEND_LOGGER_NAME);
}

} // namespace

Expand Down Expand Up @@ -130,21 +138,19 @@ void initialize()
auto backendLogger = std::make_shared<spdlog::async_logger>(
S_BACKEND_LOGGER_NAME, sharedSink, spdlog::thread_pool());

// In spdlog, the formatting is a property of the underlying sink, not the logger.
// However, we need one destination sink for thread safety because the mutex is attached to the sink.
// Therefore, we implement a custom formatter to have distinct formatting for the backend, which does not use a callback sink.
backendLogger->set_formatter(
std::make_unique<hipdnn_backend::logging::ComponentFormatter>());
spdlog::register_logger(backendLogger);
// Use a simple pattern formatter for the single unified logger
// Component name is already included in the message (e.g., "[hipdnn_backend] ...")
backendLogger->set_pattern(BACKEND_LOGGER_PATTERN);

auto callbackReceiverLogger = std::make_shared<spdlog::async_logger>(
S_CALLBACK_RECEIVER_LOGGER_NAME, sharedSink, spdlog::thread_pool());
// Use ComponentFormatter which detects "hipdnn_callback_receiver" and applies appropriate formatting
callbackReceiverLogger->set_formatter(
std::make_unique<hipdnn_backend::logging::ComponentFormatter>());
spdlog::register_logger(callbackReceiverLogger);
// Set spdlog to accept all messages (trace is most verbose)
// Actual filtering is done in HIPDNN_BACKEND_LOG*() macro via isLogLevelEnabled()
backendLogger->set_level(spdlog::level::trace);

spdlog::register_logger(backendLogger);

setLogLevel(logLevel);
// Update the data_sdk log level cache for use by the
// HIPDNN_BACKEND_LOG*() macros to filter-out logs based on level.
hipdnn_data_sdk::logging::setLogLevel(logLevel);

s_loggingInitialized = true;

Expand All @@ -167,66 +173,47 @@ void cleanup()
s_loggingInitialized = false;
}

void setLogLevel(hipdnnSeverity_t severity)
namespace
{
// Helper to convert hipdnnSeverity_t to spdlog level
spdlog::level::level_enum toSpdlogLevel(hipdnnSeverity_t severity)
{
switch(severity)
{
case HIPDNN_SEV_OFF:
spdlog::set_level(spdlog::level::off);
break;
case HIPDNN_SEV_INFO:
spdlog::set_level(spdlog::level::info);
break;
case HIPDNN_SEV_WARN:
spdlog::set_level(spdlog::level::warn);
break;
case HIPDNN_SEV_ERROR:
spdlog::set_level(spdlog::level::err);
break;
case HIPDNN_SEV_FATAL:
spdlog::set_level(spdlog::level::critical);
break;
return spdlog::level::critical;
case HIPDNN_SEV_ERROR:
return spdlog::level::err;
case HIPDNN_SEV_WARN:
return spdlog::level::warn;
case HIPDNN_SEV_INFO:
return spdlog::level::info;
case HIPDNN_SEV_OFF:
default:
// Unknown severity, default to off
spdlog::set_level(spdlog::level::off);
break;
return spdlog::level::off;
}
}
} // namespace

std::shared_ptr<spdlog::logger> getCallbackReceiverLogger()
void logMessage(hipdnnSeverity_t severity, const std::string& message)
{
return spdlog::get(S_CALLBACK_RECEIVER_LOGGER_NAME);
}
// Check log level using data_sdk infrastructure
if(!hipdnn_data_sdk::logging::isLogLevelEnabled(severity))
{
return;
}

std::shared_ptr<spdlog::logger> getBackendLogger()
{
return spdlog::get(S_BACKEND_LOGGER_NAME);
if(auto logger = getBackendLogger())
{
logger->log(toSpdlogLevel(severity), message);
}
}

void hipdnnLoggingCallback(hipdnnSeverity_t severity, const char* msg)
{
initialize();

if(auto logger = getCallbackReceiverLogger())
{
switch(severity)
{
case HIPDNN_SEV_FATAL:
logger->critical(msg);
break;
case HIPDNN_SEV_ERROR:
logger->error(msg);
break;
case HIPDNN_SEV_WARN:
logger->warn(msg);
break;
case HIPDNN_SEV_OFF:
break;
default:
logger->info(msg);
break;
}
}
// Message already includes component name from source (frontend/plugins)
// Route through central backend logMessage function
logMessage(severity, msg);
}

} // namespace logging
Expand Down
67 changes: 45 additions & 22 deletions projects/hipdnn/backend/src/logging/Logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,52 @@
// Backend-specific logging macros
// These are separate from HIPDNN_LOG_* used by frontend/plugins to avoid conflicts
#ifdef HIPDNN_BACKEND_COMPILATION
#define _HIPDNN_BACKEND_LOG_ACTION(spdlog_level, ...) \
do \
{ \
hipdnn_backend::logging::initialize(); \
auto _logger = hipdnn_backend::logging::getBackendLogger(); \
if(_logger && _logger->should_log(spdlog_level)) \
{ \
_logger->log(spdlog_level, __VA_ARGS__); \
} \
#include <fmt/format.h>
#include <hipdnn_data_sdk/logging/LogLevel.hpp>

#define HIPDNN_BACKEND_LOG_INFO(...) \
do \
{ \
hipdnn_backend::logging::initialize(); \
if(hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_INFO)) \
{ \
hipdnn_backend::logging::logMessage( \
HIPDNN_SEV_INFO, fmt::format("[hipdnn_backend] {}", fmt::format(__VA_ARGS__))); \
} \
} while(0)

#define HIPDNN_BACKEND_LOG_WARN(...) \
do \
{ \
hipdnn_backend::logging::initialize(); \
if(hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_WARN)) \
{ \
hipdnn_backend::logging::logMessage( \
HIPDNN_SEV_WARN, fmt::format("[hipdnn_backend] {}", fmt::format(__VA_ARGS__))); \
} \
} while(0)

#define HIPDNN_BACKEND_LOG_ERROR(...) \
do \
{ \
hipdnn_backend::logging::initialize(); \
if(hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_ERROR)) \
{ \
hipdnn_backend::logging::logMessage( \
HIPDNN_SEV_ERROR, fmt::format("[hipdnn_backend] {}", fmt::format(__VA_ARGS__))); \
} \
} while(0)
Comment on lines +40 to 49
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting, I guess this is how you handle the double formatting hehe.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[2026-02-09 19:35:28.114] [tid 232181] [info] System Information: {System Name: Linux, Node Name: bb88fa0967dd, Release: 5.15.0-112-generic, Version: #122-Ubuntu SMP Thu May 23 07:48:21 UTC 2024, Machine: x86_64}
[2026-02-09 19:35:28.234] [tid 232181] [info] HIP Device Information: {Device: 0, Name: AMD Instinct MI210, Global Mem: 68702699520 bytes, Compute: 9.0, MPs: 104, Clock: 1700000 kHz}
[2026-02-09 19:35:28.234] [tid 232181] [info] [hipdnn_backend] API called: [hipdnnCreate] handle_ptr=0x7ffd79576e40
[2026-02-09 19:35:28.234] [tid 232181] [info] [hipdnn_backend] Attempting to load plugin from [/develop/work/rocmlibs2/projects/hipdnn/build/debug/installdir/lib/hipdnn_plugins/engines/libmiopen_legacy_plugin.so]
[2026-02-09 19:35:28.234] [tid 232181] [info] [hipdnn_backend] SharedLibrary: Attempting to load shared library from final absolute path: /develop/work/rocmlibs2/projects/hipdnn/build/debug/installdir/lib/hipdnn_plugins/engines/libmiopen_legacy_plugin.so
[2026-02-09 19:35:30.631] [tid 232181] [info] [hipdnn_backend] Plugin loaded successfully: /develop/work/rocmlibs2/projects/hipdnn/build/debug/installdir/lib/hipdnn_plugins/engines/libmiopen_legacy_plugin.so
[2026-02-09 19:35:30.631] [tid 232216] [info] [miopen_plugin] API success: [hipdnnPluginSetLoggingCallbackImpl] 
[2026-02-09 19:35:30.631] [tid 232181] [info] [hipdnn_backend] Plugin info: name=miopen_plugin, version=1.0.0, type=HIPDNN_PLUGIN_TYPE_ENGINE(1)
[2026-02-09 19:35:30.631] [tid 232216] [info] [miopen_plugin] API called: [hipdnnEnginePluginGetAllEngineIdsImpl] engineIds=0x0, maxEngines=0, numEngines=0x7ffd79575e84
[2026-02-09 19:35:30.631] [tid 232216] [info] [miopen_plugin] API success: [hipdnnEnginePluginGetAllEngineIdsImpl] numEngines=1 totalEngines=1
[2026-02-09 19:35:30.631] [tid 232216] [info] [miopen_plugin] API called: [hipdnnEnginePluginGetAllEngineIdsImpl] engineIds=0x563a322412f0, maxEngines=1, numEngines=0x7ffd79575e84
[2026-02-09 19:35:30.631] [tid 232216] [info] [miopen_plugin] API success: [hipdnnEnginePluginGetAllEngineIdsImpl] numEngines=1 totalEngines=1
[2026-02-09 19:35:30.631] [tid 232181] [info] [hipdnn_backend] Attempting to load plugin from [/develop/work/rocmlibs2/projects/hipdnn/build/debug/installdir/lib/hipdnn_plugins/engines/libmiopen_plugin.so]
[2026-02-09 19:35:30.631] [tid 232181] [info] [hipdnn_backend] SharedLibrary: Attempting to load shared library from final absolute path: /develop/work/rocmlibs2/projects/hipdnn/build/debug/installdir/lib/hipdnn_plugins/engines/libmiopen_plugin.so
[2026-02-09 19:35:30.633] [tid 232217] [info] [miopen_plugin] API success: [hipdnnPluginSetLoggingCallbackImpl] 
[2026-02-09 19:35:30.634] [tid 232217] [info] [miopen_plugin] API called: [hipdnnEnginePluginGetAllEngineIdsImpl] engineIds=0x0, maxEngines=0, numEngines=0x7ffd79575e84
[2026-02-09 19:35:30.634] [tid 232217] [info] [miopen_plugin] API success: [hipdnnEnginePluginGetAllEngineIdsImpl] numEngines=1 totalEngines=1
[2026-02-09 19:35:30.634] [tid 232217] [info] [miopen_plugin] API called: [hipdnnEnginePluginGetAllEngineIdsImpl] engineIds=0x563a2e1a46c0, maxEngines=1, numEngines=0x7ffd79575e84
[2026-02-09 19:35:30.634] [tid 232217] [info] [miopen_plugin] API success: [hipdnnEnginePluginGetAllEngineIdsImpl] numEngines=1 totalEngines=1
[2026-02-09 19:35:30.634] [tid 232181] [error] [hipdnn_backend] Error occured in status:HIPDNN_STATUS_UNKNOWN message:Error loading plugin from [/develop/work/rocmlibs2/projects/hipdnn/build/debug/installdir/lib/hipdnn_plugins/engines/libmiopen_plugin.so]: Engine ID 1563989756945604898 already exists in the list
[2026-02-09 19:35:30.634] [tid 232216] [info] [miopen_plugin] API called: [hipdnnEnginePluginCreateImpl] handle_ptr=0x7ffd795762e0
[2026-02-09 19:35:30.678] [tid 232216] [info] [miopen_plugin] Creating MiopenContainer
[2026-02-09 19:35:30.678] [tid 232216] [info] [miopen_plugin] API success: [hipdnnEnginePluginCreateImpl] createdHandle=0x563a3222ba30
[2026-02-09 19:35:30.678] [tid 232181] [info] [hipdnn_backend] Created handle: 0x563a00776ee0
[2026-02-09 19:35:30.678] [tid 232181] [info] [hipdnn_backend] API success: [hipdnnCreate] createHandle=hipdnnHandle: {stream=null, EnginePluginResourceManager: {loadedPlugins=1, loadedPluginPaths=[/develop/work/rocmlibs2/projects/hipdnn/build/debug/installdir/lib/hipdnn_plugins/engines/libmiopen_legacy_plugin.so]}}
Running convolution fprop graph fp32 [NCHW]...
[2026-02-09 19:35:30.678] [tid 232181] [info] [hipdnn_frontend] Creating new Graph instance


#define HIPDNN_BACKEND_LOG_INFO(...) \
_HIPDNN_BACKEND_LOG_ACTION(spdlog::level::level_enum::info, __VA_ARGS__)
#define HIPDNN_BACKEND_LOG_WARN(...) \
_HIPDNN_BACKEND_LOG_ACTION(spdlog::level::level_enum::warn, __VA_ARGS__)
#define HIPDNN_BACKEND_LOG_ERROR(...) \
_HIPDNN_BACKEND_LOG_ACTION(spdlog::level::level_enum::err, __VA_ARGS__)
#define HIPDNN_BACKEND_LOG_FATAL(...) \
_HIPDNN_BACKEND_LOG_ACTION(spdlog::level::level_enum::critical, __VA_ARGS__)
#define HIPDNN_BACKEND_LOG_FATAL(...) \
do \
{ \
hipdnn_backend::logging::initialize(); \
if(hipdnn_data_sdk::logging::isLogLevelEnabled(HIPDNN_SEV_FATAL)) \
{ \
hipdnn_backend::logging::logMessage( \
HIPDNN_SEV_FATAL, fmt::format("[hipdnn_backend] {}", fmt::format(__VA_ARGS__))); \
} \
} while(0)
#endif // HIPDNN_BACKEND_COMPILATION

namespace hipdnn_backend::logging
Expand All @@ -40,11 +67,7 @@ void initialize();

void cleanup();

void setLogLevel(hipdnnSeverity_t severity);

std::shared_ptr<spdlog::logger> getBackendLogger();

std::shared_ptr<spdlog::logger> getCallbackReceiverLogger();
void logMessage(hipdnnSeverity_t severity, const std::string& message);

void hipdnnLoggingCallback(hipdnnSeverity_t severity, const char* msg);

Expand Down
38 changes: 0 additions & 38 deletions projects/hipdnn/backend/src/logging/LoggingUtils.hpp

This file was deleted.