Correct style warnings from clang-tidy for rabit. (#6095)

This commit is contained in:
Jiaming Yuan
2020-09-08 12:13:58 +08:00
committed by GitHub
parent da61d9460b
commit b0001a6e29
19 changed files with 736 additions and 868 deletions

View File

@@ -19,7 +19,7 @@
#define _CALLER "N/A"
#endif // (defined(__GNUC__) && !defined(__clang__))
namespace MPI {
namespace MPI { // NOLINT
/*! \brief MPI data type just to be compatible with MPI reduce function*/
class Datatype;
}
@@ -36,7 +36,7 @@ class IEngine {
* used to prepare the data used by AllReduce
* \param arg additional possible argument used to invoke the preprocessor
*/
typedef void (PreprocFunction) (void *arg);
typedef void (PreprocFunction) (void *arg); // NOLINT
/*!
* \brief reduce function, the same form of MPI reduce function is used,
* to be compatible with MPI interface
@@ -48,11 +48,11 @@ class IEngine {
* the definition of the reduce function should be type aware
* \param dtype the data type object, to be compatible with MPI reduce
*/
typedef void (ReduceFunction) (const void *src,
typedef void (ReduceFunction) (const void *src, // NOLINT
void *dst, int count,
const MPI::Datatype &dtype);
/*! \brief virtual destructor */
virtual ~IEngine() {}
~IEngine() = default;
/*!
* \brief Allgather function, each node have a segment of data in the ring of sendrecvbuf,
* the data provided by current node k is [slice_begin, slice_end),
@@ -68,7 +68,7 @@ class IEngine {
* \param _file caller file name used to generate unique cache key
* \param _line caller line number used to generate unique cache key
* \param _caller caller function name used to generate unique cache key
*/
*/
virtual void Allgather(void *sendrecvbuf,
size_t total_size,
size_t slice_begin,
@@ -96,8 +96,8 @@ class IEngine {
size_t type_nbytes,
size_t count,
ReduceFunction reducer,
PreprocFunction prepare_fun = NULL,
void *prepare_arg = NULL,
PreprocFunction prepare_fun = nullptr,
void *prepare_arg = nullptr,
const char* _file = _FILE,
const int _line = _LINE,
const char* _caller = _CALLER) = 0;
@@ -119,7 +119,7 @@ class IEngine {
* call this function when IEngine throws an exception,
* this function should only be used for test purposes
*/
virtual void InitAfterException(void) = 0;
virtual void InitAfterException() = 0;
/*!
* \brief loads the latest check point
* \param global_model pointer to the globally shared model/state
@@ -143,7 +143,7 @@ class IEngine {
* \sa CheckPoint, VersionNumber
*/
virtual int LoadCheckPoint(Serializable *global_model,
Serializable *local_model = NULL) = 0;
Serializable *local_model = nullptr) = 0;
/*!
* \brief checkpoints the model, meaning a stage of execution was finished
* every time we call check point, a version number increases by ones
@@ -161,7 +161,7 @@ class IEngine {
* \sa LoadCheckPoint, VersionNumber
*/
virtual void CheckPoint(const Serializable *global_model,
const Serializable *local_model = NULL) = 0;
const Serializable *local_model = nullptr) = 0;
/*!
* \brief This function can be used to replace CheckPoint for global_model only,
* when certain condition is met (see detailed explanation).
@@ -188,17 +188,17 @@ class IEngine {
* which means how many calls to CheckPoint we made so far
* \sa LoadCheckPoint, CheckPoint
*/
virtual int VersionNumber(void) const = 0;
virtual int VersionNumber() const = 0;
/*! \brief gets rank of previous node in ring topology */
virtual int GetRingPrevRank(void) const = 0;
virtual int GetRingPrevRank() const = 0;
/*! \brief gets rank of current node */
virtual int GetRank(void) const = 0;
virtual int GetRank() const = 0;
/*! \brief gets total number of nodes */
virtual int GetWorldSize(void) const = 0;
virtual int GetWorldSize() const = 0;
/*! \brief whether we run in distribted mode */
virtual bool IsDistributed(void) const = 0;
virtual bool IsDistributed() const = 0;
/*! \brief gets the host name of the current node */
virtual std::string GetHost(void) const = 0;
virtual std::string GetHost() const = 0;
/*!
* \brief prints the msg in the tracker,
* this function can be used to communicate progress information to
@@ -211,9 +211,9 @@ class IEngine {
/*! \brief initializes the engine module */
bool Init(int argc, char *argv[]);
/*! \brief finalizes the engine module */
bool Finalize(void);
bool Finalize();
/*! \brief singleton method to get engine */
IEngine *GetEngine(void);
IEngine *GetEngine();
/*! \brief namespace that contains stubs to be compatible with MPI */
namespace mpi {
@@ -280,14 +280,14 @@ void Allgather(void* sendrecvbuf,
* \param _line caller line number used to generate unique cache key
* \param _caller caller function name used to generate unique cache key
*/
void Allreduce_(void *sendrecvbuf,
void Allreduce_(void *sendrecvbuf, // NOLINT
size_t type_nbytes,
size_t count,
IEngine::ReduceFunction red,
mpi::DataType dtype,
mpi::OpType op,
IEngine::PreprocFunction prepare_fun = NULL,
void *prepare_arg = NULL,
IEngine::PreprocFunction prepare_fun = nullptr,
void *prepare_arg = nullptr,
const char* _file = _FILE,
const int _line = _LINE,
const char* _caller = _CALLER);
@@ -298,9 +298,9 @@ void Allreduce_(void *sendrecvbuf,
class ReduceHandle {
public:
// constructor
ReduceHandle(void);
ReduceHandle();
// destructor
~ReduceHandle(void);
~ReduceHandle();
/*!
* \brief initialize the reduce function,
* with the type the reduce function needs to deal with
@@ -323,8 +323,8 @@ class ReduceHandle {
void Allreduce(void *sendrecvbuf,
size_t type_nbytes,
size_t count,
IEngine::PreprocFunction prepare_fun = NULL,
void *prepare_arg = NULL,
IEngine::PreprocFunction prepare_fun = nullptr,
void *prepare_arg = nullptr,
const char* _file = _FILE,
const int _line = _LINE,
const char* _caller = _CALLER);
@@ -333,11 +333,11 @@ class ReduceHandle {
protected:
// handle function field
void *handle_;
void *handle_ {nullptr};
// reduce function of the reducer
IEngine::ReduceFunction *redfunc_;
IEngine::ReduceFunction *redfunc_{nullptr};
// handle to the type field
void *htype_;
void *htype_{nullptr};
// the created type in 4 bytes
size_t created_type_nbytes_;
};

View File

@@ -19,12 +19,12 @@
namespace rabit {
namespace utils {
/*! \brief re-use definition of dmlc::SeekStream */
typedef dmlc::SeekStream SeekStream;
using SeekStream = dmlc::SeekStream;
/*! \brief fixed size memory buffer */
struct MemoryFixSizeBuffer : public SeekStream {
public:
// similar to SEEK_END in libc
static size_t constexpr SeekEnd = std::numeric_limits<size_t>::max();
static size_t constexpr kSeekEnd = std::numeric_limits<size_t>::max();
public:
MemoryFixSizeBuffer(void *p_buffer, size_t buffer_size)
@@ -32,31 +32,31 @@ struct MemoryFixSizeBuffer : public SeekStream {
buffer_size_(buffer_size) {
curr_ptr_ = 0;
}
virtual ~MemoryFixSizeBuffer(void) {}
virtual size_t Read(void *ptr, size_t size) {
~MemoryFixSizeBuffer() override = default;
size_t Read(void *ptr, size_t size) override {
size_t nread = std::min(buffer_size_ - curr_ptr_, size);
if (nread != 0) std::memcpy(ptr, p_buffer_ + curr_ptr_, nread);
curr_ptr_ += nread;
return nread;
}
virtual void Write(const void *ptr, size_t size) {
void Write(const void *ptr, size_t size) override {
if (size == 0) return;
utils::Assert(curr_ptr_ + size <= buffer_size_,
"write position exceed fixed buffer size");
std::memcpy(p_buffer_ + curr_ptr_, ptr, size);
curr_ptr_ += size;
}
virtual void Seek(size_t pos) {
if (pos == SeekEnd) {
void Seek(size_t pos) override {
if (pos == kSeekEnd) {
curr_ptr_ = buffer_size_;
} else {
curr_ptr_ = static_cast<size_t>(pos);
}
}
virtual size_t Tell(void) {
size_t Tell() override {
return curr_ptr_;
}
virtual bool AtEnd(void) const {
virtual bool AtEnd() const {
return curr_ptr_ == buffer_size_;
}
@@ -76,8 +76,8 @@ struct MemoryBufferStream : public SeekStream {
: p_buffer_(p_buffer) {
curr_ptr_ = 0;
}
virtual ~MemoryBufferStream(void) {}
virtual size_t Read(void *ptr, size_t size) {
~MemoryBufferStream() override = default;
size_t Read(void *ptr, size_t size) override {
utils::Assert(curr_ptr_ <= p_buffer_->length(),
"read can not have position excceed buffer length");
size_t nread = std::min(p_buffer_->length() - curr_ptr_, size);
@@ -85,7 +85,7 @@ struct MemoryBufferStream : public SeekStream {
curr_ptr_ += nread;
return nread;
}
virtual void Write(const void *ptr, size_t size) {
void Write(const void *ptr, size_t size) override {
if (size == 0) return;
if (curr_ptr_ + size > p_buffer_->length()) {
p_buffer_->resize(curr_ptr_+size);
@@ -93,13 +93,13 @@ struct MemoryBufferStream : public SeekStream {
std::memcpy(&(*p_buffer_)[0] + curr_ptr_, ptr, size);
curr_ptr_ += size;
}
virtual void Seek(size_t pos) {
void Seek(size_t pos) override {
curr_ptr_ = static_cast<size_t>(pos);
}
virtual size_t Tell(void) {
size_t Tell() override {
return curr_ptr_;
}
virtual bool AtEnd(void) const {
virtual bool AtEnd() const {
return curr_ptr_ == p_buffer_->length();
}

View File

@@ -19,45 +19,45 @@ namespace engine {
namespace mpi {
// template function to translate type to enum indicator
template<typename DType>
inline DataType GetType(void);
inline DataType GetType();
template<>
inline DataType GetType<char>(void) {
inline DataType GetType<char>() {
return kChar;
}
template<>
inline DataType GetType<unsigned char>(void) {
inline DataType GetType<unsigned char>() {
return kUChar;
}
template<>
inline DataType GetType<int>(void) {
inline DataType GetType<int>() {
return kInt;
}
template<>
inline DataType GetType<unsigned int>(void) { // NOLINT(*)
inline DataType GetType<unsigned int>() { // NOLINT(*)
return kUInt;
}
template<>
inline DataType GetType<long>(void) { // NOLINT(*)
inline DataType GetType<long>() { // NOLINT(*)
return kLong;
}
template<>
inline DataType GetType<unsigned long>(void) { // NOLINT(*)
inline DataType GetType<unsigned long>() { // NOLINT(*)
return kULong;
}
template<>
inline DataType GetType<float>(void) {
inline DataType GetType<float>() {
return kFloat;
}
template<>
inline DataType GetType<double>(void) {
inline DataType GetType<double>() {
return kDouble;
}
template<>
inline DataType GetType<long long>(void) { // NOLINT(*)
inline DataType GetType<long long>() { // NOLINT(*)
return kLongLong;
}
template<>
inline DataType GetType<unsigned long long>(void) { // NOLINT(*)
inline DataType GetType<unsigned long long>() { // NOLINT(*)
return kULongLong;
}
} // namespace mpi
@@ -94,7 +94,7 @@ struct BitOR {
};
template<typename OP, typename DType>
inline void Reducer(const void *src_, void *dst_, int len, const MPI::Datatype &dtype) {
const DType* src = (const DType*)src_;
const DType* src = static_cast<const DType*>(src_);
DType* dst = (DType*)dst_; // NOLINT(*)
for (int i = 0; i < len; i++) {
OP::Reduce(dst[i], src[i]);
@@ -107,27 +107,27 @@ inline bool Init(int argc, char *argv[]) {
return engine::Init(argc, argv);
}
// finalize the rabit engine
inline bool Finalize(void) {
inline bool Finalize() {
return engine::Finalize();
}
// get the rank of the previous worker in ring topology
inline int GetRingPrevRank(void) {
inline int GetRingPrevRank() {
return engine::GetEngine()->GetRingPrevRank();
}
// get the rank of current process
inline int GetRank(void) {
inline int GetRank() {
return engine::GetEngine()->GetRank();
}
// the the size of the world
inline int GetWorldSize(void) {
inline int GetWorldSize() {
return engine::GetEngine()->GetWorldSize();
}
// whether rabit is distributed
inline bool IsDistributed(void) {
inline bool IsDistributed() {
return engine::GetEngine()->IsDistributed();
}
// get the name of current processor
inline std::string GetProcessorName(void) {
inline std::string GetProcessorName() {
return engine::GetEngine()->GetHost();
}
// broadcast data to all other nodes from root
@@ -183,7 +183,7 @@ inline void Allreduce(DType *sendrecvbuf, size_t count,
// C++11 support for lambda prepare function
#if DMLC_USE_CXX11
inline void InvokeLambda_(void *fun) {
inline void InvokeLambda(void *fun) {
(*static_cast<std::function<void()>*>(fun))();
}
template<typename OP, typename DType>
@@ -193,7 +193,7 @@ inline void Allreduce(DType *sendrecvbuf, size_t count,
const int _line,
const char* _caller) {
engine::Allreduce_(sendrecvbuf, sizeof(DType), count, op::Reducer<OP, DType>,
engine::mpi::GetType<DType>(), OP::kType, InvokeLambda_, &prepare_fun,
engine::mpi::GetType<DType>(), OP::kType, InvokeLambda, &prepare_fun,
_file, _line, _caller);
}
@@ -245,7 +245,7 @@ inline void LazyCheckPoint(const Serializable *global_model) {
engine::GetEngine()->LazyCheckPoint(global_model);
}
// return the version number of currently stored model
inline int VersionNumber(void) {
inline int VersionNumber() {
return engine::GetEngine()->VersionNumber();
}
// ---------------------------------
@@ -253,7 +253,7 @@ inline int VersionNumber(void) {
// ---------------------------------
// function to perform reduction for Reducer
template<typename DType, void (*freduce)(DType &dst, const DType &src)>
inline void ReducerSafe_(const void *src_, void *dst_, int len_, const MPI::Datatype &dtype) {
inline void ReducerSafeImpl(const void *src_, void *dst_, int len_, const MPI::Datatype &dtype) {
const size_t kUnit = sizeof(DType);
const char *psrc = reinterpret_cast<const char*>(src_);
char *pdst = reinterpret_cast<char*>(dst_);
@@ -269,7 +269,7 @@ inline void ReducerSafe_(const void *src_, void *dst_, int len_, const MPI::Data
}
// function to perform reduction for Reducer
template<typename DType, void (*freduce)(DType &dst, const DType &src)> // NOLINT(*)
inline void ReducerAlign_(const void *src_, void *dst_,
inline void ReducerAlignImpl(const void *src_, void *dst_,
int len_, const MPI::Datatype &dtype) {
const DType *psrc = reinterpret_cast<const DType*>(src_);
DType *pdst = reinterpret_cast<DType*>(dst_);
@@ -278,12 +278,12 @@ inline void ReducerAlign_(const void *src_, void *dst_,
}
}
template<typename DType, void (*freduce)(DType &dst, const DType &src)> // NOLINT(*)
inline Reducer<DType, freduce>::Reducer(void) {
inline Reducer<DType, freduce>::Reducer() {
// it is safe to directly use handle for aligned data types
if (sizeof(DType) == 8 || sizeof(DType) == 4 || sizeof(DType) == 1) {
this->handle_.Init(ReducerAlign_<DType, freduce>, sizeof(DType));
this->handle_.Init(ReducerAlignImpl<DType, freduce>, sizeof(DType));
} else {
this->handle_.Init(ReducerSafe_<DType, freduce>, sizeof(DType));
this->handle_.Init(ReducerSafeImpl<DType, freduce>, sizeof(DType));
}
}
template<typename DType, void (*freduce)(DType &dst, const DType &src)> // NOLINT(*)
@@ -298,8 +298,8 @@ inline void Reducer<DType, freduce>::Allreduce(DType *sendrecvbuf, size_t count,
}
// function to perform reduction for SerializeReducer
template<typename DType>
inline void SerializeReducerFunc_(const void *src_, void *dst_,
int len_, const MPI::Datatype &dtype) {
inline void SerializeReducerFuncImpl(const void *src_, void *dst_,
int len_, const MPI::Datatype &dtype) {
int nbytes = engine::ReduceHandle::TypeSize(dtype);
// temp space
for (int i = 0; i < len_; ++i) {
@@ -315,8 +315,8 @@ inline void SerializeReducerFunc_(const void *src_, void *dst_,
}
}
template<typename DType>
inline SerializeReducer<DType>::SerializeReducer(void) {
handle_.Init(SerializeReducerFunc_<DType>, sizeof(DType));
inline SerializeReducer<DType>::SerializeReducer() {
handle_.Init(SerializeReducerFuncImpl<DType>, sizeof(DType));
}
// closure to call Allreduce
template<typename DType>
@@ -327,8 +327,8 @@ struct SerializeReduceClosure {
void *prepare_arg;
std::string *p_buffer;
// invoke the closure
inline void Run(void) {
if (prepare_fun != NULL) prepare_fun(prepare_arg);
inline void Run() {
if (prepare_fun != nullptr) prepare_fun(prepare_arg);
for (size_t i = 0; i < count; ++i) {
utils::MemoryFixSizeBuffer fs(BeginPtr(*p_buffer) + i * max_nbyte, max_nbyte);
sendrecvobj[i].Save(fs);
@@ -368,7 +368,7 @@ inline void Reducer<DType, freduce>::Allreduce(DType *sendrecvbuf, size_t count,
const char* _file,
const int _line,
const char* _caller) {
this->Allreduce(sendrecvbuf, count, InvokeLambda_, &prepare_fun,
this->Allreduce(sendrecvbuf, count, InvokeLambda, &prepare_fun,
_file, _line, _caller);
}
template<typename DType>
@@ -378,7 +378,7 @@ inline void SerializeReducer<DType>::Allreduce(DType *sendrecvobj,
const char* _file,
const int _line,
const char* _caller) {
this->Allreduce(sendrecvobj, max_nbytes, count, InvokeLambda_, &prepare_fun,
this->Allreduce(sendrecvobj, max_nbytes, count, InvokeLambda, &prepare_fun,
_file, _line, _caller);
}
#endif // DMLC_USE_CXX11

View File

@@ -15,7 +15,7 @@
#else
#include <fcntl.h>
#include <netdb.h>
#include <errno.h>
#include <cerrno>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
@@ -39,9 +39,9 @@ static inline int poll(struct pollfd *pfd, int nfds,
int timeout) { return WSAPoll ( pfd, nfds, timeout ); }
#else
#include <sys/poll.h>
typedef int SOCKET;
typedef size_t sock_size_t;
const int INVALID_SOCKET = -1;
using SOCKET = int;
using sock_size_t = size_t; // NOLINT
const int kInvalidSocket = -1;
#endif // defined(_WIN32)
namespace rabit {
@@ -50,11 +50,11 @@ namespace utils {
struct SockAddr {
sockaddr_in addr;
// constructor
SockAddr(void) {}
SockAddr() = default;
SockAddr(const char *url, int port) {
this->Set(url, port);
}
inline static std::string GetHostName(void) {
inline static std::string GetHostName() {
std::string buf; buf.resize(256);
utils::Check(gethostname(&buf[0], 256) != -1, "fail to get host name");
return std::string(buf.c_str());
@@ -69,20 +69,20 @@ struct SockAddr {
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_protocol = SOCK_STREAM;
addrinfo *res = NULL;
int sig = getaddrinfo(host, NULL, &hints, &res);
Check(sig == 0 && res != NULL, "cannot obtain address of %s", host);
addrinfo *res = nullptr;
int sig = getaddrinfo(host, nullptr, &hints, &res);
Check(sig == 0 && res != nullptr, "cannot obtain address of %s", host);
Check(res->ai_family == AF_INET, "Does not support IPv6");
memcpy(&addr, res->ai_addr, res->ai_addrlen);
addr.sin_port = htons(port);
freeaddrinfo(res);
}
/*! \brief return port of the address*/
inline int port(void) const {
inline int Port() const {
return ntohs(addr.sin_port);
}
/*! \return a string representation of the address */
inline std::string AddrStr(void) const {
inline std::string AddrStr() const {
std::string buf; buf.resize(256);
#ifdef _WIN32
const char *s = inet_ntop(AF_INET, (PVOID)&addr.sin_addr,
@@ -91,7 +91,7 @@ struct SockAddr {
const char *s = inet_ntop(AF_INET, &addr.sin_addr,
&buf[0], buf.length());
#endif // _WIN32
Assert(s != NULL, "cannot decode address");
Assert(s != nullptr, "cannot decode address");
return std::string(s);
}
};
@@ -104,13 +104,13 @@ class Socket {
/*! \brief the file descriptor of socket */
SOCKET sockfd;
// default conversion to int
inline operator SOCKET() const {
operator SOCKET() const { // NOLINT
return sockfd;
}
/*!
* \return last error of socket operation
*/
inline static int GetLastError(void) {
inline static int GetLastError() {
#ifdef _WIN32
return WSAGetLastError();
#else
@@ -118,7 +118,7 @@ class Socket {
#endif // _WIN32
}
/*! \return whether last error was would block */
inline static bool LastErrorWouldBlock(void) {
inline static bool LastErrorWouldBlock() {
int errsv = GetLastError();
#ifdef _WIN32
return errsv == WSAEWOULDBLOCK;
@@ -130,7 +130,7 @@ class Socket {
* \brief start up the socket module
* call this before using the sockets
*/
inline static void Startup(void) {
inline static void Startup() {
#ifdef _WIN32
WSADATA wsa_data;
if (WSAStartup(MAKEWORD(2, 2), &wsa_data) == -1) {
@@ -145,7 +145,7 @@ class Socket {
/*!
* \brief shutdown the socket module after use, all sockets need to be closed
*/
inline static void Finalize(void) {
inline static void Finalize() {
#ifdef _WIN32
WSACleanup();
#endif // _WIN32
@@ -214,7 +214,7 @@ class Socket {
return -1;
}
/*! \brief get last error code if any */
inline int GetSockError(void) const {
inline int GetSockError() const {
int error = 0;
socklen_t len = sizeof(error);
if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR,
@@ -224,25 +224,25 @@ class Socket {
return error;
}
/*! \brief check if anything bad happens */
inline bool BadSocket(void) const {
inline bool BadSocket() const {
if (IsClosed()) return true;
int err = GetSockError();
if (err == EBADF || err == EINTR) return true;
return false;
}
/*! \brief check if socket is already closed */
inline bool IsClosed(void) const {
return sockfd == INVALID_SOCKET;
inline bool IsClosed() const {
return sockfd == kInvalidSocket;
}
/*! \brief close the socket */
inline void Close(void) {
if (sockfd != INVALID_SOCKET) {
inline void Close() {
if (sockfd != kInvalidSocket) {
#ifdef _WIN32
closesocket(sockfd);
#else
close(sockfd);
#endif
sockfd = INVALID_SOCKET;
sockfd = kInvalidSocket;
} else {
Error("Socket::Close double close the socket or close without create");
}
@@ -268,7 +268,7 @@ class Socket {
class TCPSocket : public Socket{
public:
// constructor
TCPSocket(void) : Socket(INVALID_SOCKET) {
TCPSocket() : Socket(kInvalidSocket) {
}
explicit TCPSocket(SOCKET sockfd) : Socket(sockfd) {
}
@@ -297,7 +297,7 @@ class TCPSocket : public Socket{
*/
inline void Create(int af = PF_INET) {
sockfd = socket(PF_INET, SOCK_STREAM, 0);
if (sockfd == INVALID_SOCKET) {
if (sockfd == kInvalidSocket) {
Socket::Error("Create");
}
}
@@ -309,9 +309,9 @@ class TCPSocket : public Socket{
listen(sockfd, backlog);
}
/*! \brief get a new connection */
TCPSocket Accept(void) {
SOCKET newfd = accept(sockfd, NULL, NULL);
if (newfd == INVALID_SOCKET) {
TCPSocket Accept() {
SOCKET newfd = accept(sockfd, nullptr, nullptr);
if (newfd == kInvalidSocket) {
Socket::Error("Accept");
}
return TCPSocket(newfd);
@@ -320,7 +320,7 @@ class TCPSocket : public Socket{
* \brief decide whether the socket is at OOB mark
* \return 1 if at mark, 0 if not, -1 if an error occured
*/
inline int AtMark(void) const {
inline int AtMark() const {
#ifdef _WIN32
unsigned long atmark; // NOLINT(*)
if (ioctlsocket(sockfd, SIOCATMARK, &atmark) != NO_ERROR) return -1;

View File

@@ -1,87 +0,0 @@
/*!
* Copyright (c) 2015 by Contributors
* \file thread_local.h
* \brief Common utility for thread local storage.
*/
#ifndef RABIT_INTERNAL_THREAD_LOCAL_H_
#define RABIT_INTERNAL_THREAD_LOCAL_H_
#include "../include/dmlc/base.h"
#if DMLC_ENABLE_STD_THREAD
#include <mutex>
#endif // DMLC_ENABLE_STD_THREAD
#include <memory>
#include <vector>
namespace rabit {
// macro hanlding for threadlocal variables
#ifdef __GNUC__
#define MX_TREAD_LOCAL __thread
#elif __STDC_VERSION__ >= 201112L
#define MX_TREAD_LOCAL _Thread_local
#elif defined(_MSC_VER)
#define MX_TREAD_LOCAL __declspec(thread)
#endif // __GNUC__
#ifndef MX_TREAD_LOCAL
#message("Warning: Threadlocal is not enabled");
#endif // MX_TREAD_LOCAL
/*!
* \brief A threadlocal store to store threadlocal variables.
* Will return a thread local singleton of type T
* \tparam T the type we like to store
*/
template<typename T>
class ThreadLocalStore {
public:
/*! \return get a thread local singleton */
static T* Get() {
static MX_TREAD_LOCAL T* ptr = nullptr;
if (ptr == nullptr) {
ptr = new T();
Singleton()->RegisterDelete(ptr);
}
return ptr;
}
private:
/*! \brief constructor */
ThreadLocalStore() {}
/*! \brief destructor */
~ThreadLocalStore() {
for (size_t i = 0; i < data_.size(); ++i) {
delete data_[i];
}
}
/*! \return singleton of the store */
static ThreadLocalStore<T> *Singleton() {
static ThreadLocalStore<T> inst;
return &inst;
}
/*!
* \brief register str for internal deletion
* \param str the string pointer
*/
void RegisterDelete(T *str) {
#if DMLC_ENABLE_STD_THREAD
std::unique_lock<std::mutex> lock(mutex_);
data_.push_back(str);
lock.unlock();
#else
data_.push_back(str);
#endif // DMLC_ENABLE_STD_THREAD
}
#if DMLC_ENABLE_STD_THREAD
/*! \brief internal mutex */
std::mutex mutex_;
#endif // DMLC_ENABLE_STD_THREAD
/*!\brief internal data */
std::vector<T*> data_;
};
} // namespace rabit
#endif // RABIT_INTERNAL_THREAD_LOCAL_H_

View File

@@ -6,7 +6,7 @@
*/
#ifndef RABIT_INTERNAL_TIMER_H_
#define RABIT_INTERNAL_TIMER_H_
#include <time.h>
#include <ctime>
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
@@ -18,7 +18,7 @@ namespace utils {
/*!
* \brief return time in seconds, not cross platform, avoid to use this in most places
*/
inline double GetTime(void) {
inline double GetTime() {
#ifdef __MACH__
clock_serv_t cclock;
mach_timespec_t mts;

View File

@@ -8,7 +8,7 @@
#define RABIT_INTERNAL_UTILS_H_
#include <rabit/base.h>
#include <string.h>
#include <cstring>
#include <cstdio>
#include <string>
#include <cstdlib>
@@ -48,15 +48,7 @@ extern "C" {
}
#endif // _MSC_VER
#ifdef _MSC_VER
typedef unsigned char uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
typedef __int64 int64_t;
#else
#include <inttypes.h>
#endif // _MSC_VER
#include <cinttypes>
namespace rabit {
/*! \brief namespace for helper utils of the project */
@@ -184,7 +176,7 @@ inline void Error(const char *fmt, ...) {
/*! \brief replace fopen, report error when the file open fails */
inline std::FILE *FopenCheck(const char *fname, const char *flag) {
std::FILE *fp = fopen64(fname, flag);
Check(fp != NULL, "can not open file \"%s\"\n", fname);
Check(fp != nullptr, "can not open file \"%s\"\n", fname);
return fp;
}
} // namespace utils
@@ -193,7 +185,7 @@ inline std::FILE *FopenCheck(const char *fname, const char *flag) {
template<typename T>
inline T *BeginPtr(std::vector<T> &vec) { // NOLINT(*)
if (vec.size() == 0) {
return NULL;
return nullptr;
} else {
return &vec[0];
}
@@ -202,17 +194,17 @@ inline T *BeginPtr(std::vector<T> &vec) { // NOLINT(*)
template<typename T>
inline const T *BeginPtr(const std::vector<T> &vec) { // NOLINT(*)
if (vec.size() == 0) {
return NULL;
return nullptr;
} else {
return &vec[0];
}
}
inline char* BeginPtr(std::string &str) { // NOLINT(*)
if (str.length() == 0) return NULL;
if (str.length() == 0) return nullptr;
return &str[0];
}
inline const char* BeginPtr(const std::string &str) {
if (str.length() == 0) return NULL;
if (str.length() == 0) return nullptr;
return &str[0];
}
} // namespace rabit

View File

@@ -53,12 +53,12 @@ namespace rabit {
* \brief defines stream used in rabit
* see definition of Stream in dmlc/io.h
*/
typedef dmlc::Stream Stream;
using Stream = dmlc::Stream;
/*!
* \brief defines serializable objects used in rabit
* see definition of Serializable in dmlc/io.h
*/
typedef dmlc::Serializable Serializable;
using Serializable = dmlc::Serializable;
/*!
* \brief reduction operators namespace
@@ -199,8 +199,8 @@ inline void Broadcast(std::string *sendrecv_data, int root,
*/
template<typename OP, typename DType>
inline void Allreduce(DType *sendrecvbuf, size_t count,
void (*prepare_fun)(void *) = NULL,
void *prepare_arg = NULL,
void (*prepare_fun)(void *) = nullptr,
void *prepare_arg = nullptr,
const char* _file = _FILE,
const int _line = _LINE,
const char* _caller = _CALLER);
@@ -220,7 +220,7 @@ inline void Allreduce(DType *sendrecvbuf, size_t count,
* \param _file caller file name used to generate unique cache key
* \param _line caller line number used to generate unique cache key
* \param _caller caller function name used to generate unique cache key
*/
*/
template<typename DType>
inline void Allgather(DType *sendrecvbuf_,
size_t total_size,
@@ -291,7 +291,7 @@ inline void Allreduce(DType *sendrecvbuf, size_t count,
* \sa CheckPoint, VersionNumber
*/
inline int LoadCheckPoint(Serializable *global_model,
Serializable *local_model = NULL);
Serializable *local_model = nullptr);
/*!
* \brief checkpoints the model, meaning a stage of execution has finished.
* every time we call check point, a version number will be increased by one
@@ -307,7 +307,7 @@ inline int LoadCheckPoint(Serializable *global_model,
* \sa LoadCheckPoint, VersionNumber
*/
inline void CheckPoint(const Serializable *global_model,
const Serializable *local_model = NULL);
const Serializable *local_model = nullptr);
/*!
* \brief This function can be used to replace CheckPoint for global_model only,
* when certain condition is met (see detailed explanation).
@@ -366,8 +366,8 @@ class Reducer {
* \param _caller caller function name used to generate unique cache key
*/
inline void Allreduce(DType *sendrecvbuf, size_t count,
void (*prepare_fun)(void *) = NULL,
void *prepare_arg = NULL,
void (*prepare_fun)(void *) = nullptr,
void *prepare_arg = nullptr,
const char* _file = _FILE,
const int _line = _LINE,
const char* _caller = _CALLER);
@@ -422,8 +422,8 @@ class SerializeReducer {
*/
inline void Allreduce(DType *sendrecvobj,
size_t max_nbyte, size_t count,
void (*prepare_fun)(void *) = NULL,
void *prepare_arg = NULL,
void (*prepare_fun)(void *) = nullptr,
void *prepare_arg = nullptr,
const char* _file = _FILE,
const int _line = _LINE,
const char* _caller = _CALLER);

View File

@@ -15,12 +15,12 @@ namespace rabit {
* \brief defines stream used in rabit
* see definition of Stream in dmlc/io.h
*/
typedef dmlc::Stream Stream;
using Stream = dmlc::Stream ;
/*!
* \brief defines serializable objects used in rabit
* see definition of Serializable in dmlc/io.h
*/
typedef dmlc::Serializable Serializable;
using Serializable = dmlc::Serializable;
} // namespace rabit
#endif // RABIT_SERIALIZABLE_H_