source: CIVL/examples/arithmetic/matmat.cvl@ bb03188

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