cleanup testcases
This commit is contained in:
@@ -5,33 +5,30 @@ export LDFLAGS= -pthread -lm -lrt
|
||||
export CFLAGS = -Wall -O3 -msse2 -Wno-unknown-pragmas -fPIC -I../src
|
||||
|
||||
# specify tensor path
|
||||
BIN = test_allreduce test_recover test_model_recover speed_test test_local_recover
|
||||
BIN = speed_test test_model_recover test_local_recover
|
||||
# objectives that makes up rabit library
|
||||
RABIT_OBJ = allreduce_base.o allreduce_robust.o engine.o
|
||||
MPIOBJ = engine_mpi.o
|
||||
|
||||
OBJ = $(RABIT_OBJ) test_allreduce.o test_recover.o test_model_recover.o speed_test.o test_local_recover.o
|
||||
MPIBIN = test_allreduce.mpi speed_test.mpi
|
||||
OBJ = $(RABIT_OBJ) speed_test.o test_model_recover.o test_local_recover.o
|
||||
MPIBIN = speed_test.mpi
|
||||
.PHONY: clean all
|
||||
|
||||
all: $(BIN) $(MPIBIN)
|
||||
|
||||
# the rabit library
|
||||
allreduce_base.o: ../src/allreduce_base.cc ../src/*.h
|
||||
engine.o: ../src/engine.cc ../src/*.h
|
||||
allreduce_robust.o: ../src/allreduce_robust.cc ../src/*.h
|
||||
engine_mpi.o: ../src/engine_mpi.cc
|
||||
test_allreduce.o: test_allreduce.cpp ../src/*.h
|
||||
allreduce_robust.o: ../src/allreduce_robust.cc ../src/*.h
|
||||
|
||||
# programs
|
||||
speed_test.o: speed_test.cpp ../src/*.h
|
||||
test_recover.o: test_recover.cpp ../src/*.h
|
||||
test_model_recover.o: test_model_recover.cpp ../src/*.h
|
||||
test_local_recover.o: test_local_recover.cpp ../src/*.h
|
||||
|
||||
# we can link against MPI version to get use MPI
|
||||
test_allreduce: test_allreduce.o $(RABIT_OBJ)
|
||||
test_allreduce.mpi: test_allreduce.o $(MPIOBJ)
|
||||
speed_test: speed_test.o $(RABIT_OBJ)
|
||||
speed_test.mpi: speed_test.o $(MPIOBJ)
|
||||
test_recover: test_recover.o $(RABIT_OBJ)
|
||||
test_model_recover: test_model_recover.o $(RABIT_OBJ)
|
||||
test_local_recover: test_local_recover.o $(RABIT_OBJ)
|
||||
|
||||
@@ -48,4 +45,4 @@ $(MPIOBJ) :
|
||||
$(MPICXX) -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c %.cc, $^) )
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJ) $(BIN) $(MPIBIN) *~ ../src/*~
|
||||
$(RM) $(OBJ) $(BIN) $(MPIBIN) $(MPIOBJ) *~ ../src/*~
|
||||
|
||||
18
test/README.md
Normal file
18
test/README.md
Normal file
@@ -0,0 +1,18 @@
|
||||
Testcases of Rabit
|
||||
====
|
||||
This folder contains internal testcases to test correctness and efficiency of rabit API
|
||||
|
||||
The example running scripts for testcases are given by test.mk
|
||||
* type ```make -f test.mk testcasename``` to run certain testcase
|
||||
|
||||
|
||||
Helper Scripts
|
||||
====
|
||||
* test.mk contains Makefile documentation of all testcases
|
||||
* keepalive.sh helper bash to restart a program when it dies abnormally
|
||||
|
||||
List of Programs
|
||||
====
|
||||
* speed_test: test the running speed of rabit API
|
||||
* test_local_recover: test recovery of local state when error happens
|
||||
* test_model_recover: test recovery of global state when error happens
|
||||
196
test/config.h
Normal file
196
test/config.h
Normal file
@@ -0,0 +1,196 @@
|
||||
#ifndef RABIT_UTILS_CONFIG_H_
|
||||
#define RABIT_UTILS_CONFIG_H_
|
||||
/*!
|
||||
* \file config.h
|
||||
* \brief helper class to load in configures from file
|
||||
* \author Tianqi Chen
|
||||
*/
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <istream>
|
||||
#include <fstream>
|
||||
#include "./utils.h"
|
||||
|
||||
namespace rabit {
|
||||
namespace utils {
|
||||
/*!
|
||||
* \brief base implementation of config reader
|
||||
*/
|
||||
class ConfigReaderBase {
|
||||
public:
|
||||
/*!
|
||||
* \brief get current name, called after Next returns true
|
||||
* \return current parameter name
|
||||
*/
|
||||
inline const char *name(void) const {
|
||||
return s_name;
|
||||
}
|
||||
/*!
|
||||
* \brief get current value, called after Next returns true
|
||||
* \return current parameter value
|
||||
*/
|
||||
inline const char *val(void) const {
|
||||
return s_val;
|
||||
}
|
||||
/*!
|
||||
* \brief move iterator to next position
|
||||
* \return true if there is value in next position
|
||||
*/
|
||||
inline bool Next(void) {
|
||||
while (!this->IsEnd()) {
|
||||
GetNextToken(s_name);
|
||||
if (s_name[0] == '=') return false;
|
||||
if (GetNextToken( s_buf ) || s_buf[0] != '=') return false;
|
||||
if (GetNextToken( s_val ) || s_val[0] == '=') return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// called before usage
|
||||
inline void Init(void) {
|
||||
ch_buf = this->GetChar();
|
||||
}
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief to be implemented by subclass,
|
||||
* get next token, return EOF if end of file
|
||||
*/
|
||||
virtual char GetChar(void) = 0;
|
||||
/*! \brief to be implemented by child, check if end of stream */
|
||||
virtual bool IsEnd(void) = 0;
|
||||
|
||||
private:
|
||||
char ch_buf;
|
||||
char s_name[100000], s_val[100000], s_buf[100000];
|
||||
|
||||
inline void SkipLine(void) {
|
||||
do {
|
||||
ch_buf = this->GetChar();
|
||||
} while (ch_buf != EOF && ch_buf != '\n' && ch_buf != '\r');
|
||||
}
|
||||
|
||||
inline void ParseStr(char tok[]) {
|
||||
int i = 0;
|
||||
while ((ch_buf = this->GetChar()) != EOF) {
|
||||
switch (ch_buf) {
|
||||
case '\\': tok[i++] = this->GetChar(); break;
|
||||
case '\"': tok[i++] = '\0'; return;
|
||||
case '\r':
|
||||
case '\n': Error("ConfigReader: unterminated string");
|
||||
default: tok[i++] = ch_buf;
|
||||
}
|
||||
}
|
||||
Error("ConfigReader: unterminated string");
|
||||
}
|
||||
inline void ParseStrML(char tok[]) {
|
||||
int i = 0;
|
||||
while ((ch_buf = this->GetChar()) != EOF) {
|
||||
switch (ch_buf) {
|
||||
case '\\': tok[i++] = this->GetChar(); break;
|
||||
case '\'': tok[i++] = '\0'; return;
|
||||
default: tok[i++] = ch_buf;
|
||||
}
|
||||
}
|
||||
Error("unterminated string");
|
||||
}
|
||||
// return newline
|
||||
inline bool GetNextToken(char tok[]) {
|
||||
int i = 0;
|
||||
bool new_line = false;
|
||||
while (ch_buf != EOF) {
|
||||
switch (ch_buf) {
|
||||
case '#' : SkipLine(); new_line = true; break;
|
||||
case '\"':
|
||||
if (i == 0) {
|
||||
ParseStr(tok); ch_buf = this->GetChar(); return new_line;
|
||||
} else {
|
||||
Error("ConfigReader: token followed directly by string");
|
||||
}
|
||||
case '\'':
|
||||
if (i == 0) {
|
||||
ParseStrML( tok ); ch_buf = this->GetChar(); return new_line;
|
||||
} else {
|
||||
Error("ConfigReader: token followed directly by string");
|
||||
}
|
||||
case '=':
|
||||
if (i == 0) {
|
||||
ch_buf = this->GetChar();
|
||||
tok[0] = '=';
|
||||
tok[1] = '\0';
|
||||
} else {
|
||||
tok[i] = '\0';
|
||||
}
|
||||
return new_line;
|
||||
case '\r':
|
||||
case '\n':
|
||||
if (i == 0) new_line = true;
|
||||
case '\t':
|
||||
case ' ' :
|
||||
ch_buf = this->GetChar();
|
||||
if (i > 0) {
|
||||
tok[i] = '\0';
|
||||
return new_line;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
tok[i++] = ch_buf;
|
||||
ch_buf = this->GetChar();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
/*!
|
||||
* \brief an iterator use stream base, allows use all types of istream
|
||||
*/
|
||||
class ConfigStreamReader: public ConfigReaderBase {
|
||||
public:
|
||||
/*!
|
||||
* \brief constructor
|
||||
* \param istream input stream
|
||||
*/
|
||||
explicit ConfigStreamReader(std::istream &fin) : fin(fin) {}
|
||||
|
||||
protected:
|
||||
virtual char GetChar(void) {
|
||||
return fin.get();
|
||||
}
|
||||
/*! \brief to be implemented by child, check if end of stream */
|
||||
virtual bool IsEnd(void) {
|
||||
return fin.eof();
|
||||
}
|
||||
|
||||
private:
|
||||
std::istream &fin;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief an iterator that iterates over a configure file and gets the configures
|
||||
*/
|
||||
class ConfigIterator: public ConfigStreamReader {
|
||||
public:
|
||||
/*!
|
||||
* \brief constructor
|
||||
* \param fname name of configure file
|
||||
*/
|
||||
explicit ConfigIterator(const char *fname) : ConfigStreamReader(fi) {
|
||||
fi.open(fname);
|
||||
if (fi.fail()) {
|
||||
utils::Error("cannot open file %s", fname);
|
||||
}
|
||||
ConfigReaderBase::Init();
|
||||
}
|
||||
/*! \brief destructor */
|
||||
~ConfigIterator(void) {
|
||||
fi.close();
|
||||
}
|
||||
|
||||
private:
|
||||
std::ifstream fi;
|
||||
};
|
||||
} // namespace utils
|
||||
} // namespace rabit
|
||||
#endif // RABIT_UTILS_CONFIG_H_
|
||||
@@ -6,9 +6,9 @@ then
|
||||
exit -1
|
||||
fi
|
||||
nrep=0
|
||||
echo ./$@ task_id=$OMPI_COMM_WORLD_RANK
|
||||
until ./$@ task_id=$OMPI_COMM_WORLD_RANK repeat=$nrep; do
|
||||
echo ./$@ rabit_task_id=$OMPI_COMM_WORLD_RANK
|
||||
until ./$@ rabit_task_id=$OMPI_COMM_WORLD_RANK repeat=$nrep; do
|
||||
sleep 1
|
||||
nrep=$((nrep+1))
|
||||
echo ./$@ job_id=$OMPI_COMM_WORLD_RANK repeat=$nrep
|
||||
echo ./$@ rabit_task_id=$OMPI_COMM_WORLD_RANK repeat=$nrep
|
||||
done
|
||||
|
||||
121
test/mock.h
Normal file
121
test/mock.h
Normal file
@@ -0,0 +1,121 @@
|
||||
#ifndef RABIT_MOCK_H
|
||||
#define RABIT_MOCK_H
|
||||
/*!
|
||||
* \file mock.h
|
||||
* \brief This file defines a mock object to test the system
|
||||
* \author Ignacio Cano
|
||||
*/
|
||||
#include "./rabit.h"
|
||||
#include "./config.h"
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
struct MockException {
|
||||
};
|
||||
|
||||
namespace rabit {
|
||||
/*! \brief namespace of mock */
|
||||
namespace test {
|
||||
|
||||
class Mock {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
explicit Mock(const int& rank, char *config, char* round_dir) : rank(rank) {
|
||||
Init(config, round_dir);
|
||||
}
|
||||
|
||||
template<typename OP>
|
||||
inline void Allreduce(float *sendrecvbuf, size_t count) {
|
||||
utils::Assert(verify(allReduce), "[%d] error when calling allReduce", rank);
|
||||
rabit::Allreduce<OP>(sendrecvbuf, count);
|
||||
}
|
||||
|
||||
inline int LoadCheckPoint(utils::ISerializable *global_model,
|
||||
utils::ISerializable *local_model) {
|
||||
utils::Assert(verify(loadCheckpoint), "[%d] error when loading checkpoint", rank);
|
||||
return rabit::LoadCheckPoint(global_model, local_model);
|
||||
}
|
||||
|
||||
inline void CheckPoint(const utils::ISerializable *global_model,
|
||||
const utils::ISerializable *local_model) {
|
||||
utils::Assert(verify(checkpoint), "[%d] error when checkpointing", rank);
|
||||
rabit::CheckPoint(global_model, local_model);
|
||||
}
|
||||
|
||||
inline void Broadcast(std::string *sendrecv_data, int root) {
|
||||
utils::Assert(verify(broadcast), "[%d] error when broadcasting", rank);
|
||||
rabit::Broadcast(sendrecv_data, root);
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
inline void Init(char* config, char* round_dir) {
|
||||
std::stringstream ss;
|
||||
ss << round_dir << "node" << rank << ".round";
|
||||
const char* round_file = ss.str().c_str();
|
||||
std::ifstream ifs(round_file);
|
||||
int current_round = 1;
|
||||
if (!ifs.good()) {
|
||||
// file does not exists, it's the first time, so save the current round to 1
|
||||
std::ofstream ofs(round_file);
|
||||
ofs << current_round;
|
||||
ofs.close();
|
||||
} else {
|
||||
// file does exists, read the previous round, increment by one, and save it back
|
||||
ifs >> current_round;
|
||||
current_round++;
|
||||
ifs.close();
|
||||
std::ofstream ofs(round_file);
|
||||
ofs << current_round;
|
||||
ofs.close();
|
||||
}
|
||||
printf("[%d] in round %d\n", rank, current_round);
|
||||
utils::ConfigIterator itr(config);
|
||||
while (itr.Next()) {
|
||||
char round[4], node_rank[4];
|
||||
sscanf(itr.name(), "%[^_]_%s", round, node_rank);
|
||||
int i_node_rank = atoi(node_rank);
|
||||
// if it's something for me
|
||||
if (i_node_rank == rank) {
|
||||
int i_round = atoi(round);
|
||||
// in my current round
|
||||
if (i_round == current_round) {
|
||||
printf("[%d] round %d, value %s\n", rank, i_round, itr.val());
|
||||
if (strcmp("allreduce", itr.val())) record(allReduce);
|
||||
else if (strcmp("broadcast", itr.val())) record(broadcast);
|
||||
else if (strcmp("loadcheckpoint", itr.val())) record(loadCheckpoint);
|
||||
else if (strcmp("checkpoint", itr.val())) record(checkpoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void record(std::map<int,bool>& m) {
|
||||
m[rank] = false;
|
||||
}
|
||||
|
||||
inline bool verify(std::map<int,bool>& m) {
|
||||
bool result = true;
|
||||
if (m.find(rank) != m.end()) {
|
||||
result = m[rank];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int rank;
|
||||
std::map<int,bool> allReduce;
|
||||
std::map<int,bool> broadcast;
|
||||
std::map<int,bool> loadCheckpoint;
|
||||
std::map<int,bool> checkpoint;
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace rabit
|
||||
|
||||
#endif // RABIT_MOCK_H
|
||||
@@ -31,4 +31,4 @@ def main():
|
||||
sys.stderr.flush()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// This program is used to test the speed of rabit API
|
||||
#include <rabit.h>
|
||||
#include <utils.h>
|
||||
#include <timer.h>
|
||||
@@ -12,8 +13,6 @@ double max_tdiff, sum_tdiff, bcast_tdiff, tot_tdiff;
|
||||
|
||||
inline void TestMax(size_t n) {
|
||||
int rank = rabit::GetRank();
|
||||
//int nproc = rabit::GetWorldSize();
|
||||
|
||||
std::vector<float> ndata(n);
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
ndata[i] = (i * (rank+1)) % 111;
|
||||
@@ -25,7 +24,6 @@ inline void TestMax(size_t n) {
|
||||
|
||||
inline void TestSum(size_t n) {
|
||||
int rank = rabit::GetRank();
|
||||
//int nproc = rabit::GetWorldSize();
|
||||
const int z = 131;
|
||||
std::vector<float> ndata(n);
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
|
||||
20
test/test.mk
Normal file
20
test/test.mk
Normal file
@@ -0,0 +1,20 @@
|
||||
ifndef $(nslave)
|
||||
nslave=2
|
||||
endif
|
||||
ifndef $(ndata)
|
||||
ndata=10
|
||||
endif
|
||||
|
||||
# this is a makefile used to show testcases of rabit
|
||||
.PHONY: model_recover local_recover speed
|
||||
|
||||
|
||||
local_recover:
|
||||
../submit_mpi.py $(nslave) local test_local_recover $(ndata) rabit_local_replica=1
|
||||
|
||||
local_recover_10_10k:
|
||||
../submit_mpi.py 10 local test_local_recover 10000 rabit_local_replica=1
|
||||
|
||||
# this experiment test recovery with actually process exit, use keepalive to keep program alive
|
||||
model_recover_10_10k:
|
||||
../submit_mpi.py 10 local keepalive.sh test_model_recover 10000
|
||||
@@ -1,90 +0,0 @@
|
||||
#include <rabit.h>
|
||||
#include <utils.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <mock.h>
|
||||
|
||||
using namespace rabit;
|
||||
|
||||
inline void TestMax(test::Mock &mock, size_t n) {
|
||||
int rank = rabit::GetRank();
|
||||
int nproc = rabit::GetWorldSize();
|
||||
|
||||
std::vector<float> ndata(n);
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
ndata[i] = (i * (rank+1)) % 111;
|
||||
}
|
||||
mock.Allreduce<op::Max>(&ndata[0], ndata.size());
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
float rmax = (i * 1) % 111;
|
||||
for (int r = 0; r < nproc; ++r) {
|
||||
rmax = std::max(rmax, (float)((i * (r+1)) % 111));
|
||||
}
|
||||
utils::Check(rmax == ndata[i], "[%d] TestMax check failure", rank);
|
||||
}
|
||||
}
|
||||
|
||||
inline void TestSum(test::Mock &mock, size_t n) {
|
||||
int rank = rabit::GetRank();
|
||||
int nproc = rabit::GetWorldSize();
|
||||
const int z = 131;
|
||||
|
||||
std::vector<float> ndata(n);
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
ndata[i] = (i * (rank+1)) % z;
|
||||
}
|
||||
mock.Allreduce<op::Sum>(&ndata[0], ndata.size());
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
float rsum = 0.0f;
|
||||
for (int r = 0; r < nproc; ++r) {
|
||||
rsum += (float)((i * (r+1)) % z);
|
||||
}
|
||||
utils::Check(fabsf(rsum - ndata[i]) < 1e-5 ,
|
||||
"[%d] TestSum check failure, local=%g, allreduce=%g", rank, rsum, ndata[i]);
|
||||
}
|
||||
}
|
||||
|
||||
inline void TestBcast(test::Mock &mock, size_t n, int root) {
|
||||
int rank = rabit::GetRank();
|
||||
std::string s; s.resize(n);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
s[i] = char(i % 126 + 1);
|
||||
}
|
||||
std::string res;
|
||||
if (root == rank) {
|
||||
res = s;
|
||||
mock.Broadcast(&res, root);
|
||||
} else {
|
||||
mock.Broadcast(&res, root);
|
||||
}
|
||||
utils::Check(res == s, "[%d] TestBcast fail", rank);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 3) {
|
||||
printf("Usage: <ndata> <config>\n");
|
||||
return 0;
|
||||
}
|
||||
int n = atoi(argv[1]);
|
||||
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]);
|
||||
|
||||
utils::LogPrintf("[%d] start at %s\n", rank, name.c_str());
|
||||
TestMax(mock, n);
|
||||
utils::LogPrintf("[%d] !!!TestMax pass\n", rank);
|
||||
TestSum(mock, n);
|
||||
utils::LogPrintf("[%d] !!!TestSum pass\n", rank);
|
||||
int step = std::max(nproc / 3, 1);
|
||||
for (int i = 0; i < nproc; i += step) {
|
||||
TestBcast(mock, n, i);
|
||||
}
|
||||
utils::LogPrintf("[%d] !!!TestBcast pass\n", rank);
|
||||
rabit::Finalize();
|
||||
printf("[%d] all check pass\n", rank);
|
||||
return 0;
|
||||
}
|
||||
@@ -5,12 +5,28 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <mock.h>
|
||||
#include "./mock.h"
|
||||
|
||||
using namespace rabit;
|
||||
|
||||
struct MockException {
|
||||
};
|
||||
namespace rabit {
|
||||
namespace test {
|
||||
inline void CallBegin(const char *fun, int ntrial, int iter) {
|
||||
int rank = rabit::GetRank();
|
||||
if (!strcmp(fun, "Allreduce::Sum")) {
|
||||
if (ntrial == iter && rank == 0) throw MockException();
|
||||
}
|
||||
if (!strcmp(fun, "Allreduce::Max")) {
|
||||
if (ntrial == iter && rank == 3) throw MockException();
|
||||
}
|
||||
}
|
||||
inline void CallEnd(const char *fun, int ntrial, int iter) {
|
||||
int rank = rabit::GetRank();
|
||||
if (!strcmp(fun, "Allreduce::Bcast")) {
|
||||
if (ntrial == iter && rand() % 10 == rank) throw MockException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// dummy model
|
||||
class Model : public rabit::utils::ISerializable {
|
||||
@@ -31,7 +47,7 @@ class Model : public rabit::utils::ISerializable {
|
||||
}
|
||||
};
|
||||
|
||||
inline void TestMax(test::Mock &mock, Model *model, Model *local, int ntrial, int iter) {
|
||||
inline void TestMax(Model *model, Model *local, int ntrial, int iter) {
|
||||
int rank = rabit::GetRank();
|
||||
int nproc = rabit::GetWorldSize();
|
||||
const int z = iter + 111;
|
||||
@@ -39,11 +55,11 @@ inline void TestMax(test::Mock &mock, Model *model, Model *local, int ntrial, in
|
||||
std::vector<float> ndata(model->data.size());
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
ndata[i] = (i * (rank+1)) % z + local->data[i];
|
||||
}
|
||||
mock.Allreduce<op::Max>(&ndata[0], ndata.size());
|
||||
if (ntrial == iter && rank == 1) {
|
||||
throw MockException();
|
||||
}
|
||||
}
|
||||
test::CallBegin("Allreduce::Max", ntrial, iter);
|
||||
rabit::Allreduce<op::Max>(&ndata[0], ndata.size());
|
||||
test::CallEnd("Allreduce::Max", ntrial, iter);
|
||||
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
float rmax = (i * 1) % z + model->data[i];
|
||||
for (int r = 0; r < nproc; ++r) {
|
||||
@@ -58,7 +74,7 @@ inline void TestMax(test::Mock &mock, Model *model, Model *local, int ntrial, in
|
||||
}
|
||||
}
|
||||
|
||||
inline void TestSum(test::Mock &mock, Model *model, Model *local, int ntrial, int iter) {
|
||||
inline void TestSum(Model *model, Model *local, int ntrial, int iter) {
|
||||
int rank = rabit::GetRank();
|
||||
int nproc = rabit::GetWorldSize();
|
||||
const int z = 131 + iter;
|
||||
@@ -67,11 +83,10 @@ inline void TestSum(test::Mock &mock, Model *model, Model *local, int ntrial, in
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
ndata[i] = (i * (rank+1)) % z + local->data[i];
|
||||
}
|
||||
if (ntrial == iter && rank == 0) {
|
||||
throw MockException();
|
||||
}
|
||||
mock.Allreduce<op::Sum>(&ndata[0], ndata.size());
|
||||
|
||||
test::CallBegin("Allreduce::Sum", ntrial, iter);
|
||||
Allreduce<op::Sum>(&ndata[0], ndata.size());
|
||||
test::CallEnd("Allreduce::Sum", ntrial, iter);
|
||||
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
float rsum = 0.0f;
|
||||
for (int r = 0; r < nproc; ++r) {
|
||||
@@ -86,7 +101,7 @@ inline void TestSum(test::Mock &mock, Model *model, Model *local, int ntrial, in
|
||||
}
|
||||
}
|
||||
|
||||
inline void TestBcast(test::Mock &mock, size_t n, int root, int ntrial) {
|
||||
inline void TestBcast(size_t n, int root, int ntrial, int iter) {
|
||||
int rank = rabit::GetRank();
|
||||
std::string s; s.resize(n);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
@@ -95,16 +110,20 @@ inline void TestBcast(test::Mock &mock, size_t n, int root, int ntrial) {
|
||||
std::string res;
|
||||
if (root == rank) {
|
||||
res = s;
|
||||
mock.Broadcast(&res, root);
|
||||
test::CallBegin("Broadcast", ntrial, iter);
|
||||
rabit::Broadcast(&res, root);
|
||||
test::CallBegin("Broadcast", ntrial, iter);
|
||||
} else {
|
||||
mock.Broadcast(&res, root);
|
||||
test::CallBegin("Broadcast", ntrial, iter);
|
||||
rabit::Broadcast(&res, root);
|
||||
test::CallEnd("Broadcast", ntrial, iter);
|
||||
}
|
||||
utils::Check(res == s, "[%d] TestBcast fail", rank);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 3) {
|
||||
printf("Usage: <ndata> <config>\n");
|
||||
printf("Usage: <ndata>\n");
|
||||
return 0;
|
||||
}
|
||||
int n = atoi(argv[1]);
|
||||
@@ -112,7 +131,6 @@ int main(int argc, char *argv[]) {
|
||||
int rank = rabit::GetRank();
|
||||
int nproc = rabit::GetWorldSize();
|
||||
std::string name = rabit::GetProcessorName();
|
||||
test::Mock mock(rank, argv[2], argv[3]);
|
||||
Model model, local;
|
||||
srand(0);
|
||||
int ntrial = 0;
|
||||
@@ -131,14 +149,14 @@ int main(int argc, char *argv[]) {
|
||||
utils::LogPrintf("[%d] reload-trail=%d, init iter=%d\n", rank, ntrial, iter);
|
||||
}
|
||||
for (int r = iter; r < 3; ++r) {
|
||||
TestMax(mock, &model, &local, ntrial, r);
|
||||
TestMax(&model, &local, ntrial, r);
|
||||
utils::LogPrintf("[%d] !!!TestMax pass, iter=%d\n", rank, r);
|
||||
int step = std::max(nproc / 3, 1);
|
||||
for (int i = 0; i < nproc; i += step) {
|
||||
//TestBcast(mock, n, i, ntrial);
|
||||
TestBcast(n, i, ntrial, r);
|
||||
}
|
||||
//utils::LogPrintf("[%d] !!!TestBcast pass, iter=%d\n", rank, r);
|
||||
TestSum(mock, &model, &local, ntrial, r);
|
||||
utils::LogPrintf("[%d] !!!TestBcast pass, iter=%d\n", rank, r);
|
||||
TestSum(&model, &local, ntrial, r);
|
||||
utils::LogPrintf("[%d] !!!TestSum pass, iter=%d\n", rank, r);
|
||||
rabit::CheckPoint(&model, &local);
|
||||
utils::LogPrintf("[%d] !!!CheckPont pass, iter=%d\n", rank, r);
|
||||
|
||||
@@ -5,12 +5,28 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <mock.h>
|
||||
#include "./mock.h"
|
||||
|
||||
using namespace rabit;
|
||||
|
||||
struct MockException {
|
||||
};
|
||||
namespace rabit {
|
||||
namespace test {
|
||||
inline void CallBegin(const char *fun, int ntrial, int iter) {
|
||||
int rank = rabit::GetRank();
|
||||
if (!strcmp(fun, "Allreduce::Sum")) {
|
||||
if (ntrial == iter && rank == 0) exit(-1);
|
||||
}
|
||||
if (!strcmp(fun, "Allreduce::Max")) {
|
||||
if (ntrial == iter && rank == 3) exit(-1);
|
||||
}
|
||||
}
|
||||
inline void CallEnd(const char *fun, int ntrial, int iter) {
|
||||
int rank = rabit::GetRank();
|
||||
if (!strcmp(fun, "Allreduce::Bcast")) {
|
||||
if (ntrial == iter && rand() % 10 == rank) exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// dummy model
|
||||
class Model : public rabit::utils::ISerializable {
|
||||
@@ -31,7 +47,7 @@ class Model : public rabit::utils::ISerializable {
|
||||
}
|
||||
};
|
||||
|
||||
inline void TestMax(test::Mock &mock, Model *model, int ntrial, int iter) {
|
||||
inline void TestMax(Model *model, int ntrial, int iter) {
|
||||
int rank = rabit::GetRank();
|
||||
int nproc = rabit::GetWorldSize();
|
||||
const int z = iter + 111;
|
||||
@@ -40,10 +56,10 @@ inline void TestMax(test::Mock &mock, Model *model, int ntrial, int iter) {
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
ndata[i] = (i * (rank+1)) % z + model->data[i];
|
||||
}
|
||||
mock.Allreduce<op::Max>(&ndata[0], ndata.size());
|
||||
if (ntrial == 0 && rank == 3) {
|
||||
exit(-1);
|
||||
}
|
||||
test::CallBegin("Allreduce::Max", ntrial, iter);
|
||||
rabit::Allreduce<op::Max>(&ndata[0], ndata.size());
|
||||
test::CallEnd("Allreduce::Max", ntrial, iter);
|
||||
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
float rmax = (i * 1) % z + model->data[i];
|
||||
for (int r = 0; r < nproc; ++r) {
|
||||
@@ -54,7 +70,7 @@ inline void TestMax(test::Mock &mock, Model *model, int ntrial, int iter) {
|
||||
model->data = ndata;
|
||||
}
|
||||
|
||||
inline void TestSum(test::Mock &mock, Model *model, int ntrial, int iter) {
|
||||
inline void TestSum(Model *model, int ntrial, int iter) {
|
||||
int rank = rabit::GetRank();
|
||||
int nproc = rabit::GetWorldSize();
|
||||
const int z = 131 + iter;
|
||||
@@ -63,11 +79,9 @@ inline void TestSum(test::Mock &mock, Model *model, int ntrial, int iter) {
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
ndata[i] = (i * (rank+1)) % z + model->data[i];
|
||||
}
|
||||
if (iter == 0 && ntrial==0 && rank == 0) {
|
||||
throw MockException();
|
||||
}
|
||||
|
||||
mock.Allreduce<op::Sum>(&ndata[0], ndata.size());
|
||||
test::CallBegin("Allreduce::Sum", ntrial, iter);
|
||||
Allreduce<op::Sum>(&ndata[0], ndata.size());
|
||||
test::CallEnd("Allreduce::Sum", ntrial, iter);
|
||||
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
float rsum = model->data[i] * nproc;
|
||||
@@ -80,7 +94,7 @@ inline void TestSum(test::Mock &mock, Model *model, int ntrial, int iter) {
|
||||
model->data = ndata;
|
||||
}
|
||||
|
||||
inline void TestBcast(test::Mock &mock, size_t n, int root, int ntrial) {
|
||||
inline void TestBcast(size_t n, int root, int ntrial, int iter) {
|
||||
int rank = rabit::GetRank();
|
||||
std::string s; s.resize(n);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
@@ -89,9 +103,13 @@ inline void TestBcast(test::Mock &mock, size_t n, int root, int ntrial) {
|
||||
std::string res;
|
||||
if (root == rank) {
|
||||
res = s;
|
||||
mock.Broadcast(&res, root);
|
||||
test::CallBegin("Broadcast", ntrial, iter);
|
||||
rabit::Broadcast(&res, root);
|
||||
test::CallBegin("Broadcast", ntrial, iter);
|
||||
} else {
|
||||
mock.Broadcast(&res, root);
|
||||
test::CallBegin("Broadcast", ntrial, iter);
|
||||
rabit::Broadcast(&res, root);
|
||||
test::CallEnd("Broadcast", ntrial, iter);
|
||||
}
|
||||
utils::Check(res == s, "[%d] TestBcast fail", rank);
|
||||
}
|
||||
@@ -106,7 +124,6 @@ int main(int argc, char *argv[]) {
|
||||
int rank = rabit::GetRank();
|
||||
int nproc = rabit::GetWorldSize();
|
||||
std::string name = rabit::GetProcessorName();
|
||||
test::Mock mock(rank, argv[2], argv[3]);
|
||||
Model model;
|
||||
srand(0);
|
||||
int ntrial = 0;
|
||||
@@ -124,14 +141,14 @@ int main(int argc, char *argv[]) {
|
||||
utils::LogPrintf("[%d] reload-trail=%d, init iter=%d\n", rank, ntrial, iter);
|
||||
}
|
||||
for (int r = iter; r < 3; ++r) {
|
||||
TestMax(mock, &model, ntrial, r);
|
||||
TestMax(&model, ntrial, r);
|
||||
utils::LogPrintf("[%d] !!!TestMax pass, iter=%d\n", rank, r);
|
||||
//int step = std::max(nproc / 3, 1);
|
||||
//for (int i = 0; i < nproc; i += step) {
|
||||
//TestBcast(mock, n, i, ntrial);
|
||||
//}
|
||||
//utils::LogPrintf("[%d] !!!TestBcast pass, iter=%d\n", rank, r);
|
||||
TestSum(mock, &model, ntrial, r);
|
||||
int step = std::max(nproc / 3, 1);
|
||||
for (int i = 0; i < nproc; i += step) {
|
||||
TestBcast(n, i, ntrial, r);
|
||||
}
|
||||
utils::LogPrintf("[%d] !!!TestBcast pass, iter=%d\n", rank, r);
|
||||
TestSum(&model, ntrial, r);
|
||||
utils::LogPrintf("[%d] !!!TestSum pass, iter=%d\n", rank, r);
|
||||
rabit::CheckPoint(&model);
|
||||
utils::LogPrintf("[%d] !!!CheckPont pass, iter=%d\n", rank, r);
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
#include <rabit.h>
|
||||
#include <utils.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <mock.h>
|
||||
|
||||
using namespace rabit;
|
||||
|
||||
struct MockException {
|
||||
};
|
||||
|
||||
inline void TestMax(test::Mock &mock, size_t n, int ntrial) {
|
||||
int rank = rabit::GetRank();
|
||||
int nproc = rabit::GetWorldSize();
|
||||
|
||||
std::vector<float> ndata(n);
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
ndata[i] = (i * (rank+1)) % 111;
|
||||
}
|
||||
mock.Allreduce<op::Max>(&ndata[0], ndata.size());
|
||||
if (ntrial == 0 && rank == 15) throw MockException();
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
float rmax = (i * 1) % 111;
|
||||
for (int r = 0; r < nproc; ++r) {
|
||||
rmax = std::max(rmax, (float)((i * (r+1)) % 111));
|
||||
}
|
||||
utils::Check(rmax == ndata[i], "[%d] TestMax check failure", rank);
|
||||
}
|
||||
}
|
||||
|
||||
inline void TestSum(test::Mock &mock, size_t n, int ntrial) {
|
||||
int rank = rabit::GetRank();
|
||||
int nproc = rabit::GetWorldSize();
|
||||
const int z = 131;
|
||||
|
||||
std::vector<float> ndata(n);
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
ndata[i] = (i * (rank+1)) % z;
|
||||
}
|
||||
mock.Allreduce<op::Sum>(&ndata[0], ndata.size());
|
||||
|
||||
if (ntrial == 0 && rank == 0) throw MockException();
|
||||
|
||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||
float rsum = 0.0f;
|
||||
for (int r = 0; r < nproc; ++r) {
|
||||
rsum += (float)((i * (r+1)) % z);
|
||||
}
|
||||
utils::Check(fabsf(rsum - ndata[i]) < 1e-5 ,
|
||||
"[%d] TestSum check failure, local=%g, allreduce=%g", rank, rsum, ndata[i]);
|
||||
}
|
||||
}
|
||||
|
||||
inline void TestBcast(test::Mock &mock, size_t n, int root, int ntrial) {
|
||||
int rank = rabit::GetRank();
|
||||
std::string s; s.resize(n);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
s[i] = char(i % 126 + 1);
|
||||
}
|
||||
std::string res;
|
||||
if (root == rank) {
|
||||
res = s;
|
||||
mock.Broadcast(&res, root);
|
||||
} else {
|
||||
mock.Broadcast(&res, root);
|
||||
}
|
||||
utils::Check(res == s, "[%d] TestBcast fail", rank);
|
||||
}
|
||||
// dummy model
|
||||
class Model : public rabit::utils::ISerializable {
|
||||
public:
|
||||
// load from stream
|
||||
virtual void Load(rabit::utils::IStream &fi) {
|
||||
// do nothing
|
||||
}
|
||||
/*! \brief save the model to the stream */
|
||||
virtual void Save(rabit::utils::IStream &fo) const {
|
||||
// do nothing
|
||||
}
|
||||
virtual void InitModel(void) {
|
||||
// do nothing
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 3) {
|
||||
printf("Usage: <ndata> <config>\n");
|
||||
return 0;
|
||||
}
|
||||
int n = atoi(argv[1]);
|
||||
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]);
|
||||
Model model;
|
||||
srand(0);
|
||||
int ntrial = 0;
|
||||
while (true) {
|
||||
try {
|
||||
if (rabit::LoadCheckPoint(&model) == 0) {
|
||||
model.InitModel();
|
||||
}
|
||||
utils::LogPrintf("[%d/%d] start at %s\n", rank, ntrial, name.c_str());
|
||||
TestMax(mock, n, ntrial);
|
||||
utils::LogPrintf("[%d/%d] !!!TestMax pass\n", rank, ntrial);
|
||||
TestSum(mock, n, ntrial);
|
||||
utils::LogPrintf("[%d/%d] !!!TestSum pass\n", rank, ntrial);
|
||||
int step = std::max(nproc / 3, 1);
|
||||
for (int i = 0; i < nproc; i += step) {
|
||||
TestBcast(mock, n, i, ntrial);
|
||||
}
|
||||
utils::LogPrintf("[%d] !!!TestBcast pass\n", rank);
|
||||
// reach here
|
||||
break;
|
||||
} catch (MockException &e) {
|
||||
rabit::engine::GetEngine()->InitAfterException();
|
||||
++ntrial;
|
||||
}
|
||||
}
|
||||
rabit::Finalize();
|
||||
printf("[%d] all check pass\n", rank);
|
||||
return 0;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
# Test Case 0 -> nothing fails
|
||||
@@ -1,9 +0,0 @@
|
||||
# Test Case example config
|
||||
# You configure which methods should fail
|
||||
# Format <round>_<rank> = <operation>
|
||||
# <operation> can be one of the following = allreduce, broadcast, loadcheckpoint, checkpoint
|
||||
|
||||
1_0 = allreduce
|
||||
1_1 = broadcast
|
||||
|
||||
2_2 = allreduce
|
||||
Reference in New Issue
Block a user