Skip to content
Snippets Groups Projects
Commit 60905253 authored by Grégoire Kubler's avatar Grégoire Kubler Committed by Maxence Naud
Browse files

feat : added half_float support to fmt lib

parent 246a0c8b
No related branches found
No related tags found
2 merge requests!279v0.4.0,!242Extends the functionalities of Resize Operator
#include "aidge/data/half.hpp"
#include <fmt/core.h>
// Specialize fmt::formatter for half_float::half
template <>
struct fmt::formatter<half_float::half> : fmt::formatter<float> {
// Parses the format specifications and stores them in the base formatter
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx) {
return fmt::formatter<float>::parse(ctx);
}
// Formats the half type by first converting it to float
template <typename FormatContext>
auto format(const half_float::half& value, FormatContext& ctx) const {
return fmt::formatter<float>::format(static_cast<float>(value), ctx);
}
};
......@@ -9,7 +9,6 @@
*
********************************************************************************/
#ifndef AIDGE_LOG_H_
#define AIDGE_LOG_H_
......@@ -19,44 +18,36 @@
#include <fmt/format.h>
#include <fmt/ranges.h>
#include "aidge/data/half_fmt.hpp"
#include "aidge/utils/Attributes.hpp"
namespace Aidge {
/**
* Helper to define a context anywhere, hidding the scoped variable name
* which has no relevance.
*/
#define AIDGE_LOG_CONTEXT(...) const Log::Context logContext_##__LINE__(__VA_ARGS__)
*/
#define AIDGE_LOG_CONTEXT(...) \
const Log::Context logContext_##__LINE__(__VA_ARGS__)
template<class U>
static void discard_args(U parg) {
template <class U> static void discard_args(U parg) {
(void)parg;
}
template<class U, class... Us>
static void discard_args(U parg, Us... pargs) {
template <class U, class... Us> static void discard_args(U parg, Us... pargs) {
(void)parg;
discard_args(pargs...);
}
/**
* Aidge logging class, for displaying and file logging of events.
*/
*/
class Log {
public:
enum Level {
Debug = 0,
Info,
Notice,
Warn,
Error,
Fatal
};
public:
enum Level { Debug = 0, Info, Notice, Warn, Error, Fatal };
class Context {
public:
template <typename... Args>
Context(Args&&... args) {
public:
template <typename... Args> Context(Args &&...args) {
Log::mContext.push_back(fmt::format(std::forward<Args>(args)...));
}
......@@ -68,13 +59,12 @@ public:
/**
* Detailed messages for debugging purposes, providing information helpful
* for developers to trace and identify issues.
* Detailed insights of what is appening in an operation, not useful for the
* end-user. The operation is performed nominally.
* Detailed insights of what is appening in an operation, not useful for
* the end-user. The operation is performed nominally.
* @note This level is disabled at compile time for Release, therefore
* inducing no runtime overhead for Release.
*/
template <typename... Args>
static void debug(Args&&... args) {
*/
template <typename... Args> static void debug(Args &&...args) {
#ifndef NDEBUG
// only when compiled in Debug
log(Debug, fmt::format(std::forward<Args>(args)...));
......@@ -86,22 +76,19 @@ public:
/**
* Messages that provide a record of the normal operation, about
* the application's state, progress, or important events.
* Reports normal start, end and key steps in an operation. The operation is
* performed nominally.
*/
template <typename... Args>
static void info(Args&&... args) {
* Reports normal start, end and key steps in an operation. The operation
* is performed nominally.
*/
template <typename... Args> static void info(Args &&...args) {
log(Info, fmt::format(std::forward<Args>(args)...));
}
/**
* Applies to normal but significant conditions that may require monitoring,
* like unusual or normal fallback events.
* Reports specific paths in an operation. The operation can still be
* performed normally.
*/
template <typename... Args>
static void notice(Args&&... args) {
* Applies to normal but significant conditions that may require
* monitoring, like unusual or normal fallback events. Reports specific
* paths in an operation. The operation can still be performed normally.
*/
template <typename... Args> static void notice(Args &&...args) {
log(Notice, fmt::format(std::forward<Args>(args)...));
}
......@@ -110,9 +97,8 @@ public:
* not necessarily cause immediate problems.
* Some specific steps of the operation could not be performed, but it can
* still provide an exploitable result.
*/
template <typename... Args>
static void warn(Args&&... args) {
*/
template <typename... Args> static void warn(Args &&...args) {
log(Warn, fmt::format(std::forward<Args>(args)...));
}
......@@ -121,26 +107,24 @@ public:
* recover from, but attention is needed to prevent further issues.
* The operation could not be performed, but it does not prevent potential
* further operations.
*/
template <typename... Args>
static void error(Args&&... args) {
*/
template <typename... Args> static void error(Args &&...args) {
log(Error, fmt::format(std::forward<Args>(args)...));
}
/**
* Represents a critical error or condition that leads to the termination of
* the application, indicating a severe and unrecoverable problem.
* The operation could not be performed and any further operation is
* Represents a critical error or condition that leads to the termination
* of the application, indicating a severe and unrecoverable problem. The
* operation could not be performed and any further operation is
* impossible.
*/
template <typename... Args>
static void fatal(Args&&... args) {
*/
template <typename... Args> static void fatal(Args &&...args) {
log(Fatal, fmt::format(std::forward<Args>(args)...));
}
/**
* Set the minimum log level displayed in the console.
*/
*/
static void setConsoleLevel(Level level) {
mConsoleLevel = level;
}
......@@ -148,14 +132,14 @@ public:
/**
* Set or disable colors on console.
* Initial value should be assumed true.
*/
*/
static void setConsoleColor(bool enabled) {
mConsoleColor = enabled;
}
/**
* Set the minimum log level saved in the log file.
*/
*/
constexpr static void setFileLevel(Level level) {
mFileLevel = level;
}
......@@ -164,8 +148,8 @@ public:
* Set the log file name.
* Close the current log file and open the one with the new file name.
* If empty, stop logging into a file.
*/
static void setFileName(const std::string& fileName) {
*/
static void setFileName(const std::string &fileName) {
if (fileName != mFileName) {
mFileName = fileName;
mFile.release();
......@@ -187,8 +171,8 @@ public:
* warnings.
*/
struct fcloseDeleter {
void operator()(FILE *f) const noexcept {
std::fclose(f);
void operator()(FILE *f) const noexcept {
std::fclose(f);
}
};
......@@ -203,11 +187,12 @@ private:
static std::unique_ptr<FILE, fcloseDeleter> mFile;
static std::vector<std::string> mContext;
};
}
} // namespace Aidge
namespace {
template <>
const char *const EnumStrings<Aidge::Log::Level>::data[] = {"Debug", "Info", "Notice", "Warn", "Error", "Fatal"};
const char *const EnumStrings<Aidge::Log::Level>::data[] =
{"Debug", "Info", "Notice", "Warn", "Error", "Fatal"};
}
#endif //AIDGE_LOG_H_
#endif // AIDGE_LOG_H_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment