Skip to content

Commit

Permalink
modified testers and added possibility to choose scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
flopez committed May 10, 2020
1 parent 0530a81 commit 7ccaf96
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 50 deletions.
13 changes: 12 additions & 1 deletion include/sylver/StarPU/starpu.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@

namespace sylver {
namespace starpu {

struct StarPU {
// public:

enum class Scheduler
{
// Heterogeneous Locality Work Stealing
HLWS,
HP,
LWS,
WS,
};

static void initialize();

static int ncpu;
static int ncuda;

static Scheduler sched;

// private:
static struct starpu_conf conf;
};
Expand Down
37 changes: 29 additions & 8 deletions src/StarPU/starpu.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

#include "sylver/StarPU/hlws.hxx"
#include "sylver/StarPU/starpu.hxx"
#include "StarPU/scheduler.h"

namespace sylver {
namespace starpu {

int StarPU::ncpu = 0;
int StarPU::ncuda = 0;

StarPU::Scheduler StarPU::sched = StarPU::Scheduler::LWS;

struct starpu_conf StarPU::conf;

void StarPU::initialize() {
Expand All @@ -28,15 +31,33 @@ void StarPU::initialize() {
#else
conf.ncuda = 0;
#endif

// conf.sched_policy_name = "lws";

// conf.sched_policy_name = "ws";

conf.sched_policy_name = NULL;
sylver::starpu::StarPU::conf.sched_policy =
&sylver::starpu::HeteroLwsScheduler::starpu_sched_policy();

switch (StarPU::sched) {
case Scheduler::HLWS:
std::cout << "[StarPU::initialize] Init StarPU witth HLWS scheduler" << std::endl;
conf.sched_policy_name = NULL;
sylver::starpu::StarPU::conf.sched_policy =
&sylver::starpu::HeteroLwsScheduler::starpu_sched_policy();
break;
case Scheduler::HP:
std::cout << "[StarPU::initialize] Init StarPU witth HP scheduler" << std::endl;
conf.sched_policy_name = "heteroprio";
conf.sched_policy_init = &init_heteroprio;
break;
case Scheduler::LWS:
std::cout << "[StarPU::initialize] Init StarPU witth LWS scheduler" << std::endl;
conf.sched_policy_name = "lws";
break;
case Scheduler::WS:
std::cout << "[StarPU::initialize] Init StarPU witth WS scheduler" << std::endl;
conf.sched_policy_name = "ws";
break;
default:
std::cout << "[StarPU::initialize] Init StarPU witth LWS scheduler" << std::endl;
conf.sched_policy_name = "lws";
}


ret = starpu_init(&conf);
STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");

Expand Down
3 changes: 2 additions & 1 deletion tests/common.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,10 @@ namespace tests {

enum class Sched
{
HP, // Heteroprio
HP, // Hetero prio
HLWS, // Heterogeneous locality work stealing
LWS, // Locality work stealing
WS, // Work stealing
};

// Generates a random dense positive definte matrix. Entries are
Expand Down
25 changes: 22 additions & 3 deletions tests/testing.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace tests {
ncpu(1), ngpu(0), m(256), n(256), k(256), nb(256), ib(256), posdef(false),
check(true), chol(false), diagdom(false), algo(sylver::tests::algo::SyLVER),
usetc(true), prec(sylver::tests::prec::FP64), cond(1), itref(false), tol(1e-8),
sched(Sched::LWS)
sched(Sched::LWS), u(0.01), small(1e-20), delays(false), singular(false)
{}

void parse_opts(int argc, char** argv) {
Expand Down Expand Up @@ -136,13 +136,28 @@ namespace tests {
}
else if ( !strcmp("--sched=hlws", argv[i]) ) {
std::cout << "Using HLWS (Heterogeneous Locality Work Stealing) scheduler" << std::endl;
sched = Sched::LWS;
sched = Sched::HLWS;
}
else if ( !strcmp("--sched=hp", argv[i]) ) {
std::cout << "Using HP (Heteroprio) scheduler" << std::endl;
sched = Sched::LWS;
sched = Sched::HP;
}
else if ( !strcmp("--sched=ws", argv[i]) ) {
std::cout << "Using WS (Work Stealing) scheduler" << std::endl;
sched = Sched::WS;
}

// Cause delays in the factorization
else if ( !strcmp("--delays", argv[i]) ) {
std::cout << "Cause delays" << std::endl;
delays = true;
}
// Make matrix singular
else if ( !strcmp("--sing", argv[i]) ) {
std::cout << "Singular matrix" << std::endl;
singular = true;
}

// Command error message
else {
std::cout << "Unrecognized command " << i << std::endl;
Expand Down Expand Up @@ -172,6 +187,10 @@ namespace tests {
double tol; // Tolerence for iterative refinement
// Scheduler
Sched sched;
double u;
double small;
bool delays;
bool singular;
};

}} // End of namespace sylver::tests
104 changes: 94 additions & 10 deletions tests/testing_factor_node_indef.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#include "factor_indef.hxx"
#include "sylver/StarPU/hlws.hxx"
#include "sylver/StarPU/starpu.hxx"
// SpLDLT tests

// Sylver tests
#include "common.hxx"
#include "testing.hxx"

// STD
#include <vector>
Expand Down Expand Up @@ -41,14 +43,48 @@ namespace tests {

template<
typename T,
int iblksz=sylver::spldlt::INNER_BLOCK_SIZE,
int ib=sylver::spldlt::INNER_BLOCK_SIZE,
bool debug = false>
int factor_node_indef_test(
T u, T small, bool posdef, bool delays, bool singular, int m, int n,
int blksz, int ncpu, int ngpu=0, int test=0, int seed=0) {
int factor_node_indef_test(sylver::tests::Options test_options) {

bool failed = false;

// Threshold
T u = test_options.u;
// Small
T small = test_options.small;

// Posdef matrix
bool posdef = test_options.posdef;

// Cause delays?
bool delays = test_options.delays;
// Make singluar
bool singular = test_options.singular;

std::cout << "[factor_node_indef_test]" << " u = " << u << ", small = " << small << std::endl;
std::cout << "[factor_node_indef_test]" << " posdef = " << posdef << std::endl;
std::cout << "[factor_node_indef_test]" << " delays = " << delays << ", singular = " << singular << std::endl;

// Number of rows
int const m = test_options.m;
// Number of columns
int const n = test_options.n;
// Block dimensions
int const blksz = test_options.nb;

// Use Tensor Cores
bool const usetc = test_options.usetc;

// Check residual
bool const check = test_options.check;

// Number of CPUs
int const ncpu = test_options.ncpu;
// Number of GPUs
int const ngpu = test_options.ngpu;


std::cout << "[factor_node_indef_test] "
<< m << " x " << n << ", blksz = " << blksz
<< ", posdef = " << posdef
Expand Down Expand Up @@ -144,6 +180,24 @@ int factor_node_indef_test(
sylver::starpu::StarPU::ncpu = ncpu;
sylver::starpu::StarPU::ncuda = ngpu;

// Select scheduler
switch (test_options.sched) {
case(sylver::tests::Sched::HP):
sylver::starpu::StarPU::sched = sylver::starpu::StarPU::Scheduler::HP;
break;
case(sylver::tests::Sched::HLWS):
sylver::starpu::StarPU::sched = sylver::starpu::StarPU::Scheduler::HLWS;
break;
case(sylver::tests::Sched::LWS):
sylver::starpu::StarPU::sched = sylver::starpu::StarPU::Scheduler::LWS;
break;
case(sylver::tests::Sched::WS):
sylver::starpu::StarPU::sched = sylver::starpu::StarPU::Scheduler::WS;
break;
default:
std::runtime_error("Scheduler not available");
}

// struct starpu_conf *conf = new starpu_conf;
// starpu_conf_init(conf);
// conf->ncpus = ncpu;
Expand Down Expand Up @@ -217,7 +271,7 @@ int factor_node_indef_test(
// Init factorization
#if defined(SPLDLT_USE_STARPU)
sylver::spldlt::starpu::codelet_init<T, FactorAllocator, PoolAllocator>();
sylver::spldlt::starpu::codelet_init_indef<T, iblksz, Backup, FactorAllocator, PoolAllocator>();
sylver::spldlt::starpu::codelet_init_indef<T, ib, Backup, FactorAllocator, PoolAllocator>();
sylver::spldlt::starpu::codelet_init_factor_indef<NumericFrontType, PoolAllocator>();
sylver::spldlt::starpu::codelet_init_factor_failed<NumericFrontType>();

Expand Down Expand Up @@ -362,7 +416,7 @@ int factor_node_indef_test(

if (debug) std::cout << "nelim = " << nelim << std::endl;

EXPECT_EQ(m, nelim) << "(test " << test << " seed " << seed << ")" << std::endl;
EXPECT_EQ(m, nelim);// << "(test " << test << " seed " << seed << ")" << std::endl;

// Perform solve
T *soln = new T[m];
Expand All @@ -376,7 +430,7 @@ int factor_node_indef_test(
// Check residual
T bwderr = sylver::tests::backward_error(m, a, lda, b, 1, soln, m);
/*if(debug)*/ printf("bwderr = %le\n", bwderr);
EXPECT_LE(u*bwderr, 5e-14) << "(test " << test << " seed " << seed << ")" << std::endl;
EXPECT_LE(u*bwderr, 5e-14); // << "(test " << test << " seed " << seed << ")" << std::endl;

////////////////////////////////////////
// Print results
Expand All @@ -398,7 +452,37 @@ int factor_node_indef_test(
return failed ? -1 : 0;
}

// Run tests for the node factorization
int run_factor_node_indef_tests();
template<
typename T,
int ib=sylver::spldlt::INNER_BLOCK_SIZE,
bool debug = false>
int factor_node_indef_test(T u, T small, bool posdef, bool delays, bool singular, int m, int n,
int blksz, int ncpu, int ngpu=0, int test=0, int seed=0) {


sylver::tests::Options test_options;

test_options.u = u;
test_options.small = small;

test_options.posdef = posdef;
test_options.delays = delays;
test_options.singular = singular;

test_options.m = m;
test_options.n = n;

test_options.nb = blksz;

test_options.ncpu = ncpu;
test_options.ngpu = ngpu;

int ret = factor_node_indef_test<T, ib, debug>(test_options);

return ret;
}

// Run tests for the node factorization
int run_factor_node_indef_tests();

}} // namespace spldlt::tests

0 comments on commit 7ccaf96

Please sign in to comment.