cleanup testcases
This commit is contained in:
parent
aa2cb38543
commit
58331067f8
@ -26,7 +26,7 @@ AllreduceBase::AllreduceBase(void) {
|
|||||||
hadoop_mode = 0;
|
hadoop_mode = 0;
|
||||||
version_number = 0;
|
version_number = 0;
|
||||||
task_id = "NULL";
|
task_id = "NULL";
|
||||||
this->SetParam("reduce_buffer", "256MB");
|
this->SetParam("rabit_reduce_buffer", "256MB");
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialization function
|
// initialization function
|
||||||
@ -38,8 +38,8 @@ void AllreduceBase::Init(void) {
|
|||||||
utils::Check(task_id != NULL, "hadoop_mode is set but cannot find mapred_task_id");
|
utils::Check(task_id != NULL, "hadoop_mode is set but cannot find mapred_task_id");
|
||||||
}
|
}
|
||||||
if (task_id != NULL) {
|
if (task_id != NULL) {
|
||||||
this->SetParam("task_id", task_id);
|
this->SetParam("rabit_task_id", task_id);
|
||||||
this->SetParam("hadoop_mode", "1");
|
this->SetParam("rabit_hadoop_mode", "1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// start socket
|
// start socket
|
||||||
@ -83,9 +83,9 @@ void AllreduceBase::Shutdown(void) {
|
|||||||
void AllreduceBase::SetParam(const char *name, const char *val) {
|
void AllreduceBase::SetParam(const char *name, const char *val) {
|
||||||
if (!strcmp(name, "rabit_tracker_uri")) tracker_uri = val;
|
if (!strcmp(name, "rabit_tracker_uri")) tracker_uri = val;
|
||||||
if (!strcmp(name, "rabit_tracker_port")) tracker_port = atoi(val);
|
if (!strcmp(name, "rabit_tracker_port")) tracker_port = atoi(val);
|
||||||
if (!strcmp(name, "task_id")) task_id = val;
|
if (!strcmp(name, "rabit_task_id")) task_id = val;
|
||||||
if (!strcmp(name, "hadoop_mode")) hadoop_mode = atoi(val);
|
if (!strcmp(name, "rabit_hadoop_mode")) hadoop_mode = atoi(val);
|
||||||
if (!strcmp(name, "reduce_buffer")) {
|
if (!strcmp(name, "rabit_reduce_buffer")) {
|
||||||
char unit;
|
char unit;
|
||||||
unsigned long amount;
|
unsigned long amount;
|
||||||
if (sscanf(val, "%lu%c", &amount, &unit) == 2) {
|
if (sscanf(val, "%lu%c", &amount, &unit) == 2) {
|
||||||
|
|||||||
@ -17,10 +17,10 @@
|
|||||||
namespace rabit {
|
namespace rabit {
|
||||||
namespace engine {
|
namespace engine {
|
||||||
AllreduceRobust::AllreduceRobust(void) {
|
AllreduceRobust::AllreduceRobust(void) {
|
||||||
result_buffer_round = 1;
|
|
||||||
num_local_replica = 0;
|
num_local_replica = 0;
|
||||||
seq_counter = 0;
|
seq_counter = 0;
|
||||||
local_chkpt_version = 0;
|
local_chkpt_version = 0;
|
||||||
|
result_buffer_round = 1;
|
||||||
}
|
}
|
||||||
/*! \brief shutdown the engine */
|
/*! \brief shutdown the engine */
|
||||||
void AllreduceRobust::Shutdown(void) {
|
void AllreduceRobust::Shutdown(void) {
|
||||||
@ -42,11 +42,11 @@ void AllreduceRobust::Shutdown(void) {
|
|||||||
*/
|
*/
|
||||||
void AllreduceRobust::SetParam(const char *name, const char *val) {
|
void AllreduceRobust::SetParam(const char *name, const char *val) {
|
||||||
AllreduceBase::SetParam(name, val);
|
AllreduceBase::SetParam(name, val);
|
||||||
if (!strcmp(name, "result_buffer_round")) result_buffer_round = atoi(val);
|
if (!strcmp(name, "rabit_buffer_round")) result_buffer_round = atoi(val);
|
||||||
if (!strcmp(name, "result_replicate")) {
|
if (!strcmp(name, "rabit_global_replica")) {
|
||||||
result_buffer_round = std::max(world_size / atoi(val), 1);
|
result_buffer_round = std::max(world_size / atoi(val), 1);
|
||||||
}
|
}
|
||||||
if (!strcmp(name, "num_local_replica")) {
|
if (!strcmp(name, "rabit_local_replica")) {
|
||||||
num_local_replica = atoi(val);
|
num_local_replica = atoi(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,6 @@ parser.add_argument('-hs', '--hadoop_streaming_jar', required=True)
|
|||||||
parser.add_argument('-i', '--input', required=True)
|
parser.add_argument('-i', '--input', required=True)
|
||||||
parser.add_argument('-o', '--output', required=True)
|
parser.add_argument('-o', '--output', required=True)
|
||||||
parser.add_argument('-m', '--mapper', required=True)
|
parser.add_argument('-m', '--mapper', required=True)
|
||||||
#parser.add_argument('-r', '--reducer', required=False)
|
|
||||||
parser.add_argument('-k', '--nclusters', required=True, type=int)
|
parser.add_argument('-k', '--nclusters', required=True, type=int)
|
||||||
parser.add_argument('-itr', '--iterations', required=True, type=int)
|
parser.add_argument('-itr', '--iterations', required=True, type=int)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
"""
|
"""
|
||||||
This is an example script to create a customized job submit
|
This is an example script to create a customized job submit with mpi
|
||||||
script using rabit engine
|
script using rabit engine
|
||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
@ -34,6 +34,7 @@ def mpi_submit(nslave, args):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print 'Usage: <nslave> <machine_file> <cmd>'
|
print 'Usage: <nslave> <machine_file> <cmd>'
|
||||||
|
print 'if <machine_file> == local, we will run using local mode'
|
||||||
exit(0)
|
exit(0)
|
||||||
# call submit, with nslave, the commands to run each job and submit function
|
# call submit, with nslave, the commands to run each job and submit function
|
||||||
tracker.submit(int(sys.argv[1]), sys.argv[2:], fun_submit= mpi_submit)
|
tracker.submit(int(sys.argv[1]), sys.argv[2:], fun_submit= mpi_submit)
|
||||||
|
|||||||
@ -5,33 +5,30 @@ export LDFLAGS= -pthread -lm -lrt
|
|||||||
export CFLAGS = -Wall -O3 -msse2 -Wno-unknown-pragmas -fPIC -I../src
|
export CFLAGS = -Wall -O3 -msse2 -Wno-unknown-pragmas -fPIC -I../src
|
||||||
|
|
||||||
# specify tensor path
|
# 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
|
# objectives that makes up rabit library
|
||||||
RABIT_OBJ = allreduce_base.o allreduce_robust.o engine.o
|
RABIT_OBJ = allreduce_base.o allreduce_robust.o engine.o
|
||||||
MPIOBJ = engine_mpi.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
|
OBJ = $(RABIT_OBJ) speed_test.o test_model_recover.o test_local_recover.o
|
||||||
MPIBIN = test_allreduce.mpi speed_test.mpi
|
MPIBIN = speed_test.mpi
|
||||||
.PHONY: clean all
|
.PHONY: clean all
|
||||||
|
|
||||||
all: $(BIN) $(MPIBIN)
|
all: $(BIN) $(MPIBIN)
|
||||||
|
# the rabit library
|
||||||
allreduce_base.o: ../src/allreduce_base.cc ../src/*.h
|
allreduce_base.o: ../src/allreduce_base.cc ../src/*.h
|
||||||
engine.o: ../src/engine.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
|
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
|
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_model_recover.o: test_model_recover.cpp ../src/*.h
|
||||||
test_local_recover.o: test_local_recover.cpp ../src/*.h
|
test_local_recover.o: test_local_recover.cpp ../src/*.h
|
||||||
|
|
||||||
# we can link against MPI version to get use MPI
|
# 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: speed_test.o $(RABIT_OBJ)
|
||||||
speed_test.mpi: speed_test.o $(MPIOBJ)
|
speed_test.mpi: speed_test.o $(MPIOBJ)
|
||||||
test_recover: test_recover.o $(RABIT_OBJ)
|
|
||||||
test_model_recover: test_model_recover.o $(RABIT_OBJ)
|
test_model_recover: test_model_recover.o $(RABIT_OBJ)
|
||||||
test_local_recover: test_local_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, $^) )
|
$(MPICXX) -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c %.cc, $^) )
|
||||||
|
|
||||||
clean:
|
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
|
||||||
@ -6,9 +6,9 @@ then
|
|||||||
exit -1
|
exit -1
|
||||||
fi
|
fi
|
||||||
nrep=0
|
nrep=0
|
||||||
echo ./$@ task_id=$OMPI_COMM_WORLD_RANK
|
echo ./$@ rabit_task_id=$OMPI_COMM_WORLD_RANK
|
||||||
until ./$@ task_id=$OMPI_COMM_WORLD_RANK repeat=$nrep; do
|
until ./$@ rabit_task_id=$OMPI_COMM_WORLD_RANK repeat=$nrep; do
|
||||||
sleep 1
|
sleep 1
|
||||||
nrep=$((nrep+1))
|
nrep=$((nrep+1))
|
||||||
echo ./$@ job_id=$OMPI_COMM_WORLD_RANK repeat=$nrep
|
echo ./$@ rabit_task_id=$OMPI_COMM_WORLD_RANK repeat=$nrep
|
||||||
done
|
done
|
||||||
|
|||||||
@ -11,6 +11,9 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
struct MockException {
|
||||||
|
};
|
||||||
|
|
||||||
namespace rabit {
|
namespace rabit {
|
||||||
/*! \brief namespace of mock */
|
/*! \brief namespace of mock */
|
||||||
namespace test {
|
namespace test {
|
||||||
@ -31,4 +31,4 @@ def main():
|
|||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// This program is used to test the speed of rabit API
|
||||||
#include <rabit.h>
|
#include <rabit.h>
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
#include <timer.h>
|
#include <timer.h>
|
||||||
@ -12,8 +13,6 @@ double max_tdiff, sum_tdiff, bcast_tdiff, tot_tdiff;
|
|||||||
|
|
||||||
inline void TestMax(size_t n) {
|
inline void TestMax(size_t n) {
|
||||||
int rank = rabit::GetRank();
|
int rank = rabit::GetRank();
|
||||||
//int nproc = rabit::GetWorldSize();
|
|
||||||
|
|
||||||
std::vector<float> ndata(n);
|
std::vector<float> ndata(n);
|
||||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||||
ndata[i] = (i * (rank+1)) % 111;
|
ndata[i] = (i * (rank+1)) % 111;
|
||||||
@ -25,7 +24,6 @@ inline void TestMax(size_t n) {
|
|||||||
|
|
||||||
inline void TestSum(size_t n) {
|
inline void TestSum(size_t n) {
|
||||||
int rank = rabit::GetRank();
|
int rank = rabit::GetRank();
|
||||||
//int nproc = rabit::GetWorldSize();
|
|
||||||
const int z = 131;
|
const int z = 131;
|
||||||
std::vector<float> ndata(n);
|
std::vector<float> ndata(n);
|
||||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
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 <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <mock.h>
|
#include "./mock.h"
|
||||||
|
|
||||||
using namespace rabit;
|
using namespace rabit;
|
||||||
|
namespace rabit {
|
||||||
struct MockException {
|
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
|
// dummy model
|
||||||
class Model : public rabit::utils::ISerializable {
|
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 rank = rabit::GetRank();
|
||||||
int nproc = rabit::GetWorldSize();
|
int nproc = rabit::GetWorldSize();
|
||||||
const int z = iter + 111;
|
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());
|
std::vector<float> ndata(model->data.size());
|
||||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||||
ndata[i] = (i * (rank+1)) % z + local->data[i];
|
ndata[i] = (i * (rank+1)) % z + local->data[i];
|
||||||
}
|
}
|
||||||
mock.Allreduce<op::Max>(&ndata[0], ndata.size());
|
test::CallBegin("Allreduce::Max", ntrial, iter);
|
||||||
if (ntrial == iter && rank == 1) {
|
rabit::Allreduce<op::Max>(&ndata[0], ndata.size());
|
||||||
throw MockException();
|
test::CallEnd("Allreduce::Max", ntrial, iter);
|
||||||
}
|
|
||||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||||
float rmax = (i * 1) % z + model->data[i];
|
float rmax = (i * 1) % z + model->data[i];
|
||||||
for (int r = 0; r < nproc; ++r) {
|
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 rank = rabit::GetRank();
|
||||||
int nproc = rabit::GetWorldSize();
|
int nproc = rabit::GetWorldSize();
|
||||||
const int z = 131 + iter;
|
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) {
|
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||||
ndata[i] = (i * (rank+1)) % z + local->data[i];
|
ndata[i] = (i * (rank+1)) % z + local->data[i];
|
||||||
}
|
}
|
||||||
if (ntrial == iter && rank == 0) {
|
test::CallBegin("Allreduce::Sum", ntrial, iter);
|
||||||
throw MockException();
|
Allreduce<op::Sum>(&ndata[0], ndata.size());
|
||||||
}
|
test::CallEnd("Allreduce::Sum", ntrial, iter);
|
||||||
mock.Allreduce<op::Sum>(&ndata[0], ndata.size());
|
|
||||||
|
|
||||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||||
float rsum = 0.0f;
|
float rsum = 0.0f;
|
||||||
for (int r = 0; r < nproc; ++r) {
|
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();
|
int rank = rabit::GetRank();
|
||||||
std::string s; s.resize(n);
|
std::string s; s.resize(n);
|
||||||
for (size_t i = 0; i < n; ++i) {
|
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;
|
std::string res;
|
||||||
if (root == rank) {
|
if (root == rank) {
|
||||||
res = s;
|
res = s;
|
||||||
mock.Broadcast(&res, root);
|
test::CallBegin("Broadcast", ntrial, iter);
|
||||||
|
rabit::Broadcast(&res, root);
|
||||||
|
test::CallBegin("Broadcast", ntrial, iter);
|
||||||
} else {
|
} 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);
|
utils::Check(res == s, "[%d] TestBcast fail", rank);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
printf("Usage: <ndata> <config>\n");
|
printf("Usage: <ndata>\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int n = atoi(argv[1]);
|
int n = atoi(argv[1]);
|
||||||
@ -112,7 +131,6 @@ int main(int argc, char *argv[]) {
|
|||||||
int rank = rabit::GetRank();
|
int rank = rabit::GetRank();
|
||||||
int nproc = rabit::GetWorldSize();
|
int nproc = rabit::GetWorldSize();
|
||||||
std::string name = rabit::GetProcessorName();
|
std::string name = rabit::GetProcessorName();
|
||||||
test::Mock mock(rank, argv[2], argv[3]);
|
|
||||||
Model model, local;
|
Model model, local;
|
||||||
srand(0);
|
srand(0);
|
||||||
int ntrial = 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);
|
utils::LogPrintf("[%d] reload-trail=%d, init iter=%d\n", rank, ntrial, iter);
|
||||||
}
|
}
|
||||||
for (int r = iter; r < 3; ++r) {
|
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);
|
utils::LogPrintf("[%d] !!!TestMax pass, iter=%d\n", rank, r);
|
||||||
int step = std::max(nproc / 3, 1);
|
int step = std::max(nproc / 3, 1);
|
||||||
for (int i = 0; i < nproc; i += step) {
|
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);
|
utils::LogPrintf("[%d] !!!TestBcast pass, iter=%d\n", rank, r);
|
||||||
TestSum(mock, &model, &local, ntrial, r);
|
TestSum(&model, &local, ntrial, r);
|
||||||
utils::LogPrintf("[%d] !!!TestSum pass, iter=%d\n", rank, r);
|
utils::LogPrintf("[%d] !!!TestSum pass, iter=%d\n", rank, r);
|
||||||
rabit::CheckPoint(&model, &local);
|
rabit::CheckPoint(&model, &local);
|
||||||
utils::LogPrintf("[%d] !!!CheckPont pass, iter=%d\n", rank, r);
|
utils::LogPrintf("[%d] !!!CheckPont pass, iter=%d\n", rank, r);
|
||||||
|
|||||||
@ -5,12 +5,28 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <mock.h>
|
#include "./mock.h"
|
||||||
|
|
||||||
using namespace rabit;
|
using namespace rabit;
|
||||||
|
namespace rabit {
|
||||||
struct MockException {
|
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
|
// dummy model
|
||||||
class Model : public rabit::utils::ISerializable {
|
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 rank = rabit::GetRank();
|
||||||
int nproc = rabit::GetWorldSize();
|
int nproc = rabit::GetWorldSize();
|
||||||
const int z = iter + 111;
|
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) {
|
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||||
ndata[i] = (i * (rank+1)) % z + model->data[i];
|
ndata[i] = (i * (rank+1)) % z + model->data[i];
|
||||||
}
|
}
|
||||||
mock.Allreduce<op::Max>(&ndata[0], ndata.size());
|
test::CallBegin("Allreduce::Max", ntrial, iter);
|
||||||
if (ntrial == 0 && rank == 3) {
|
rabit::Allreduce<op::Max>(&ndata[0], ndata.size());
|
||||||
exit(-1);
|
test::CallEnd("Allreduce::Max", ntrial, iter);
|
||||||
}
|
|
||||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||||
float rmax = (i * 1) % z + model->data[i];
|
float rmax = (i * 1) % z + model->data[i];
|
||||||
for (int r = 0; r < nproc; ++r) {
|
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;
|
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 rank = rabit::GetRank();
|
||||||
int nproc = rabit::GetWorldSize();
|
int nproc = rabit::GetWorldSize();
|
||||||
const int z = 131 + iter;
|
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) {
|
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||||
ndata[i] = (i * (rank+1)) % z + model->data[i];
|
ndata[i] = (i * (rank+1)) % z + model->data[i];
|
||||||
}
|
}
|
||||||
if (iter == 0 && ntrial==0 && rank == 0) {
|
test::CallBegin("Allreduce::Sum", ntrial, iter);
|
||||||
throw MockException();
|
Allreduce<op::Sum>(&ndata[0], ndata.size());
|
||||||
}
|
test::CallEnd("Allreduce::Sum", ntrial, iter);
|
||||||
|
|
||||||
mock.Allreduce<op::Sum>(&ndata[0], ndata.size());
|
|
||||||
|
|
||||||
for (size_t i = 0; i < ndata.size(); ++i) {
|
for (size_t i = 0; i < ndata.size(); ++i) {
|
||||||
float rsum = model->data[i] * nproc;
|
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;
|
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();
|
int rank = rabit::GetRank();
|
||||||
std::string s; s.resize(n);
|
std::string s; s.resize(n);
|
||||||
for (size_t i = 0; i < n; ++i) {
|
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;
|
std::string res;
|
||||||
if (root == rank) {
|
if (root == rank) {
|
||||||
res = s;
|
res = s;
|
||||||
mock.Broadcast(&res, root);
|
test::CallBegin("Broadcast", ntrial, iter);
|
||||||
|
rabit::Broadcast(&res, root);
|
||||||
|
test::CallBegin("Broadcast", ntrial, iter);
|
||||||
} else {
|
} 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);
|
utils::Check(res == s, "[%d] TestBcast fail", rank);
|
||||||
}
|
}
|
||||||
@ -106,7 +124,6 @@ int main(int argc, char *argv[]) {
|
|||||||
int rank = rabit::GetRank();
|
int rank = rabit::GetRank();
|
||||||
int nproc = rabit::GetWorldSize();
|
int nproc = rabit::GetWorldSize();
|
||||||
std::string name = rabit::GetProcessorName();
|
std::string name = rabit::GetProcessorName();
|
||||||
test::Mock mock(rank, argv[2], argv[3]);
|
|
||||||
Model model;
|
Model model;
|
||||||
srand(0);
|
srand(0);
|
||||||
int ntrial = 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);
|
utils::LogPrintf("[%d] reload-trail=%d, init iter=%d\n", rank, ntrial, iter);
|
||||||
}
|
}
|
||||||
for (int r = iter; r < 3; ++r) {
|
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);
|
utils::LogPrintf("[%d] !!!TestMax pass, iter=%d\n", rank, r);
|
||||||
//int step = std::max(nproc / 3, 1);
|
int step = std::max(nproc / 3, 1);
|
||||||
//for (int i = 0; i < nproc; i += step) {
|
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);
|
utils::LogPrintf("[%d] !!!TestBcast pass, iter=%d\n", rank, r);
|
||||||
TestSum(mock, &model, ntrial, r);
|
TestSum(&model, ntrial, r);
|
||||||
utils::LogPrintf("[%d] !!!TestSum pass, iter=%d\n", rank, r);
|
utils::LogPrintf("[%d] !!!TestSum pass, iter=%d\n", rank, r);
|
||||||
rabit::CheckPoint(&model);
|
rabit::CheckPoint(&model);
|
||||||
utils::LogPrintf("[%d] !!!CheckPont pass, iter=%d\n", rank, r);
|
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
|
|
||||||
Loading…
x
Reference in New Issue
Block a user