source: CIVL/examples/arithmetic/matmatBad.cvl

main
Last change on this file was b689afd, checked in by Stephen Siegel <siegel@…>, 4 weeks ago

Getting rid of unused examples that are not good and starting to clean
up others.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@6036 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/* matmat.cvl: two matrix-matrix multiplication algorithms.
2 * The first is the standard one, the second uses a complex
3 * tiling optimization. This model is used to determine
4 * whether the two are equivalent. Example:
5 * civl verify matmatBad.cvl -inputBOUND=4
6 * or (if you want to find the minimal counterexample)
7 * civl verify matmatBad.cvl -inputBOUND=4 -min
8 * will verify equivalent for all matrix dimensions and tile
9 * sizes in the range 1..4.
10 */
11#define MIN(lhs, A, B) if ((A)<(B)) lhs=(A); else lhs=(B);
12
13$input int BOUND = 3;
14$input int L;
15$assume(1<=L && L<=BOUND);
16$input int M;
17$assume(1<=M && M<=BOUND);
18$input int N;
19$assume(1<=N && N<=BOUND);
20$input int TILE_SIZE;
21$assume(1<=TILE_SIZE && TILE_SIZE<=BOUND);
22$input double A[L][M];
23$input double B[M][N];
24double C[L][N]; // A*B computed by standard algorithm
25double D[L][N]; // A*B computed by tiled algorithm
26
27void spec() {
28 for (int i = 0; i < L; i++)
29 for (int j = 0; j < N; j++) {
30 C[i][j] = 0.0;
31 for (int k = 0; k < M; k++)
32 C[i][j] += A[i][k] * B[k][j];
33 }
34}
35
36void rowdist() {
37 int hi1, hi2, hi3;
38
39 for (int i = 0; i < L; i++) {
40 for (int j = 0; j < N; j++) {
41 D[i][j] = 0.0;
42 }
43 }
44
45 for (int ii = 0; ii < L; ii+=TILE_SIZE) {
46 for (int jj = 0; jj < N; jj+=TILE_SIZE) {
47 for (int kk = 0; kk < M; kk+=TILE_SIZE) {
48 MIN(hi1, ii+TILE_SIZE, L);
49 for (int i = ii; i < hi1; i++) {
50 MIN(hi2, jj+TILE_SIZE, N);
51 for (int j = jj; j < hi2; j++) {
52 MIN(hi3, kk+TILE_SIZE, M);
53 for (int k = kk; k < hi1; k++) // oops hi1->hi3
54 D[i][j] = D[i][j] + A[i][k] * B[k][j];
55 }
56 }
57 }
58 }
59 }
60}
61
62void main() {
63 spec();
64 rowdist();
65 for (int i = 0; i < L; i++) {
66 for (int j = 0; j < N; j++) {
67 $assert(C[i][j] == D[i][j]);
68 }
69 }
70}
Note: See TracBrowser for help on using the repository browser.