summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/disparity/src/c/script_disparity.c
diff options
context:
space:
mode:
authorLeo Chan <leochanj@live.unc.edu>2020-10-22 01:53:21 -0400
committerJoshua Bakita <jbakita@cs.unc.edu>2020-10-22 01:56:35 -0400
commitd17b33131c14864bd1eae275f49a3f148e21cf29 (patch)
tree0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/benchmarks/disparity/src/c/script_disparity.c
parent601ed25a4c5b66cb75315832c15613a727db2c26 (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/c/script_disparity.c')
-rw-r--r--SD-VBS/benchmarks/disparity/src/c/script_disparity.c132
1 files changed, 132 insertions, 0 deletions
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/********************************
2Author: 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
11int 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}