thesis version

This commit is contained in:
2021-05-10 18:14:13 +02:00
commit b688da651b
191 changed files with 35833 additions and 0 deletions

127
tests/edsl/edsl.cpp Normal file
View File

@ -0,0 +1,127 @@
#include <catch.hpp>
#include <alsk/alsk.h>
using namespace alsk::arg;
using namespace alsk::edsl;
static int counterDo, counterThen, counterDone;
struct Do { void operator()() { ++counterDo; } };
struct Then { void operator()() { ++counterThen; } };
struct Done { void operator()() { ++counterDone; } };
struct Produce0 { int operator()(int x) { return x+1; } };
struct Produce1 { int operator()(int x) { return x-2; } };
struct Consume { int operator()(int x, int y) { return x*y; } };
// TODO? avoid copies so it is truly stateful
struct Generate { int value; int operator()(int b) { return ++value+b; } };
struct Transform0 { int operator()(int x) { return x+1; } };
struct Transform1 { int operator()(int x) { return x-2; } };
struct Produce { int operator()(int x, int y) { return x*y; } };
struct Select {
int mod;
int operator()(int a, int b) { if(a%mod == b%mod) return std::min(a, b); return (a%mod > b%mod)? a : b; }
};
TEST_CASE("edsl") {
auto aDo = makeOperand<Do>();
auto aThen = makeOperand<Then>();
auto aDone = makeOperand<Done>();
auto aProduce0 = makeOperand<Produce0>();
auto aProduce1 = makeOperand<Produce1>();
auto aConsume = makeOperand<Consume>();
auto e0 = aDo & (5*aThen) & aDone;
using E0 = decltype(e0);
using S0 = alsk::S<alsk::Serial, Do, alsk::S<alsk::Farm, Then>, Done>;
using L0 = alsk::L<alsk::Serial, void(), void(), alsk::L<alsk::Farm, void(), void()>, void()>;
auto e1 = 5*(aDo, 2*aThen, aDone);
using E1 = decltype(e1);
using S1 = alsk::S<alsk::Farm, alsk::S<alsk::Serial, Do, alsk::S<alsk::Farm, Then>, Done>>;
using L1 = alsk::L<alsk::Farm, void(), alsk::L<alsk::Serial, void(), void(), alsk::L<alsk::Farm, void(), void()>, void()>>;
auto e2 = link<R<2>(int)>(
link<int(P<0>)>(aProduce0),
link<int(P<0>)>(aProduce1),
link<int(R<1>, R<0>)>(aConsume)
);
SECTION("Construction") {
REQUIRE(std::is_same<E0::Signature, void()>{});
REQUIRE(std::is_same<E0::Struct, S0>{});
REQUIRE(std::is_same<E0::Links, L0>{});
REQUIRE(std::is_same<E1::Signature, void()>{});
REQUIRE(std::is_same<E1::Struct, S1>{});
REQUIRE(std::is_same<E1::Links, L1>{});
}
SECTION("Linking") {
{
auto f2 = implement<alsk::exec::Sequential>(e2);
REQUIRE(f2(0) == -2);
REQUIRE(f2(2) == 0);
REQUIRE(f2(5) == 18);
}
}
SECTION("Setup") {
auto f0 = implement<alsk::exec::Sequential>(e0);
REQUIRE(f0.skeleton.task<1>().n == 5);
}
SECTION("Check run") {
{
auto f0 = implement<alsk::exec::Sequential>(e0);
counterDo = counterThen = counterDone = 0;
f0();
REQUIRE(counterDo == 1);
REQUIRE(counterThen == 5);
REQUIRE(counterDone == 1);
}
{
auto f1 = implement<alsk::exec::Sequential>(e1);
counterDo = counterThen = counterDone = 0;
f1();
REQUIRE(counterDo == 5);
REQUIRE(counterThen == 10);
REQUIRE(counterDone == 5);
}
}
SECTION("Complex case") {
auto generate = makeOperand<Generate>();
auto transform0 = makeOperand<Transform0>();
auto transform1 = makeOperand<Transform1>();
auto produce = makeOperand<Produce>();
auto select = makeOperand<int(int, int), Select>();
auto innerTask = link<R<3>(int)>(
link<int(P<0>)>(generate),
link<int(R<0>)>(transform0),
link<int(R<0>)>(transform1),
link<int(R<2>, R<1>)>(produce)
);
auto task = link<int(int)>(10 * link<R<3>(P<0>)>(innerTask)) ->* select;
auto f = implement<alsk::exec::Sequential>(task);
f.skeleton.select.mod = 5;
REQUIRE(f(4) == 18);
REQUIRE(f(5) == 28);
REQUIRE(f(6) == 40);
REQUIRE(f(7) == 54);
REQUIRE(f(8) == 70);
}
}

