Unify logging facilities. (#3982)
* Unify logging facilities. * Enhance `ConsoleLogger` to handle different verbosity. * Override macros from `dmlc`. * Don't use specialized gamma when building with GPU. * Remove verbosity cache in monitor. * Test monitor. * Deprecate `silent`. * Fix doc and messages. * Fix python test. * Fix silent tests.
This commit is contained in:
@@ -480,7 +480,7 @@ class BulkAllocator {
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void Allocate(int device_idx, bool silent, Args... args) {
|
||||
void Allocate(int device_idx, Args... args) {
|
||||
size_t size = GetSizeBytes(args...);
|
||||
|
||||
char *ptr = AllocateDevice(device_idx, size, MemoryT);
|
||||
|
||||
@@ -116,7 +116,6 @@ inline static bool CmpSecond(const std::pair<float, unsigned> &a,
|
||||
#if XGBOOST_STRICT_R_MODE
|
||||
// check nan
|
||||
bool CheckNAN(double v);
|
||||
double LogGamma(double v);
|
||||
#else
|
||||
template<typename T>
|
||||
inline bool CheckNAN(T v) {
|
||||
@@ -126,9 +125,19 @@ inline bool CheckNAN(T v) {
|
||||
return std::isnan(v);
|
||||
#endif
|
||||
}
|
||||
#endif // XGBOOST_STRICT_R_MODE_
|
||||
|
||||
// GPU version is not uploaded in CRAN anyway.
|
||||
// Specialize only when using R with CPU.
|
||||
#if XGBOOST_STRICT_R_MODE && !defined(XGBOOST_USE_CUDA)
|
||||
double LogGamma(double v);
|
||||
|
||||
#else // Not R or R with GPU.
|
||||
|
||||
template<typename T>
|
||||
XGBOOST_DEVICE inline T LogGamma(T v) {
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#if _MSC_VER >= 1800
|
||||
return lgamma(v);
|
||||
#else
|
||||
@@ -136,12 +145,15 @@ XGBOOST_DEVICE inline T LogGamma(T v) {
|
||||
", poisson regression will be disabled")
|
||||
utils::Error("lgamma function was not available until VS2013");
|
||||
return static_cast<T>(1.0);
|
||||
#endif
|
||||
#endif // _MSC_VER >= 1800
|
||||
|
||||
#else
|
||||
return lgamma(v);
|
||||
#endif
|
||||
}
|
||||
#endif // XGBOOST_STRICT_R_MODE_
|
||||
|
||||
#endif // XGBOOST_STRICT_R_MODE && !defined(XGBOOST_USE_CUDA)
|
||||
|
||||
} // namespace common
|
||||
} // namespace xgboost
|
||||
#endif // XGBOOST_COMMON_MATH_H_
|
||||
|
||||
@@ -49,15 +49,19 @@ struct Monitor {
|
||||
Timer timer;
|
||||
size_t count{0};
|
||||
};
|
||||
bool debug_verbose = false;
|
||||
std::string label = "";
|
||||
std::map<std::string, Statistics> statistics_map;
|
||||
Timer self_timer;
|
||||
bool IsVerbose() {
|
||||
// Don't cache debug verbosity in here to deal with changed parameter.
|
||||
return (ConsoleLogger::GlobalVerbosity() == ConsoleLogger::LV::kDebug);
|
||||
}
|
||||
|
||||
public:
|
||||
Monitor() { self_timer.Start(); }
|
||||
|
||||
~Monitor() {
|
||||
if (!debug_verbose) return;
|
||||
if (!IsVerbose()) return;
|
||||
|
||||
LOG(CONSOLE) << "======== Monitor: " << label << " ========";
|
||||
for (auto &kv : statistics_map) {
|
||||
@@ -70,13 +74,12 @@ struct Monitor {
|
||||
}
|
||||
self_timer.Stop();
|
||||
}
|
||||
void Init(std::string label, bool debug_verbose) {
|
||||
this->debug_verbose = debug_verbose;
|
||||
void Init(std::string label) {
|
||||
this->label = label;
|
||||
}
|
||||
void Start(const std::string &name) { statistics_map[name].timer.Start(); }
|
||||
void Start(const std::string &name, GPUSet devices) {
|
||||
if (debug_verbose) {
|
||||
if (IsVerbose()) {
|
||||
#ifdef __CUDACC__
|
||||
for (auto device : devices) {
|
||||
cudaSetDevice(device);
|
||||
@@ -91,7 +94,7 @@ struct Monitor {
|
||||
statistics_map[name].count++;
|
||||
}
|
||||
void Stop(const std::string &name, GPUSet devices) {
|
||||
if (debug_verbose) {
|
||||
if (IsVerbose()) {
|
||||
#ifdef __CUDACC__
|
||||
for (auto device : devices) {
|
||||
cudaSetDevice(device);
|
||||
|
||||
Reference in New Issue
Block a user