summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <birte.friesel@uos.de>2025-01-16 08:20:48 +0100
committerBirte Kristina Friesel <birte.friesel@uos.de>2025-01-16 08:20:48 +0100
commit935c98b276021d6e2811f4176b09d4e98c22fc98 (patch)
tree94a67e1fbdef1eb5c0c01fbfce46431d2a331631
parentd83ae32594f5407c71a67f1b913fe9893f30015e (diff)
HST-S: indent -linux
-rw-r--r--HST-S/baselines/cpu/app_baseline.c588
-rw-r--r--HST-S/dpu/task.c183
-rw-r--r--HST-S/host/app.c667
-rwxr-xr-xHST-S/support/common.h16
-rw-r--r--HST-S/support/params.h124
-rwxr-xr-xHST-S/support/timer.h140
6 files changed, 924 insertions, 794 deletions
diff --git a/HST-S/baselines/cpu/app_baseline.c b/HST-S/baselines/cpu/app_baseline.c
index 745e384..bb4e28a 100644
--- a/HST-S/baselines/cpu/app_baseline.c
+++ b/HST-S/baselines/cpu/app_baseline.c
@@ -24,10 +24,10 @@
#include <numaif.h>
#include <numa.h>
-struct bitmask* bitmask_in;
-struct bitmask* bitmask_out;
+struct bitmask *bitmask_in;
+struct bitmask *bitmask_out;
-void* mp_pages[1];
+void *mp_pages[1];
int mp_status[1];
int mp_nodes[1];
int numa_node_in = -1;
@@ -41,7 +41,6 @@ int numa_node_local = -1;
int numa_node_in_is_local = 0;
#endif
-
#include "../../support/common.h"
#include "../../support/timer.h"
@@ -49,364 +48,399 @@ int numa_node_in_is_local = 0;
#define STR(x) #x
// Pointer declaration
-static T* A;
+static T *A;
static T *A_local;
-static unsigned int* histo_host;
+static unsigned int *histo_host;
typedef struct Params {
- unsigned int input_size;
- unsigned int bins;
- int n_warmup;
- int n_reps;
- const char *file_name;
- int exp;
- int n_threads;
+ unsigned int input_size;
+ unsigned int bins;
+ int n_warmup;
+ int n_reps;
+ const char *file_name;
+ int exp;
+ int n_threads;
#if NUMA
- struct bitmask* bitmask_in;
- struct bitmask* bitmask_out;
- int numa_node_cpu;
+ struct bitmask *bitmask_in;
+ struct bitmask *bitmask_out;
+ int numa_node_cpu;
#endif
#if NUMA_MEMCPY
- int numa_node_cpu_memcpy;
- struct bitmask* bitmask_cpu;
+ int numa_node_cpu_memcpy;
+ struct bitmask *bitmask_cpu;
#endif
-}Params;
+} Params;
/**
* @brief creates input arrays
* @param nr_elements how many elements in input arrays
*/
-static void read_input(T* A, const Params p) {
-
- char dctFileName[100];
- FILE *File = NULL;
-
- // Open input file
- unsigned short temp;
- sprintf(dctFileName, "%s", p.file_name);
- if((File = fopen(dctFileName, "rb")) != NULL) {
- for(unsigned int y = 0; y < p.input_size; y++) {
- if (fread(&temp, sizeof(unsigned short), 1, File) == 1) {
- A[y] = (unsigned int)ByteSwap16(temp);
- if(A[y] >= 4096)
- A[y] = 4095;
- } else {
- //printf("out of bounds read at offset %d -- seeking back to 0\n", y);
- rewind(File);
- }
- }
- fclose(File);
- } else {
- printf("%s does not exist\n", dctFileName);
- exit(1);
- }
+static void read_input(T *A, const Params p)
+{
+
+ char dctFileName[100];
+ FILE *File = NULL;
+
+ // Open input file
+ unsigned short temp;
+ sprintf(dctFileName, "%s", p.file_name);
+ if ((File = fopen(dctFileName, "rb")) != NULL) {
+ for (unsigned int y = 0; y < p.input_size; y++) {
+ if (fread(&temp, sizeof(unsigned short), 1, File) == 1) {
+ A[y] = (unsigned int)ByteSwap16(temp);
+ if (A[y] >= 4096)
+ A[y] = 4095;
+ } else {
+ //printf("out of bounds read at offset %d -- seeking back to 0\n", y);
+ rewind(File);
+ }
+ }
+ fclose(File);
+ } else {
+ printf("%s does not exist\n", dctFileName);
+ exit(1);
+ }
}
/**
* @brief compute output in the host
*/
-static void histogram_host(unsigned int* histo, T* A, unsigned int bins, unsigned int nr_elements, int exp, unsigned int nr_of_dpus, int t) {
-
- omp_set_num_threads(t);
-
- if(!exp){
- #pragma omp parallel for
- for (unsigned int i = 0; i < nr_of_dpus; i++) {
- for (unsigned int j = 0; j < nr_elements; j++) {
- T d = A[j];
- histo[i * bins + ((d * bins) >> DEPTH)] += 1;
- }
- }
- }
- else{
- #pragma omp parallel for
- for (unsigned int j = 0; j < nr_elements; j++) {
- T d = A[j];
- #pragma omp atomic update
- histo[(d * bins) >> DEPTH] += 1;
- }
- }
+static void histogram_host(unsigned int *histo, T *A, unsigned int bins,
+ unsigned int nr_elements, int exp,
+ unsigned int nr_of_dpus, int t)
+{
+
+ omp_set_num_threads(t);
+
+ if (!exp) {
+#pragma omp parallel for
+ for (unsigned int i = 0; i < nr_of_dpus; i++) {
+ for (unsigned int j = 0; j < nr_elements; j++) {
+ T d = A[j];
+ histo[i * bins + ((d * bins) >> DEPTH)] += 1;
+ }
+ }
+ } else {
+#pragma omp parallel for
+ for (unsigned int j = 0; j < nr_elements; j++) {
+ T d = A[j];
+#pragma omp atomic update
+ histo[(d * bins) >> DEPTH] += 1;
+ }
+ }
}
// Params ---------------------------------------------------------------------
-void usage() {
- fprintf(stderr,
- "\nUsage: ./program [options]"
- "\n"
- "\nGeneral options:"
- "\n -h help"
- "\n -w <W> # of untimed warmup iterations (default=1)"
- "\n -e <E> # of timed repetition iterations (default=3)"
- "\n -t <T> # of threads (default=8)"
- "\n -x <X> Weak (0) or strong (1) scaling (default=0)"
- "\n"
- "\nBenchmark-specific options:"
- "\n -i <I> input size (default=1536*1024 elements)"
- "\n -b <B> histogram size (default=256 bins)"
- "\n -f <F> input image file (default=../input/image_VanHateren.iml)"
- "\n");
+void usage()
+{
+ fprintf(stderr,
+ "\nUsage: ./program [options]"
+ "\n"
+ "\nGeneral options:"
+ "\n -h help"
+ "\n -w <W> # of untimed warmup iterations (default=1)"
+ "\n -e <E> # of timed repetition iterations (default=3)"
+ "\n -t <T> # of threads (default=8)"
+ "\n -x <X> Weak (0) or strong (1) scaling (default=0)"
+ "\n"
+ "\nBenchmark-specific options:"
+ "\n -i <I> input size (default=1536*1024 elements)"
+ "\n -b <B> histogram size (default=256 bins)"
+ "\n -f <F> input image file (default=../input/image_VanHateren.iml)"
+ "\n");
}
-struct Params input_params(int argc, char **argv) {
- struct Params p;
- p.input_size = 1536 * 1024;
- p.bins = 256;
- p.n_warmup = 1;
- p.n_reps = 3;
- p.n_threads = 8;
- p.exp = 1;
- p.file_name = "../../input/image_VanHateren.iml";
+struct Params input_params(int argc, char **argv)
+{
+ struct Params p;
+ p.input_size = 1536 * 1024;
+ p.bins = 256;
+ p.n_warmup = 1;
+ p.n_reps = 3;
+ p.n_threads = 8;
+ p.exp = 1;
+ p.file_name = "../../input/image_VanHateren.iml";
#if NUMA
- p.bitmask_in = NULL;
- p.bitmask_out = NULL;
- p.numa_node_cpu = -1;
+ p.bitmask_in = NULL;
+ p.bitmask_out = NULL;
+ p.numa_node_cpu = -1;
#endif
#if NUMA_MEMCPY
- p.numa_node_cpu_memcpy = -1;
- p.bitmask_cpu = NULL;
+ p.numa_node_cpu_memcpy = -1;
+ p.bitmask_cpu = NULL;
#endif
- int opt;
- while((opt = getopt(argc, argv, "hi:b:w:e:f:x:t:A:B:C:D:M:")) >= 0) {
- switch(opt) {
- case 'h':
- usage();
- exit(0);
- break;
- case 'i': p.input_size = atoi(optarg); break;
- case 'b': p.bins = atoi(optarg); break;
- case 'w': p.n_warmup = atoi(optarg); break;
- case 'e': p.n_reps = atoi(optarg); break;
- case 'f': p.file_name = optarg; break;
- case 'x': p.exp = atoi(optarg); break;
- case 't': p.n_threads = atoi(optarg); break;
+ int opt;
+ while ((opt = getopt(argc, argv, "hi:b:w:e:f:x:t:A:B:C:D:M:")) >= 0) {
+ switch (opt) {
+ case 'h':
+ usage();
+ exit(0);
+ break;
+ case 'i':
+ p.input_size = atoi(optarg);
+ break;
+ case 'b':
+ p.bins = atoi(optarg);
+ break;
+ case 'w':
+ p.n_warmup = atoi(optarg);
+ break;
+ case 'e':
+ p.n_reps = atoi(optarg);
+ break;
+ case 'f':
+ p.file_name = optarg;
+ break;
+ case 'x':
+ p.exp = atoi(optarg);
+ break;
+ case 't':
+ p.n_threads = atoi(optarg);
+ break;
#if NUMA
- case 'A': p.bitmask_in = numa_parse_nodestring(optarg); break;
- case 'B': p.bitmask_out = numa_parse_nodestring(optarg); break;
- case 'C': p.numa_node_cpu = atoi(optarg); break;
+ case 'A':
+ p.bitmask_in = numa_parse_nodestring(optarg);
+ break;
+ case 'B':
+ p.bitmask_out = numa_parse_nodestring(optarg);
+ break;
+ case 'C':
+ p.numa_node_cpu = atoi(optarg);
+ break;
#if NUMA_MEMCPY
- case 'D': p.bitmask_cpu = numa_parse_nodestring(optarg); break;
- case 'M': p.numa_node_cpu_memcpy = atoi(optarg); break;
-#endif // NUMA_MEMCPY
-#endif // NUMA
- default:
- fprintf(stderr, "\nUnrecognized option!\n");
- usage();
- exit(0);
- }
- }
- assert(p.n_threads > 0 && "Invalid # of ranks!");
-
- return p;
+ case 'D':
+ p.bitmask_cpu = numa_parse_nodestring(optarg);
+ break;
+ case 'M':
+ p.numa_node_cpu_memcpy = atoi(optarg);
+ break;
+#endif // NUMA_MEMCPY
+#endif // NUMA
+ default:
+ fprintf(stderr, "\nUnrecognized option!\n");
+ usage();
+ exit(0);
+ }
+ }
+ assert(p.n_threads > 0 && "Invalid # of ranks!");
+
+ return p;
}
/**
* @brief Main of the Host Application.
*/
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
+
+ struct Params p = input_params(argc, argv);
- struct Params p = input_params(argc, argv);
+ uint32_t nr_of_dpus;
- uint32_t nr_of_dpus;
-
- const unsigned int input_size = p.input_size; // Size of input image
- if(!p.exp)
- assert(input_size % p.n_threads == 0 && "Input size!");
- else
- assert(input_size % p.n_threads == 0 && "Input size!");
+ const unsigned int input_size = p.input_size; // Size of input image
+ if (!p.exp)
+ assert(input_size % p.n_threads == 0 && "Input size!");
+ else
+ assert(input_size % p.n_threads == 0 && "Input size!");
- // Input/output allocation
+ // Input/output allocation
#if NUMA
- if (p.bitmask_in) {
- numa_set_membind(p.bitmask_in);
- numa_free_nodemask(p.bitmask_in);
- }
- A = numa_alloc(input_size * sizeof(T));
+ if (p.bitmask_in) {
+ numa_set_membind(p.bitmask_in);
+ numa_free_nodemask(p.bitmask_in);
+ }
+ A = numa_alloc(input_size * sizeof(T));
#else
- A = malloc(input_size * sizeof(T));
+ A = malloc(input_size * sizeof(T));
#endif
- // Create an input file with arbitrary data.
- read_input(A, p);
+ // Create an input file with arbitrary data.
+ read_input(A, p);
#if NUMA
- if (p.bitmask_out) {
- numa_set_membind(p.bitmask_out);
- numa_free_nodemask(p.bitmask_out);
- }
+ if (p.bitmask_out) {
+ numa_set_membind(p.bitmask_out);
+ numa_free_nodemask(p.bitmask_out);
+ }
#endif
- if(!p.exp) {
- // upstream code left nr_of_dpus uninitialized
- nr_of_dpus = p.n_threads;
+ if (!p.exp) {
+ // upstream code left nr_of_dpus uninitialized
+ nr_of_dpus = p.n_threads;
#if NUMA
- histo_host = numa_alloc(nr_of_dpus * p.bins * sizeof(unsigned int));
+ histo_host =
+ numa_alloc(nr_of_dpus * p.bins * sizeof(unsigned int));
#else
- histo_host = malloc(nr_of_dpus * p.bins * sizeof(unsigned int));
+ histo_host = malloc(nr_of_dpus * p.bins * sizeof(unsigned int));
#endif
- } else {
+ } else {
#if NUMA
- histo_host = numa_alloc(p.bins * sizeof(unsigned int));
+ histo_host = numa_alloc(p.bins * sizeof(unsigned int));
#else
- histo_host = malloc(p.bins * sizeof(unsigned int));
+ histo_host = malloc(p.bins * sizeof(unsigned int));
#endif
- }
+ }
#if NUMA
#if NUMA_MEMCPY
- if (p.bitmask_cpu) {
- numa_set_membind(p.bitmask_cpu);
- numa_free_nodemask(p.bitmask_cpu);
- }
+ if (p.bitmask_cpu) {
+ numa_set_membind(p.bitmask_cpu);
+ numa_free_nodemask(p.bitmask_cpu);
+ }
#else
- struct bitmask *bitmask_all = numa_allocate_nodemask();
- numa_bitmask_setall(bitmask_all);
- numa_set_membind(bitmask_all);
- numa_free_nodemask(bitmask_all);
-#endif // NUMA_MEMCPY
-#endif // NUMA
+ struct bitmask *bitmask_all = numa_allocate_nodemask();
+ numa_bitmask_setall(bitmask_all);
+ numa_set_membind(bitmask_all);
+ numa_free_nodemask(bitmask_all);
+#endif // NUMA_MEMCPY
+#endif // NUMA
#if NUMA
- mp_pages[0] = A;
- if (move_pages(0, 1, mp_pages, NULL, mp_status, 0) == -1) {
- perror("move_pages(A)");
- }
- else if (mp_status[0] < 0) {
- printf("move_pages error: %d", mp_status[0]);
- }
- else {
- numa_node_in = mp_status[0];
- }
-
- mp_pages[0] = histo_host;
- if (move_pages(0, 1, mp_pages, NULL, mp_status, 0) == -1) {
- perror("move_pages(C)");
- }
- else if (mp_status[0] < 0) {
- printf("move_pages error: %d", mp_status[0]);
- }
- else {
- numa_node_out = mp_status[0];
- }
-
- numa_node_cpu = p.numa_node_cpu;
- if (numa_node_cpu != -1) {
- if (numa_run_on_node(numa_node_cpu) == -1) {
- perror("numa_run_on_node");
- numa_node_cpu = -1;
- }
- }
+ mp_pages[0] = A;
+ if (move_pages(0, 1, mp_pages, NULL, mp_status, 0) == -1) {
+ perror("move_pages(A)");
+ } else if (mp_status[0] < 0) {
+ printf("move_pages error: %d", mp_status[0]);
+ } else {
+ numa_node_in = mp_status[0];
+ }
+
+ mp_pages[0] = histo_host;
+ if (move_pages(0, 1, mp_pages, NULL, mp_status, 0) == -1) {
+ perror("move_pages(C)");
+ } else if (mp_status[0] < 0) {
+ printf("move_pages error: %d", mp_status[0]);
+ } else {
+ numa_node_out = mp_status[0];
+ }
+
+ numa_node_cpu = p.numa_node_cpu;
+ if (numa_node_cpu != -1) {
+ if (numa_run_on_node(numa_node_cpu) == -1) {
+ perror("numa_run_on_node");
+ numa_node_cpu = -1;
+ }
+ }
#endif
#if NUMA_MEMCPY
- numa_node_in_is_local = ((numa_node_cpu == numa_node_in) || (numa_node_cpu + 8 == numa_node_in)) * 1;
+ numa_node_in_is_local = ((numa_node_cpu == numa_node_in)
+ || (numa_node_cpu + 8 == numa_node_in)) * 1;
#endif
- Timer timer;
+ Timer timer;
#if NUMA_MEMCPY
- numa_node_cpu_memcpy = p.numa_node_cpu_memcpy;
- start(&timer, 1, 0);
- if (!numa_node_in_is_local) {
- A_local = (T*) numa_alloc(input_size * sizeof(T));
- }
- stop(&timer, 1);
- if (!numa_node_in_is_local) {
- if (p.numa_node_cpu_memcpy != -1) {
- if (numa_run_on_node(p.numa_node_cpu_memcpy) == -1) {
- perror("numa_run_on_node");
- numa_node_cpu_memcpy = -1;
- }
- }
- }
- start(&timer, 2, 0);
- if (!numa_node_in_is_local) {
- memcpy(A_local, A, input_size * sizeof(T));
- } else {
- A_local = A;
- }
- stop(&timer, 2);
- if (p.numa_node_cpu != -1) {
- if (numa_run_on_node(p.numa_node_cpu) == -1) {
- perror("numa_run_on_node");
- numa_node_cpu = -1;
- }
- }
- mp_pages[0] = A_local;
- if (move_pages(0, 1, mp_pages, NULL, mp_status, 0) == -1) {
- perror("move_pages(A_local)");
- }
- else if (mp_status[0] < 0) {
- printf("move_pages error: %d", mp_status[0]);
- }
- else {
- numa_node_local = mp_status[0];
- }
+ numa_node_cpu_memcpy = p.numa_node_cpu_memcpy;
+ start(&timer, 1, 0);
+ if (!numa_node_in_is_local) {
+ A_local = (T *) numa_alloc(input_size * sizeof(T));
+ }
+ stop(&timer, 1);
+ if (!numa_node_in_is_local) {
+ if (p.numa_node_cpu_memcpy != -1) {
+ if (numa_run_on_node(p.numa_node_cpu_memcpy) == -1) {
+ perror("numa_run_on_node");
+ numa_node_cpu_memcpy = -1;
+ }
+ }
+ }
+ start(&timer, 2, 0);
+ if (!numa_node_in_is_local) {
+ memcpy(A_local, A, input_size * sizeof(T));
+ } else {
+ A_local = A;
+ }
+ stop(&timer, 2);
+ if (p.numa_node_cpu != -1) {
+ if (numa_run_on_node(p.numa_node_cpu) == -1) {
+ perror("numa_run_on_node");
+ numa_node_cpu = -1;
+ }
+ }
+ mp_pages[0] = A_local;
+ if (move_pages(0, 1, mp_pages, NULL, mp_status, 0) == -1) {
+ perror("move_pages(A_local)");
+ } else if (mp_status[0] < 0) {
+ printf("move_pages error: %d", mp_status[0]);
+ } else {
+ numa_node_local = mp_status[0];
+ }
#else
- A_local = A;
+ A_local = A;
#endif
- start(&timer, 0, 0);
+ start(&timer, 0, 0);
- if(!p.exp)
- memset(histo_host, 0, nr_of_dpus * p.bins * sizeof(unsigned int));
- else
- memset(histo_host, 0, p.bins * sizeof(unsigned int));
+ if (!p.exp)
+ memset(histo_host, 0,
+ nr_of_dpus * p.bins * sizeof(unsigned int));
+ else
+ memset(histo_host, 0, p.bins * sizeof(unsigned int));
- histogram_host(histo_host, A_local, p.bins, input_size, p.exp, nr_of_dpus, p.n_threads);
+ histogram_host(histo_host, A_local, p.bins, input_size, p.exp,
+ nr_of_dpus, p.n_threads);
- stop(&timer, 0);
+ stop(&timer, 0);
#if NUMA_MEMCPY
- start(&timer, 3, 0);
- if (!numa_node_in_is_local) {
- numa_free(A_local, input_size * sizeof(T));
- }
- stop(&timer, 3);
+ start(&timer, 3, 0);
+ if (!numa_node_in_is_local) {
+ numa_free(A_local, input_size * sizeof(T));
+ }
+ stop(&timer, 3);
#endif
- unsigned int nr_threads = 0;
+ unsigned int nr_threads = 0;
#pragma omp parallel
#pragma omp atomic
- nr_threads++;
+ nr_threads++;
#if NUMA_MEMCPY
- printf("[::] HST-S-CPU-MEMCPY | n_threads=%d e_type=%s n_elements=%d n_bins=%d"
- " numa_node_in=%d numa_node_local=%d numa_node_out=%d numa_node_cpu=%d numa_node_cpu_memcpy=%d numa_distance_in_cpu=%d numa_distance_cpu_out=%d"
- " | throughput_MBps=%f",
- nr_threads, XSTR(T), input_size, p.exp ? p.bins : p.bins * nr_of_dpus,
- numa_node_in, numa_node_local, numa_node_out, numa_node_cpu, numa_node_cpu_memcpy, numa_distance(numa_node_in, numa_node_cpu), numa_distance(numa_node_cpu, numa_node_out),
- input_size * sizeof(T) / timer.time[0]);
- printf(" throughput_MOpps=%f",
- input_size / timer.time[0]);
- printf(" latency_kernel_us=%f latency_alloc_us=%f latency_memcpy_us=%f latency_free_us=%f latency_total_us=%f\n",
- timer.time[0], timer.time[1], timer.time[2], timer.time[3],
- timer.time[0] + timer.time[1] + timer.time[2] + timer.time[3]);
+ printf
+ ("[::] HST-S-CPU-MEMCPY | n_threads=%d e_type=%s n_elements=%d n_bins=%d"
+ " numa_node_in=%d numa_node_local=%d numa_node_out=%d numa_node_cpu=%d numa_node_cpu_memcpy=%d numa_distance_in_cpu=%d numa_distance_cpu_out=%d"
+ " | throughput_MBps=%f", nr_threads, XSTR(T), input_size,
+ p.exp ? p.bins : p.bins * nr_of_dpus, numa_node_in,
+ numa_node_local, numa_node_out, numa_node_cpu,
+ numa_node_cpu_memcpy, numa_distance(numa_node_in, numa_node_cpu),
+ numa_distance(numa_node_cpu, numa_node_out),
+ input_size * sizeof(T) / timer.time[0]);
+ printf(" throughput_MOpps=%f", input_size / timer.time[0]);
+ printf
+ (" latency_kernel_us=%f latency_alloc_us=%f latency_memcpy_us=%f latency_free_us=%f latency_total_us=%f\n",
+ timer.time[0], timer.time[1], timer.time[2], timer.time[3],
+ timer.time[0] + timer.time[1] + timer.time[2] + timer.time[3]);
#else
- printf("[::] HST-S-CPU | n_threads=%d e_type=%s n_elements=%d n_bins=%d"
+ printf("[::] HST-S-CPU | n_threads=%d e_type=%s n_elements=%d n_bins=%d"
#if NUMA
- " numa_node_in=%d numa_node_out=%d numa_node_cpu=%d numa_distance_in_cpu=%d numa_distance_cpu_out=%d"
+ " numa_node_in=%d numa_node_out=%d numa_node_cpu=%d numa_distance_in_cpu=%d numa_distance_cpu_out=%d"
#endif
- " | throughput_MBps=%f",
- nr_threads, XSTR(T), input_size, p.exp ? p.bins : p.bins * nr_of_dpus,
+ " | throughput_MBps=%f",
+ nr_threads, XSTR(T), input_size,
+ p.exp ? p.bins : p.bins * nr_of_dpus,
#if NUMA
- numa_node_in, numa_node_out, numa_node_cpu, numa_distance(numa_node_in, numa_node_cpu), numa_distance(numa_node_cpu, numa_node_out),
+ numa_node_in, numa_node_out, numa_node_cpu,
+ numa_distance(numa_node_in, numa_node_cpu),
+ numa_distance(numa_node_cpu, numa_node_out),
#endif
- input_size * sizeof(T) / timer.time[0]);
- printf(" throughput_MOpps=%f latency_us=%f\n",
- input_size / timer.time[0], timer.time[0]);
-#endif // NUMA_MEMCPY
+ input_size * sizeof(T) / timer.time[0]);
+ printf(" throughput_MOpps=%f latency_us=%f\n",
+ input_size / timer.time[0], timer.time[0]);
+#endif // NUMA_MEMCPY
#if NUMA
- numa_free(A, input_size * sizeof(T));
- if (!p.exp) {
- numa_free(histo_host, nr_of_dpus * p.bins * sizeof(unsigned int));
- } else {
- numa_free(histo_host, p.bins * sizeof(unsigned int));
- }
+ numa_free(A, input_size * sizeof(T));
+ if (!p.exp) {
+ numa_free(histo_host,
+ nr_of_dpus * p.bins * sizeof(unsigned int));
+ } else {
+ numa_free(histo_host, p.bins * sizeof(unsigned int));
+ }
#else
- free(A);
- free(histo_host);
+ free(A);
+ free(histo_host);
#endif
- return 0;
+ return 0;
}
diff --git a/HST-S/dpu/task.c b/HST-S/dpu/task.c
index 135f0d1..0333072 100644
--- a/HST-S/dpu/task.c
+++ b/HST-S/dpu/task.c
@@ -15,102 +15,121 @@
__host dpu_arguments_t DPU_INPUT_ARGUMENTS;
// Array for communication between adjacent tasklets
-uint32_t* message[NR_TASKLETS];
+uint32_t *message[NR_TASKLETS];
// DPU histogram
-uint32_t* histo_dpu;
+uint32_t *histo_dpu;
// Barrier
BARRIER_INIT(my_barrier, NR_TASKLETS);
// Histogram in each tasklet
-static void histogram(uint32_t* histo, uint32_t bins, T *input, unsigned int l_size){
- for(unsigned int j = 0; j < l_size; j++) {
- T d = input[j];
- histo[(d * bins) >> DEPTH] += 1;
- }
+static void histogram(uint32_t *histo, uint32_t bins, T *input,
+ unsigned int l_size)
+{
+ for (unsigned int j = 0; j < l_size; j++) {
+ T d = input[j];
+ histo[(d * bins) >> DEPTH] += 1;
+ }
}
extern int main_kernel1(void);
-int (*kernels[nr_kernels])(void) = {main_kernel1};
+int (*kernels[nr_kernels])(void) = { main_kernel1 };
-int main(void) {
- // Kernel
- return kernels[DPU_INPUT_ARGUMENTS.kernel]();
+int main(void)
+{
+ // Kernel
+ return kernels[DPU_INPUT_ARGUMENTS.kernel] ();
}
// main_kernel1
-int main_kernel1() {
- unsigned int tasklet_id = me();
+int main_kernel1()
+{
+ unsigned int tasklet_id = me();
#if PRINT
- printf("tasklet_id = %u\n", tasklet_id);
+ printf("tasklet_id = %u\n", tasklet_id);
#endif
- if (tasklet_id == 0){ // Initialize once the cycle counter
- mem_reset(); // Reset the heap
- }
- // Barrier
- barrier_wait(&my_barrier);
-
- uint32_t input_size_dpu_bytes = DPU_INPUT_ARGUMENTS.size;
- uint32_t input_size_dpu_bytes_transfer = DPU_INPUT_ARGUMENTS.transfer_size; // Transfer input size per DPU in bytes
- uint32_t bins = DPU_INPUT_ARGUMENTS.bins;
-
- // Address of the current processing block in MRAM
- uint32_t base_tasklet = tasklet_id << BLOCK_SIZE_LOG2;
- uint32_t mram_base_addr_A = (uint32_t)DPU_MRAM_HEAP_POINTER;
- uint32_t mram_base_addr_histo = (uint32_t)(DPU_MRAM_HEAP_POINTER + input_size_dpu_bytes_transfer);
-
- // Initialize a local cache to store the MRAM block
- T *cache_A = (T *) mem_alloc(BLOCK_SIZE);
-
- // Local histogram
- uint32_t *histo = (uint32_t *) mem_alloc(bins * sizeof(uint32_t));
-
- // Initialize local histogram
- for(unsigned int i = 0; i < bins; i++){
- histo[i] = 0;
- }
-
- // Compute histogram
- for(unsigned int byte_index = base_tasklet; byte_index < input_size_dpu_bytes; byte_index += BLOCK_SIZE * NR_TASKLETS){
-
- // Bound checking
- uint32_t l_size_bytes = (byte_index + BLOCK_SIZE >= input_size_dpu_bytes) ? (input_size_dpu_bytes - byte_index) : BLOCK_SIZE;
-
- // Load cache with current MRAM block
- mram_read((const __mram_ptr void*)(mram_base_addr_A + byte_index), cache_A, l_size_bytes);
-
- // Histogram in each tasklet
- histogram(histo, bins, cache_A, l_size_bytes >> DIV);
-
- }
- message[tasklet_id] = histo;
-
- // Barrier
- barrier_wait(&my_barrier);
-
- uint32_t *histo_dpu = message[0];
-
- for (unsigned int i = tasklet_id; i < bins; i += NR_TASKLETS){
- uint32_t b = 0;
- for (unsigned int j = 0; j < NR_TASKLETS; j++){
- b += *(message[j] + i);
- }
- histo_dpu[i] = b;
- }
-
- // Barrier
- barrier_wait(&my_barrier);
-
- // Write dpu histogram to current MRAM block
- if(tasklet_id == 0){
- if(bins * sizeof(uint32_t) <= 2048)
- mram_write(histo_dpu, (__mram_ptr void*)(mram_base_addr_histo), bins * sizeof(uint32_t));
- else
- for(unsigned int offset = 0; offset < ((bins * sizeof(uint32_t)) >> 11); offset++){
- mram_write(histo_dpu + (offset << 9), (__mram_ptr void*)(mram_base_addr_histo + (offset << 11)), 2048);
- }
- }
-
- return 0;
+ if (tasklet_id == 0) { // Initialize once the cycle counter
+ mem_reset(); // Reset the heap
+ }
+ // Barrier
+ barrier_wait(&my_barrier);
+
+ uint32_t input_size_dpu_bytes = DPU_INPUT_ARGUMENTS.size;
+ uint32_t input_size_dpu_bytes_transfer = DPU_INPUT_ARGUMENTS.transfer_size; // Transfer input size per DPU in bytes
+ uint32_t bins = DPU_INPUT_ARGUMENTS.bins;
+
+ // Address of the current processing block in MRAM
+ uint32_t base_tasklet = tasklet_id << BLOCK_SIZE_LOG2;
+ uint32_t mram_base_addr_A = (uint32_t) DPU_MRAM_HEAP_POINTER;
+ uint32_t mram_base_addr_histo =
+ (uint32_t) (DPU_MRAM_HEAP_POINTER + input_size_dpu_bytes_transfer);
+
+ // Initialize a local cache to store the MRAM block
+ T *cache_A = (T *) mem_alloc(BLOCK_SIZE);
+
+ // Local histogram
+ uint32_t *histo = (uint32_t *) mem_alloc(bins * sizeof(uint32_t));
+
+ // Initialize local histogram
+ for (unsigned int i = 0; i < bins; i++) {
+ histo[i] = 0;
+ }
+
+ // Compute histogram
+ for (unsigned int byte_index = base_tasklet;
+ byte_index < input_size_dpu_bytes;
+ byte_index += BLOCK_SIZE * NR_TASKLETS) {
+
+ // Bound checking
+ uint32_t l_size_bytes =
+ (byte_index + BLOCK_SIZE >=
+ input_size_dpu_bytes) ? (input_size_dpu_bytes -
+ byte_index) : BLOCK_SIZE;
+
+ // Load cache with current MRAM block
+ mram_read((const __mram_ptr void *)(mram_base_addr_A +
+ byte_index), cache_A,
+ l_size_bytes);
+
+ // Histogram in each tasklet
+ histogram(histo, bins, cache_A, l_size_bytes >> DIV);
+
+ }
+ message[tasklet_id] = histo;
+
+ // Barrier
+ barrier_wait(&my_barrier);
+
+ uint32_t *histo_dpu = message[0];
+
+ for (unsigned int i = tasklet_id; i < bins; i += NR_TASKLETS) {
+ uint32_t b = 0;
+ for (unsigned int j = 0; j < NR_TASKLETS; j++) {
+ b += *(message[j] + i);
+ }
+ histo_dpu[i] = b;
+ }
+
+ // Barrier
+ barrier_wait(&my_barrier);
+
+ // Write dpu histogram to current MRAM block
+ if (tasklet_id == 0) {
+ if (bins * sizeof(uint32_t) <= 2048)
+ mram_write(histo_dpu,
+ (__mram_ptr void *)(mram_base_addr_histo),
+ bins * sizeof(uint32_t));
+ else
+ for (unsigned int offset = 0;
+ offset < ((bins * sizeof(uint32_t)) >> 11);
+ offset++) {
+ mram_write(histo_dpu + (offset << 9),
+ (__mram_ptr void
+ *)(mram_base_addr_histo +
+ (offset << 11)), 2048);
+ }
+ }
+
+ return 0;
}
diff --git a/HST-S/host/app.c b/HST-S/host/app.c
index 2c4e6a5..7f66f6e 100644
--- a/HST-S/host/app.c
+++ b/HST-S/host/app.c
@@ -40,362 +40,415 @@
#endif
// Pointer declaration
-static T* A;
-static unsigned int* histo_host;
-static unsigned int* histo;
+static T *A;
+static unsigned int *histo_host;
+static unsigned int *histo;
// Create input arrays
-static void read_input(T* A, const Params p) {
-
- char dctFileName[100];
- FILE *File = NULL;
-
- // Open input file
- unsigned short temp;
- sprintf(dctFileName, "%s", p.file_name);
- if((File = fopen(dctFileName, "rb")) != NULL) {
- for(unsigned int y = 0; y < p.input_size; y++) {
- if (fread(&temp, sizeof(unsigned short), 1, File) == 1) {
- A[y] = (unsigned int)ByteSwap16(temp);
- if(A[y] >= 4096)
- A[y] = 4095;
- } else {
- //printf("out of bounds read at offset %d -- seeking back to 0\n", y);
- rewind(File);
- }
- }
- fclose(File);
- } else {
- printf("%s does not exist\n", dctFileName);
- exit(1);
- }
+static void read_input(T *A, const Params p)
+{
+
+ char dctFileName[100];
+ FILE *File = NULL;
+
+ // Open input file
+ unsigned short temp;
+ sprintf(dctFileName, "%s", p.file_name);
+ if ((File = fopen(dctFileName, "rb")) != NULL) {
+ for (unsigned int y = 0; y < p.input_size; y++) {
+ if (fread(&temp, sizeof(unsigned short), 1, File) == 1) {
+ A[y] = (unsigned int)ByteSwap16(temp);
+ if (A[y] >= 4096)
+ A[y] = 4095;
+ } else {
+ //printf("out of bounds read at offset %d -- seeking back to 0\n", y);
+ rewind(File);
+ }
+ }
+ fclose(File);
+ } else {
+ printf("%s does not exist\n", dctFileName);
+ exit(1);
+ }
}
// Compute output in the host
-static void histogram_host(unsigned int* histo, T* A, unsigned int bins, unsigned int nr_elements, int exp, unsigned int nr_of_dpus) {
- if(!exp){
- for (unsigned int i = 0; i < nr_of_dpus; i++) {
- for (unsigned int j = 0; j < nr_elements; j++) {
- T d = A[j];
- histo[i * bins + ((d * bins) >> DEPTH)] += 1;
- }
- }
- }
- else{
- for (unsigned int j = 0; j < nr_elements; j++) {
- T d = A[j];
- histo[(d * bins) >> DEPTH] += 1;
- }
- }
+static void histogram_host(unsigned int *histo, T *A, unsigned int bins,
+ unsigned int nr_elements, int exp,
+ unsigned int nr_of_dpus)
+{
+ if (!exp) {
+ for (unsigned int i = 0; i < nr_of_dpus; i++) {
+ for (unsigned int j = 0; j < nr_elements; j++) {
+ T d = A[j];
+ histo[i * bins + ((d * bins) >> DEPTH)] += 1;
+ }
+ }
+ } else {
+ for (unsigned int j = 0; j < nr_elements; j++) {
+ T d = A[j];
+ histo[(d * bins) >> DEPTH] += 1;
+ }
+ }
}
// Main of the Host Application
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
- struct Params p = input_params(argc, argv);
+ struct Params p = input_params(argc, argv);
- struct dpu_set_t dpu_set, dpu;
- uint32_t nr_of_dpus;
- uint32_t nr_of_ranks;
+ struct dpu_set_t dpu_set, dpu;
+ uint32_t nr_of_dpus;
+ uint32_t nr_of_ranks;
#if ENERGY
- struct dpu_probe_t probe;
- DPU_ASSERT(dpu_probe_init("energy_probe", &probe));
+ struct dpu_probe_t probe;
+ DPU_ASSERT(dpu_probe_init("energy_probe", &probe));
#endif
- // Timer declaration
- Timer timer;
+ // Timer declaration
+ Timer timer;
- int numa_node_rank = -2;
+ int numa_node_rank = -2;
- // Allocate DPUs and load binary
+ // Allocate DPUs and load binary
#if !WITH_ALLOC_OVERHEAD
- DPU_ASSERT(dpu_alloc(NR_DPUS, DPU_ALLOC_PROFILE, &dpu_set));
- timer.time[0] = 0; // alloc
+ DPU_ASSERT(dpu_alloc(NR_DPUS, DPU_ALLOC_PROFILE, &dpu_set));
+ timer.time[0] = 0; // alloc
#endif
#if !WITH_LOAD_OVERHEAD
- DPU_ASSERT(dpu_load(dpu_set, DPU_BINARY, NULL));
- DPU_ASSERT(dpu_get_nr_dpus(dpu_set, &nr_of_dpus));
- DPU_ASSERT(dpu_get_nr_ranks(dpu_set, &nr_of_ranks));
- assert(nr_of_dpus == NR_DPUS);
- timer.time[1] = 0; // load
+ DPU_ASSERT(dpu_load(dpu_set, DPU_BINARY, NULL));
+ DPU_ASSERT(dpu_get_nr_dpus(dpu_set, &nr_of_dpus));
+ DPU_ASSERT(dpu_get_nr_ranks(dpu_set, &nr_of_ranks));
+ assert(nr_of_dpus == NR_DPUS);
+ timer.time[1] = 0; // load
#endif
#if !WITH_FREE_OVERHEAD
- timer.time[6] = 0; // free
+ timer.time[6] = 0; // free
#endif
- unsigned int i = 0;
- unsigned int input_size; // Size of input image
- unsigned int dpu_s = p.dpu_s;
- if(p.exp == 0)
- input_size = p.input_size * NR_DPUS; // Size of input image
- else if(p.exp == 1)
- input_size = p.input_size; // Size of input image
- else
- input_size = p.input_size * dpu_s; // Size of input image
-
- const unsigned int input_size_8bytes =
- ((input_size * sizeof(T)) % 8) != 0 ? roundup(input_size, 8) : input_size; // Input size per DPU (max.), 8-byte aligned
- const unsigned int input_size_dpu = divceil(input_size, NR_DPUS); // Input size per DPU (max.)
- const unsigned int input_size_dpu_8bytes =
- ((input_size_dpu * sizeof(T)) % 8) != 0 ? roundup(input_size_dpu, 8) : input_size_dpu; // Input size per DPU (max.), 8-byte aligned
-
- // Input/output allocation
- A = malloc(input_size_dpu_8bytes * NR_DPUS * sizeof(T));
- T *bufferA = A;
- histo_host = malloc(p.bins * sizeof(unsigned int));
- histo = malloc(NR_DPUS * p.bins * sizeof(unsigned int));
-
- // Create an input file with arbitrary data
- read_input(A, p);
- if(p.exp == 0){
- for(unsigned int j = 1; j < NR_DPUS; j++){
- memcpy(&A[j * input_size_dpu_8bytes], &A[0], input_size_dpu_8bytes * sizeof(T));
- }
- }
- else if(p.exp == 2){
- for(unsigned int j = 1; j < dpu_s; j++)
- memcpy(&A[j * p.input_size], &A[0], p.input_size * sizeof(T));
- }
-
- // Loop over main kernel
- for(int rep = 0; rep < p.n_warmup + p.n_reps; rep++) {
- memset(histo_host, 0, p.bins * sizeof(unsigned int));
- memset(histo, 0, NR_DPUS * p.bins * sizeof(unsigned int));
+ unsigned int i = 0;
+ unsigned int input_size; // Size of input image
+ unsigned int dpu_s = p.dpu_s;
+ if (p.exp == 0)
+ input_size = p.input_size * NR_DPUS; // Size of input image
+ else if (p.exp == 1)
+ input_size = p.input_size; // Size of input image
+ else
+ input_size = p.input_size * dpu_s; // Size of input image
+
+ const unsigned int input_size_8bytes = ((input_size * sizeof(T)) % 8) != 0 ? roundup(input_size, 8) : input_size; // Input size per DPU (max.), 8-byte aligned
+ const unsigned int input_size_dpu = divceil(input_size, NR_DPUS); // Input size per DPU (max.)
+ const unsigned int input_size_dpu_8bytes = ((input_size_dpu * sizeof(T)) % 8) != 0 ? roundup(input_size_dpu, 8) : input_size_dpu; // Input size per DPU (max.), 8-byte aligned
+
+ // Input/output allocation
+ A = malloc(input_size_dpu_8bytes * NR_DPUS * sizeof(T));
+ T *bufferA = A;
+ histo_host = malloc(p.bins * sizeof(unsigned int));
+ histo = malloc(NR_DPUS * p.bins * sizeof(unsigned int));
+
+ // Create an input file with arbitrary data
+ read_input(A, p);
+ if (p.exp == 0) {
+ for (unsigned int j = 1; j < NR_DPUS; j++) {
+ memcpy(&A[j * input_size_dpu_8bytes], &A[0],
+ input_size_dpu_8bytes * sizeof(T));
+ }
+ } else if (p.exp == 2) {
+ for (unsigned int j = 1; j < dpu_s; j++)
+ memcpy(&A[j * p.input_size], &A[0],
+ p.input_size * sizeof(T));
+ }
+ // Loop over main kernel
+ for (int rep = 0; rep < p.n_warmup + p.n_reps; rep++) {
+ memset(histo_host, 0, p.bins * sizeof(unsigned int));
+ memset(histo, 0, NR_DPUS * p.bins * sizeof(unsigned int));
#if WITH_ALLOC_OVERHEAD
- if(rep >= p.n_warmup) {
- start(&timer, 0, 0);
- }
- DPU_ASSERT(dpu_alloc(NR_DPUS, DPU_ALLOC_PROFILE, &dpu_set));
- if(rep >= p.n_warmup) {
- stop(&timer, 0);
- }
+ if (rep >= p.n_warmup) {
+ start(&timer, 0, 0);
+ }
+ DPU_ASSERT(dpu_alloc(NR_DPUS, DPU_ALLOC_PROFILE, &dpu_set));
+ if (rep >= p.n_warmup) {
+ stop(&timer, 0);
+ }
#endif
#if WITH_DPUINFO
- printf("DPUs:");
- DPU_FOREACH (dpu_set, dpu) {
- int rank = dpu_get_rank_id(dpu_get_rank(dpu_from_set(dpu))) & DPU_TARGET_MASK;
- int slice = dpu_get_slice_id(dpu_from_set(dpu));
- int member = dpu_get_member_id(dpu_from_set(dpu));
- printf(" %d(%d.%d)", rank, slice, member);
- }
- printf("\n");
+ printf("DPUs:");
+ DPU_FOREACH(dpu_set, dpu) {
+ int rank =
+ dpu_get_rank_id(dpu_get_rank(dpu_from_set(dpu))) &
+ DPU_TARGET_MASK;
+ int slice = dpu_get_slice_id(dpu_from_set(dpu));
+ int member = dpu_get_member_id(dpu_from_set(dpu));
+ printf(" %d(%d.%d)", rank, slice, member);
+ }
+ printf("\n");
#endif
#if WITH_LOAD_OVERHEAD
- if(rep >= p.n_warmup) {
- start(&timer, 1, 0);
- }
- DPU_ASSERT(dpu_load(dpu_set, DPU_BINARY, NULL));
- if(rep >= p.n_warmup) {
- stop(&timer, 1);
- }
- DPU_ASSERT(dpu_get_nr_dpus(dpu_set, &nr_of_dpus));
- DPU_ASSERT(dpu_get_nr_ranks(dpu_set, &nr_of_ranks));
- assert(nr_of_dpus == NR_DPUS);
+ if (rep >= p.n_warmup) {
+ start(&timer, 1, 0);
+ }
+ DPU_ASSERT(dpu_load(dpu_set, DPU_BINARY, NULL));
+ if (rep >= p.n_warmup) {
+ stop(&timer, 1);
+ }
+ DPU_ASSERT(dpu_get_nr_dpus(dpu_set, &nr_of_dpus));
+ DPU_ASSERT(dpu_get_nr_ranks(dpu_set, &nr_of_ranks));
+ assert(nr_of_dpus == NR_DPUS);
#endif
- // int prev_rank_id = -1;
- int rank_id = -1;
- DPU_FOREACH (dpu_set, dpu) {
- rank_id = dpu_get_rank_id(dpu_get_rank(dpu_from_set(dpu))) & DPU_TARGET_MASK;
- if ((numa_node_rank != -2) && numa_node_rank != dpu_get_rank_numa_node(dpu_get_rank(dpu_from_set(dpu)))) {
- numa_node_rank = -1;
- } else {
- numa_node_rank = dpu_get_rank_numa_node(dpu_get_rank(dpu_from_set(dpu)));
- }
- /*
- if (rank_id != prev_rank_id) {
- printf("/dev/dpu_rank%d @ NUMA node %d\n", rank_id, numa_node_rank);
- prev_rank_id = rank_id;
- }
- */
- }
-
- // Compute output on CPU (performance comparison and verification purposes)
- if(rep >= p.n_warmup) {
- start(&timer, 2, 0);
- }
- histogram_host(histo_host, A, p.bins, p.input_size, 1, NR_DPUS);
- if(rep >= p.n_warmup) {
- stop(&timer, 2);
- }
-
- if(rep >= p.n_warmup) {
- start(&timer, 3, 0);
- }
- // Input arguments
- unsigned int kernel = 0;
- i = 0;
- dpu_arguments_t input_arguments[NR_DPUS];
- for(i=0; i<NR_DPUS-1; i++) {
- input_arguments[i].size=input_size_dpu_8bytes * sizeof(T);
- input_arguments[i].transfer_size=input_size_dpu_8bytes * sizeof(T);
- input_arguments[i].bins=p.bins;
- input_arguments[i].kernel=kernel;
- }
- input_arguments[NR_DPUS-1].size=(input_size_8bytes - input_size_dpu_8bytes * (NR_DPUS-1)) * sizeof(T);
- input_arguments[NR_DPUS-1].transfer_size=input_size_dpu_8bytes * sizeof(T);
- input_arguments[NR_DPUS-1].bins=p.bins;
- input_arguments[NR_DPUS-1].kernel=kernel;
-
- // Copy input arrays
- i = 0;
- DPU_FOREACH(dpu_set, dpu, i) {
- DPU_ASSERT(dpu_prepare_xfer(dpu, &input_arguments[i]));
- }
- DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_TO_DPU, "DPU_INPUT_ARGUMENTS", 0, sizeof(input_arguments[0]), DPU_XFER_DEFAULT));
- DPU_FOREACH(dpu_set, dpu, i) {
- DPU_ASSERT(dpu_prepare_xfer(dpu, bufferA + input_size_dpu_8bytes * i));
- }
- DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_TO_DPU, DPU_MRAM_HEAP_POINTER_NAME, 0, input_size_dpu_8bytes * sizeof(T), DPU_XFER_DEFAULT));
- if(rep >= p.n_warmup) {
- stop(&timer, 3);
- }
-
- // Run DPU kernel
- if(rep >= p.n_warmup) {
- start(&timer, 4, 0);
- #if ENERGY
- DPU_ASSERT(dpu_probe_start(&probe));
- #endif
- }
-
- DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS));
- if(rep >= p.n_warmup) {
- stop(&timer, 4);
- #if ENERGY
- DPU_ASSERT(dpu_probe_stop(&probe));
- #endif
- }
+ // int prev_rank_id = -1;
+ int rank_id = -1;
+ DPU_FOREACH(dpu_set, dpu) {
+ rank_id =
+ dpu_get_rank_id(dpu_get_rank(dpu_from_set(dpu))) &
+ DPU_TARGET_MASK;
+ if ((numa_node_rank != -2)
+ && numa_node_rank !=
+ dpu_get_rank_numa_node(dpu_get_rank
+ (dpu_from_set(dpu)))) {
+ numa_node_rank = -1;
+ } else {
+ numa_node_rank =
+ dpu_get_rank_numa_node(dpu_get_rank
+ (dpu_from_set(dpu)));
+ }
+ /*
+ if (rank_id != prev_rank_id) {
+ printf("/dev/dpu_rank%d @ NUMA node %d\n", rank_id, numa_node_rank);
+ prev_rank_id = rank_id;
+ }
+ */
+ }
+
+ // Compute output on CPU (performance comparison and verification purposes)
+ if (rep >= p.n_warmup) {
+ start(&timer, 2, 0);
+ }
+ histogram_host(histo_host, A, p.bins, p.input_size, 1, NR_DPUS);
+ if (rep >= p.n_warmup) {
+ stop(&timer, 2);
+ }
+
+ if (rep >= p.n_warmup) {
+ start(&timer, 3, 0);
+ }
+ // Input arguments
+ unsigned int kernel = 0;
+ i = 0;
+ dpu_arguments_t input_arguments[NR_DPUS];
+ for (i = 0; i < NR_DPUS - 1; i++) {
+ input_arguments[i].size =
+ input_size_dpu_8bytes * sizeof(T);
+ input_arguments[i].transfer_size =
+ input_size_dpu_8bytes * sizeof(T);
+ input_arguments[i].bins = p.bins;
+ input_arguments[i].kernel = kernel;
+ }
+ input_arguments[NR_DPUS - 1].size =
+ (input_size_8bytes -
+ input_size_dpu_8bytes * (NR_DPUS - 1)) * sizeof(T);
+ input_arguments[NR_DPUS - 1].transfer_size =
+ input_size_dpu_8bytes * sizeof(T);
+ input_arguments[NR_DPUS - 1].bins = p.bins;
+ input_arguments[NR_DPUS - 1].kernel = kernel;
+
+ // Copy input arrays
+ i = 0;
+ DPU_FOREACH(dpu_set, dpu, i) {
+ DPU_ASSERT(dpu_prepare_xfer(dpu, &input_arguments[i]));
+ }
+ DPU_ASSERT(dpu_push_xfer
+ (dpu_set, DPU_XFER_TO_DPU, "DPU_INPUT_ARGUMENTS", 0,
+ sizeof(input_arguments[0]), DPU_XFER_DEFAULT));
+ DPU_FOREACH(dpu_set, dpu, i) {
+ DPU_ASSERT(dpu_prepare_xfer
+ (dpu, bufferA + input_size_dpu_8bytes * i));
+ }
+ DPU_ASSERT(dpu_push_xfer
+ (dpu_set, DPU_XFER_TO_DPU,
+ DPU_MRAM_HEAP_POINTER_NAME, 0,
+ input_size_dpu_8bytes * sizeof(T),
+ DPU_XFER_DEFAULT));
+ if (rep >= p.n_warmup) {
+ stop(&timer, 3);
+ }
+ // Run DPU kernel
+ if (rep >= p.n_warmup) {
+ start(&timer, 4, 0);
+#if ENERGY
+ DPU_ASSERT(dpu_probe_start(&probe));
+#endif
+ }
+ DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS));
+ if (rep >= p.n_warmup) {
+ stop(&timer, 4);
+#if ENERGY
+ DPU_ASSERT(dpu_probe_stop(&probe));
+#endif
+ }
#if PRINT
- {
- unsigned int each_dpu = 0;
- printf("Display DPU Logs\n");
- DPU_FOREACH (dpu_set, dpu) {
- printf("DPU#%d:\n", each_dpu);
- DPU_ASSERT(dpulog_read_for_dpu(dpu.dpu, stdout));
- each_dpu++;
- }
- }
+ {
+ unsigned int each_dpu = 0;
+ printf("Display DPU Logs\n");
+ DPU_FOREACH(dpu_set, dpu) {
+ printf("DPU#%d:\n", each_dpu);
+ DPU_ASSERT(dpulog_read_for_dpu
+ (dpu.dpu, stdout));
+ each_dpu++;
+ }
+ }
#endif
- i = 0;
- if(rep >= p.n_warmup) {
- start(&timer, 5, 0);
- }
- // PARALLEL RETRIEVE TRANSFER
- DPU_FOREACH(dpu_set, dpu, i) {
- DPU_ASSERT(dpu_prepare_xfer(dpu, histo + p.bins * i));
- }
- DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_FROM_DPU, DPU_MRAM_HEAP_POINTER_NAME, input_size_dpu_8bytes * sizeof(T), p.bins * sizeof(unsigned int), DPU_XFER_DEFAULT));
-
- // Final histogram merging
- for(i = 1; i < NR_DPUS; i++){
- for(unsigned int j = 0; j < p.bins; j++){
- histo[j] += histo[j + i * p.bins];
- }
- }
- if(rep >= p.n_warmup) {
- stop(&timer, 5);
- }
-
+ i = 0;
+ if (rep >= p.n_warmup) {
+ start(&timer, 5, 0);
+ }
+ // PARALLEL RETRIEVE TRANSFER
+ DPU_FOREACH(dpu_set, dpu, i) {
+ DPU_ASSERT(dpu_prepare_xfer(dpu, histo + p.bins * i));
+ }
+ DPU_ASSERT(dpu_push_xfer
+ (dpu_set, DPU_XFER_FROM_DPU,
+ DPU_MRAM_HEAP_POINTER_NAME,
+ input_size_dpu_8bytes * sizeof(T),
+ p.bins * sizeof(unsigned int), DPU_XFER_DEFAULT));
+
+ // Final histogram merging
+ for (i = 1; i < NR_DPUS; i++) {
+ for (unsigned int j = 0; j < p.bins; j++) {
+ histo[j] += histo[j + i * p.bins];
+ }
+ }
+ if (rep >= p.n_warmup) {
+ stop(&timer, 5);
+ }
#if WITH_ALLOC_OVERHEAD
#if WITH_FREE_OVERHEAD
- if(rep >= p.n_warmup) {
- start(&timer, 6, 0);
- }
+ if (rep >= p.n_warmup) {
+ start(&timer, 6, 0);
+ }
#endif
- DPU_ASSERT(dpu_free(dpu_set));
+ DPU_ASSERT(dpu_free(dpu_set));
#if WITH_FREE_OVERHEAD
- if(rep >= p.n_warmup) {
- stop(&timer, 6);
- }
+ if (rep >= p.n_warmup) {
+ stop(&timer, 6);
+ }
#endif
#endif
- if (rep >= p.n_warmup) {
- printf("[::] HST-S-UPMEM | n_dpus=%d n_ranks=%d n_tasklets=%d e_type=%s n_elements=%d n_bins=%d",
- nr_of_dpus, nr_of_ranks, NR_TASKLETS, XSTR(T), input_size, p.bins);
- printf(" b_with_alloc_overhead=%d b_with_load_overhead=%d b_with_free_overhead=%d numa_node_rank=%d ",
- WITH_ALLOC_OVERHEAD, WITH_LOAD_OVERHEAD, WITH_FREE_OVERHEAD, numa_node_rank);
- printf("| latency_alloc_us=%f latency_load_us=%f latency_cpu_us=%f latency_write_us=%f latency_kernel_us=%f latency_read_us=%f latency_free_us=%f",
- timer.time[0],
- timer.time[1],
- timer.time[2],
- timer.time[3],
- timer.time[4],
- timer.time[5],
- timer.time[6]);
- printf(" throughput_cpu_MBps=%f throughput_upmem_kernel_MBps=%f throughput_upmem_total_MBps=%f",
- input_size * sizeof(T) / timer.time[2],
- input_size * sizeof(T) / (timer.time[4]),
- input_size * sizeof(T) / (timer.time[0] + timer.time[1] + timer.time[3] + timer.time[4] + timer.time[5] + timer.time[6]));
- printf(" throughput_upmem_wxr_MBps=%f throughput_upmem_lwxr_MBps=%f throughput_upmem_alwxr_MBps=%f",
- input_size * sizeof(T) / (timer.time[3] + timer.time[4] + timer.time[5]),
- input_size * sizeof(T) / (timer.time[1] + timer.time[3] + timer.time[4] + timer.time[5]),
- input_size * sizeof(T) / (timer.time[0] + timer.time[1] + timer.time[3] + timer.time[4] + timer.time[5]));
- printf(" throughput_cpu_MOpps=%f throughput_upmem_kernel_MOpps=%f throughput_upmem_total_MOpps=%f",
- input_size / timer.time[2],
- input_size / (timer.time[4]),
- input_size / (timer.time[0] + timer.time[1] + timer.time[3] + timer.time[4] + timer.time[5] + timer.time[6]));
- printf(" throughput_upmem_wxr_MOpps=%f throughput_upmem_lwxr_MOpps=%f throughput_upmem_alwxr_MOpps=%f\n",
- input_size / (timer.time[3] + timer.time[4] + timer.time[5]),
- input_size / (timer.time[1] + timer.time[3] + timer.time[4] + timer.time[5]),
- input_size / (timer.time[0] + timer.time[1] + timer.time[3] + timer.time[4] + timer.time[5]));
- }
-
- }
-
- #if ENERGY
- double energy;
- DPU_ASSERT(dpu_probe_get(&probe, DPU_ENERGY, DPU_AVERAGE, &energy));
- printf("DPU Energy (J): %f\t", energy);
- #endif
-
- // Check output
- bool status = true;
- if(p.exp == 1)
- for (unsigned int j = 0; j < p.bins; j++) {
- if(histo_host[j] != histo[j]){
- status = false;
+ if (rep >= p.n_warmup) {
+ printf
+ ("[::] HST-S-UPMEM | n_dpus=%d n_ranks=%d n_tasklets=%d e_type=%s n_elements=%d n_bins=%d",
+ nr_of_dpus, nr_of_ranks, NR_TASKLETS, XSTR(T),
+ input_size, p.bins);
+ printf
+ (" b_with_alloc_overhead=%d b_with_load_overhead=%d b_with_free_overhead=%d numa_node_rank=%d ",
+ WITH_ALLOC_OVERHEAD, WITH_LOAD_OVERHEAD,
+ WITH_FREE_OVERHEAD, numa_node_rank);
+ printf
+ ("| latency_alloc_us=%f latency_load_us=%f latency_cpu_us=%f latency_write_us=%f latency_kernel_us=%f latency_read_us=%f latency_free_us=%f",
+ timer.time[0], timer.time[1], timer.time[2],
+ timer.time[3], timer.time[4], timer.time[5],
+ timer.time[6]);
+ printf
+ (" throughput_cpu_MBps=%f throughput_upmem_kernel_MBps=%f throughput_upmem_total_MBps=%f",
+ input_size * sizeof(T) / timer.time[2],
+ input_size * sizeof(T) / (timer.time[4]),
+ input_size * sizeof(T) / (timer.time[0] +
+ timer.time[1] +
+ timer.time[3] +
+ timer.time[4] +
+ timer.time[5] +
+ timer.time[6]));
+ printf
+ (" throughput_upmem_wxr_MBps=%f throughput_upmem_lwxr_MBps=%f throughput_upmem_alwxr_MBps=%f",
+ input_size * sizeof(T) / (timer.time[3] +
+ timer.time[4] +
+ timer.time[5]),
+ input_size * sizeof(T) / (timer.time[1] +
+ timer.time[3] +
+ timer.time[4] +
+ timer.time[5]),
+ input_size * sizeof(T) / (timer.time[0] +
+ timer.time[1] +
+ timer.time[3] +
+ timer.time[4] +
+ timer.time[5]));
+ printf
+ (" throughput_cpu_MOpps=%f throughput_upmem_kernel_MOpps=%f throughput_upmem_total_MOpps=%f",
+ input_size / timer.time[2],
+ input_size / (timer.time[4]),
+ input_size / (timer.time[0] + timer.time[1] +
+ timer.time[3] + timer.time[4] +
+ timer.time[5] + timer.time[6]));
+ printf
+ (" throughput_upmem_wxr_MOpps=%f throughput_upmem_lwxr_MOpps=%f throughput_upmem_alwxr_MOpps=%f\n",
+ input_size / (timer.time[3] + timer.time[4] +
+ timer.time[5]),
+ input_size / (timer.time[1] + timer.time[3] +
+ timer.time[4] + timer.time[5]),
+ input_size / (timer.time[0] + timer.time[1] +
+ timer.time[3] + timer.time[4] +
+ timer.time[5]));
+ }
+
+ }
+
+#if ENERGY
+ double energy;
+ DPU_ASSERT(dpu_probe_get(&probe, DPU_ENERGY, DPU_AVERAGE, &energy));
+ printf("DPU Energy (J): %f\t", energy);
+#endif
+
+ // Check output
+ bool status = true;
+ if (p.exp == 1)
+ for (unsigned int j = 0; j < p.bins; j++) {
+ if (histo_host[j] != histo[j]) {
+ status = false;
#if PRINT
- printf("%u - %u: %u -- %u\n", j, j, histo_host[j], histo[j]);
+ printf("%u - %u: %u -- %u\n", j, j,
+ histo_host[j], histo[j]);
#endif
- }
- }
- else if(p.exp == 2)
- for (unsigned int j = 0; j < p.bins; j++) {
- if(dpu_s * histo_host[j] != histo[j]){
- status = false;
+ }
+ } else if (p.exp == 2)
+ for (unsigned int j = 0; j < p.bins; j++) {
+ if (dpu_s * histo_host[j] != histo[j]) {
+ status = false;
#if PRINT
- printf("%u - %u: %u -- %u\n", j, j, dpu_s * histo_host[j], histo[j]);
+ printf("%u - %u: %u -- %u\n", j, j,
+ dpu_s * histo_host[j], histo[j]);
#endif
- }
- }
- else
- for (unsigned int j = 0; j < p.bins; j++) {
- if(NR_DPUS * histo_host[j] != histo[j]){
- status = false;
+ }
+ } else
+ for (unsigned int j = 0; j < p.bins; j++) {
+ if (NR_DPUS * histo_host[j] != histo[j]) {
+ status = false;
#if PRINT
- printf("%u - %u: %u -- %u\n", j, j, NR_DPUS * histo_host[j], histo[j]);
+ printf("%u - %u: %u -- %u\n", j, j,
+ NR_DPUS * histo_host[j], histo[j]);
#endif
- }
- }
- if (status) {
- printf("[" ANSI_COLOR_GREEN "OK" ANSI_COLOR_RESET "] Outputs are equal\n");
- } else {
- printf("[" ANSI_COLOR_RED "ERROR" ANSI_COLOR_RESET "] Outputs differ!\n");
- }
-
- // Deallocation
- free(A);
- free(histo_host);
- free(histo);
+ }
+ }
+ if (status) {
+ printf("[" ANSI_COLOR_GREEN "OK" ANSI_COLOR_RESET
+ "] Outputs are equal\n");
+ } else {
+ printf("[" ANSI_COLOR_RED "ERROR" ANSI_COLOR_RESET
+ "] Outputs differ!\n");
+ }
+
+ // Deallocation
+ free(A);
+ free(histo_host);
+ free(histo);
#if !WITH_ALLOC_OVERHEAD
DPU_ASSERT(dpu_free(dpu_set));
#endif
-
- return status ? 0 : -1;
+
+ return status ? 0 : -1;
}
diff --git a/HST-S/support/common.h b/HST-S/support/common.h
index 30df40d..e0cacbb 100755
--- a/HST-S/support/common.h
+++ b/HST-S/support/common.h
@@ -13,8 +13,8 @@
// Data type
#define T uint32_t
-#define DIV 2 // Shift right to divide by sizeof(T)
-#define REGS (BLOCK_SIZE >> 2) // 32 bits
+#define DIV 2 // Shift right to divide by sizeof(T)
+#define REGS (BLOCK_SIZE >> 2) // 32 bits
// Pixel depth
#define DEPTH 12
@@ -22,19 +22,19 @@
// Structures used by both the host and the dpu to communicate information
typedef struct {
- uint32_t size;
- uint32_t transfer_size;
- uint32_t bins;
+ uint32_t size;
+ uint32_t transfer_size;
+ uint32_t bins;
enum kernels {
- kernel1 = 0,
- nr_kernels = 1,
+ kernel1 = 0,
+ nr_kernels = 1,
} kernel;
} dpu_arguments_t;
#ifndef ENERGY
#define ENERGY 0
#endif
-#define PRINT 0
+#define PRINT 0
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
diff --git a/HST-S/support/params.h b/HST-S/support/params.h
index e29449b..3028a50 100644
--- a/HST-S/support/params.h
+++ b/HST-S/support/params.h
@@ -4,64 +4,80 @@
#include "common.h"
typedef struct Params {
- unsigned int input_size;
- unsigned int bins;
- int n_warmup;
- int n_reps;
- const char *file_name;
- int exp;
- int dpu_s;
-}Params;
+ unsigned int input_size;
+ unsigned int bins;
+ int n_warmup;
+ int n_reps;
+ const char *file_name;
+ int exp;
+ int dpu_s;
+} Params;
-static void usage() {
- fprintf(stderr,
- "\nUsage: ./program [options]"
- "\n"
- "\nGeneral options:"
- "\n -h help"
- "\n -w <W> # of untimed warmup iterations (default=1)"
- "\n -e <E> # of timed repetition iterations (default=3)"
- "\n -x <X> Weak (0) or strong (1, 2) scaling (default=0)"
- "\n"
- "\nBenchmark-specific options:"
- "\n -i <I> input size (default=1536*1024 elements)"
- "\n -b <B> histogram size (default=256 bins)"
- "\n -f <F> input image file (default=../input/image_VanHateren.iml)"
- "\n");
+static void usage()
+{
+ fprintf(stderr,
+ "\nUsage: ./program [options]"
+ "\n"
+ "\nGeneral options:"
+ "\n -h help"
+ "\n -w <W> # of untimed warmup iterations (default=1)"
+ "\n -e <E> # of timed repetition iterations (default=3)"
+ "\n -x <X> Weak (0) or strong (1, 2) scaling (default=0)"
+ "\n"
+ "\nBenchmark-specific options:"
+ "\n -i <I> input size (default=1536*1024 elements)"
+ "\n -b <B> histogram size (default=256 bins)"
+ "\n -f <F> input image file (default=../input/image_VanHateren.iml)"
+ "\n");
}
-struct Params input_params(int argc, char **argv) {
- struct Params p;
- p.input_size = 1536 * 1024;
- p.bins = 256;
- p.n_warmup = 1;
- p.n_reps = 3;
- p.exp = 0;
- p.file_name = "./input/image_VanHateren.iml";
- p.dpu_s = 64;
+struct Params input_params(int argc, char **argv)
+{
+ struct Params p;
+ p.input_size = 1536 * 1024;
+ p.bins = 256;
+ p.n_warmup = 1;
+ p.n_reps = 3;
+ p.exp = 0;
+ p.file_name = "./input/image_VanHateren.iml";
+ p.dpu_s = 64;
- int opt;
- while((opt = getopt(argc, argv, "hi:b:w:e:f:x:z:")) >= 0) {
- switch(opt) {
- case 'h':
- usage();
- exit(0);
- break;
- case 'i': p.input_size = atoi(optarg); break;
- case 'b': p.bins = atoi(optarg); break;
- case 'w': p.n_warmup = atoi(optarg); break;
- case 'e': p.n_reps = atoi(optarg); break;
- case 'f': p.file_name = optarg; break;
- case 'x': p.exp = atoi(optarg); break;
- case 'z': p.dpu_s = atoi(optarg); break;
- default:
- fprintf(stderr, "\nUnrecognized option!\n");
- usage();
- exit(0);
- }
- }
- assert(NR_DPUS > 0 && "Invalid # of dpus!");
+ int opt;
+ while ((opt = getopt(argc, argv, "hi:b:w:e:f:x:z:")) >= 0) {
+ switch (opt) {
+ case 'h':
+ usage();
+ exit(0);
+ break;
+ case 'i':
+ p.input_size = atoi(optarg);
+ break;
+ case 'b':
+ p.bins = atoi(optarg);
+ break;
+ case 'w':
+ p.n_warmup = atoi(optarg);
+ break;
+ case 'e':
+ p.n_reps = atoi(optarg);
+ break;
+ case 'f':
+ p.file_name = optarg;
+ break;
+ case 'x':
+ p.exp = atoi(optarg);
+ break;
+ case 'z':
+ p.dpu_s = atoi(optarg);
+ break;
+ default:
+ fprintf(stderr, "\nUnrecognized option!\n");
+ usage();
+ exit(0);
+ }
+ }
+ assert(NR_DPUS > 0 && "Invalid # of dpus!");
- return p;
+ return p;
}
#endif
diff --git a/HST-S/support/timer.h b/HST-S/support/timer.h
index 4d597b9..df68334 100755
--- a/HST-S/support/timer.h
+++ b/HST-S/support/timer.h
@@ -1,66 +1,74 @@
-/*
- * Copyright (c) 2016 University of Cordoba and University of Illinois
- * All rights reserved.
- *
- * Developed by: IMPACT Research Group
- * University of Cordoba and University of Illinois
- * http://impact.crhc.illinois.edu/
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * with the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * > Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimers.
- * > Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimers in the
- * documentation and/or other materials provided with the distribution.
- * > Neither the names of IMPACT Research Group, University of Cordoba,
- * University of Illinois nor the names of its contributors may be used
- * to endorse or promote products derived from this Software without
- * specific prior written permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
- * THE SOFTWARE.
- *
- */
-
-#include <sys/time.h>
-
-typedef struct Timer{
-
- struct timeval startTime[7];
- struct timeval stopTime[7];
- double time[7];
-
-}Timer;
-
-void start(Timer *timer, int i, int rep) {
- if(rep == 0) {
- timer->time[i] = 0.0;
- }
- gettimeofday(&timer->startTime[i], NULL);
-}
-
-void stop(Timer *timer, int i) {
- gettimeofday(&timer->stopTime[i], NULL);
- timer->time[i] += (timer->stopTime[i].tv_sec - timer->startTime[i].tv_sec) * 1000000.0 +
- (timer->stopTime[i].tv_usec - timer->startTime[i].tv_usec);
-}
-
-void print(Timer *timer, int i, int REP) { printf("Time (ms): %f\t", timer->time[i] / (1000 * REP)); }
-
-void printall(Timer *timer, int maxt) {
- for (int i = 0; i <= maxt; i++) {
- printf(" timer%d_us=%f", i, timer->time[i]);
- }
- printf("\n");
-}
+/*
+ * Copyright (c) 2016 University of Cordoba and University of Illinois
+ * All rights reserved.
+ *
+ * Developed by: IMPACT Research Group
+ * University of Cordoba and University of Illinois
+ * http://impact.crhc.illinois.edu/
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * > Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimers.
+ * > Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimers in the
+ * documentation and/or other materials provided with the distribution.
+ * > Neither the names of IMPACT Research Group, University of Cordoba,
+ * University of Illinois nor the names of its contributors may be used
+ * to endorse or promote products derived from this Software without
+ * specific prior written permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
+ * THE SOFTWARE.
+ *
+ */
+
+#include <sys/time.h>
+
+typedef struct Timer {
+
+ struct timeval startTime[7];
+ struct timeval stopTime[7];
+ double time[7];
+
+} Timer;
+
+void start(Timer *timer, int i, int rep)
+{
+ if (rep == 0) {
+ timer->time[i] = 0.0;
+ }
+ gettimeofday(&timer->startTime[i], NULL);
+}
+
+void stop(Timer *timer, int i)
+{
+ gettimeofday(&timer->stopTime[i], NULL);
+ timer->time[i] +=
+ (timer->stopTime[i].tv_sec -
+ timer->startTime[i].tv_sec) * 1000000.0 +
+ (timer->stopTime[i].tv_usec - timer->startTime[i].tv_usec);
+}
+
+void print(Timer *timer, int i, int REP)
+{
+ printf("Time (ms): %f\t", timer->time[i] / (1000 * REP));
+}
+
+void printall(Timer *timer, int maxt)
+{
+ for (int i = 0; i <= maxt; i++) {
+ printf(" timer%d_us=%f", i, timer->time[i]);
+ }
+ printf("\n");
+}