diff --git a/README.md b/README.md index d4fa97339..17b556f03 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ -AllReduce Abstraction +rabit: Robust Allreduce and Broadcast Interface ==== -* Tianqi, Nacho, Tianyi +rabit is a light weight library designed to provide fault tolerant interface of Allreduce and Broadcast. -Go! +Contributors: https://github.com/tqchen/rabit/graphs/contributors + +Design Goal +==== +* rabit should run fast +* rabit is light weight +* rabit dig safe burrows to avoid disasters diff --git a/src/config.h b/src/config.h index 45da45bdb..146948adc 100644 --- a/src/config.h +++ b/src/config.h @@ -1,5 +1,5 @@ -#ifndef ALLREDUCE_UTILS_CONFIG_H_ -#define ALLREDUCE_UTILS_CONFIG_H_ +#ifndef RABIT_UTILS_CONFIG_H_ +#define RABIT_UTILS_CONFIG_H_ /*! * \file config.h * \brief helper class to load in configures from file @@ -12,6 +12,7 @@ #include #include "./utils.h" +namespace rabit { namespace utils { /*! * \brief base implementation of config reader @@ -191,5 +192,5 @@ class ConfigIterator: public ConfigStreamReader { std::ifstream fi; }; } // namespace utils - -#endif // ALLREDUCE_UTILS_CONFIG_H_ +} // namespace rabit +#endif // RABIT_UTILS_CONFIG_H_ diff --git a/src/engine.cc b/src/engine.cc index 375f8e770..de58f4c4e 100644 --- a/src/engine.cc +++ b/src/engine.cc @@ -13,6 +13,7 @@ #include "./engine_base.h" #include "./engine_robust.h" +namespace rabit { namespace engine { // singleton sync manager AllReduceRobust manager; @@ -37,3 +38,4 @@ IEngine *GetEngine(void) { return &manager; } } // namespace engine +} // namespace rabit diff --git a/src/engine.h b/src/engine.h index d3493945f..aede4ac74 100644 --- a/src/engine.h +++ b/src/engine.h @@ -3,17 +3,18 @@ * \brief This file defines the core interface of allreduce library * \author Tianqi Chen, Nacho, Tianyi */ -#ifndef ALLREDUCE_ENGINE_H -#define ALLREDUCE_ENGINE_H +#ifndef RABIT_ENGINE_H +#define RABIT_ENGINE_H #include "./io.h" - namespace MPI { /*! \brief MPI data type just to be compatible with MPI reduce function*/ class Datatype; } -/*! \brief namespace of allreduce functionality */ +/*! \brief namespace of rabit */ +namespace rabit { +/*! \brief core interface of engine */ namespace engine { /*! \brief interface of core AllReduce engine */ class IEngine { @@ -79,4 +80,5 @@ void Finalize(void); IEngine *GetEngine(void); } // namespace engine -#endif // ALLREDUCE_ENGINE_H +} // namespace rabit +#endif // RABIT_ENGINE_H diff --git a/src/engine_base.cc b/src/engine_base.cc index eec2330fc..4e9a65229 100644 --- a/src/engine_base.cc +++ b/src/engine_base.cc @@ -10,6 +10,7 @@ #include #include "./engine_base.h" +namespace rabit { namespace engine { // constructor AllReduceBase::AllReduceBase(void) { @@ -373,4 +374,5 @@ AllReduceBase::TryBroadcast(void *sendrecvbuf_, size_t total_size, int root) { } return kSuccess; } -} // namespace engine +} // namespace engine +} // namespace rabit diff --git a/src/engine_base.h b/src/engine_base.h index 582cf5e17..2fd5a761b 100644 --- a/src/engine_base.h +++ b/src/engine_base.h @@ -8,8 +8,8 @@ * * \author Tianqi Chen, Ignacio Cano, Tianyi Zhou */ -#ifndef ALLREDUCE_ENGINE_BASE_H -#define ALLREDUCE_ENGINE_BASE_H +#ifndef RABIT_ENGINE_BASE_H +#define RABIT_ENGINE_BASE_H #include #include @@ -25,7 +25,7 @@ class Datatype { Datatype(size_t type_size) : type_size(type_size) {} }; } - +namespace rabit { namespace engine { /*! \brief implementation of basic AllReduce engine */ class AllReduceBase : public IEngine { @@ -246,4 +246,5 @@ class AllReduceBase : public IEngine { int world_size; }; } // namespace engine -#endif // ALLREDUCE_ENGINE_BASE_H +} // namespace rabit +#endif // RABIT_ENGINE_BASE_H diff --git a/src/engine_robust-inl.h b/src/engine_robust-inl.h index 42558a750..1eae685cc 100644 --- a/src/engine_robust-inl.h +++ b/src/engine_robust-inl.h @@ -4,9 +4,10 @@ * * \author Tianqi Chen */ -#ifndef ALLREDUCE_ENGINE_ROBUST_INL_H -#define ALLREDUCE_ENGINE_ROBUST_INL_H +#ifndef RABIT_ENGINE_ROBUST_INL_H +#define RABIT_ENGINE_ROBUST_INL_H +namespace rabit { namespace engine { /*! * \brief run message passing algorithm on the allreduce tree @@ -147,4 +148,5 @@ AllReduceRobust::MsgPassing(const NodeType &node_value, return kSuccess; } } // namespace engine -#endif // ALLREDUCE_ENGINE_ROBUST_INL_H +} // namespace rabit +#endif // RABIT_ENGINE_ROBUST_INL_H diff --git a/src/engine_robust.cc b/src/engine_robust.cc index 6b820f98a..cd393f445 100644 --- a/src/engine_robust.cc +++ b/src/engine_robust.cc @@ -12,6 +12,7 @@ #include "./utils.h" #include "./engine_robust.h" +namespace rabit { namespace engine { AllReduceRobust::AllReduceRobust(void) { result_buffer_round = 1; @@ -589,3 +590,5 @@ bool AllReduceRobust::RecoverExec(void *buf, size_t size, int flag, int seqno) { return true; } } // namespace engine +} // namespace rabit + diff --git a/src/engine_robust.h b/src/engine_robust.h index 92febdd70..0dbf31852 100644 --- a/src/engine_robust.h +++ b/src/engine_robust.h @@ -7,12 +7,13 @@ * * \author Tianqi Chen, Ignacio Cano, Tianyi Zhou */ -#ifndef ALLREDUCE_ENGINE_ROBUST_H -#define ALLREDUCE_ENGINE_ROBUST_H +#ifndef RABIT_ENGINE_ROBUST_H +#define RABIT_ENGINE_ROBUST_H #include #include "./engine.h" #include "./engine_base.h" +namespace rabit { namespace engine { /*! \brief implementation of fault tolerant all reduce engine */ class AllReduceRobust : public AllReduceBase { @@ -348,7 +349,8 @@ class AllReduceRobust : public AllReduceBase { }; } // namespace engine +} // namespace rabit // implementation of inline template function #include "./engine_robust-inl.h" -#endif // ALLREDUCE_ENGINE_ROBUST_H +#endif // RABIT_ENGINE_ROBUST_H diff --git a/src/io.h b/src/io.h index 97a33f163..913acaa9a 100644 --- a/src/io.h +++ b/src/io.h @@ -1,5 +1,5 @@ -#ifndef ALLREDUCE_UTILS_IO_H -#define ALLREDUCE_UTILS_IO_H +#ifndef RABIT_UTILS_IO_H +#define RABIT_UTILS_IO_H #include #include #include @@ -10,6 +10,7 @@ * \brief general stream interface for serialization, I/O * \author Tianqi Chen */ +namespace rabit { namespace utils { /*! * \brief interface of stream I/O, used to serialize model @@ -211,4 +212,5 @@ class FileStream : public ISeekStream { FILE *fp; }; } // namespace utils +} // namespace rabit #endif diff --git a/src/mock.h b/src/mock.h index d6afd49c6..1dd004c8b 100644 --- a/src/mock.h +++ b/src/mock.h @@ -1,17 +1,17 @@ -#ifndef ALLREDUCE_MOCK_H -#define ALLREDUCE_MOCK_H +#ifndef RABIT_MOCK_H +#define RABIT_MOCK_H /*! * \file mock.h * \brief This file defines a mock object to test the system - * \author Tianqi Chen, Nacho, Tianyi + * \author Ignacio Cano */ -#include "./allreduce.h" +#include "./rabit.h" #include "./config.h" #include #include #include - +namespace rabit { /*! \brief namespace of mock */ namespace test { @@ -27,22 +27,22 @@ public: template inline void AllReduce(float *sendrecvbuf, size_t count) { utils::Assert(verify(allReduce), "[%d] error when calling allReduce", rank); - sync::AllReduce(sendrecvbuf, count); + rabit::AllReduce(sendrecvbuf, count); } inline bool LoadCheckPoint(utils::ISerializable *p_model) { utils::Assert(verify(loadCheckpoint), "[%d] error when loading checkpoint", rank); - return sync::LoadCheckPoint(p_model); + return rabit::LoadCheckPoint(p_model); } inline void CheckPoint(const utils::ISerializable &model) { utils::Assert(verify(checkpoint), "[%d] error when checkpointing", rank); - sync::CheckPoint(model); + rabit::CheckPoint(model); } inline void Broadcast(std::string *sendrecv_data, int root) { utils::Assert(verify(broadcast), "[%d] error when broadcasting", rank); - sync::Bcast(sendrecv_data, root); + rabit::Bcast(sendrecv_data, root); } @@ -110,6 +110,7 @@ private: }; -} +} // namespace test +} // namespace rabit -#endif // ALLREDUCE_MOCK_H +#endif // RABIT_MOCK_H diff --git a/src/allreduce.h b/src/rabit.h similarity index 95% rename from src/allreduce.h rename to src/rabit.h index 3f389a591..635e3ff87 100644 --- a/src/allreduce.h +++ b/src/rabit.h @@ -1,7 +1,7 @@ -#ifndef ALLREDUCE_H -#define ALLREDUCE_H +#ifndef RABIT_RABIT_H +#define RABIT_RABIT_H /*! - * \file allreduce.h + * \file rabit.h * \brief This file defines a template wrapper of engine to give more flexible * AllReduce operations * @@ -9,8 +9,8 @@ */ #include "./engine.h" -/*! \brief namespace of all reduce */ -namespace sync { +/*! \brief namespace of rabit */ +namespace rabit { /*! \brief namespace of operator */ namespace op { struct Max { @@ -109,5 +109,5 @@ inline bool LoadCheckPoint(utils::ISerializable *p_model) { inline void CheckPoint(const utils::ISerializable &model) { engine::GetEngine()->CheckPoint(model); } -} // namespace allreduce -#endif // ALLREDUCE_H +} // namespace rabit +#endif // RABIT_ALLREDUCE_H diff --git a/src/socket.h b/src/socket.h index 8f6d969e6..296b8aeea 100644 --- a/src/socket.h +++ b/src/socket.h @@ -1,5 +1,5 @@ -#ifndef ALLREDUCE_SOCKET_H -#define ALLREDUCE_SOCKET_H +#ifndef RABIT_SOCKET_H +#define RABIT_SOCKET_H /*! * \file socket.h * \brief this file aims to provide a wrapper of sockets @@ -32,6 +32,7 @@ typedef size_t sock_size_t; const int INVALID_SOCKET = -1; #endif +namespace rabit { namespace utils { /*! \brief data structure for network address */ struct SockAddr { @@ -432,5 +433,6 @@ struct SelectHelper { SOCKET maxfd; fd_set read_set, write_set, except_set; }; -} +} // namespace utils +} // namespace rabit #endif diff --git a/src/utils.h b/src/utils.h index a371d6059..d09667d89 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,5 +1,5 @@ -#ifndef ALLREDUCE_UTILS_H_ -#define ALLREDUCE_UTILS_H_ +#ifndef RABIT_UTILS_H_ +#define RABIT_UTILS_H_ /*! * \file utils.h * \brief simple utils to support the code @@ -11,7 +11,7 @@ #include #include -#ifndef ALLREDUCE_STRICT_CXX98_ +#ifndef RABIT_STRICT_CXX98_ #include #endif @@ -50,13 +50,14 @@ typedef long int64_t; #include #endif +namespace rabit { /*! \brief namespace for helper utils of the project */ namespace utils { /*! \brief error message buffer length */ const int kPrintBuffer = 1 << 12; -#ifndef ALLREDUCE_CUSTOMIZE_MSG_ +#ifndef RABIT_CUSTOMIZE_MSG_ /*! * \brief handling of Assert error, caused by in-apropriate input * \param msg error message @@ -81,14 +82,14 @@ inline void HandleLogPrint(const char *msg) { fflush(stderr); } #else -#ifndef ALLREDUCE_STRICT_CXX98_ +#ifndef RABIT_STRICT_CXX98_ // include declarations, some one must implement this void HandleAssertError(const char *msg); void HandleCheckError(const char *msg); void HandlePrint(const char *msg); #endif #endif -#ifdef ALLREDUCE_STRICT_CXX98_ +#ifdef RABIT_STRICT_CXX98_ // these function pointers are to be assigned extern "C" void (*Printf)(const char *fmt, ...); extern "C" int (*SPrintf)(char *buf, size_t size, const char *fmt, ...); @@ -186,4 +187,5 @@ inline const T *BeginPtr(const std::vector &vec) { return &vec[0]; } } -#endif // ALLREDUCE_UTILS_H_ +} // namespace rabit +#endif // RABIT_UTILS_H_ diff --git a/test/test_allreduce.cpp b/test/test_allreduce.cpp index 02cb4057f..7f9ad9f78 100644 --- a/test/test_allreduce.cpp +++ b/test/test_allreduce.cpp @@ -1,16 +1,15 @@ -#include +#include #include #include #include #include #include - -using namespace sync; +using namespace rabit; inline void TestMax(test::Mock &mock, size_t n) { - int rank = sync::GetRank(); - int nproc = sync::GetWorldSize(); + int rank = rabit::GetRank(); + int nproc = rabit::GetWorldSize(); std::vector ndata(n); for (size_t i = 0; i < ndata.size(); ++i) { @@ -27,8 +26,8 @@ inline void TestMax(test::Mock &mock, size_t n) { } inline void TestSum(test::Mock &mock, size_t n) { - int rank = sync::GetRank(); - int nproc = sync::GetWorldSize(); + int rank = rabit::GetRank(); + int nproc = rabit::GetWorldSize(); const int z = 131; std::vector ndata(n); @@ -47,7 +46,7 @@ inline void TestSum(test::Mock &mock, size_t n) { } inline void TestBcast(test::Mock &mock, size_t n, int root) { - int rank = sync::GetRank(); + int rank = rabit::GetRank(); std::string s; s.resize(n); for (size_t i = 0; i < n; ++i) { s[i] = char(i % 126 + 1); @@ -68,10 +67,10 @@ int main(int argc, char *argv[]) { return 0; } int n = atoi(argv[1]); - sync::Init(argc, argv); - int rank = sync::GetRank(); - int nproc = sync::GetWorldSize(); - std::string name = sync::GetProcessorName(); + rabit::Init(argc, argv); + int rank = rabit::GetRank(); + int nproc = rabit::GetWorldSize(); + std::string name = rabit::GetProcessorName(); test::Mock mock(rank, argv[2], argv[3]); @@ -84,7 +83,7 @@ int main(int argc, char *argv[]) { TestBcast(mock, n, i); } utils::LogPrintf("[%d] !!!TestBcast pass\n", rank); - sync::Finalize(); + rabit::Finalize(); printf("[%d] all check pass\n", rank); return 0; }