Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger Improvement Episode 2 #352

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions common/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void tt_assert_message(std::ostream& os, T const& t, Ts const&... ts) {
template <typename... Ts>
[[noreturn]] void tt_throw(
char const* file, int line, const std::string& assert_type, char const* condition_str, Ts const&... messages) {
#if 0
std::stringstream trace_message_ss = {};
trace_message_ss << assert_type << " @ " << file << ":" << line << ": " << condition_str << std::endl;
if constexpr (sizeof...(messages) > 0) {
Expand All @@ -56,6 +57,8 @@ template <typename... Ts>
trace_message_ss << std::flush;
LoggerDevice::get().flush();
throw std::runtime_error(trace_message_ss.str());
#endif
std::terminate();
}

template <typename... Ts>
Expand Down
9 changes: 9 additions & 0 deletions common/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "logger_.hpp"

#define LogSiliconDriver 0
#define LogEmulationDriver 1

#if 0

#pragma once
#include <algorithm>
#include <cctype>
Expand Down Expand Up @@ -264,3 +271,5 @@ static void log_trace_(LogTypeDevice type, std::string const& src_info, char con
#define log_debug(...) ((void)0)
#define log_profile(...) ((void)0)
#endif

#endif // 0
62 changes: 56 additions & 6 deletions common/logger_.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,90 @@ struct Options {
*/
void initialize(const Options& options = Options{});

/**
* Macros to support the old logging API.
* Implementation deliberately mirrors original inconsistent pattern.
*/
#define log_info(type, ...) \
do { \
::tt::umd::logger::detail::ensure_initialized(); \
SPDLOG_INFO(__VA_ARGS__); \
} while (0)

#define log_trace(type, fmt, ...) \
do { \
::tt::umd::logger::detail::ensure_initialized(); \
SPDLOG_TRACE(__VA_ARGS__); \
} while (0)

#define log_debug(type, ...) \
do { \
::tt::umd::logger::detail::ensure_initialized(); \
SPDLOG_DEBUG(__VA_ARGS__); \
} while (0)

#define log_warning(type, ...) \
do { \
::tt::umd::logger::detail::ensure_initialized(); \
SPDLOG_WARN(__VA_ARGS__); \
} while (0)

#define log_error(...) \
do { \
::tt::umd::logger::detail::ensure_initialized(); \
SPDLOG_ERROR(__VA_ARGS__); \
} while (0)

#define log_fatal(...) \
do { \
::tt::umd::logger::detail::ensure_initialized(); \
SPDLOG_CRITICAL(__VA_ARGS__); \
std::terminate(); \
} while (0)

#define log_assert(cond, ...) \
do { \
if (!(cond)) { \
::tt::umd::logger::detail::ensure_initialized(); \
SPDLOG_CRITICAL(__VA_ARGS__); \
std::terminate(); \
} \
} while (0)

/**
* Macros for using the logger.
*/
#define UMD_TRACE(...) \
#define LOG_TRACE(...) \
do { \
::tt::umd::logger::detail::ensure_initialized(); \
SPDLOG_TRACE(__VA_ARGS__); \
} while (0)

#define UMD_DEBUG(...) \
#define LOG_DEBUG(...) \
do { \
::tt::umd::logger::detail::ensure_initialized(); \
SPDLOG_DEBUG(__VA_ARGS__); \
} while (0)

#define UMD_INFO(...) \
#define LOG_INFO(...) \
do { \
::tt::umd::logger::detail::ensure_initialized(); \
SPDLOG_INFO(__VA_ARGS__); \
} while (0)

#define UMD_WARN(...) \
#define LOG_WARN(...) \
do { \
::tt::umd::logger::detail::ensure_initialized(); \
SPDLOG_WARN(__VA_ARGS__); \
} while (0)

#define UMD_ERROR(...) \
#define LOG_ERROR(...) \
do { \
::tt::umd::logger::detail::ensure_initialized(); \
SPDLOG_ERROR(__VA_ARGS__); \
} while (0)

#define UMD_CRITICAL(...) \
#define LOG_CRITICAL(...) \
do { \
::tt::umd::logger::detail::ensure_initialized(); \
SPDLOG_CRITICAL(__VA_ARGS__); \
Expand Down
2 changes: 2 additions & 0 deletions device/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <utility>
#include <vector>

#include "fmt/ranges.h"
#include "fmt/std.h"
#include "logger.hpp"
#include "umd/device/architecture_implementation.h"
#include "umd/device/driver_atomics.h"
Expand Down
2 changes: 2 additions & 0 deletions device/cpuset_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "cpuset_lib.hpp"
#include "fmt/core.h"
#include "fmt/ranges.h"
#include "fmt/std.h"
#include "logger.hpp"
#include "umd/device/cluster.h"

Expand Down
2 changes: 2 additions & 0 deletions device/hugepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <fcntl.h> // for O_RDWR and other constants
#include <sys/stat.h> // for umask

#include <fstream>

#include "cpuset_lib.hpp"
#include "logger.hpp"

Expand Down
2 changes: 2 additions & 0 deletions device/pcie/pci_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include <cstdint>
#include <cstring> // for memcpy
#include <filesystem>
#include <fstream>
#include <vector>

#include "assert.hpp"
Expand Down
1 change: 1 addition & 0 deletions device/simulation/tt_simulation_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <uv.h>

#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
Expand Down
7 changes: 4 additions & 3 deletions device/tt_cluster_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "umd/device/tt_cluster_descriptor.h"

#include <filesystem>
#include <fstream>
#include <memory>
#include <sstream>
Expand Down Expand Up @@ -169,10 +170,10 @@ int tt_ClusterDescriptor::get_ethernet_link_coord_distance(
galaxy_shelves_exit_chip_coords_per_y_dim.at(location_b.shelf).at(location_b.y);
log_assert(
shelf_to_shelf_connection.destination_chip_coords.size(),
"Expecting at least one shelf-to-shelf connection, possibly one-to-many")
"Expecting at least one shelf-to-shelf connection, possibly one-to-many");

// for each shelf-to-shelf connection at location_b.y, find the distance to location_a, take min
int distance = std::numeric_limits<int>::max();
// for each shelf-to-shelf connection at location_b.y, find the distance to location_a, take min
int distance = std::numeric_limits<int>::max();
eth_coord_t exit_shelf = shelf_to_shelf_connection.source_chip_coord;
for (eth_coord_t next_shelf : shelf_to_shelf_connection.destination_chip_coords) {
log_assert(
Expand Down
4 changes: 2 additions & 2 deletions tests/microbenchmark/device_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include <iostream>
#include <random>

#include "cluster.h"
#include "device/tt_soc_descriptor.h"
#include "l1_address_map.h"
#include "tests/test_utils/generate_cluster_desc.hpp"
#include "umd/device/cluster.h"
#include "umd/device/tt_soc_descriptor.h"

using tt::umd::Cluster;

Expand Down
32 changes: 16 additions & 16 deletions tests/misc/test_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ TEST_F(LoggerTest, BasicLogging) {
tt::umd::logger::initialize(options);

// Write some test messages
UMD_INFO("Test message 1");
UMD_INFO("Test message 2");
UMD_INFO("Test message 4");
UMD_INFO("Test message 3");
LOG_INFO("Test message 1");
LOG_INFO("Test message 2");
LOG_INFO("Test message 4");
LOG_INFO("Test message 3");

// Force flush by destroying the logger
spdlog::drop_all();
Expand All @@ -83,9 +83,9 @@ TEST_F(LoggerTest, LogLevels) {
options.log_level = spdlog::level::info; // Set to INFO level
tt::umd::logger::initialize(options);

UMD_DEBUG("Debug message"); // Shouldn't appear
UMD_INFO("Info message"); // Should appear
UMD_ERROR("Error message"); // Should appear
LOG_DEBUG("Debug message"); // Shouldn't appear
LOG_INFO("Info message"); // Should appear
LOG_ERROR("Error message"); // Should appear

spdlog::drop_all();

Expand All @@ -103,7 +103,7 @@ TEST_F(LoggerTest, FormatPatterns) {
options.pattern = "[%l] %v"; // Level and message
tt::umd::logger::initialize(options);

UMD_INFO("Test message");
LOG_INFO("Test message");

spdlog::drop_all();

Expand All @@ -121,12 +121,12 @@ TEST_F(LoggerTest, MultipleInitialization) {
// Initialize multiple times - should use first initialization only
tt::umd::logger::initialize(options);

UMD_INFO("First message");
LOG_INFO("First message");

options.pattern = "DIFFERENT: %v";
tt::umd::logger::initialize(options); // Should be ignored

UMD_INFO("Second message");
LOG_INFO("Second message");

spdlog::drop_all();

Expand Down Expand Up @@ -155,7 +155,7 @@ TEST_F(LoggerTest, DiskPerformance) {
{
Timestamp ts;
for (size_t i = 0; i < num_messages; i++) {
UMD_INFO("Test message");
LOG_INFO("Test message");
}
std::cout << ts.to_string() << " for " << num_messages << " messages to disk" << std::endl;
}
Expand All @@ -164,7 +164,7 @@ TEST_F(LoggerTest, DiskPerformance) {
{
Timestamp ts;
for (size_t i = 0; i < num_messages; i++) {
UMD_TRACE("Shouldn't be logged");
LOG_TRACE("Shouldn't be logged");
}
std::cout << ts.to_string() << " for " << num_messages << " messages below level threshold" << std::endl;
}
Expand All @@ -182,7 +182,7 @@ TEST_F(LoggerTest, StderrPerformance) {
{
Timestamp ts;
for (size_t i = 0; i < num_messages; i++) {
UMD_INFO("Test message");
LOG_INFO("Test message");
}
std::cout << ts.to_string() << " for " << num_messages << " messages to stderr" << std::endl;
}
Expand All @@ -191,7 +191,7 @@ TEST_F(LoggerTest, StderrPerformance) {
{
Timestamp ts;
for (size_t i = 0; i < num_messages; i++) {
UMD_TRACE("Shouldn't be logged");
LOG_TRACE("Shouldn't be logged");
}
std::cout << ts.to_string() << " for " << num_messages << " messages below level threshold" << std::endl;
}
Expand All @@ -209,7 +209,7 @@ TEST_F(LoggerTest, StderrAndDiskPerformance) {
{
Timestamp ts;
for (size_t i = 0; i < num_messages; i++) {
UMD_INFO("Test message");
LOG_INFO("Test message");
}
std::cout << ts.to_string() << " for " << num_messages << " messages to disk & stderr" << std::endl;
}
Expand All @@ -218,7 +218,7 @@ TEST_F(LoggerTest, StderrAndDiskPerformance) {
{
Timestamp ts;
for (size_t i = 0; i < num_messages; i++) {
UMD_TRACE("Shouldn't be logged");
LOG_TRACE("Shouldn't be logged");
}
std::cout << ts.to_string() << " for " << num_messages << " messages below level threshold" << std::endl;
}
Expand Down