Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal benchmarking script that supports apex and has debug mode #64

Open
wants to merge 10 commits into
base: paper_patches
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/src/codegenvisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ struct StatementVisitor {
//auto const& rk = std::get<std::shared_ptr<range_kind>>(node->indexSet.kind);
//auto & indices = rk->args;

os << "chplx::forall(chplx::Range{";
os << "chplx::forall(HPX_CURRENT_SOURCE_LOCATION(), chplx::Range{";

if(node->indexSet.size() == 1) {
ExprVisitor ev{os};
Expand Down Expand Up @@ -680,7 +680,7 @@ struct StatementVisitor {
//auto const& rk = std::get<std::shared_ptr<range_kind>>(node->indexSet.kind);
//auto & indices = rk->args;

os << "chplx::coforall(chplx::Range{";
os << "chplx::coforall(HPX_CURRENT_SOURCE_LOCATION(), chplx::Range{";
/*
if(std::holds_alternative<int_kind>(indices[0].kind)) {
os << int_kind::value(indices[0].literal[0]);
Expand Down
1 change: 1 addition & 0 deletions backend/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(tests
fnc
forall
tup
stream
)

foreach(test ${tests})
Expand Down
51 changes: 29 additions & 22 deletions backend/test/forall/forall.cpp.good
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ namespace forall {
B(i) = 1.000000;
});
#line 43 "forall.chpl"
chplx::forall(chplx::Range{0, 9}, [&](auto i) {
chplx::forall(
HPX_CURRENT_SOURCE_LOCATION(), chplx::Range{0, 9}, [&](auto i) {
#line 44 "forall.chpl"
B(i) = 1.000000;
});
B(i) = 1.000000;
});
};

void __thisModule::__main()
Expand All @@ -36,20 +37,22 @@ namespace forall {
std::cout << i << std::endl;
});
#line 16 "forall.chpl"
chplx::forall(chplx::Range{0, 10}, [&](auto i) {
chplx::forall(
HPX_CURRENT_SOURCE_LOCATION(), chplx::Range{0, 10}, [&](auto i) {
#line 17 "forall.chpl"
std::cout << i << std::endl;
});
std::cout << i << std::endl;
});
#line 20 "forall.chpl"
chplx::forLoop(chplx::Range{0, N}, [&](auto i) {
#line 21 "forall.chpl"
std::cout << i << std::endl;
});
#line 24 "forall.chpl"
chplx::forall(chplx::Range{0, N}, [&](auto i) {
chplx::forall(
HPX_CURRENT_SOURCE_LOCATION(), chplx::Range{0, N}, [&](auto i) {
#line 25 "forall.chpl"
std::cout << i << std::endl;
});
std::cout << i << std::endl;
});
#line 28 "forall.chpl"
chplx::forLoop(chplx::Range{0, N + 1}, [&](auto i) {
#line 29 "forall.chpl"
Expand All @@ -58,29 +61,32 @@ namespace forall {
std::cout << i << std::endl;
});
#line 33 "forall.chpl"
chplx::forall(chplx::Range{0, N + 1}, [&](auto i) {
chplx::forall(
HPX_CURRENT_SOURCE_LOCATION(), chplx::Range{0, N + 1}, [&](auto i) {
#line 34 "forall.chpl"
A(i) = 1.000000;
A(i) = 1.000000;
#line 35 "forall.chpl"
std::cout << i << std::endl;
});
std::cout << i << std::endl;
});
#line 48 "forall.chpl"
chplx::forLoop(chplx::Range{0, 9}, [&](auto i) {
#line 49 "forall.chpl"
A(i) = i;
});
#line 51 "forall.chpl"
chplx::forall(chplx::Range{0, 9}, [&](auto i) {
chplx::forall(
HPX_CURRENT_SOURCE_LOCATION(), chplx::Range{0, 9}, [&](auto i) {
#line 52 "forall.chpl"
A(i) = i;
});
A(i) = i;
});
#line 54 "forall.chpl"
chplx::Array<std::int64_t, chplx::Domain<1>> B(chplx::Range(0, 2));
#line 56 "forall.chpl"
chplx::coforall(chplx::Range{0, 2}, [&](auto tid) {
chplx::coforall(
HPX_CURRENT_SOURCE_LOCATION(), chplx::Range{0, 2}, [&](auto tid) {
#line 57 "forall.chpl"
B(tid) = tid;
});
B(tid) = tid;
});
#line 60 "forall.chpl"
chplx::forLoop(chplx::Range{0, 2}, [&](auto i) {
#line 61 "forall.chpl"
Expand All @@ -89,10 +95,11 @@ namespace forall {
#line 63 "forall.chpl"
chplx::Array<std::int64_t, chplx::Domain<1>> C(chplx::Range(0, 2));
#line 64 "forall.chpl"
chplx::coforall(chplx::Range{0, 2}, [&](auto tid) {
chplx::coforall(
HPX_CURRENT_SOURCE_LOCATION(), chplx::Range{0, 2}, [&](auto tid) {
#line 65 "forall.chpl"
C(tid) = tid;
});
C(tid) = tid;
});
#line 67 "forall.chpl"
chplx::forLoop(chplx::Range{0, 2}, [&](auto i) {
#line 68 "forall.chpl"
Expand Down
97 changes: 97 additions & 0 deletions backend/test/gups.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
use Time;
use Math;
use CTypes;

extern proc getenv(name : c_string) : c_string;

proc computeProblemSize(numArrays : int, physicalMemoryBytes : int, memRatio : int, returnLog2 : bool) {
var totalMem = physicalMemoryBytes;
var memoryTarget = totalMem / memRatio;
var numBytesPerType : int = c_sizeof(int) : int;
var bytesPerIndex :int = numArrays * numBytesPerType;
var numIndices : int = memoryTarget / bytesPerIndex;

var lgProblemSize : int = ceil(log2(numIndices:real)) : int;

if (returnLog2) {
numIndices = 2**lgProblemSize;
if (numIndices * bytesPerIndex <= memoryTarget) {
numIndices *= 2;
lgProblemSize += 1;
}
}

return if returnLog2 then lgProblemSize else numIndices;
}

proc getNextRandom(x : int) : int {
var poly = 0x7;
var hirandbit = 0x1 << (64-1);
return (x << 1) ^ (if (x & hirandbit) then poly else 0);
}

proc computeM2Values(m2 : [] int, count : int) {
var nextval = 0x1;
for i in 0..count {
m2[i] = nextval;
nextval = getNextRandom(nextval);
nextval = getNextRandom(nextval);
}
}

proc getNthRandom(N : int, m2 : [] int, m2count :int) {
var ran = 0x2;
var i :int = ceil(log2(N)) : int;
var val = 0;
var J = 0;
for j in 0..i {
J = i-j;
for k in 1..m2count {
if ((ran >> (k-1)) & 1) then val ^= m2(k-1);
}
ran = val;
if ((N >> J) & 1) then getNextRandom(ran);
}
return ran;
}

proc RAStream(vals : [] int, numvals : int, m2 : [] int, m2count : int) {
var val = getNthRandom(2, m2, m2count);
for i in 0..numvals {
val = getNextRandom(val);
vals[i] = val;
}
}

param randWidth = 64;
param physicalMemory = 17179869184; //1024;
var memRatio = 4;
var numTables = 1;

var m2 : [0..randWidth] int;
computeM2Values(m2, randWidth);

var N_U = 0;
var n = 0;
n = computeProblemSize(numTables, physicalMemory, memRatio, false);
N_U = n+2;

var z = N_U;
var randval: [0..z] int;

var indexMask = z - 1;
var T : [0..z] int;

for i in 0..z {
T[i] = i;
}

var timer : stopwatch;

timer.start();
RAStream(randval, z, m2, randWidth);
forall r in 0..z {
T ( randval ( r ) & indexMask ) ^= randval(r);
}
timer.stop();
writeln(getenv('CHPL_RT_NUM_THREADS_PER_LOCALE'.c_str()):string,",", timer.elapsed());
111 changes: 111 additions & 0 deletions backend/test/gups_cpp.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
proc getNextRandom(x : int) : int {
var poly = 0;
inlinecxx("{} = 0x7;", poly);
var hirandbit = 0;
inlinecxx("{} = 0x1 << (64-1);", hirandbit);
inlinecxx("{} = ({} << 1) ^ ( ({} & {}) ? {} : 0);", x, x, x, hirandbit, poly);
return x;
}

proc computeProblemSize(numArrays : int, physicalMemoryBytes : int, memRatio : int, returnLog2 : bool) : int {
var totalMem = physicalMemoryBytes;
var memoryTarget = totalMem / memRatio;
var numBytesPerType = 0;
inlinecxx("{} = sizeof(std::int64_t);", numBytesPerType);
var bytesPerIndex = numArrays * numBytesPerType;
var numIndices = memoryTarget / bytesPerIndex;

var lgProblemSize = 0;
inlinecxx("{} = std::log2(numIndices);", lgProblemSize);

if (returnLog2) {
//numIndices = 2**lgProblemSize;
inlinecxx("{} = std::pow(2,{});", numIndices, lgProblemSize);
inlinecxx("if({} * {} <= {})", numIndices, bytesPerIndex, memoryTarget);
inlinecxx("{} *= 2;", numIndices);
inlinecxx("if({} * {} <= {})", numIndices, bytesPerIndex, memoryTarget);
inlinecxx("{} += 1;", lgProblemSize);
}

var retval : int = 0;
inlinecxx("{} = {} ? {} : {};", retval, returnLog2, lgProblemSize, numIndices);
return retval;
}


proc computeM2Values(m2 : [] int, count : int) :bool {
var nextval = 0;
inlinecxx("{} = 0x1;", nextval);
for i in 0..count {
m2[i] = nextval;
nextval = getNextRandom(nextval);
nextval = getNextRandom(nextval);
}

return true;
}

proc getNthRandom(N : int, m2 : [] int, m2count : int) {
var ran = 0;
inlinecxx("{} = 0x2;", ran);
var i = 0;
inlinecxx("{} = std::ceil(std::log2(static_cast<double>({})));", i, N);
var val = 0;
var J = 0;
for j in 0..i {
J = i-j;
for k in 1..m2count {
inlinecxx("if (({} >> ({}-1)) & 1) {} ^= {} [ ({}-1) ];", ran, k, val, m2, k);
}
ran = val;
inlinecxx("if(({} >> {}) & 1) {} = getNextRandom({});", N, J, ran, ran);
}

return ran;
}

proc RAStream(vals : [] int, numvals : int, m2 : [] int, m2count : int) {

var val = getNthRandom(2, m2, m2count);
for i in 0..numvals {
val = getNextRandom(val);
vals[i] = val;
}
}

param randWidth = 64;
var physicalMemory = 0;
inlinecxx("{} = 17179869184l;", physicalMemory);
param memRatio = 4;
param numTables = 1;

var m2 : [0..randWidth] int;
var val = computeM2Values(m2, randWidth);

var N_U = 0;
var n = 1;
n = computeProblemSize(numTables, physicalMemory, memRatio, false);
inlinecxx("{} = {}+2;", N_U, n);

var z : int;
z = N_U;
var randval : [0..z] int;

var indexMask = z - 1;

var T : [0..z] int;

for i in 0..z {
T[i] = i;
}

inlinecxx("hpx::chrono::high_resolution_timer gups;");

RAStream(randval, z, m2, randWidth);
forall r in 0..z {
inlinecxx("{} [ {} [ {} ] & {} ] ^= {} [ {} ];", T, randval, r, indexMask, randval, r);
}

inlinecxx("auto elapsed = gups.elapsed();");

inlinecxx("std::cout << hpx::resource::get_num_threads() << \",\" << elapsed << std::endl;");
19 changes: 11 additions & 8 deletions backend/test/heat/heat.cpp.good
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ namespace heat {
#line 27 "heat.chpl"
auto NX = nx + 1;
#line 28 "heat.chpl"
chplx::forall(chplx::Range{1, NX - 1}, [&](auto i) {
chplx::forall(HPX_CURRENT_SOURCE_LOCATION(), chplx::Range{1, NX - 1},
[&](auto i) {
#line 30 "heat.chpl"
d2(i) = d(i) +
(((dt * k) / (dx * dx)) * ((d(1 + i) + d(1 - i)) - (2 * d(i))));
});
d2(i) = d(i) +
(((dt * k) / (dx * dx)) *
((d(1 + i) + d(1 - i)) - (2 * d(i))));
});
#line 32 "heat.chpl"
d2(0) = d2(1 - NX);
#line 33 "heat.chpl"
Expand Down Expand Up @@ -49,12 +51,13 @@ namespace heat {
#line 41 "heat.chpl"
chplx::Array<double, chplx::Domain<1>> data2(chplx::Range(0, NX));
#line 43 "heat.chpl"
chplx::forall(chplx::Range{0, NX}, [&](auto i) {
chplx::forall(
HPX_CURRENT_SOURCE_LOCATION(), chplx::Range{0, NX}, [&](auto i) {
#line 44 "heat.chpl"
data(i) = 1 + (((i - 1) + nx) % nx);
data(i) = 1 + (((i - 1) + nx) % nx);
#line 45 "heat.chpl"
data2(i) = 0;
});
data2(i) = 0;
});
#line 52 "heat.chpl"
hpx::chrono::high_resolution_timer t;
#line 54 "heat.chpl"
Expand Down
Loading
Loading