source: CIVL/examples/arithmetic/matmat.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.7 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 matmat.cvl -inputBOUND=4
6 * will verify equivalent for all matrix dimensions and tile
7 * sizes in the range 1..4.
8 */
9#define MIN(lhs, A, B) if ((A)<(B)) lhs=(A); else lhs=(B);
10
11$input int BOUND = 3;
12$input int L;
13$assume(1<=L && L<=BOUND);
14$input int M;
15$assume(1<=M && M<=BOUND);
16$input int N;
17$assume(1<=N && N<=BOUND);
18$input int TILE_SIZE;
19$assume(1<=TILE_SIZE && TILE_SIZE<=BOUND);
20$input double A[L][M];
21$input double B[M][N];
22double C[L][N]; // A*B computed by standard algorithm
23double D[L][N]; // A*B computed by tiled algorithm
24
25void spec() {
26 for (int i = 0; i < L; i++)
27 for (int j = 0; j < N; j++) {
28 C[i][j] = 0.0;
29 for (int k = 0; k < M; k++)
30 C[i][j] += A[i][k] * B[k][j];
31 }
32}
33
34void rowdist() {
35 int hi1, hi2, hi3;
36
37 for (int i = 0; i < L; i++) {
38 for (int j = 0; j < N; j++) {
39 D[i][j] = 0.0;
40 }
41 }
42
43 for (int ii = 0; ii < L; ii+=TILE_SIZE) {
44 for (int jj = 0; jj < N; jj+=TILE_SIZE) {
45 for (int kk = 0; kk < M; kk+=TILE_SIZE) {
46 MIN(hi1, ii+TILE_SIZE, L);
47 for (int i = ii; i < hi1; i++) {
48 MIN(hi2, jj+TILE_SIZE, N);
49 for (int j = jj; j < hi2; j++) {
50 MIN(hi3, kk+TILE_SIZE, M);
51 for (int k = kk; k < hi3; k++)
52 D[i][j] = D[i][j] + A[i][k] * B[k][j];
53 }
54 }
55 }
56 }
57 }
58}
59
60void main() {
61 spec();
62 rowdist();
63 for (int i = 0; i < L; i++) {
64 for (int j = 0; j < N; j++) {
65 $assert(C[i][j] == D[i][j]);
66 }
67 }
68}
Note: See TracBrowser for help on using the repository browser.