diff options
author | Leo Chan <leochanj@live.unc.edu> | 2020-10-22 01:53:21 -0400 |
---|---|---|
committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-22 01:56:35 -0400 |
commit | d17b33131c14864bd1eae275f49a3f148e21cf29 (patch) | |
tree | 0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/benchmarks/disparity/src | |
parent | 601ed25a4c5b66cb75315832c15613a727db2c26 (diff) |
Squashed commit of the sb-vbs branch.
Includes the SD-VBS benchmarks modified to:
- Use libextra to loop as realtime jobs
- Preallocate memory before starting their main computation
- Accept input via stdin instead of via argc
Does not include the SD-VBS matlab code.
Fixes libextra execution in LITMUS^RT.
Diffstat (limited to 'SD-VBS/benchmarks/disparity/src')
-rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/computeSAD.c | 27 | ||||
-rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/correlateSAD_2D.c | 34 | ||||
-rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/disparity.h | 24 | ||||
-rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/finalSAD.c | 28 | ||||
-rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/findDisparity.c | 29 | ||||
-rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/getDisparity.c | 43 | ||||
-rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/integralImage2D2D.c | 31 | ||||
-rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/padarray2.c | 33 | ||||
-rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/padarray4.c | 41 | ||||
-rw-r--r-- | SD-VBS/benchmarks/disparity/src/c/script_disparity.c | 132 |
10 files changed, 422 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/disparity/src/c/computeSAD.c b/SD-VBS/benchmarks/disparity/src/c/computeSAD.c new file mode 100644 index 0000000..e12bd55 --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/computeSAD.c | |||
@@ -0,0 +1,27 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include "disparity.h" | ||
8 | |||
9 | void computeSAD(I2D *Ileft, I2D* Iright_moved, F2D* SAD) | ||
10 | { | ||
11 | int rows, cols, i, j, diff; | ||
12 | |||
13 | rows = Ileft->height; | ||
14 | cols = Ileft->width; | ||
15 | |||
16 | for(i=0; i<rows; i++) | ||
17 | { | ||
18 | for(j=0; j<cols; j++) | ||
19 | { | ||
20 | diff = subsref(Ileft,i,j) - subsref(Iright_moved,i,j); | ||
21 | subsref(SAD,i,j) = diff * diff; | ||
22 | } | ||
23 | } | ||
24 | |||
25 | return; | ||
26 | } | ||
27 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/correlateSAD_2D.c b/SD-VBS/benchmarks/disparity/src/c/correlateSAD_2D.c new file mode 100644 index 0000000..6b43cbd --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/correlateSAD_2D.c | |||
@@ -0,0 +1,34 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include "disparity.h" | ||
8 | |||
9 | void correlateSAD_2D(I2D* Ileft, I2D* Iright, I2D* Iright_moved, int win_sz, int disparity, F2D* SAD, F2D* integralImg, F2D* retSAD, I2D* range) | ||
10 | { | ||
11 | int rows, cols; | ||
12 | int i, j, endRM; | ||
13 | //I2D *range; | ||
14 | |||
15 | //iResetArray(range,1,2,0); | ||
16 | subsref(range,0,0) = 0; | ||
17 | subsref(range,0,1) = disparity; | ||
18 | |||
19 | rows = Iright_moved->height; | ||
20 | cols = Iright_moved->width; | ||
21 | |||
22 | for(i=0; i<rows*cols; i++) | ||
23 | asubsref(Iright_moved,i) = 0; | ||
24 | |||
25 | padarray4(Iright, range, -1, Iright_moved); | ||
26 | |||
27 | computeSAD(Ileft, Iright_moved, SAD); | ||
28 | integralImage2D2D(SAD, integralImg); | ||
29 | finalSAD(integralImg, win_sz, retSAD); | ||
30 | |||
31 | //iFreeHandle(range); | ||
32 | return; | ||
33 | } | ||
34 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/disparity.h b/SD-VBS/benchmarks/disparity/src/c/disparity.h new file mode 100644 index 0000000..8617a87 --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/disparity.h | |||
@@ -0,0 +1,24 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #ifndef _DISP_ | ||
6 | #define _DISP_ | ||
7 | |||
8 | #include "sdvbs_common.h" | ||
9 | void computeSAD(I2D *Ileft, I2D* Iright_moved, F2D* SAD); | ||
10 | I2D* getDisparity(I2D* Ileft, I2D* Iright, int win_sz, int max_shift, | ||
11 | I2D* minSAD, I2D* retDisp, I2D* halfWin, | ||
12 | I2D* IrightPadded, I2D* IleftPadded, I2D* Iright_moved, | ||
13 | F2D* retSAD, F2D* SAD, F2D* integralImg, | ||
14 | I2D* range); | ||
15 | void finalSAD(F2D* integralImg, int win_sz, F2D* retSAD); | ||
16 | void findDisparity(F2D* retSAD, F2D* minSAD, I2D* retDisp, int level, int nr, int nc); | ||
17 | void integralImage2D2D(F2D* SAD, F2D* integralImg); | ||
18 | void correlateSAD_2D(I2D* Ileft, I2D* Iright, I2D* Iright_moved, int win_sz, int disparity, F2D* SAD, F2D* integralImg, F2D* retSAD, I2D* range); | ||
19 | I2D* padarray2(I2D* inMat, I2D* borderMat); | ||
20 | void padarray4(I2D* inMat, I2D* borderMat, int dir, I2D* paddedArray); | ||
21 | |||
22 | #endif | ||
23 | |||
24 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/finalSAD.c b/SD-VBS/benchmarks/disparity/src/c/finalSAD.c new file mode 100644 index 0000000..8155820 --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/finalSAD.c | |||
@@ -0,0 +1,28 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include "disparity.h" | ||
8 | |||
9 | void finalSAD(F2D* integralImg, int win_sz, F2D* retSAD) | ||
10 | { | ||
11 | int endR, endC; | ||
12 | int i, j, k; | ||
13 | |||
14 | endR = integralImg->height; | ||
15 | endC = integralImg->width; | ||
16 | |||
17 | k = 0; | ||
18 | for(j=0; j<(endC-win_sz); j++) | ||
19 | { | ||
20 | for(i=0; i<(endR-win_sz); i++) | ||
21 | { | ||
22 | subsref(retSAD,i,j) = subsref(integralImg,(win_sz+i),(j+win_sz)) + subsref(integralImg,(i+1) ,(j+1)) - subsref(integralImg,(i+1),(j+win_sz)) - subsref(integralImg,(win_sz+i),(j+1)); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | return; | ||
27 | } | ||
28 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/findDisparity.c b/SD-VBS/benchmarks/disparity/src/c/findDisparity.c new file mode 100644 index 0000000..6335daf --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/findDisparity.c | |||
@@ -0,0 +1,29 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include "disparity.h" | ||
8 | |||
9 | void findDisparity(F2D* retSAD, F2D* minSAD, I2D* retDisp, int level, int nr, int nc) | ||
10 | { | ||
11 | int i, j, a, b; | ||
12 | |||
13 | for(i=0; i<nr; i++) | ||
14 | { | ||
15 | for(j=0; j<nc; j++) | ||
16 | { | ||
17 | a = subsref(retSAD,i,j); | ||
18 | b = subsref(minSAD,i,j); | ||
19 | if(a<b) | ||
20 | { | ||
21 | subsref(minSAD,i,j) = a; | ||
22 | subsref(retDisp,i,j) = level; | ||
23 | } | ||
24 | } | ||
25 | } | ||
26 | return; | ||
27 | } | ||
28 | |||
29 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/getDisparity.c b/SD-VBS/benchmarks/disparity/src/c/getDisparity.c new file mode 100644 index 0000000..3246e97 --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/getDisparity.c | |||
@@ -0,0 +1,43 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include "disparity.h" | ||
8 | |||
9 | I2D* getDisparity(I2D* Ileft, I2D* Iright, int win_sz, int max_shift, | ||
10 | I2D* minSAD, I2D* retDisp, I2D* halfWin, | ||
11 | I2D* IrightPadded, I2D* IleftPadded, I2D* Iright_moved, | ||
12 | F2D* retSAD, F2D* SAD, F2D* integralImg, | ||
13 | I2D* range) | ||
14 | { | ||
15 | int nr, nc, k; | ||
16 | int half_win_sz, rows, cols; | ||
17 | |||
18 | nr = Ileft->height; | ||
19 | nc = Ileft->width; | ||
20 | half_win_sz=win_sz/2; | ||
21 | |||
22 | |||
23 | fResetArray(minSAD, nr, nc, 255.0*255.0); | ||
24 | iResetArray(retDisp, nr, nc,max_shift); | ||
25 | iResetArray(halfWin, 1,2,half_win_sz); | ||
26 | |||
27 | rows = IleftPadded->height; | ||
28 | cols = IleftPadded->width; | ||
29 | fResetArray(SAD, rows, cols,255); | ||
30 | fResetArray(integralImg, rows, cols,0); | ||
31 | //fResetArray(retSAD,rows-win_sz, cols-win_sz, 0); | ||
32 | iResetArray(Iright_moved, rows, cols, 0); | ||
33 | |||
34 | for( k=0; k<max_shift; k++) | ||
35 | { | ||
36 | correlateSAD_2D(IleftPadded, IrightPadded, Iright_moved, win_sz, k, SAD, integralImg, retSAD, range); | ||
37 | findDisparity(retSAD, minSAD, retDisp, k, nr, nc); | ||
38 | } | ||
39 | |||
40 | |||
41 | return retDisp; | ||
42 | } | ||
43 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/integralImage2D2D.c b/SD-VBS/benchmarks/disparity/src/c/integralImage2D2D.c new file mode 100644 index 0000000..cc964d1 --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/integralImage2D2D.c | |||
@@ -0,0 +1,31 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include "disparity.h" | ||
8 | |||
9 | void integralImage2D2D(F2D* SAD, F2D* integralImg) | ||
10 | { | ||
11 | int nr, nc, i, j; | ||
12 | |||
13 | nr = SAD->height; | ||
14 | nc = SAD->width; | ||
15 | |||
16 | for(i=0; i<nc; i++) | ||
17 | subsref(integralImg,0,i) = subsref(SAD,0,i); | ||
18 | |||
19 | for(i=1; i<nr; i++) | ||
20 | for(j=0; j<nc; j++) | ||
21 | { | ||
22 | subsref(integralImg,i,j) = subsref(integralImg, (i-1), j) + subsref(SAD,i,j); | ||
23 | } | ||
24 | |||
25 | for(i=0; i<nr; i++) | ||
26 | for(j=1; j<nc; j++) | ||
27 | subsref(integralImg,i,j) = subsref(integralImg, i, (j-1)) + subsref(integralImg,i,j); | ||
28 | |||
29 | return; | ||
30 | |||
31 | } | ||
diff --git a/SD-VBS/benchmarks/disparity/src/c/padarray2.c b/SD-VBS/benchmarks/disparity/src/c/padarray2.c new file mode 100644 index 0000000..49f1938 --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/padarray2.c | |||
@@ -0,0 +1,33 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include "disparity.h" | ||
8 | |||
9 | I2D* padarray2(I2D* inMat, I2D* borderMat) | ||
10 | { | ||
11 | int rows, cols, bRows, bCols, newRows, newCols; | ||
12 | I2D *paddedArray; | ||
13 | int i, j; | ||
14 | |||
15 | rows = inMat->height; | ||
16 | cols = inMat->width; | ||
17 | |||
18 | bRows = borderMat->data[0]; | ||
19 | bCols = borderMat->data[1]; | ||
20 | |||
21 | newRows = rows + bRows*2; | ||
22 | newCols = cols + bCols*2; | ||
23 | |||
24 | paddedArray = iSetArray(newRows, newCols, 0); | ||
25 | |||
26 | for(i=0; i<rows; i++) | ||
27 | for(j=0; j<cols; j++) | ||
28 | subsref(paddedArray, (bRows+i), (bCols+j)) = subsref(inMat, i, j); | ||
29 | |||
30 | return paddedArray; | ||
31 | |||
32 | } | ||
33 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/padarray4.c b/SD-VBS/benchmarks/disparity/src/c/padarray4.c new file mode 100644 index 0000000..321cad9 --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/padarray4.c | |||
@@ -0,0 +1,41 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <math.h> | ||
8 | #include "disparity.h" | ||
9 | |||
10 | void padarray4(I2D* inMat, I2D* borderMat, int dir, I2D* paddedArray) | ||
11 | { | ||
12 | int rows, cols, bRows, bCols, newRows, newCols; | ||
13 | int i, j; | ||
14 | int adir; | ||
15 | |||
16 | adir = abs(dir); | ||
17 | rows = inMat->height; | ||
18 | cols = inMat->width; | ||
19 | |||
20 | bRows = borderMat->data[0]; | ||
21 | bCols = borderMat->data[1]; | ||
22 | |||
23 | newRows = rows + bRows; | ||
24 | newCols = cols + bCols; | ||
25 | |||
26 | if(dir ==1) | ||
27 | { | ||
28 | for(i=0; i<rows; i++) | ||
29 | for(j=0; j<cols; j++) | ||
30 | subsref(paddedArray, i, j) = subsref(inMat,i,j); | ||
31 | } | ||
32 | else | ||
33 | { | ||
34 | for(i=0; i<rows-bRows; i++) | ||
35 | for(j=0; j<cols-bCols; j++) | ||
36 | subsref(paddedArray, (bRows+i), (bCols+j)) = subsref(inMat,i,j); | ||
37 | } | ||
38 | |||
39 | return; | ||
40 | } | ||
41 | |||
diff --git a/SD-VBS/benchmarks/disparity/src/c/script_disparity.c b/SD-VBS/benchmarks/disparity/src/c/script_disparity.c new file mode 100644 index 0000000..431c02c --- /dev/null +++ b/SD-VBS/benchmarks/disparity/src/c/script_disparity.c | |||
@@ -0,0 +1,132 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include "disparity.h" | ||
8 | #include <malloc.h> | ||
9 | #include "extra.h" | ||
10 | #define DISPARITY_MEM 1<<24 | ||
11 | int main(int argc, char* argv[]) | ||
12 | { | ||
13 | SET_UP | ||
14 | mallopt(M_TOP_PAD, DISPARITY_MEM); | ||
15 | mallopt(M_MMAP_MAX, 0); | ||
16 | int rows = 32; | ||
17 | int cols = 32; | ||
18 | I2D *imleft, *imright; | ||
19 | volatile I2D* retDisparity; | ||
20 | I2D *IrightPadded, *IleftPadded, *Iright_moved; | ||
21 | I2D *retDisp, *halfWin; | ||
22 | I2D *range; | ||
23 | F2D *retSAD, *minSAD, *SAD, *integralImg; | ||
24 | unsigned int *start, *endC, *elapsed; | ||
25 | |||
26 | int i, j; | ||
27 | char im1[100], im2[100], timFile[100]; | ||
28 | int WIN_SZ=8, SHIFT=64; | ||
29 | FILE* fp; | ||
30 | |||
31 | printf("Image 1: "); | ||
32 | scanf("%s", im1); | ||
33 | printf("Image 2: "); | ||
34 | scanf("%s", im2); | ||
35 | #ifdef CHECK | ||
36 | char checkFile[100] = "./expected_C.txt"; | ||
37 | #endif | ||
38 | imleft = readImage(im1); | ||
39 | imright = readImage(im2); | ||
40 | |||
41 | rows = imleft->height; | ||
42 | cols = imleft->width; | ||
43 | |||
44 | #ifdef test | ||
45 | WIN_SZ = 2; | ||
46 | SHIFT = 1; | ||
47 | #endif | ||
48 | #ifdef sim_fast | ||
49 | WIN_SZ = 4; | ||
50 | SHIFT = 4; | ||
51 | #endif | ||
52 | #ifdef sim | ||
53 | WIN_SZ = 4; | ||
54 | SHIFT = 8; | ||
55 | #endif | ||
56 | |||
57 | |||
58 | int nr, nc, k; | ||
59 | int half_win_sz; | ||
60 | nr = imleft->height; | ||
61 | nc = imleft->width; | ||
62 | half_win_sz = WIN_SZ / 2; | ||
63 | |||
64 | minSAD = fSetArray(nr, nc, 255.0*255.0); | ||
65 | retDisp = iSetArray(nr, nc, SHIFT); | ||
66 | halfWin = iSetArray(1,2,half_win_sz); | ||
67 | |||
68 | |||
69 | if(WIN_SZ > 1) | ||
70 | { | ||
71 | IleftPadded = padarray2(imleft, halfWin); | ||
72 | IrightPadded = padarray2(imright, halfWin); | ||
73 | } | ||
74 | else | ||
75 | { | ||
76 | IleftPadded = imleft; | ||
77 | IrightPadded = imright; | ||
78 | } | ||
79 | |||
80 | int paddedRows, paddedCols; | ||
81 | paddedRows = IleftPadded->height; | ||
82 | paddedCols = IleftPadded->width; | ||
83 | SAD = fSetArray(paddedRows, paddedCols,255); | ||
84 | integralImg = fSetArray(paddedRows, paddedCols,0); | ||
85 | retSAD = fMallocHandle(paddedRows- WIN_SZ, paddedCols - WIN_SZ); | ||
86 | Iright_moved = iSetArray(paddedRows, paddedCols, 0); | ||
87 | |||
88 | range = iMallocHandle(1, 2); | ||
89 | printf("starting..\n"); | ||
90 | for_each_job{ | ||
91 | retDisparity = getDisparity(imleft, imright, WIN_SZ, SHIFT, | ||
92 | minSAD, retDisp, halfWin, | ||
93 | IrightPadded, IleftPadded, Iright_moved, | ||
94 | retSAD, SAD, integralImg, | ||
95 | range); | ||
96 | } | ||
97 | printf("ending\n"); | ||
98 | |||
99 | #ifdef CHECK | ||
100 | /** Self checking - use expected.txt from data directory **/ | ||
101 | { | ||
102 | int tol, ret=0; | ||
103 | tol = 2; | ||
104 | #ifdef GENERATE_OUTPUT | ||
105 | writeMatrix(retDisparity, argv[1]); | ||
106 | #endif | ||
107 | ret = selfCheck(retDisparity, checkFile, tol); | ||
108 | if (ret == -1) | ||
109 | printf("Error in Disparity Map\n"); | ||
110 | } | ||
111 | /** Self checking done **/ | ||
112 | #endif | ||
113 | |||
114 | //end of benchmark | ||
115 | fFreeHandle(minSAD); | ||
116 | fFreeHandle(SAD); | ||
117 | fFreeHandle(integralImg); | ||
118 | iFreeHandle(IrightPadded); | ||
119 | iFreeHandle(IleftPadded); | ||
120 | iFreeHandle(Iright_moved); | ||
121 | fFreeHandle(retSAD); | ||
122 | iFreeHandle(imleft); | ||
123 | iFreeHandle(imright); | ||
124 | iFreeHandle(retDisparity); | ||
125 | iFreeHandle(halfWin); | ||
126 | iFreeHandle(range); | ||
127 | free(start); | ||
128 | free(endC); | ||
129 | free(elapsed); | ||
130 | WRITE_TO_FILE; | ||
131 | return 0; | ||
132 | } | ||