From 624091b680c3207856164ebfafcb8a266ce3efe1 Mon Sep 17 00:00:00 2001 From: Andrew Gallagher Date: Fri, 15 Dec 2023 13:31:34 -0800 Subject: [PATCH] Fix some buck2 build errors Summary: Fix some issues w/ the rules/deps where we weren't properly attaching all required headers to rules, preventing RE from working. This fixes the buck2 build for the `opt4ml` contbuild. Reviewed By: rahulg Differential Revision: D52168385 fbshipit-source-id: 12a79b91142c8ef21c75c33ffa5056bb9be184ba --- flashlight/fl/common/Logging.cpp | 36 +++++++++++++++++++++++++++++++- flashlight/fl/common/Utils.cpp | 31 --------------------------- flashlight/fl/common/Utils.h | 5 ----- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/flashlight/fl/common/Logging.cpp b/flashlight/fl/common/Logging.cpp index da68bd598..c7908a3d4 100644 --- a/flashlight/fl/common/Logging.cpp +++ b/flashlight/fl/common/Logging.cpp @@ -6,12 +6,12 @@ */ #include +#include #include #include #include #include "flashlight/fl/common/Logging.h" -#include "flashlight/fl/common/Utils.h" #include "flashlight/fl/common/stacktrace/Backward.h" namespace fl { @@ -46,6 +46,40 @@ std::string getFileName(const std::string& path) { return path.substr(separatorIndex + 1, path.length() - separatorIndex); } +// Returns high resolution time formatted as: +// MMDD HH MM SS UUUUUU +// 0206 08:42:42.123456 +std::string dateTimeWithMicroSeconds() { + auto systemTime = std::chrono::system_clock::now(); + const time_t secondsSinceEpoc = + std::chrono::system_clock::to_time_t(systemTime); + const struct tm* timeinfo = localtime(&secondsSinceEpoc); + + // Formate date and time to the seconds as: + // MMDD HH MM SS + // 1231 08:42:42 + constexpr size_t bufferSize = 50; + char buffer[bufferSize]; + const size_t nWrittenBytes = std::strftime(buffer, 30, "%m%d %T", timeinfo); + if (!nWrittenBytes) { + return "getTime() failed to format time"; + } + + const std::chrono::system_clock::time_point timeInSecondsResolution = + std::chrono::system_clock::from_time_t(secondsSinceEpoc); + const auto usec = std::chrono::duration_cast( + systemTime - timeInSecondsResolution); + + // Add msec and usec. + std::snprintf( + buffer + nWrittenBytes, + bufferSize - nWrittenBytes, + ".%06" PRId64, + static_cast(usec.count())); + + return buffer; +} + void addContext( const char* fullPath, int lineNumber, diff --git a/flashlight/fl/common/Utils.cpp b/flashlight/fl/common/Utils.cpp index 6de89df8c..3d59a53ab 100644 --- a/flashlight/fl/common/Utils.cpp +++ b/flashlight/fl/common/Utils.cpp @@ -26,37 +26,6 @@ bool f16Supported() { return defaultTensorBackend().isDataTypeSupported(fl::dtype::f16); } -std::string dateTimeWithMicroSeconds() { - auto systemTime = std::chrono::system_clock::now(); - const time_t secondsSinceEpoc = - std::chrono::system_clock::to_time_t(systemTime); - const struct tm* timeinfo = localtime(&secondsSinceEpoc); - - // Formate date and time to the seconds as: - // MMDD HH MM SS - // 1231 08:42:42 - constexpr size_t bufferSize = 50; - char buffer[bufferSize]; - const size_t nWrittenBytes = std::strftime(buffer, 30, "%m%d %T", timeinfo); - if (!nWrittenBytes) { - return "getTime() failed to format time"; - } - - const std::chrono::system_clock::time_point timeInSecondsResolution = - std::chrono::system_clock::from_time_t(secondsSinceEpoc); - const auto usec = std::chrono::duration_cast( - systemTime - timeInSecondsResolution); - - // Add msec and usec. - std::snprintf( - buffer + nWrittenBytes, - bufferSize - nWrittenBytes, - ".%06" PRId64, - static_cast(usec.count())); - - return buffer; -} - size_t divRoundUp(size_t numerator, size_t denominator) { if (!numerator) { return 0; diff --git a/flashlight/fl/common/Utils.h b/flashlight/fl/common/Utils.h index b0b89ae78..a851c8d1c 100644 --- a/flashlight/fl/common/Utils.h +++ b/flashlight/fl/common/Utils.h @@ -29,11 +29,6 @@ class Tensor; */ FL_API bool f16Supported(); -// Returns high resolution time formatted as: -// MMDD HH MM SS UUUUUU -// 0206 08:42:42.123456 -FL_API std::string dateTimeWithMicroSeconds(); - // Returns round-up result of integer division. // throws invalid_argument exception on zero denominator. FL_API size_t divRoundUp(size_t numerator, size_t denominator);