Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ tool/pb2/*
tool/python/pb2/*
src/test/data/*
tmp
log*
build/
tmp/
.sync
Expand Down
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ SINGA_SRCS := src/driver.cc \
src/utils/param.cc \
src/utils/updater.cc \
src/utils/blob.cc \
src/utils/image_transform.cc
src/utils/image_transform.cc \
src/utils/log.cc

SINGA_HDRS := include/singa.h \
include/singa/utils/math_blob.h \
Expand All @@ -132,6 +133,7 @@ SINGA_HDRS := include/singa.h \
include/utils/tinydir.h \
include/utils/tokenizer.h \
include/utils/image_transform.h \
include/utils/log.h \
include/server.h \
include/worker.h \
include/stub.h \
Expand Down
39 changes: 39 additions & 0 deletions include/singa/utils/log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*************************************************************/

#ifndef SINGA_UTILS_LOG_H_
#define SINGA_UTILS_LOG_H_

#include <string>

namespace singa {

/*
* Display information in screen rather than in normal glogs.
* These info are important to be shown to users at runtime,
* e.g., training steps, accuracy, loss ...
*/
void Display(const std::string& info, const char* file, int line);
#define DISPLAY(x) singa::Display(x, __FILE__, __LINE__)

} // namespace singa

#endif // SINGA_UTILS_LOG_H_
15 changes: 11 additions & 4 deletions src/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
#include <chrono>
#include "mshadow/tensor.h"
#include "singa/proto/common.pb.h"
#include "singa/utils/cluster.h"
#include "singa/utils/factory.h"
#include "singa/utils/log.h"
#include "singa/utils/param.h"
#include "singa/utils/singleton.h"
#include "singa/utils/factory.h"
#include "singa/utils/cluster.h"

namespace singa {

Expand Down Expand Up @@ -59,7 +60,10 @@ void Stop(void* running) {
}

void Server::Run() {
LOG(ERROR) << "Server (group = " << grp_id_ <<", id = " << id_ << ") start";
string display = "Server (group = " + std::to_string(grp_id_) + ", id = "
+ std::to_string(id_) + ") start";
LOG(INFO) << display;
DISPLAY(display);
auto cluster = Cluster::Get();
if (cluster->nserver_groups()) {
CHECK_GT(slice2group_.size(), 0);
Expand Down Expand Up @@ -132,7 +136,10 @@ void Server::Run() {
msg->set_type(kStop);
dealer->Send(&msg);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
LOG(ERROR) << "Server (group = " << grp_id_ << ", id = " << id_ << ") stops";
string displaly = "Server (group = " + std::to_string(grp_id_) + ", id = "
+ std::to_string(id_) + ") stops";
LOG(INFO) << display;
DISPLAY(display);
delete dealer;
}

Expand Down
5 changes: 4 additions & 1 deletion src/stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "singa/proto/common.pb.h"
#include "singa/utils/cluster.h"
#include "singa/utils/common.h"
#include "singa/utils/log.h"
#include "singa/utils/tinydir.h"
#include "singa/utils/math_blob.h"

Expand Down Expand Up @@ -176,7 +177,9 @@ void Stub::Run(const vector<int>& slice2server,
}
}
}
LOG(ERROR) << "Stub in process " << procs_id << " stops";
string display = "Stub in process " + std::to_string(procs_id) + " stops";
LOG(INFO) << display;
DISPLAY(display);
for (auto& entry : inter_dealers)
delete entry.second;
}
Expand Down
7 changes: 5 additions & 2 deletions src/utils/cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <fstream>
#include "singa/utils/log.h"

namespace singa {
using std::vector;
Expand All @@ -47,8 +48,10 @@ void Cluster::Register(int pid, const std::string& endpoint) {
procs_id_ = cluster_rt_->RegistProc(endpoint, pid);
CHECK_GE(procs_id_, 0);
CHECK_LT(procs_id_, nprocs());
LOG(ERROR) << "proc #" << procs_id_ << " -> " << endpoint
<< " (pid = " << pid << ")";
string display = "proc #" + std::to_string(procs_id_) + " -> " + endpoint
+ " (pid = " + std::to_string(pid) + ")";
LOG(INFO) << display;
DISPLAY(display);
}

void Cluster::Init(int job, const SingaProto& singaConf,
Expand Down
53 changes: 53 additions & 0 deletions src/utils/log.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*************************************************************/

#include "singa/utils/log.h"
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <cstdio>

namespace singa {

using std::string;

pid_t GetTID() {
return (pid_t)(uintptr_t)pthread_self();
}

void Display(const std::string& info, const char* file, int line) {
time_t rw_time = time(nullptr);
struct tm tm_time;
localtime_r(&rw_time, &tm_time);
printf("[%02d%02d %02d:%02d:%02d %5d:%03d %s:%d] %s\n",
1 + tm_time.tm_mon,
tm_time.tm_mday,
tm_time.tm_hour,
tm_time.tm_min,
tm_time.tm_sec,
getpid(),
static_cast<unsigned>(GetTID())%1000,
file,
line,
info.c_str());
}

} // namespace singa
24 changes: 18 additions & 6 deletions src/worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <typeinfo>
#include "singa/utils/cluster.h"
#include "singa/utils/factory.h"
#include "singa/utils/log.h"
#include "singa/utils/singleton.h"
#include "singa/utils/context.h"

Expand Down Expand Up @@ -64,8 +65,11 @@ void Worker::Run() {
// setup gpu device
auto context = Singleton<Context>::Instance();
int device = context->device_id(std::this_thread::get_id());
LOG(ERROR) << "Worker (group = " << grp_id_ <<", id = " << id_ << ") "
<< " start on " << (device >= 0 ? "GPU " + std::to_string(device) : "CPU");
string display = "Worker (group = " + std::to_string(grp_id_) + ", id = "
+ std::to_string(id_) + ") start on "
+ (device >= 0 ? "GPU " + std::to_string(device) : "CPU");
LOG(INFO) << display;
DISPLAY(display);
if (device >= 0)
context->ActivateDevice(device);

Expand All @@ -83,7 +87,9 @@ void Worker::Run() {
}
if (TestNow(step_) && test_net_ != nullptr) {
CollectAll(step_, train_net_);
LOG(ERROR) << "Test @ step " + std::to_string(step_);
string display = "Test @ step " + std::to_string(step_);
LOG(INFO) << display;
DISPLAY(display);
Test(job_conf_.test_steps(), kTest, test_net_);
}
if (CheckpointNow(step_) && grp_id_ == 0) {
Expand All @@ -108,7 +114,10 @@ void Worker::Run() {
Msg* msg = new Msg(Addr(grp_id_, id_, kWorkerParam), Addr(-1, -1, kStub));
msg->set_type(kStop);
dealer_->Send(&msg); // use param dealer to send the stop msg
LOG(ERROR) << "Worker (group = " <<grp_id_ << ", id = " << id_ << ") stops";
display = "Worker (group = " + std::to_string(grp_id_) + ", id = "
+ std::to_string(id_) + ") stops";
LOG(INFO) << display;
DISPLAY(display);
}

void Worker::Test(int steps, Phase phase, NeuralNet* net) {
Expand Down Expand Up @@ -318,8 +327,11 @@ void Worker::Display(int flag, const std::string& prefix, NeuralNet* net) {
for (auto layer : net->layers()) {
if (layer->partition_id() == id_) {
const string& disp = layer->ToString(false, flag);
if (disp.length())
LOG(ERROR) << prefix << " " << disp;
if (disp.length()) {
string display = prefix + " " + disp;
LOG(INFO) << display;
DISPLAY(display);
}
}
}
}
Expand Down