source: CIVL/examples/arithmetic/matmatBad.cvl@ 397ae5f

main test-branch
Last change on this file since 397ae5f was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 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#include<civlc.cvh>
12#define MIN(lhs, A, B) if ((A)<(B)) lhs=(A); else lhs=(B);
13
14$input int BOUND = 3;
15$input int L;
16$assume(1<=L && L<=BOUND);
17$input int M;
18$assume(1<=M && M<=BOUND);
19$input int N;
20$assume(1<=N && N<=BOUND);
21$input int TILE_SIZE;
22$assume(1<=TILE_SIZE && TILE_SIZE<=BOUND);
23$input double A[L][M];
24$input double B[M][N];
25double C[L][N]; // A*B computed by standard algorithm
26double D[L][N]; // A*B computed by tiled algorithm
27
28void spec() {
29 for (int i = 0; i < L; i++)
30 for (int j = 0; j < N; j++) {
31 C[i][j] = 0.0;
32 for (int k = 0; k < M; k++)
33 C[i][j] += A[i][k] * B[k][j];
34 }
35}
36
37void rowdist() {
38 int hi1, hi2, hi3;
39
40 for (int i = 0; i < L; i++) {
41 for (int j = 0; j < N; j++) {
42 D[i][j] = 0.0;
43 }
44 }
45
46 for (int ii = 0; ii < L; ii+=TILE_SIZE) {
47 for (int jj = 0; jj < N; jj+=TILE_SIZE) {
48 for (int kk = 0; kk < M; kk+=TILE_SIZE) {
49 MIN(hi1, ii+TILE_SIZE, L);
50 for (int i = ii; i < hi1; i++) {
51 MIN(hi2, jj+TILE_SIZE, N);
52 for (int j = jj; j < hi2; j++) {
53 MIN(hi3, kk+TILE_SIZE, M);
54 for (int k = kk; k < hi1; k++) // oops hi1->hi3
55 D[i][j] = D[i][j] + A[i][k] * B[k][j];
56 }
57 }
58 }
59 }
60 }
61}
62
63void main() {
64 spec();
65 rowdist();
66 for (int i = 0; i < L; i++) {
67 for (int j = 0; j < N; j++) {
68 $assert(C[i][j] == D[i][j]);
69 }
70 }
71}
Note: See TracBrowser for help on using the repository browser.