From d17b33131c14864bd1eae275f49a3f148e21cf29 Mon Sep 17 00:00:00 2001 From: Leo Chan Date: Thu, 22 Oct 2020 01:53:21 -0400 Subject: 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. --- .../multi_ncut/src/c/.computeMultiW.c.swp | Bin 0 -> 12288 bytes .../multi_ncut/src/c/script_multi_ncut.c | 90 +++++++++++++ SD-VBS/benchmarks/multi_ncut/src/c/segment-graph.c | 95 ++++++++++++++ SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c | 142 +++++++++++++++++++++ SD-VBS/benchmarks/multi_ncut/src/c/segment.h | 46 +++++++ 5 files changed, 373 insertions(+) create mode 100644 SD-VBS/benchmarks/multi_ncut/src/c/.computeMultiW.c.swp create mode 100644 SD-VBS/benchmarks/multi_ncut/src/c/script_multi_ncut.c create mode 100644 SD-VBS/benchmarks/multi_ncut/src/c/segment-graph.c create mode 100644 SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c create mode 100644 SD-VBS/benchmarks/multi_ncut/src/c/segment.h (limited to 'SD-VBS/benchmarks/multi_ncut/src') 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 Binary files /dev/null and b/SD-VBS/benchmarks/multi_ncut/src/c/.computeMultiW.c.swp 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 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#include +#include +#include "segment.h" +#include "extra.h" +#define MAX_EDGE 500000 +int main(int argc, char* argv[]) +{ + SET_UP + float sigma = 0.6; + float k = 4; + int min_size = 10; + char im1[256]; + int num_ccs[1] = {0}; + I2D *out; + I2D* im; + I2D* seg; + I2D* kernel; + I2D* ind; + I2D* output; + int ret; + int *segments; + edge* edges; + universe* u; + + F2D *imageOut, *tempOut; + F2D *edgeWeights, *in; + printf("Input image: "); + scanf("%s", im1); + im = readImage(im1); + + + int height, width, num_edges, num_vertices; + height = im->height; + width = im->width; + num_edges = MAX_EDGE; + num_vertices = width * height; + segments = (int *) malloc(height*width*sizeof(int)); + edges = (edge*)malloc(sizeof(edge)*width*height*4); + imageOut = fSetArray(height, width, 0); + tempOut = fSetArray(height, width, 0); + kernel = iMallocHandle(1,5); + edgeWeights = fMallocHandle(1, num_edges); + in = fDeepCopy(edgeWeights); + ind = fMallocHandle(1, num_edges); + u = (universe*)malloc(sizeof(universe)); + u->elts = (uni_elt*)malloc(sizeof(uni_elt)*num_vertices); + output = iMallocHandle(height, width); + + printf("start\n"); + for_each_job{ + seg = segment_image(im, sigma, k, min_size, num_ccs, segments, edges, imageOut, tempOut, kernel, edgeWeights, in, ind, u, output); + out = seg; + } + printf("end..\n"); +#ifdef CHECK + /** Self checking - use expected.txt from data directory **/ + { + int ret=0; + float tol = 0; + +#ifdef GENERATE_OUTPUT + writeMatrix(out, argv[1]); +#endif + + ret = selfCheck(out, "./expected_C.txt", tol); + if(ret < 0) + printf("Error in Multi N Cut\n"); + } +#endif + + iFreeHandle(im); + free(edges); + free(segments); + free(tempOut); + free(imageOut); + free(edgeWeights); + free(in); + free(ind); + free(output); + free(u->elts); + free(u); + WRITE_TO_FILE + return 0; +} + + 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 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#include +#include +#include "segment.h" + +// threshold function +#define THRESHOLD(size, c) (c/size) + +int find(universe* u, int x) +{ + int y=x; + while (y != u->elts[y].p) + y = u->elts[y].p; + u->elts[x].p = y; + return y; +} + +void join(universe* u, int x, int y) +{ + if (u->elts[x].rank > u->elts[y].rank) + { + u->elts[y].p = x; + u->elts[x].size += u->elts[y].size; + } + else + { + u->elts[x].p = y; + u->elts[y].size += u->elts[x].size; + if (u->elts[x].rank == u->elts[y].rank) + u->elts[y].rank++; + } + u->num--; + return ; +} + +universe *segment_graph(int num_vertices, int num_edges, edge *edges, float c, F2D* edgeWeights, F2D* in, I2D* ind, + universe* u) +{ + float threshold[num_vertices]; + int i, a, b, j, k; + //universe *u; + //F2D *edgeWeights; + I2D *indices; + + edgeWeights = fResetHandle(edgeWeights,1,num_edges); + + for(i=0; ielts = (uni_elt*)malloc(sizeof(uni_elt)*num_vertices); + u->num = num_vertices; + for(i=0; ielts[i].rank = 0; + u->elts[i].size = 1; + u->elts[i].p = i; + } + + // init thresholds + for (i = 0; i < num_vertices; i++) + arrayref(threshold,i) = THRESHOLD(1,c); + + // for each edge, in non-decreasing weight order... + for (i = 0; i < num_edges; i++) + { + edge *pedge = &edges[ asubsref(indices,i) ]; + + // components conected by this edge + a = find(u, pedge->a); + b = find(u, pedge->b); + if (a != b) + { + if ((pedge->w <= arrayref(threshold,a)) && (pedge->w <= arrayref(threshold,b))) + { + join(u, a, b); + a = find(u, a); + arrayref(threshold,a) = pedge->w + THRESHOLD(u->elts[a].size, c); + } + } + } + + //fFreeHandle(edgeWeights); + //iFreeHandle(indices); + + return u; +} + diff --git a/SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c b/SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c new file mode 100644 index 0000000..72bc16f --- /dev/null +++ b/SD-VBS/benchmarks/multi_ncut/src/c/segment-image.c @@ -0,0 +1,142 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#include +#include +#include +#include "segment.h" + +#ifndef M_PI +#define M_PI 3.141592653589793 +#endif + +// dissimilarity measure between pixels +float diff(F2D *r, int x1, int y1, int x2, int y2) +{ + return sqrt(abs(( subsref(r,y1,x1) * subsref(r,y1,x1)) - ( subsref(r,y2,x2) * subsref(r,y2,x2)))); +} + +I2D *segment_image(I2D* im, float sigma, float c, int min_size, int *num_ccs, + int* segments, edge* edges, + F2D* imageOut, F2D* tempOut, I2D* kernel, + F2D* edgeWeights, F2D* in, I2D* ind, + universe* u, + I2D* output) +{ + int width = im->width; + int height = im->height; + int num = 0, x, y, i; + F2D* smooth_im; + //I2D *output; + //edge* edges; + int components = 0; +/* int *colors = (int *) malloc(width*height*sizeof(int)); */ + //segments = (int *) malloc(height*width*sizeof(int)); + + // smooth each color channel + smooth_im = imageReblur(im, imageOut, tempOut, kernel); + + //build graph + //edges = (edge*)malloc(sizeof(edge)*width*height*4); + + for (y = 0; y < height; y++) + { + for (x = 0; x < width; x++) + { + segments[y*width+x] = -1; + if (x < width-1) + { + edges[num].a = y * width + x; + edges[num].b = y * width + (x+1); + edges[num].w = diff(smooth_im, x, y, x+1, y); + num++; + } + + if (y < height-1) + { + edges[num].a = y * width + x; + edges[num].b = (y+1) * width + x; + edges[num].w = diff(smooth_im, x, y, x, y+1); + num++; + } + + if ((x < width-1) && (y < height-1)) + { + edges[num].a = y * width + x; + edges[num].b = (y+1) * width + (x+1); + edges[num].w = diff(smooth_im, x, y, x+1, y+1); + num++; + } + + if ((x < width-1) && (y > 0)) + { + edges[num].a = y * width + x; + edges[num].b = (y-1) * width + (x+1); + edges[num].w = diff(smooth_im, x, y, x+1, y-1); + num++; + } + } + } + + //free(smooth_im); + + // segment + u = segment_graph(width*height, num, edges, c, edgeWeights, in, ind, u); + + // post process small components + for (i = 0; i < num; i++) + { + int a, b; + a = find(u,edges[i].a); + b = find(u,edges[i].b); + if ((a != b) && ((u->elts[a].size < min_size) || (u->elts[b].size < min_size))) + join(u, a, b); + } + + //free(edges); + arrayref(num_ccs,0) = u->num; + + // pick random colors for each component + //output = iMallocHandle(height, width); + +/* srand(time(0)); + for (i = 0; i < width*height; i++) + { + float temp; + temp = rand()/((float)RAND_MAX); + colors[i] = (int)(temp*255); + } +*/ + + for (y = 0; y < height; y++) + { + for (x = 0; x < width; x++) + { + int comp; + comp = find(u, y * width + x); + if(segments[comp] == -1) + segments[comp] = components++; + subsref(output, y, x) = segments[comp]; + } + } + +/* + for (y = 0; y < height; y++) + { + for (x = 0; x < width; x++) + { + int comp; + comp = find(u, y * width + x); + subsref(output, y, x) = colors[comp]; + } + } +*/ + //free(u->elts); + //free(u); + //free(segments); + + return output; +} + + diff --git a/SD-VBS/benchmarks/multi_ncut/src/c/segment.h b/SD-VBS/benchmarks/multi_ncut/src/c/segment.h new file mode 100644 index 0000000..73ed8de --- /dev/null +++ b/SD-VBS/benchmarks/multi_ncut/src/c/segment.h @@ -0,0 +1,46 @@ +/******************************** +Author: Sravanthi Kota Venkata +********************************/ + +#ifndef SEGMENT +#define SEGMENT + +#include "sdvbs_common.h" + +typedef struct +{ + float w; + int a, b; +} edge; + +typedef struct +{ + int rank; + int p; + int size; +} uni_elt; + +typedef struct +{ + uni_elt *elts; + int num; +}universe; + +/* use imRef to access image data. */ +#define imRef(im, x, y) (im->data[y*im->width+x]) + +I2D *segment_image(I2D *im, float sigma, float c, int min_size, int *num_ccs, + int* segments, edge* edges, + F2D* imageOut, F2D* tempOut, I2D* kernel, F2D* edgeWeights, F2D* in, I2D* ind, + universe* u, + I2D* output); +universe *segment_graph(int num_vertices, int num_edges, edge *edges, float c, F2D* edgeWeights, F2D* in, I2D* ind, + universe* u); +void join(universe* u, int x, int y); +int find(universe* u, int x); +float diff(F2D *r, int x1, int y1, int x2, int y2); + + +#endif + + -- cgit v1.2.2 From 163c440444c74a4e0bbe0a8db3d1ca725413994b Mon Sep 17 00:00:00 2001 From: Joshua Bakita Date: Thu, 22 Oct 2020 03:17:31 -0400 Subject: Make SD-VBS compatible with run_bench.sh and cleanup SD-VBS: - Run silently - Fix some whitespace errors - Don't duplicate extra.h - Auto-detect if building with LITMUS-RT - Disable result checking - Add helper symlinks Misc: - Remove unused code from libextra - Set some missing rt_param fields in libextra - Disable CSV info dump from computeSMTslowdown.sh - Widen scope of .gitignore on .txt files - Include list of 2MB DIS pair benchmarks and inputs --- SD-VBS/benchmarks/multi_ncut/src/c/script_multi_ncut.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'SD-VBS/benchmarks/multi_ncut/src') 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 index e4f7912..77c6b71 100644 --- a/SD-VBS/benchmarks/multi_ncut/src/c/script_multi_ncut.c +++ b/SD-VBS/benchmarks/multi_ncut/src/c/script_multi_ncut.c @@ -28,7 +28,6 @@ int main(int argc, char* argv[]) F2D *imageOut, *tempOut; F2D *edgeWeights, *in; - printf("Input image: "); scanf("%s", im1); im = readImage(im1); @@ -50,13 +49,12 @@ int main(int argc, char* argv[]) u->elts = (uni_elt*)malloc(sizeof(uni_elt)*num_vertices); output = iMallocHandle(height, width); - printf("start\n"); for_each_job{ - seg = segment_image(im, sigma, k, min_size, num_ccs, segments, edges, imageOut, tempOut, kernel, edgeWeights, in, ind, u, output); - out = seg; + seg = segment_image(im, sigma, k, min_size, num_ccs, segments, edges, imageOut, tempOut, kernel, edgeWeights, in, ind, u, output); + out = seg; } - printf("end..\n"); -#ifdef CHECK + +#ifdef CHECK /** Self checking - use expected.txt from data directory **/ { int ret=0; -- cgit v1.2.2