62
tests/edsl/op/farm.cpp Normal file
View File

@ -0,0 +1,62 @@
#include <catch.hpp>
#include <alsk/alsk.h>
using namespace alsk::edsl;
struct Do { void operator()() { std::puts("Do"); } };
TEST_CASE("edsl::Farm") {
auto aDo = makeOperand<Do>();
auto e0 = *aDo;
using E0 = decltype(e0);
using S0 = alsk::S<alsk::Farm, Do>;
using L0 = alsk::L<alsk::Farm, void(), void()>;
auto e1 = 5*aDo;
using E1 = decltype(e1);
using S1 = alsk::S<alsk::Farm, Do>;
using L1 = alsk::L<alsk::Farm, void(), void()>;
auto e2 = aDo*3;
using E2 = decltype(e2);
using S2 = alsk::S<alsk::Farm, Do>;
using L2 = alsk::L<alsk::Farm, void(), void()>;
auto e3 = farm(aDo, 3);
using E3 = decltype(e3);
using S3 = alsk::S<alsk::Farm, Do>;
using L3 = alsk::L<alsk::Farm, void(), void()>;
SECTION("Construction") {
REQUIRE(std::is_same<E0::Struct, S0>{});
REQUIRE(std::is_same<E0::Links, L0>{});
REQUIRE(std::is_same<E0::Signature, void()>{});
REQUIRE(std::is_same<E1::Struct, S1>{});
REQUIRE(std::is_same<E1::Links, L1>{});
REQUIRE(std::is_same<E1::Signature, void()>{});
REQUIRE(std::is_same<E2::Struct, S2>{});
REQUIRE(std::is_same<E2::Links, L2>{});
REQUIRE(std::is_same<E2::Signature, void()>{});
REQUIRE(std::is_same<E3::Struct, S3>{});
REQUIRE(std::is_same<E3::Links, L3>{});
REQUIRE(std::is_same<E3::Signature, void()>{});
}
SECTION("Setup") {
auto f0 = implement<alsk::exec::Sequential>(e0);
REQUIRE(f0.skeleton.n == 0);
auto f1 = implement<alsk::exec::Sequential>(e1);
REQUIRE(f1.skeleton.n == 5);
auto f2 = implement<alsk::exec::Sequential>(e2);
REQUIRE(f2.skeleton.n == 3);
auto f3 = implement<alsk::exec::Sequential>(e3);
REQUIRE(f3.skeleton.n == 3);
}
}

52
tests/edsl/op/farmsel.cpp Normal file
View File

@ -0,0 +1,52 @@
#include <catch.hpp>
#include <alsk/alsk.h>
using namespace alsk::edsl;
struct Generate { int operator()() { return 0; } };
struct Select { int operator()(int a, int b) { return std::max(a, b); } };
TEST_CASE("edsl::FarmSel") {
auto generate = makeOperand<int(), Generate>();
auto select = makeOperand<int(int, int), Select>();
auto e0 = (10 * generate) ->* select;
using E0 = decltype(e0);
using S0 = alsk::S<alsk::FarmSel, Generate, Select>;
using L0 = alsk::L<alsk::FarmSel, int(), int(), int(int, int)>;
auto e1 = link<void(int)>(*generate) ->* select;
using E1 = decltype(e1);
using S1 = alsk::S<alsk::FarmSel, Generate, Select>;
using L1 = alsk::L<alsk::FarmSel, int(int), int(), int(int, int)>;
auto e2 = farm(generate).select(select);
using E2 = decltype(e2);
using S2 = alsk::S<alsk::FarmSel, Generate, Select>;
using L2 = alsk::L<alsk::FarmSel, int(), int(), int(int, int)>;
SECTION("Construction") {
REQUIRE(std::is_same<E0::Struct, S0>{});
REQUIRE(std::is_same<E0::Links, L0>{});
REQUIRE(std::is_same<E0::Signature, int()>{});
REQUIRE(std::is_same<E1::Struct, S1>{});
REQUIRE(std::is_same<E1::Links, L1>{});
REQUIRE(std::is_same<E1::Signature, int(int)>{});
REQUIRE(std::is_same<E2::Struct, S2>{});
REQUIRE(std::is_same<E2::Links, L2>{});
REQUIRE(std::is_same<E2::Signature, int()>{});
}
SECTION("Setup") {
auto f0 = implement<alsk::exec::DynamicPool>(e0);
REQUIRE(f0.skeleton.n == 10);
auto f1 = implement<alsk::exec::DynamicPool>(e1);
REQUIRE(f1.skeleton.n == 0);
auto f2 = implement<alsk::exec::DynamicPool>(e2);
REQUIRE(f2.skeleton.n == 0);
}
}

