提交 5d2a0877 编写于 作者: Y Yu Yang 提交者: GitHub

Merge pull request #2747 from reyoung/feature/correct_glog_check

Correct GLOG CHECK in Paddle
...@@ -142,7 +142,7 @@ SocketServer::SocketServer(const std::string &addr, int port, int rdmaCpu) ...@@ -142,7 +142,7 @@ SocketServer::SocketServer(const std::string &addr, int port, int rdmaCpu)
} }
/// trigger to initialize RDMA lib /// trigger to initialize RDMA lib
PCHECK(RdmaClientDaemons::get()) << "initilizate RDMA failed\n"; CHECK(RdmaClientDaemons::get()) << "initilizate RDMA failed\n";
} }
SocketServer::~SocketServer() { SocketServer::~SocketServer() {
...@@ -168,7 +168,7 @@ void SocketServer::tcpServer() { ...@@ -168,7 +168,7 @@ void SocketServer::tcpServer() {
/// First call to socket() function /// First call to socket() function
socket_ = socket(AF_INET, SOCK_STREAM, 0); socket_ = socket(AF_INET, SOCK_STREAM, 0);
PCHECK(socket_ >= 0) << "ERROR opening socket"; CHECK(socket_ >= 0) << "ERROR opening socket";
/// Initialize socket structure /// Initialize socket structure
bzero((char *)&serv_addr, sizeof(serv_addr)); bzero((char *)&serv_addr, sizeof(serv_addr));
...@@ -176,7 +176,7 @@ void SocketServer::tcpServer() { ...@@ -176,7 +176,7 @@ void SocketServer::tcpServer() {
serv_addr.sin_port = htons(port_); serv_addr.sin_port = htons(port_);
if (!addr_.empty()) { if (!addr_.empty()) {
server = gethostbyname(addr_.c_str()); server = gethostbyname(addr_.c_str());
PCHECK(server) << "ERROR, no such host: " << addr_; CHECK(server) << "ERROR, no such host: " << addr_;
bcopy((char *)server->h_addr, bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr, (char *)&serv_addr.sin_addr.s_addr,
server->h_length); server->h_length);
...@@ -187,7 +187,7 @@ void SocketServer::tcpServer() { ...@@ -187,7 +187,7 @@ void SocketServer::tcpServer() {
setOption(socket_); setOption(socket_);
/// Now bind the host address using bind() call. /// Now bind the host address using bind() call.
PCHECK(bind(socket_, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) >= 0) CHECK(bind(socket_, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) >= 0)
<< "ERROR on binding " << addr_; << "ERROR on binding " << addr_;
/// Now start listening for the clients, here process will /// Now start listening for the clients, here process will
...@@ -201,7 +201,7 @@ void SocketServer::tcpServer() { ...@@ -201,7 +201,7 @@ void SocketServer::tcpServer() {
if (stopping_) { if (stopping_) {
break; break;
} }
PCHECK(newsockfd >= 0) << "ERROR on accept"; CHECK(newsockfd >= 0) << "ERROR on accept";
constexpr int kPeerNameLen = 128; constexpr int kPeerNameLen = 128;
char peerName[kPeerNameLen]; char peerName[kPeerNameLen];
CHECK(inet_ntop(AF_INET, &cli_addr.sin_addr, peerName, kPeerNameLen)); CHECK(inet_ntop(AF_INET, &cli_addr.sin_addr, peerName, kPeerNameLen));
...@@ -227,14 +227,14 @@ void SocketServer::rdmaServer() { ...@@ -227,14 +227,14 @@ void SocketServer::rdmaServer() {
/// First call to socket() function /// First call to socket() function
rdmaSocket_ = rdma::ssocket(rdmaCpu_); rdmaSocket_ = rdma::ssocket(rdmaCpu_);
PCHECK(rdmaSocket_) << "ERROR opening RDMA socket"; CHECK(rdmaSocket_) << "ERROR opening RDMA socket";
PCHECK(rdma::bind(rdmaSocket_, rdmaUri_.c_str()) == 0) CHECK(rdma::bind(rdmaSocket_, rdmaUri_.c_str()) == 0)
<< "ERROR bind RDMA socket"; << "ERROR bind RDMA socket";
/// Now start listening for the clients, here process will /// Now start listening for the clients, here process will
/// go in sleep mode and will wait for the incoming connection /// go in sleep mode and will wait for the incoming connection
PCHECK(rdma::listen(rdmaSocket_) == 0) << "ERROR listen RDMA socket"; CHECK(rdma::listen(rdmaSocket_) == 0) << "ERROR listen RDMA socket";
while (true) { while (true) {
/// Accept actual connection from the client /// Accept actual connection from the client
...@@ -242,7 +242,7 @@ void SocketServer::rdmaServer() { ...@@ -242,7 +242,7 @@ void SocketServer::rdmaServer() {
if (stopping_) { if (stopping_) {
break; break;
} }
PCHECK(newsock) << "ERROR on accept"; CHECK(newsock) << "ERROR on accept";
constexpr int kPeerNameLen = 128; constexpr int kPeerNameLen = 128;
char peerName[kPeerNameLen]; char peerName[kPeerNameLen];
...@@ -290,7 +290,7 @@ RdmaClientDaemons::RdmaClientDaemons() { ...@@ -290,7 +290,7 @@ RdmaClientDaemons::RdmaClientDaemons() {
onlineCpus_ = rdma::numCpus(); onlineCpus_ = rdma::numCpus();
for (auto i = 0; i < onlineCpus_; i++) { for (auto i = 0; i < onlineCpus_; i++) {
socket = rdma::csocket(i); socket = rdma::csocket(i);
PCHECK(socket) << "ERROR open client socket daemon"; CHECK(socket) << "ERROR open client socket daemon";
rdmaClientSocket_.push_back(socket); rdmaClientSocket_.push_back(socket);
} }
...@@ -355,7 +355,7 @@ void SocketClient::TcpClient(const std::string &serverAddr, int serverPort) { ...@@ -355,7 +355,7 @@ void SocketClient::TcpClient(const std::string &serverAddr, int serverPort) {
/// Create a socket point /// Create a socket point
int sockfd = socket(AF_INET, SOCK_STREAM, 0); int sockfd = socket(AF_INET, SOCK_STREAM, 0);
PCHECK(sockfd >= 0) << "ERROR opening socket"; CHECK(sockfd >= 0) << "ERROR opening socket";
#if defined(__OSX__) || defined(__APPLE__) #if defined(__OSX__) || defined(__APPLE__)
server = getipnodebyname(serverAddr.c_str(), AF_INET, AI_DEFAULT, &errRet); server = getipnodebyname(serverAddr.c_str(), AF_INET, AI_DEFAULT, &errRet);
...@@ -396,8 +396,8 @@ void SocketClient::TcpClient(const std::string &serverAddr, int serverPort) { ...@@ -396,8 +396,8 @@ void SocketClient::TcpClient(const std::string &serverAddr, int serverPort) {
} }
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(std::chrono::seconds(1));
} else { } else {
PCHECK(errno != 0) << "ERROR connecting to " << serverAddr << ":" CHECK(errno != 0) << "ERROR connecting to " << serverAddr << ":"
<< serverPort << "errorno: " << errno; << serverPort << "errorno: " << errno;
} }
} while (errno == ECONNREFUSED); } while (errno == ECONNREFUSED);
...@@ -426,7 +426,7 @@ void SocketClient::RdmaClient(const std::string &serverAddr, int serverPort) { ...@@ -426,7 +426,7 @@ void SocketClient::RdmaClient(const std::string &serverAddr, int serverPort) {
/// connect to server with socket daemon /// connect to server with socket daemon
sock = rdma::connect(socketDaemon_, rdmaUri.c_str()); sock = rdma::connect(socketDaemon_, rdmaUri.c_str());
PCHECK(sock) << "ERROR connect to server" << rdmaUri; CHECK(sock) << "ERROR connect to server" << rdmaUri;
std::vector<std::string> seg; std::vector<std::string> seg;
str::split(rdmaUri, '/', &seg); str::split(rdmaUri, '/', &seg);
......
...@@ -51,7 +51,7 @@ size_t SocketChannel::read(void* buf, size_t size) { ...@@ -51,7 +51,7 @@ size_t SocketChannel::read(void* buf, size_t size) {
else else
len = rdma::read(rdmaSocket_, (char*)buf + total, size - total); len = rdma::read(rdmaSocket_, (char*)buf + total, size - total);
PCHECK(len >= 0) << " peer=" << peerName_; CHECK(len >= 0) << " peer=" << peerName_;
if (len <= 0) { if (len <= 0) {
return total; return total;
} }
...@@ -69,7 +69,7 @@ size_t SocketChannel::write(const void* buf, size_t size) { ...@@ -69,7 +69,7 @@ size_t SocketChannel::write(const void* buf, size_t size) {
else else
len = rdma::write(rdmaSocket_, (char*)buf + total, size - total); len = rdma::write(rdmaSocket_, (char*)buf + total, size - total);
PCHECK(len >= 0) << " peer=" << peerName_; CHECK(len >= 0) << " peer=" << peerName_;
if (len <= 0) { if (len <= 0) {
return total; return total;
} }
...@@ -98,10 +98,10 @@ static size_t readwritev(IOFunc iofunc, ...@@ -98,10 +98,10 @@ static size_t readwritev(IOFunc iofunc,
while (size < total) { while (size < total) {
ssize_t len = ssize_t len =
iofunc(socket, &iovs[curIov], std::min(iovcnt - curIov, maxiovs)); iofunc(socket, &iovs[curIov], std::min(iovcnt - curIov, maxiovs));
PCHECK(len > 0) << " peer=" << peerName << " curIov=" << curIov CHECK(len > 0) << " peer=" << peerName << " curIov=" << curIov
<< " iovCnt=" << iovcnt << " iovCnt=" << iovcnt
<< " iovs[curIov].base=" << iovs[curIov].iov_base << " iovs[curIov].base=" << iovs[curIov].iov_base
<< " iovs[curIov].iov_len=" << iovs[curIov].iov_len; << " iovs[curIov].iov_len=" << iovs[curIov].iov_len;
size += len; size += len;
/// restore iovs[curIov] to the original value /// restore iovs[curIov] to the original value
...@@ -183,7 +183,7 @@ void SocketChannel::writeMessage(const std::vector<struct iovec>& userIovs) { ...@@ -183,7 +183,7 @@ void SocketChannel::writeMessage(const std::vector<struct iovec>& userIovs) {
header.totalLength += iov.iov_len; header.totalLength += iov.iov_len;
} }
PCHECK(writev(iovs) == (size_t)header.totalLength); CHECK(writev(iovs) == (size_t)header.totalLength);
} }
std::unique_ptr<MsgReader> SocketChannel::readMessage() { std::unique_ptr<MsgReader> SocketChannel::readMessage() {
...@@ -194,7 +194,7 @@ std::unique_ptr<MsgReader> SocketChannel::readMessage() { ...@@ -194,7 +194,7 @@ std::unique_ptr<MsgReader> SocketChannel::readMessage() {
return nullptr; return nullptr;
} }
PCHECK(len == sizeof(header)); CHECK(len == sizeof(header));
std::unique_ptr<MsgReader> msgReader(new MsgReader(this, header.numIovs)); std::unique_ptr<MsgReader> msgReader(new MsgReader(this, header.numIovs));
...@@ -209,7 +209,7 @@ std::unique_ptr<MsgReader> SocketChannel::readMessage() { ...@@ -209,7 +209,7 @@ std::unique_ptr<MsgReader> SocketChannel::readMessage() {
MsgReader::MsgReader(SocketChannel* channel, size_t numBlocks) MsgReader::MsgReader(SocketChannel* channel, size_t numBlocks)
: channel_(channel), blockLengths_(numBlocks), currentBlockIndex_(0) { : channel_(channel), blockLengths_(numBlocks), currentBlockIndex_(0) {
size_t size = numBlocks * sizeof(blockLengths_[0]); size_t size = numBlocks * sizeof(blockLengths_[0]);
PCHECK(channel_->read(&blockLengths_[0], size) == size); CHECK(channel_->read(&blockLengths_[0], size) == size);
} }
void MsgReader::readBlocks(const std::vector<void*>& bufs) { void MsgReader::readBlocks(const std::vector<void*>& bufs) {
...@@ -223,12 +223,12 @@ void MsgReader::readBlocks(const std::vector<void*>& bufs) { ...@@ -223,12 +223,12 @@ void MsgReader::readBlocks(const std::vector<void*>& bufs) {
++currentBlockIndex_; ++currentBlockIndex_;
} }
PCHECK(channel_->readv(&iovs) == totalLength); CHECK(channel_->readv(&iovs) == totalLength);
} }
void MsgReader::readNextBlock(void* buf) { void MsgReader::readNextBlock(void* buf) {
CHECK_LT(currentBlockIndex_, blockLengths_.size()); CHECK_LT(currentBlockIndex_, blockLengths_.size());
PCHECK(channel_->read(buf, getNextBlockLength()) == getNextBlockLength()); CHECK(channel_->read(buf, getNextBlockLength()) == getNextBlockLength());
++currentBlockIndex_; ++currentBlockIndex_;
} }
......
...@@ -113,7 +113,7 @@ void SocketServer::run() { ...@@ -113,7 +113,7 @@ void SocketServer::run() {
/* First call to socket() function */ /* First call to socket() function */
socket_ = socket(AF_INET, SOCK_STREAM, 0); socket_ = socket(AF_INET, SOCK_STREAM, 0);
PCHECK(socket_ >= 0) << "ERROR opening socket"; CHECK(socket_ >= 0) << "ERROR opening socket";
/* Initialize socket structure */ /* Initialize socket structure */
bzero((char*)&serv_addr, sizeof(serv_addr)); bzero((char*)&serv_addr, sizeof(serv_addr));
...@@ -122,7 +122,7 @@ void SocketServer::run() { ...@@ -122,7 +122,7 @@ void SocketServer::run() {
serv_addr.sin_port = htons(port_); serv_addr.sin_port = htons(port_);
/* Now bind the host address using bind() call.*/ /* Now bind the host address using bind() call.*/
PCHECK(bind(socket_, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) >= 0) CHECK(bind(socket_, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) >= 0)
<< "ERROR on binding"; << "ERROR on binding";
/* Now start listening for the clients, here process will /* Now start listening for the clients, here process will
...@@ -134,7 +134,7 @@ void SocketServer::run() { ...@@ -134,7 +134,7 @@ void SocketServer::run() {
while (true) { while (true) {
/* Accept actual connection from the client */ /* Accept actual connection from the client */
newsockfd = accept(socket_, (struct sockaddr*)&cli_addr, &clilen); newsockfd = accept(socket_, (struct sockaddr*)&cli_addr, &clilen);
PCHECK(newsockfd >= 0) << "ERROR on accept"; CHECK(newsockfd >= 0) << "ERROR on accept";
SocketWorker* worker = new SocketWorker(newsockfd); SocketWorker* worker = new SocketWorker(newsockfd);
worker->start(); worker->start();
...@@ -146,17 +146,17 @@ void SocketWorker::run() { ...@@ -146,17 +146,17 @@ void SocketWorker::run() {
while (true) { while (true) {
int64_t n = channel_.readAll(&header, sizeof(header)); int64_t n = channel_.readAll(&header, sizeof(header));
PCHECK(n == sizeof(header)) << "ERROR reading from socket"; CHECK(n == sizeof(header)) << "ERROR reading from socket";
buffer_.resize(header.dataLength); buffer_.resize(header.dataLength);
n = channel_.readAll(&buffer_[0], header.dataLength); n = channel_.readAll(&buffer_[0], header.dataLength);
PCHECK(n == header.dataLength) << "ERROR reading from socket"; CHECK(n == header.dataLength) << "ERROR reading from socket";
/* Write a response to the client */ /* Write a response to the client */
n = channel_.writeAll(&header, sizeof(header)); n = channel_.writeAll(&header, sizeof(header));
PCHECK(n == sizeof(header)) << "ERROR reading from socket"; CHECK(n == sizeof(header)) << "ERROR reading from socket";
n = channel_.writeAll(buffer_.data(), buffer_.size()); n = channel_.writeAll(buffer_.data(), buffer_.size());
PCHECK(n == header.dataLength) << "ERROR writing to socket"; CHECK(n == header.dataLength) << "ERROR writing to socket";
} }
} }
...@@ -177,9 +177,9 @@ SocketClient::SocketClient(const std::string& serverAddr, int serverPort) { ...@@ -177,9 +177,9 @@ SocketClient::SocketClient(const std::string& serverAddr, int serverPort) {
/* Create a socket point */ /* Create a socket point */
int sockfd = socket(AF_INET, SOCK_STREAM, 0); int sockfd = socket(AF_INET, SOCK_STREAM, 0);
PCHECK(sockfd >= 0) << "ERROR opening socket"; CHECK(sockfd >= 0) << "ERROR opening socket";
server = gethostbyname(serverAddr.c_str()); server = gethostbyname(serverAddr.c_str());
PCHECK(server) << "ERROR, no such host: " << serverAddr; CHECK(server) << "ERROR, no such host: " << serverAddr;
bzero((char*)&serv_addr, sizeof(serv_addr)); bzero((char*)&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;
...@@ -189,7 +189,7 @@ SocketClient::SocketClient(const std::string& serverAddr, int serverPort) { ...@@ -189,7 +189,7 @@ SocketClient::SocketClient(const std::string& serverAddr, int serverPort) {
serv_addr.sin_port = htons(serverPort); serv_addr.sin_port = htons(serverPort);
/* Now connect to the server */ /* Now connect to the server */
PCHECK(connect(sockfd, (sockaddr*)&serv_addr, sizeof(serv_addr)) >= 0) CHECK(connect(sockfd, (sockaddr*)&serv_addr, sizeof(serv_addr)) >= 0)
<< "ERROR connecting"; << "ERROR connecting";
channel_.reset(new SocketChannel(sockfd)); channel_.reset(new SocketChannel(sockfd));
...@@ -234,18 +234,18 @@ int main(int argc, char** argv) { ...@@ -234,18 +234,18 @@ int main(int argc, char** argv) {
cpuGrad.copyFrom(gpuGrad); cpuGrad.copyFrom(gpuGrad);
header.dataLength = dataSize; header.dataLength = dataSize;
PCHECK(channel->writeAll(&header, sizeof(header)) == sizeof(header)) CHECK(channel->writeAll(&header, sizeof(header)) == sizeof(header))
<< "Client write header error"; << "Client write header error";
PCHECK(channel->writeAll(cpuGrad.getData(), dataSize) == dataSize) CHECK(channel->writeAll(cpuGrad.getData(), dataSize) == dataSize)
<< "Client write data error"; << "Client write data error";
/* Now read server response */ /* Now read server response */
PCHECK(channel->readAll(&header, sizeof(header)) == sizeof(header)) CHECK(channel->readAll(&header, sizeof(header)) == sizeof(header))
<< "Client read header error"; << "Client read header error";
CHECK_EQ((uint64_t)header.dataLength, dataSize); CHECK_EQ((uint64_t)header.dataLength, dataSize);
PCHECK(channel->readAll(cpuParam.getData(), dataSize) == dataSize) CHECK(channel->readAll(cpuParam.getData(), dataSize) == dataSize)
<< "Client read data error"; << "Client read data error";
gpuParam.copyFrom(cpuParam); gpuParam.copyFrom(cpuParam);
......
...@@ -175,7 +175,7 @@ real Tester::forwardOneBatch(const DataBatch& dataBatch, ...@@ -175,7 +175,7 @@ real Tester::forwardOneBatch(const DataBatch& dataBatch,
} }
hl_stream_synchronize(HPPL_STREAM_DEFAULT); hl_stream_synchronize(HPPL_STREAM_DEFAULT);
FILE* fp = fopen(featFile.c_str(), "ab+"); FILE* fp = fopen(featFile.c_str(), "ab+");
PCHECK(!ferror(fp)) << "Fail to open " << featFile; CHECK(!ferror(fp)) << "Fail to open " << featFile;
size_t sampleNum = featMatrices[0]->getHeight(); size_t sampleNum = featMatrices[0]->getHeight();
for (size_t i = 0; i < sampleNum; ++i) { for (size_t i = 0; i < sampleNum; ++i) {
......
...@@ -51,7 +51,7 @@ template <class T> ...@@ -51,7 +51,7 @@ template <class T>
class ThreadLocal { class ThreadLocal {
public: public:
ThreadLocal() { ThreadLocal() {
PCHECK(pthread_key_create(&threadSpecificKey_, dataDestructor) == 0); CHECK(pthread_key_create(&threadSpecificKey_, dataDestructor) == 0);
} }
~ThreadLocal() { pthread_key_delete(threadSpecificKey_); } ~ThreadLocal() { pthread_key_delete(threadSpecificKey_); }
...@@ -65,7 +65,7 @@ public: ...@@ -65,7 +65,7 @@ public:
if (!p && createLocal) { if (!p && createLocal) {
p = new T(); p = new T();
int ret = pthread_setspecific(threadSpecificKey_, p); int ret = pthread_setspecific(threadSpecificKey_, p);
PCHECK(ret == 0); CHECK(ret == 0);
} }
return p; return p;
} }
...@@ -79,7 +79,7 @@ public: ...@@ -79,7 +79,7 @@ public:
if (T* q = get(false)) { if (T* q = get(false)) {
dataDestructor(q); dataDestructor(q);
} }
PCHECK(pthread_setspecific(threadSpecificKey_, p) == 0); CHECK(pthread_setspecific(threadSpecificKey_, p) == 0);
} }
/** /**
...@@ -112,7 +112,7 @@ private: ...@@ -112,7 +112,7 @@ private:
template <class T> template <class T>
class ThreadLocalD { class ThreadLocalD {
public: public:
ThreadLocalD() { PCHECK(pthread_key_create(&threadSpecificKey_, NULL) == 0); } ThreadLocalD() { CHECK(pthread_key_create(&threadSpecificKey_, NULL) == 0); }
~ThreadLocalD() { ~ThreadLocalD() {
pthread_key_delete(threadSpecificKey_); pthread_key_delete(threadSpecificKey_);
for (auto t : threadMap_) { for (auto t : threadMap_) {
...@@ -127,7 +127,7 @@ public: ...@@ -127,7 +127,7 @@ public:
T* p = (T*)pthread_getspecific(threadSpecificKey_); T* p = (T*)pthread_getspecific(threadSpecificKey_);
if (!p) { if (!p) {
p = new T(); p = new T();
PCHECK(pthread_setspecific(threadSpecificKey_, p) == 0); CHECK(pthread_setspecific(threadSpecificKey_, p) == 0);
updateMap(p); updateMap(p);
} }
return p; return p;
...@@ -141,7 +141,7 @@ public: ...@@ -141,7 +141,7 @@ public:
if (T* q = (T*)pthread_getspecific(threadSpecificKey_)) { if (T* q = (T*)pthread_getspecific(threadSpecificKey_)) {
dataDestructor(q); dataDestructor(q);
} }
PCHECK(pthread_setspecific(threadSpecificKey_, p) == 0); CHECK(pthread_setspecific(threadSpecificKey_, p) == 0);
updateMap(p); updateMap(p);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册