summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/multi_ncut/src
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/multi_ncut/src
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/multi_ncut/src')
-rw-r--r--SD-VBS/benchmarks/multi_ncut/src/c/.computeMultiW.c.swpbin0 -> 12288 bytes
-rw-r--r--SD-VBS/benchmarks/multi_ncut/src/c/script_multi_ncut.c90
-rw-r--r--SD-VBS/benchmarks/multi_ncut/src/c/segment-graph.c95
-rw-r--r--SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c142
-rw-r--r--SD-VBS/benchmarks/multi_ncut/src/c/segment.h46
5 files changed, 373 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/multi_ncut/src/c/.computeMultiW.c.swp b/SD-VBS/benchmarks/multi_ncut/src/c/.computeMultiW.c.swp
new file mode 100644
index 0000000..a3b35c6
--- /dev/null
+++ b/SD-VBS/benchmarks/multi_ncut/src/c/.computeMultiW.c.swp
Binary files differ
diff --git a/SD-VBS/benchmarks/multi_ncut/src/c/script_multi_ncut.c b/SD-VBS/benchmarks/multi_ncut/src/c/script_multi_ncut.c
new file mode 100644
index 0000000..e4f7912
--- /dev/null
+++ b/SD-VBS/benchmarks/multi_ncut/src/c/script_multi_ncut.c
@@ -0,0 +1,90 @@
1/********************************
2Author: Sravanthi Kota Venkata
3********************************/
4
5#include <stdio.h>
6#include <stdlib.h>
7#include "segment.h"
8#include "extra.h"
9#define MAX_EDGE 500000
10int main(int argc, char* argv[])
11{
12 SET_UP
13 float sigma = 0.6;
14 float k = 4;
15 int min_size = 10;
16 char im1[256];
17 int num_ccs[1] = {0};
18 I2D *out;
19 I2D* im;
20 I2D* seg;
21 I2D* kernel;
22 I2D* ind;
23 I2D* output;
24 int ret;
25 int *segments;
26 edge* edges;
27 universe* u;
28
29 F2D *imageOut, *tempOut;
30 F2D *edgeWeights, *in;
31 printf("Input image: ");
32 scanf("%s", im1);
33 im = readImage(im1);
34
35
36 int height, width, num_edges, num_vertices;
37 height = im->height;
38 width = im->width;
39 num_edges = MAX_EDGE;
40 num_vertices = width * height;
41 segments = (int *) malloc(height*width*sizeof(int));
42 edges = (edge*)malloc(sizeof(edge)*width*height*4);
43 imageOut = fSetArray(height, width, 0);
44 tempOut = fSetArray(height, width, 0);
45 kernel = iMallocHandle(1,5);
46 edgeWeights = fMallocHandle(1, num_edges);
47 in = fDeepCopy(edgeWeights);
48 ind = fMallocHandle(1, num_edges);
49 u = (universe*)malloc(sizeof(universe));
50 u->elts = (uni_elt*)malloc(sizeof(uni_elt)*num_vertices);
51 output = iMallocHandle(height, width);
52
53 printf("start\n");
54 for_each_job{
55 seg = segment_image(im, sigma, k, min_size, num_ccs, segments, edges, imageOut, tempOut, kernel, edgeWeights, in, ind, u, output);
56 out = seg;
57 }
58 printf("end..\n");
59#ifdef CHECK
60 /** Self checking - use expected.txt from data directory **/
61 {
62 int ret=0;
63 float tol = 0;
64
65#ifdef GENERATE_OUTPUT
66 writeMatrix(out, argv[1]);
67#endif
68
69 ret = selfCheck(out, "./expected_C.txt", tol);
70 if(ret < 0)
71 printf("Error in Multi N Cut\n");
72 }
73#endif
74
75 iFreeHandle(im);
76 free(edges);
77 free(segments);
78 free(tempOut);
79 free(imageOut);
80 free(edgeWeights);
81 free(in);
82 free(ind);
83 free(output);
84 free(u->elts);
85 free(u);
86 WRITE_TO_FILE
87 return 0;
88}
89
90
diff --git a/SD-VBS/benchmarks/multi_ncut/src/c/segment-graph.c b/SD-VBS/benchmarks/multi_ncut/src/c/segment-graph.c
new file mode 100644
index 0000000..13b219b
--- /dev/null
+++ b/SD-VBS/benchmarks/multi_ncut/src/c/segment-graph.c
@@ -0,0 +1,95 @@
1/********************************
2Author: Sravanthi Kota Venkata
3********************************/
4
5#include <stdio.h>
6#include <stdlib.h>
7#include "segment.h"
8
9// threshold function
10#define THRESHOLD(size, c) (c/size)
11
12int find(universe* u, int x)
13{
14 int y=x;
15 while (y != u->elts[y].p)
16 y = u->elts[y].p;
17 u->elts[x].p = y;
18 return y;
19}
20
21void join(universe* u, int x, int y)
22{
23 if (u->elts[x].rank > u->elts[y].rank)
24 {
25 u->elts[y].p = x;
26 u->elts[x].size += u->elts[y].size;
27 }
28 else
29 {
30 u->elts[x].p = y;
31 u->elts[y].size += u->elts[x].size;
32 if (u->elts[x].rank == u->elts[y].rank)
33 u->elts[y].rank++;
34 }
35 u->num--;
36 return ;
37}
38
39universe *segment_graph(int num_vertices, int num_edges, edge *edges, float c, F2D* edgeWeights, F2D* in, I2D* ind,
40 universe* u)
41{
42 float threshold[num_vertices];
43 int i, a, b, j, k;
44 //universe *u;
45 //F2D *edgeWeights;
46 I2D *indices;
47
48 edgeWeights = fResetHandle(edgeWeights,1,num_edges);
49
50 for(i=0; i<num_edges; i++)
51 asubsref(edgeWeights,i) = edges[i].w;
52
53 // sort edges by weight
54 indices = fResortIndices(edgeWeights,1, in, ind);
55
56 // make a disjoint-set forest
57 //u = (universe*)malloc(sizeof(universe));
58 //u->elts = (uni_elt*)malloc(sizeof(uni_elt)*num_vertices);
59 u->num = num_vertices;
60 for(i=0; i<num_vertices; i++)
61 {
62 u->elts[i].rank = 0;
63 u->elts[i].size = 1;
64 u->elts[i].p = i;
65 }
66
67 // init thresholds
68 for (i = 0; i < num_vertices; i++)
69 arrayref(threshold,i) = THRESHOLD(1,c);
70
71 // for each edge, in non-decreasing weight order...
72 for (i = 0; i < num_edges; i++)
73 {
74 edge *pedge = &edges[ asubsref(indices,i) ];
75
76 // components conected by this edge
77 a = find(u, pedge->a);
78 b = find(u, pedge->b);
79 if (a != b)
80 {
81 if ((pedge->w <= arrayref(threshold,a)) && (pedge->w <= arrayref(threshold,b)))
82 {
83 join(u, a, b);
84 a = find(u, a);
85 arrayref(threshold,a) = pedge->w + THRESHOLD(u->elts[a].size, c);
86 }
87 }
88 }
89
<