Skip to content

Commit

Permalink
add an e2e test for iterator ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
mtghorbani committed Jul 19, 2024
1 parent b56c0ff commit 7276bbb
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/variable-ordering.stur
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
symbols: N, M
iters: covar -> i, j, k, iter
covar(j, k) := X(i, j) * X(i, k) * (0 < iter <= 1000)
covar:D(i, j) := (0 <= i < N) * (0 <= j < N)
X:D(i, j) := (0 <= i < M) * (0 <= j < N)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

#include <iostream>
#include <random>
#include <algorithm>
#include <chrono>

using namespace std;
using namespace std::chrono;

extern "C"
void fn(double ** covar, double ** X, int N, int M) {


long time_computation = 0, start_computation, end_computation;
start_computation = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
for (int i = 0; i < M; ++i) {

for (int j = 0; j < N; ++j) {

for (int k = 0; k < min({(j) + 1, N}); ++k) {


covar[j][k] += (X[i][k] * X[i][j]);
}
}
}
end_computation = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
time_computation = end_computation - start_computation;
cout << time_computation << endl;
long time_reconstruction = 0, start_reconstruction, end_reconstruction;
start_reconstruction = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
for (int j = 0; j < N; ++j) {

int kp = j;
for (int k = max({(j) + 1, 0}); k < N; ++k) {

int jp = k;
covar[j][k] = covar[jp][kp];
}
}
end_reconstruction = duration_cast<microseconds>(system_clock::now().time_since_epoch()).count();
time_reconstruction = end_reconstruction - start_reconstruction;
cout << time_reconstruction << endl;

}
22 changes: 22 additions & 0 deletions src/test/scala/uk/ac/ed/dal/structtensor/codegen/CodegenTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2130,4 +2130,26 @@ class CodegenTest extends AnyFlatSpec with Matchers {
val lines2 = file2.getLines().toList
lines2 should be(lines1)
}

it should "generate code with variable ordering without the body" in {
Utils.cnt = 0
Main.main(
Array(
"-i",
"examples/variable-ordering.stur",
"-o",
"src/test/resources/test_outputs/variable-ordering_wo_body_test.cpp"
)
)

val file1 = scala.io.Source.fromFile(
"src/test/resources/correct_test_outputs/variable-ordering_wo_body.cpp"
)
val file2 = scala.io.Source.fromFile(
"src/test/resources/test_outputs/variable-ordering_wo_body_test.cpp"
)
val lines1 = file1.getLines().toList
val lines2 = file2.getLines().toList
lines2 should be(lines1)
}
}

0 comments on commit 7276bbb

Please sign in to comment.