Medial Code Documentation
Loading...
Searching...
No Matches
engine.cc
Go to the documentation of this file.
1
9#include <rabit/base.h>
10#include <dmlc/thread_local.h>
11
12#include <memory>
14#include "allreduce_base.h"
15
16namespace rabit {
17namespace engine {
18// singleton sync manager
19#ifndef RABIT_USE_BASE
20#ifndef RABIT_USE_MOCK
21using Manager = AllreduceBase;
22#else
23typedef AllreduceMock Manager;
24#endif // RABIT_USE_MOCK
25#else
26typedef AllreduceBase Manager;
27#endif // RABIT_USE_BASE
28
32 std::unique_ptr<Manager> engine;
34 bool initialized{false};
36 ThreadLocalEntry() = default;
37};
38
39// define the threadlocal store.
41
43bool Init(int argc, char *argv[]) {
45 if (e->engine.get() == nullptr) {
46 e->initialized = true;
47 e->engine.reset(new Manager());
48 return e->engine->Init(argc, argv);
49 } else {
50 return true;
51 }
52}
53
55bool Finalize() {
57 if (e->engine.get() != nullptr) {
58 if (e->engine->Shutdown()) {
59 e->engine.reset(nullptr);
60 e->initialized = false;
61 return true;
62 } else {
63 return false;
64 }
65 } else {
66 return true;
67 }
68}
69
72 // un-initialized default manager.
73 static AllreduceBase default_manager;
75 IEngine* ptr = e->engine.get();
76 if (ptr == nullptr) {
77 utils::Check(!e->initialized, "the rabit has not been initialized");
78 return &default_manager;
79 } else {
80 return ptr;
81 }
82}
83
84// perform in-place allgather, on sendrecvbuf
85void Allgather(void *sendrecvbuf_, size_t total_size,
86 size_t slice_begin,
87 size_t slice_end,
88 size_t size_prev_slice) {
89 GetEngine()->Allgather(sendrecvbuf_, total_size, slice_begin,
90 slice_end, size_prev_slice);
91}
92
93
94// perform in-place allreduce, on sendrecvbuf
95void Allreduce_(void *sendrecvbuf, // NOLINT
96 size_t type_nbytes,
97 size_t count,
101 IEngine::PreprocFunction prepare_fun,
102 void *prepare_arg) {
103 GetEngine()->Allreduce(sendrecvbuf, type_nbytes, count, red, prepare_fun, prepare_arg);
104}
105} // namespace engine
106} // namespace rabit
Basic implementation of AllReduce using TCP non-block socket and tree-shape reduction.
A threadlocal store to store threadlocal variables. Will return a thread local singleton of type T.
Definition thread_local.h:35
static T * Get()
Definition thread_local.h:38
implementation of basic Allreduce engine
Definition allreduce_base.h:42
interface of core Allreduce engine
Definition engine.h:22
virtual void Allreduce(void *sendrecvbuf_, size_t type_nbytes, size_t count, ReduceFunction reducer, PreprocFunction prepare_fun=nullptr, void *prepare_arg=nullptr)=0
performs in-place Allreduce, on sendrecvbuf this function is NOT thread-safe
void() PreprocFunction(void *arg)
Preprocessing function, that is called before AllReduce, used to prepare the data used by AllReduce.
Definition engine.h:29
void() ReduceFunction(const void *src, void *dst, int count, const MPI::Datatype &dtype)
reduce function, the same form of MPI reduce function is used, to be compatible with MPI interface In...
Definition engine.h:41
virtual void Allgather(void *sendrecvbuf, size_t total_size, size_t slice_begin, size_t slice_end, size_t size_prev_slice)=0
Allgather function, each node have a segment of data in the ring of sendrecvbuf, the data provided by...
This file defines the core interface of rabit library.
DataType
enum of supported data types
Definition engine.h:141
OpType
enum of all operators
Definition engine.h:132
bool Init(int argc, char *argv[])
initializes the engine module
Definition engine.cc:43
void Allreduce_(void *sendrecvbuf, size_t type_nbytes, size_t count, IEngine::ReduceFunction red, mpi::DataType dtype, mpi::OpType op, IEngine::PreprocFunction prepare_fun=nullptr, void *prepare_arg=nullptr)
perform in-place Allreduce, on sendrecvbuf this is an internal function used by rabit to be able to c...
Definition engine.cc:95
bool Finalize()
finalizes the engine module
Definition engine.cc:55
void Allgather(void *sendrecvbuf, size_t total_size, size_t slice_begin, size_t slice_end, size_t size_prev_slice)
Allgather function, each node have a segment of data in the ring of sendrecvbuf, the data provided by...
Definition engine.cc:85
IEngine * GetEngine()
singleton method to get engine
Definition engine.cc:71
void Check(bool exp, const char *fmt,...)
same as assert, but this is intended to be used as a message for users
Definition utils.h:91
namespace of rabit
Definition engine.h:18
Macros common to all headers.
entry to to easily hold returning information
Definition engine.cc:30
std::unique_ptr< Manager > engine
stores the current engine
Definition engine.cc:32
ThreadLocalEntry()=default
constructor
bool initialized
whether init has been called
Definition engine.cc:34
Portable thread local storage.