Fix and optimize logger (#4002)
* Fix logging switch statement. * Remove debug_verbose_ in AllReducer. * Don't construct the stream when not needed. * Make default constructor deleted. * Remove redundant IsVerbose.
This commit is contained in:
@@ -842,7 +842,6 @@ void Gather(int device_idx, T *out, const T *in, const int *instId, int nVals) {
|
||||
|
||||
class AllReducer {
|
||||
bool initialised_;
|
||||
bool debug_verbose_;
|
||||
size_t allreduce_bytes_; // Keep statistics of the number of bytes communicated
|
||||
size_t allreduce_calls_; // Keep statistics of the number of reduce calls
|
||||
#ifdef XGBOOST_USE_NCCL
|
||||
@@ -850,8 +849,9 @@ class AllReducer {
|
||||
std::vector<cudaStream_t> streams;
|
||||
std::vector<int> device_ordinals;
|
||||
#endif
|
||||
|
||||
public:
|
||||
AllReducer() : initialised_(false),debug_verbose_(false), allreduce_bytes_(0),
|
||||
AllReducer() : initialised_(false), allreduce_bytes_(0),
|
||||
allreduce_calls_(0) {}
|
||||
|
||||
/**
|
||||
@@ -863,10 +863,9 @@ class AllReducer {
|
||||
* \param device_ordinals The device ordinals.
|
||||
*/
|
||||
|
||||
void Init(const std::vector<int> &device_ordinals, bool debug_verbose) {
|
||||
void Init(const std::vector<int> &device_ordinals) {
|
||||
#ifdef XGBOOST_USE_NCCL
|
||||
/** \brief this >monitor . init. */
|
||||
this->debug_verbose_ = debug_verbose;
|
||||
this->device_ordinals = device_ordinals;
|
||||
comms.resize(device_ordinals.size());
|
||||
dh::safe_nccl(ncclCommInitAll(comms.data(),
|
||||
@@ -893,7 +892,7 @@ class AllReducer {
|
||||
ncclCommDestroy(comm);
|
||||
}
|
||||
}
|
||||
if (debug_verbose_) {
|
||||
if (xgboost::ConsoleLogger::ShouldLog(xgboost::ConsoleLogger::LV::kDebug)) {
|
||||
LOG(CONSOLE) << "======== NCCL Statistics========";
|
||||
LOG(CONSOLE) << "AllReduce calls: " << allreduce_calls_;
|
||||
LOG(CONSOLE) << "AllReduce total MB communicated: " << allreduce_bytes_/1000000;
|
||||
|
||||
@@ -52,16 +52,12 @@ struct Monitor {
|
||||
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 (!IsVerbose()) return;
|
||||
if (!ConsoleLogger::ShouldLog(ConsoleLogger::LV::kDebug)) return;
|
||||
|
||||
LOG(CONSOLE) << "======== Monitor: " << label << " ========";
|
||||
for (auto &kv : statistics_map) {
|
||||
@@ -79,7 +75,7 @@ struct Monitor {
|
||||
}
|
||||
void Start(const std::string &name) { statistics_map[name].timer.Start(); }
|
||||
void Start(const std::string &name, GPUSet devices) {
|
||||
if (IsVerbose()) {
|
||||
if (ConsoleLogger::ShouldLog(ConsoleLogger::LV::kDebug)) {
|
||||
#ifdef __CUDACC__
|
||||
for (auto device : devices) {
|
||||
cudaSetDevice(device);
|
||||
@@ -94,7 +90,7 @@ struct Monitor {
|
||||
statistics_map[name].count++;
|
||||
}
|
||||
void Stop(const std::string &name, GPUSet devices) {
|
||||
if (IsVerbose()) {
|
||||
if (ConsoleLogger::ShouldLog(ConsoleLogger::LV::kDebug)) {
|
||||
#ifdef __CUDACC__
|
||||
for (auto device : devices) {
|
||||
cudaSetDevice(device);
|
||||
|
||||
Reference in New Issue
Block a user