52
tests/edsl/op/itersel.cpp Normal file
View File

@ -0,0 +1,52 @@
#include <catch.hpp>
#include <alsk/alsk.h>
using namespace alsk::edsl;
struct Generate { int operator()() { return 0; } };
struct Select { int operator()(int a, int b) { return std::max(a, b); } };
TEST_CASE("edsl::IterSel") {
auto generate = makeOperand<int(), Generate>();
auto select = makeOperand<int(int, int), Select>();
auto e0 = iter(generate, 10).select(select);
using E0 = decltype(e0);
using S0 = alsk::S<alsk::IterSel, Generate, Select>;
using L0 = alsk::L<alsk::IterSel, int(), int(), int(int, int)>;
auto e1 = &(link<void(int)>(*generate) ->* select);
using E1 = decltype(e1);
using S1 = alsk::S<alsk::IterSel, Generate, Select>;
using L1 = alsk::L<alsk::IterSel, int(int), int(), int(int, int)>;
auto e2 = seq(link<void(int)>(*generate) ->* select);
using E2 = decltype(e2);
using S2 = alsk::S<alsk::IterSel, Generate, Select>;
using L2 = alsk::L<alsk::IterSel, int(int), int(), int(int, int)>;
SECTION("Construction") {
REQUIRE(std::is_same<E0::Struct, S0>{});
REQUIRE(std::is_same<E0::Links, L0>{});
REQUIRE(std::is_same<E0::Signature, int()>{});
REQUIRE(std::is_same<E1::Struct, S1>{});
REQUIRE(std::is_same<E1::Links, L1>{});
REQUIRE(std::is_same<E1::Signature, int(int)>{});
REQUIRE(std::is_same<E2::Struct, S2>{});
REQUIRE(std::is_same<E2::Links, L2>{});
REQUIRE(std::is_same<E2::Signature, int(int)>{});
}
SECTION("Setup") {
auto f0 = implement<alsk::exec::DynamicPool>(e0);
REQUIRE(f0.skeleton.n == 10);
auto f1 = implement<alsk::exec::DynamicPool>(e1);
REQUIRE(f1.skeleton.n == 0);
auto f2 = implement<alsk::exec::DynamicPool>(e2);
REQUIRE(f2.skeleton.n == 0);
}
}

50
tests/edsl/op/loop.cpp Normal file
View File

@ -0,0 +1,50 @@
#include <catch.hpp>
#include <alsk/alsk.h>
using namespace alsk::edsl;
struct Do { void operator()() { std::puts("Do"); } };
TEST_CASE("edsl::Loop") {
auto aDo = makeOperand<Do>();
auto e0 = loop(aDo);
using E0 = decltype(e0);
using S0 = alsk::S<alsk::Loop, Do>;
using L0 = alsk::L<alsk::Loop, void(), void()>;
auto e1 = seq(5*aDo);
using E1 = decltype(e1);
using S1 = alsk::S<alsk::Loop, Do>;
using L1 = alsk::L<alsk::Loop, void(), void()>;
auto e2 = &(aDo*3);
using E2 = decltype(e2);
using S2 = alsk::S<alsk::Loop, Do>;
using L2 = alsk::L<alsk::Loop, void(), void()>;
SECTION("Construction") {
REQUIRE(std::is_same<E0::Struct, S0>{});
REQUIRE(std::is_same<E0::Links, L0>{});
REQUIRE(std::is_same<E0::Signature, void()>{});
REQUIRE(std::is_same<E1::Struct, S1>{});
REQUIRE(std::is_same<E1::Links, L1>{});
REQUIRE(std::is_same<E1::Signature, void()>{});
REQUIRE(std::is_same<E2::Struct, S2>{});
REQUIRE(std::is_same<E2::Links, L2>{});
REQUIRE(std::is_same<E2::Signature, void()>{});
}
SECTION("Setup") {
auto f0 = implement<alsk::exec::Sequential>(e0);
REQUIRE(f0.skeleton.n == 0);
auto f1 = implement<alsk::exec::Sequential>(e1);
REQUIRE(f1.skeleton.n == 5);
auto f2 = implement<alsk::exec::Sequential>(e2);
REQUIRE(f2.skeleton.n == 3);
}
}

