diff --git a/common/assert.hpp b/common/assert.hpp index 66ad6686..05f6bdb8 100644 --- a/common/assert.hpp +++ b/common/assert.hpp @@ -45,6 +45,7 @@ void tt_assert_message(std::ostream& os, T const& t, Ts const&... ts) { template [[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) { @@ -56,6 +57,8 @@ template trace_message_ss << std::flush; LoggerDevice::get().flush(); throw std::runtime_error(trace_message_ss.str()); +#endif + std::terminate(); } template diff --git a/common/logger.hpp b/common/logger.hpp index 942a5208..7d19e4bd 100644 --- a/common/logger.hpp +++ b/common/logger.hpp @@ -4,6 +4,13 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include "logger_.hpp" + +#define LogSiliconDriver 0 +#define LogEmulationDriver 1 + +#if 0 + #pragma once #include #include @@ -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 diff --git a/common/logger_.hpp b/common/logger_.hpp index 047611ad..a95c0b35 100644 --- a/common/logger_.hpp +++ b/common/logger_.hpp @@ -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__); \ diff --git a/device/cluster.cpp b/device/cluster.cpp index a29e6dc9..2836b44a 100644 --- a/device/cluster.cpp +++ b/device/cluster.cpp @@ -36,6 +36,8 @@ #include #include +#include "fmt/ranges.h" +#include "fmt/std.h" #include "logger.hpp" #include "umd/device/architecture_implementation.h" #include "umd/device/driver_atomics.h" diff --git a/device/cpuset_lib.cpp b/device/cpuset_lib.cpp index 5c9f278b..854faafa 100644 --- a/device/cpuset_lib.cpp +++ b/device/cpuset_lib.cpp @@ -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" diff --git a/device/hugepage.cpp b/device/hugepage.cpp index 8883bff2..fad1c733 100644 --- a/device/hugepage.cpp +++ b/device/hugepage.cpp @@ -9,6 +9,8 @@ #include // for O_RDWR and other constants #include // for umask +#include + #include "cpuset_lib.hpp" #include "logger.hpp" diff --git a/device/pcie/pci_device.cpp b/device/pcie/pci_device.cpp index c49a9d78..1f554b58 100644 --- a/device/pcie/pci_device.cpp +++ b/device/pcie/pci_device.cpp @@ -15,6 +15,8 @@ #include #include // for memcpy +#include +#include #include #include "assert.hpp" diff --git a/device/simulation/tt_simulation_device.cpp b/device/simulation/tt_simulation_device.cpp index 086eb520..848d12dd 100644 --- a/device/simulation/tt_simulation_device.cpp +++ b/device/simulation/tt_simulation_device.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include diff --git a/device/tt_cluster_descriptor.cpp b/device/tt_cluster_descriptor.cpp index 1dde5383..69ce27dc 100644 --- a/device/tt_cluster_descriptor.cpp +++ b/device/tt_cluster_descriptor.cpp @@ -4,6 +4,7 @@ #include "umd/device/tt_cluster_descriptor.h" +#include #include #include #include @@ -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::max(); + // for each shelf-to-shelf connection at location_b.y, find the distance to location_a, take min + int distance = std::numeric_limits::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( diff --git a/tests/microbenchmark/device_fixture.hpp b/tests/microbenchmark/device_fixture.hpp index b4b744b8..25a8f960 100644 --- a/tests/microbenchmark/device_fixture.hpp +++ b/tests/microbenchmark/device_fixture.hpp @@ -9,10 +9,10 @@ #include #include -#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; diff --git a/tests/misc/test_logger.cpp b/tests/misc/test_logger.cpp index 1ed54ac2..c92e7c45 100644 --- a/tests/misc/test_logger.cpp +++ b/tests/misc/test_logger.cpp @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; }