Skip to content

Commit

Permalink
Fix some buck2 build errors
Browse files Browse the repository at this point in the history
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
  • Loading branch information
andrewjcg authored and facebook-github-bot committed Dec 15, 2023
1 parent 04e72e4 commit 624091b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 37 deletions.
36 changes: 35 additions & 1 deletion flashlight/fl/common/Logging.cpp
Expand Up @@ -6,12 +6,12 @@
*/

#include <array>
#include <inttypes.h>
#include <stdexcept>
#include <thread>
#include <utility>

#include "flashlight/fl/common/Logging.h"
#include "flashlight/fl/common/Utils.h"
#include "flashlight/fl/common/stacktrace/Backward.h"

namespace fl {
Expand Down Expand Up @@ -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<std::chrono::microseconds>(
systemTime - timeInSecondsResolution);

// Add msec and usec.
std::snprintf(
buffer + nWrittenBytes,
bufferSize - nWrittenBytes,
".%06" PRId64,
static_cast<int64_t>(usec.count()));

return buffer;
}

void addContext(
const char* fullPath,
int lineNumber,
Expand Down
31 changes: 0 additions & 31 deletions flashlight/fl/common/Utils.cpp
Expand Up @@ -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<std::chrono::microseconds>(
systemTime - timeInSecondsResolution);

// Add msec and usec.
std::snprintf(
buffer + nWrittenBytes,
bufferSize - nWrittenBytes,
".%06" PRId64,
static_cast<int64_t>(usec.count()));

return buffer;
}

size_t divRoundUp(size_t numerator, size_t denominator) {
if (!numerator) {
return 0;
Expand Down
5 changes: 0 additions & 5 deletions flashlight/fl/common/Utils.h
Expand Up @@ -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);
Expand Down

0 comments on commit 624091b

Please sign in to comment.