46
tests/edsl/op/operand.cpp Normal file
View File

@ -0,0 +1,46 @@
#include <catch.hpp>
#include <alsk/alsk.h>
using namespace alsk::edsl;
struct A { void operator()() {} };
struct B { int operator()(float) { return {}; } };
void f() {}
TEST_CASE("edsl::Operand") {
SECTION("from function-object") {
{
auto x = makeOperand<A>();
using X = decltype(x);
REQUIRE(std::is_same<X::Struct, A>{});
REQUIRE(std::is_same<X::Links, void()>{});
}
{
auto x = makeOperand<int(alsk::arg::P<0>), B>();
using X = decltype(x);
REQUIRE(std::is_same<X::Struct, B>{});
REQUIRE(std::is_same<X::Links, int(alsk::arg::P<0>)>{});
}
}
SECTION("from function") {
{
auto x = alskMakeOperand(f);
using X = decltype(x);
REQUIRE(std::is_same<X::Struct, Fn<void(&)(), f>>{});
REQUIRE(std::is_same<X::Links, void()>{});
}
{
using Signature = int const&(&)(int const&, int const&);
auto x = makeOperand<Signature, std::min<int>>();
using X = decltype(x);
REQUIRE(std::is_same<X::Struct, Fn<Signature, std::min<int>>>{});
REQUIRE(std::is_same<X::Links, int const&(int const&, int const&)>{});
}
}
}

37
tests/edsl/op/serial.cpp Normal file
View File

@ -0,0 +1,37 @@
#include <catch.hpp>
#include <alsk/alsk.h>
using namespace alsk::edsl;
struct Do { void operator()() { std::puts("Do"); } };
struct Then { void operator()() { std::puts("Then"); } };
struct Done { void operator()() { std::puts("Done"); } };
TEST_CASE("edsl::Serial") {
auto aDo = makeOperand<Do>();
auto aThen = makeOperand<Then>();
auto aDone = makeOperand<Done>();
using E0 = decltype(aDo & aThen);
using E1 = decltype(aDo, aThen, aDone);
using S0 = alsk::S<alsk::Serial, Do, Then>;
using S1 = alsk::S<alsk::Serial, Do, Then, Done>;
using L0 = alsk::L<alsk::Serial, void(), void(), void()>;
using L1 = alsk::L<alsk::Serial, void(), void(), void(), void()>;
SECTION("Construction") {
REQUIRE(std::is_same<E0::Signature, void()>{});
REQUIRE(std::is_same<E1::Signature, void()>{});
REQUIRE(std::is_same<E0::Struct, S0>{});
REQUIRE(std::is_same<E1::Struct, S1>{});
REQUIRE(std::is_same<E0::Links, L0>{});
REQUIRE(std::is_same<E1::Links, L1>{});
}
SECTION("Setup") {
}
}

23
tests/edsl/op/while.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <catch.hpp>
#include <alsk/alsk.h>
using namespace alsk::edsl;
struct Pred { int n; bool operator()() { return --n; } };
struct Do { void operator()() { std::puts("Do"); } };
TEST_CASE("edsl::While") {
auto aPred = makeOperand<bool(), Pred>();
auto aDo = makeOperand<Do>();
auto e0 = while_(aPred).do_(aDo);
using E0 = decltype(e0);
using S0 = alsk::S<alsk::While, Pred, Do>;
using L0 = alsk::L<alsk::While, void(), bool(), void()>;
SECTION("Construction") {
REQUIRE(std::is_same<E0::Struct, S0>{});
REQUIRE(std::is_same<E0::Links, L0>{});
REQUIRE(std::is_same<E0::Signature, void()>{});
}
}