summaryrefslogtreecommitdiff
path: root/VA
diff options
context:
space:
mode:
authorJuan Gomez Luna <juan.gomez@safari.ethz.ch>2021-06-16 19:46:05 +0200
committerJuan Gomez Luna <juan.gomez@safari.ethz.ch>2021-06-16 19:46:05 +0200
commit3de4b495fb176eba9a0eb517a4ce05903cb67acb (patch)
treefc6776a94549d2d4039898f183dbbeb2ce013ba9 /VA
parentef5c3688c486b80a56d3c1cded25f2b2387f2668 (diff)
PrIM -- first commit
Diffstat (limited to 'VA')
-rw-r--r--VA/Makefile46
-rw-r--r--VA/baselines/cpu/Makefile5
-rw-r--r--VA/baselines/cpu/README9
-rw-r--r--VA/baselines/cpu/app_baseline.c132
-rw-r--r--VA/baselines/gpu/Makefile5
-rw-r--r--VA/baselines/gpu/README9
-rw-r--r--VA/baselines/gpu/vec_add.cu101
-rw-r--r--VA/dpu/task.c78
-rw-r--r--VA/host/app.c222
-rwxr-xr-xVA/support/common.h62
-rw-r--r--VA/support/params.h56
-rwxr-xr-xVA/support/timer.h59
12 files changed, 784 insertions, 0 deletions
diff --git a/VA/Makefile b/VA/Makefile
new file mode 100644
index 0000000..ab1bd97
--- /dev/null
+++ b/VA/Makefile
@@ -0,0 +1,46 @@
+DPU_DIR := dpu
+HOST_DIR := host
+BUILDDIR ?= bin
+NR_TASKLETS ?= 16
+BL ?= 10
+NR_DPUS ?= 1
+TYPE ?= INT32
+ENERGY ?= 0
+
+define conf_filename
+ ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3)_TYPE_$(4).conf
+endef
+CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL},${TYPE})
+
+HOST_TARGET := ${BUILDDIR}/host_code
+DPU_TARGET := ${BUILDDIR}/dpu_code
+
+COMMON_INCLUDES := support
+HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c)
+DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c)
+
+.PHONY: all clean test
+
+__dirs := $(shell mkdir -p ${BUILDDIR})
+
+COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES}
+HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} -D${TYPE} -DENERGY=${ENERGY}
+DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${TYPE}
+
+all: ${HOST_TARGET} ${DPU_TARGET}
+
+${CONF}:
+ $(RM) $(call conf_filename,*,*)
+ touch ${CONF}
+
+${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF}
+ $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS}
+
+${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF}
+ dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES}
+
+clean:
+ $(RM) -r $(BUILDDIR)
+
+test: all
+ ./${HOST_TARGET}
diff --git a/VA/baselines/cpu/Makefile b/VA/baselines/cpu/Makefile
new file mode 100644
index 0000000..f320d87
--- /dev/null
+++ b/VA/baselines/cpu/Makefile
@@ -0,0 +1,5 @@
+all:
+ gcc -o va -fopenmp app_baseline.c
+
+clean:
+ rm va
diff --git a/VA/baselines/cpu/README b/VA/baselines/cpu/README
new file mode 100644
index 0000000..1b979ac
--- /dev/null
+++ b/VA/baselines/cpu/README
@@ -0,0 +1,9 @@
+Vector addition (VA)
+
+Compilation instructions
+
+ make
+
+Execution instructions
+
+ ./va -t 4
diff --git a/VA/baselines/cpu/app_baseline.c b/VA/baselines/cpu/app_baseline.c
new file mode 100644
index 0000000..ecd8efa
--- /dev/null
+++ b/VA/baselines/cpu/app_baseline.c
@@ -0,0 +1,132 @@
+/**
+* @file app.c
+* @brief Template for a Host Application Source File.
+*
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <assert.h>
+#include <stdint.h>
+
+#include <omp.h>
+#include "../../support/timer.h"
+
+static int32_t *A;
+static int32_t *B;
+static int32_t *C;
+static int32_t *C2;
+
+/**
+* @brief creates a "test file" by filling a buffer of 64MB with pseudo-random values
+* @param nr_elements how many 32-bit elements we want the file to be
+* @return the buffer address
+*/
+void *create_test_file(unsigned int nr_elements) {
+ srand(0);
+ printf("nr_elements\t%u\t", nr_elements);
+ A = (uint32_t*) malloc(nr_elements * sizeof(uint32_t));
+ B = (uint32_t*) malloc(nr_elements * sizeof(uint32_t));
+ C = (uint32_t*) malloc(nr_elements * sizeof(uint32_t));
+
+ for (int i = 0; i < nr_elements; i++) {
+ A[i] = (int) (rand());
+ B[i] = (int) (rand());
+ }
+
+}
+
+/**
+* @brief compute output in the host
+*/
+static void vector_addition_host(unsigned int nr_elements, int t) {
+ omp_set_num_threads(t);
+ #pragma omp parallel for
+ for (int i = 0; i < nr_elements; i++) {
+ C[i] = A[i] + B[i];
+ }
+}
+
+// Params ---------------------------------------------------------------------
+typedef struct Params {
+ int input_size;
+ int n_warmup;
+ int n_reps;
+ int n_threads;
+}Params;
+
+void usage() {
+ fprintf(stderr,
+ "\nUsage: ./program [options]"
+ "\n"
+ "\nGeneral options:"
+ "\n -h help"
+ "\n -t <T> # of threads (default=8)"
+ "\n -w <W> # of untimed warmup iterations (default=1)"
+ "\n -e <E> # of timed repetition iterations (default=3)"
+ "\n"
+ "\nBenchmark-specific options:"
+ "\n -i <I> input size (default=8M elements)"
+ "\n");
+}
+
+struct Params input_params(int argc, char **argv) {
+ struct Params p;
+ p.input_size = 16777216;
+ p.n_warmup = 1;
+ p.n_reps = 3;
+ p.n_threads = 5;
+
+ int opt;
+ while((opt = getopt(argc, argv, "hi:w:e:t:")) >= 0) {
+ switch(opt) {
+ case 'h':
+ usage();
+ exit(0);
+ break;
+ case 'i': p.input_size = atoi(optarg); break;
+ case 'w': p.n_warmup = atoi(optarg); break;
+ case 'e': p.n_reps = atoi(optarg); break;
+ case 't': p.n_threads = atoi(optarg); break;
+ 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) {
+
+ struct Params p = input_params(argc, argv);
+
+ const unsigned int file_size = p.input_size;
+
+ // Create an input file with arbitrary data.
+ create_test_file(file_size);
+
+ Timer timer;
+ start(&timer, 0, 0);
+
+ vector_addition_host(file_size, p.n_threads);
+
+ stop(&timer, 0);
+ printf("Kernel ");
+ print(&timer, 0, 1);
+ printf("\n");
+
+ free(A);
+ free(B);
+ free(C);
+
+ return 0;
+ }
diff --git a/VA/baselines/gpu/Makefile b/VA/baselines/gpu/Makefile
new file mode 100644
index 0000000..0b822b6
--- /dev/null
+++ b/VA/baselines/gpu/Makefile
@@ -0,0 +1,5 @@
+all:
+ /usr/local/cuda/bin/nvcc vec_add.cu -I/usr/local/cuda/include -lm -o va
+
+clean:
+ rm va
diff --git a/VA/baselines/gpu/README b/VA/baselines/gpu/README
new file mode 100644
index 0000000..3cfa0c6
--- /dev/null
+++ b/VA/baselines/gpu/README
@@ -0,0 +1,9 @@
+Vector addition (VA)
+
+Compilation instructions
+
+ make
+
+Execution instructions
+
+ ./va
diff --git a/VA/baselines/gpu/vec_add.cu b/VA/baselines/gpu/vec_add.cu
new file mode 100644
index 0000000..c0c259b
--- /dev/null
+++ b/VA/baselines/gpu/vec_add.cu
@@ -0,0 +1,101 @@
+/* File: vec_add.cu
+ * Purpose: Implement vector addition on a gpu using cuda
+ *
+ * Compile: nvcc [-g] [-G] -o vec_add vec_add.cu
+ * Run: ./vec_add
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <math.h>
+
+__global__ void Vec_add(unsigned int x[], unsigned int y[], unsigned int z[], int n) {
+ int thread_id = blockIdx.x * blockDim.x + threadIdx.x;
+ if (thread_id < n){
+ z[thread_id] = x[thread_id] + y[thread_id];
+ }
+}
+
+
+int main(int argc, char* argv[]) {
+ int n, m;
+ unsigned int *h_x, *h_y, *h_z;
+ unsigned int *d_x, *d_y, *d_z;
+ size_t size;
+
+ /* Define vector length */
+ n = 2621440;
+ m = 320;
+ size = m * n * sizeof(unsigned int);
+
+ // Allocate memory for the vectors on host memory.
+ h_x = (unsigned int*) malloc(size);
+ h_y = (unsigned int*) malloc(size);
+ h_z = (unsigned int*) malloc(size);
+
+ for (int i = 0; i < n * m; i++) {
+ h_x[i] = i+1;
+ h_y[i] = n-i;
+ }
+
+ printf("Input size = %d\n", n * m);
+
+ // Print original vectors.
+ /*printf("h_x = ");
+ for (int i = 0; i < m; i++){
+ printf("%u ", h_x[i]);
+ }
+ printf("\n\n");
+ printf("h_y = ");
+ for (int i = 0; i < m; i++){
+ printf("%u ", h_y[i]);
+ }
+ printf("\n\n");*/
+
+ // Event creation
+ cudaEvent_t start, stop;
+ cudaEventCreate(&start);
+ cudaEventCreate(&stop);
+ float time1 = 0;
+
+ /* Allocate vectors in device memory */
+ cudaMalloc(&d_x, size);
+ cudaMalloc(&d_y, size);
+ cudaMalloc(&d_z, size);
+
+ /* Copy vectors from host memory to device memory */
+ cudaMemcpy(d_x, h_x, size, cudaMemcpyHostToDevice);
+ cudaMemcpy(d_y, h_y, size, cudaMemcpyHostToDevice);
+
+ // Start timer
+ cudaEventRecord( start, 0 );
+
+ /* Kernel Call */
+ Vec_add<<<(n * m) / 256, 256>>>(d_x, d_y, d_z, n * m);
+
+ // End timer
+ cudaEventRecord( stop, 0 );
+ cudaEventSynchronize( stop );
+ cudaEventElapsedTime( &time1, start, stop );
+
+ cudaMemcpy(h_z, d_z, size, cudaMemcpyDeviceToHost);
+ /*printf("The sum is: \n");
+ for (int i = 0; i < m; i++){
+ printf("%u ", h_z[i]);
+ }
+ printf("\n");*/
+
+ printf("Execution time = %f ms\n", time1);
+
+ /* Free device memory */
+ cudaFree(d_x);
+ cudaFree(d_y);
+ cudaFree(d_z);
+ /* Free host memory */
+ free(h_x);
+ free(h_y);
+ free(h_z);
+
+ return 0;
+} /* main */
diff --git a/VA/dpu/task.c b/VA/dpu/task.c
new file mode 100644
index 0000000..bb41303
--- /dev/null
+++ b/VA/dpu/task.c
@@ -0,0 +1,78 @@
+/*
+* Vector addition with multiple tasklets
+*
+*/
+#include <stdint.h>
+#include <stdio.h>
+#include <defs.h>
+#include <mram.h>
+#include <alloc.h>
+#include <perfcounter.h>
+#include <barrier.h>
+
+#include "../support/common.h"
+
+__host dpu_arguments_t DPU_INPUT_ARGUMENTS;
+
+// vector_addition: Computes the vector addition of a cached block
+static void vector_addition(T *bufferB, T *bufferA, unsigned int l_size) {
+ for (unsigned int i = 0; i < l_size; i++){
+ bufferB[i] += bufferA[i];
+ }
+}
+
+// Barrier
+BARRIER_INIT(my_barrier, NR_TASKLETS);
+
+extern int main_kernel1(void);
+
+int (*kernels[nr_kernels])(void) = {main_kernel1};
+
+int main(void) {
+ // Kernel
+ return kernels[DPU_INPUT_ARGUMENTS.kernel]();
+}
+
+// main_kernel1
+int main_kernel1() {
+ unsigned int tasklet_id = me();
+#if PRINT
+ 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; // Input size per DPU in bytes
+ uint32_t input_size_dpu_bytes_transfer = DPU_INPUT_ARGUMENTS.transfer_size; // Transfer input size per DPU in bytes
+
+ // 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_B = (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);
+ T *cache_B = (T *) mem_alloc(BLOCK_SIZE);
+
+ 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((__mram_ptr void const*)(mram_base_addr_A + byte_index), cache_A, l_size_bytes);
+ mram_read((__mram_ptr void const*)(mram_base_addr_B + byte_index), cache_B, l_size_bytes);
+
+ // Computer vector addition
+ vector_addition(cache_B, cache_A, l_size_bytes >> DIV);
+
+ // Write cache to current MRAM block
+ mram_write(cache_B, (__mram_ptr void*)(mram_base_addr_B + byte_index), l_size_bytes);
+
+ }
+
+ return 0;
+}
diff --git a/VA/host/app.c b/VA/host/app.c
new file mode 100644
index 0000000..c7c02f3
--- /dev/null
+++ b/VA/host/app.c
@@ -0,0 +1,222 @@
+/**
+* app.c
+* VA Host Application Source File
+*
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <dpu.h>
+#include <dpu_log.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <assert.h>
+
+#include "../support/common.h"
+#include "../support/timer.h"
+#include "../support/params.h"
+
+// Define the DPU Binary path as DPU_BINARY here
+#ifndef DPU_BINARY
+#define DPU_BINARY "./bin/dpu_code"
+#endif
+
+#if ENERGY
+#include <dpu_probe.h>
+#endif
+
+// Pointer declaration
+static T* A;
+static T* B;
+static T* C;
+static T* C2;
+
+// Create input arrays
+static void read_input(T* A, T* B, unsigned int nr_elements) {
+ srand(0);
+ printf("nr_elements\t%u\t", nr_elements);
+ for (unsigned int i = 0; i < nr_elements; i++) {
+ A[i] = (T) (rand());
+ B[i] = (T) (rand());
+ }
+}
+
+// Compute output in the host
+static void vector_addition_host(T* C, T* A, T* B, unsigned int nr_elements) {
+ for (unsigned int i = 0; i < nr_elements; i++) {
+ C[i] = A[i] + B[i];
+ }
+}
+
+// Main of the Host Application
+int main(int argc, char **argv) {
+
+ struct Params p = input_params(argc, argv);
+
+ struct dpu_set_t dpu_set, dpu;
+ uint32_t nr_of_dpus;
+
+#if ENERGY
+ struct dpu_probe_t probe;
+ DPU_ASSERT(dpu_probe_init("energy_probe", &probe));
+#endif
+
+ // Allocate DPUs and load binary
+ DPU_ASSERT(dpu_alloc(NR_DPUS, NULL, &dpu_set));
+ DPU_ASSERT(dpu_load(dpu_set, DPU_BINARY, NULL));
+ DPU_ASSERT(dpu_get_nr_dpus(dpu_set, &nr_of_dpus));
+ printf("Allocated %d DPU(s)\n", nr_of_dpus);
+ unsigned int i = 0;
+
+ const unsigned int input_size = p.exp == 0 ? p.input_size * nr_of_dpus : p.input_size; // Total input size (weak or strong scaling)
+ 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_of_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_of_dpus * sizeof(T));
+ B = malloc(input_size_dpu_8bytes * nr_of_dpus * sizeof(T));
+ C = malloc(input_size_dpu_8bytes * nr_of_dpus * sizeof(T));
+ C2 = malloc(input_size_dpu_8bytes * nr_of_dpus * sizeof(T));
+ T *bufferA = A;
+ T *bufferB = B;
+ T *bufferC = C2;
+
+ // Create an input file with arbitrary data
+ read_input(A, B, input_size);
+
+ // Timer declaration
+ Timer timer;
+
+ printf("NR_TASKLETS\t%d\tBL\t%d\n", NR_TASKLETS, BL);
+
+ // Loop over main kernel
+ for(int rep = 0; rep < p.n_warmup + p.n_reps; rep++) {
+
+ // Compute output on CPU (performance comparison and verification purposes)
+ if(rep >= p.n_warmup)
+ start(&timer, 0, rep - p.n_warmup);
+ vector_addition_host(C, A, B, input_size);
+ if(rep >= p.n_warmup)
+ stop(&timer, 0);
+
+ printf("Load input data\n");
+ if(rep >= p.n_warmup)
+ start(&timer, 1, rep - p.n_warmup);
+ // Input arguments
+ unsigned int kernel = 0;
+ dpu_arguments_t input_arguments[NR_DPUS];
+ for(i=0; i<nr_of_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].kernel=kernel;
+ }
+ input_arguments[nr_of_dpus-1].size=(input_size_8bytes - input_size_dpu_8bytes * (NR_DPUS-1)) * sizeof(T);
+ input_arguments[nr_of_dpus-1].transfer_size=input_size_dpu_8bytes * sizeof(T);
+ input_arguments[nr_of_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));
+
+ DPU_FOREACH(dpu_set, dpu, i) {
+ DPU_ASSERT(dpu_prepare_xfer(dpu, bufferB + input_size_dpu_8bytes * i));
+ }
+ DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_TO_DPU, DPU_MRAM_HEAP_POINTER_NAME, input_size_dpu_8bytes * sizeof(T), input_size_dpu_8bytes * sizeof(T), DPU_XFER_DEFAULT));
+ if(rep >= p.n_warmup)
+ stop(&timer, 1);
+
+ printf("Run program on DPU(s) \n");
+ // Run DPU kernel
+ if(rep >= p.n_warmup) {
+ start(&timer, 2, rep - p.n_warmup);
+ #if ENERGY
+ DPU_ASSERT(dpu_probe_start(&probe));
+ #endif
+ }
+ DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS));
+ if(rep >= p.n_warmup) {
+ stop(&timer, 2);
+ #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++;
+ }
+ }
+#endif
+
+ printf("Retrieve results\n");
+ if(rep >= p.n_warmup)
+ start(&timer, 3, rep - p.n_warmup);
+ i = 0;
+ // PARALLEL RETRIEVE TRANSFER
+ DPU_FOREACH(dpu_set, dpu, i) {
+ DPU_ASSERT(dpu_prepare_xfer(dpu, bufferC + input_size_dpu_8bytes * i));
+ }
+ DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_FROM_DPU, DPU_MRAM_HEAP_POINTER_NAME, input_size_dpu_8bytes * sizeof(T), input_size_dpu_8bytes * sizeof(T), DPU_XFER_DEFAULT));
+ if(rep >= p.n_warmup)
+ stop(&timer, 3);
+
+ }
+
+ // Print timing results
+ printf("CPU ");
+ print(&timer, 0, p.n_reps);
+ printf("CPU-DPU ");
+ print(&timer, 1, p.n_reps);
+ printf("DPU Kernel ");
+ print(&timer, 2, p.n_reps);
+ printf("DPU-CPU ");
+ print(&timer, 3, p.n_reps);
+
+#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;
+ for (i = 0; i < input_size; i++) {
+ if(C[i] != bufferC[i]){
+ status = false;
+#if PRINT
+ printf("%d: %u -- %u\n", i, C[i], bufferC[i]);
+#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(B);
+ free(C);
+ free(C2);
+ DPU_ASSERT(dpu_free(dpu_set));
+
+ return status ? 0 : -1;
+}
diff --git a/VA/support/common.h b/VA/support/common.h
new file mode 100755
index 0000000..c1043fd
--- /dev/null
+++ b/VA/support/common.h
@@ -0,0 +1,62 @@
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+// Structures used by both the host and the dpu to communicate information
+typedef struct {
+ uint32_t size;
+ uint32_t transfer_size;
+ enum kernels {
+ kernel1 = 0,
+ nr_kernels = 1,
+ } kernel;
+} dpu_arguments_t;
+
+// Transfer size between MRAM and WRAM
+#ifdef BL
+#define BLOCK_SIZE_LOG2 BL
+#define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2)
+#else
+#define BLOCK_SIZE_LOG2 8
+#define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2)
+#define BL BLOCK_SIZE_LOG2
+#endif
+
+// Data type
+#ifdef UINT32
+#define T uint32_t
+#define DIV 2 // Shift right to divide by sizeof(T)
+#elif UINT64
+#define T uint64_t
+#define DIV 3 // Shift right to divide by sizeof(T)
+#elif INT32
+#define T int32_t
+#define DIV 2 // Shift right to divide by sizeof(T)
+#elif INT64
+#define T int64_t
+#define DIV 3 // Shift right to divide by sizeof(T)
+#elif FLOAT
+#define T float
+#define DIV 2 // Shift right to divide by sizeof(T)
+#elif DOUBLE
+#define T double
+#define DIV 3 // Shift right to divide by sizeof(T)
+#elif CHAR
+#define T char
+#define DIV 0 // Shift right to divide by sizeof(T)
+#elif SHORT
+#define T short
+#define DIV 1 // Shift right to divide by sizeof(T)
+#endif
+
+#ifndef ENERGY
+#define ENERGY 0
+#endif
+#define PRINT 0
+
+#define ANSI_COLOR_RED "\x1b[31m"
+#define ANSI_COLOR_GREEN "\x1b[32m"
+#define ANSI_COLOR_RESET "\x1b[0m"
+
+#define divceil(n, m) (((n)-1) / (m) + 1)
+#define roundup(n, m) ((n / m) * m + m)
+#endif
diff --git a/VA/support/params.h b/VA/support/params.h
new file mode 100644
index 0000000..efb34f3
--- /dev/null
+++ b/VA/support/params.h
@@ -0,0 +1,56 @@
+#ifndef _PARAMS_H_
+#define _PARAMS_H_
+
+#include "common.h"
+
+typedef struct Params {
+ unsigned int input_size;
+ int n_warmup;
+ int n_reps;
+ int exp;
+}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) scaling (default=0)"
+ "\n"
+ "\nBenchmark-specific options:"
+ "\n -i <I> input size (default=2621440 elements)"
+ "\n");
+}
+
+struct Params input_params(int argc, char **argv) {
+ struct Params p;
+ p.input_size = 2621440;
+ p.n_warmup = 1;
+ p.n_reps = 3;
+ p.exp = 0;
+
+ int opt;
+ while((opt = getopt(argc, argv, "hi:w:e:x:")) >= 0) {
+ switch(opt) {
+ case 'h':
+ usage();
+ exit(0);
+ break;
+ case 'i': p.input_size = atoi(optarg); break;
+ case 'w': p.n_warmup = atoi(optarg); break;
+ case 'e': p.n_reps = atoi(optarg); break;
+ case 'x': p.exp = atoi(optarg); break;
+ default:
+ fprintf(stderr, "\nUnrecognized option!\n");
+ usage();
+ exit(0);
+ }
+ }
+ assert(NR_DPUS > 0 && "Invalid # of dpus!");
+
+ return p;
+}
+#endif
diff --git a/VA/support/timer.h b/VA/support/timer.h
new file mode 100755
index 0000000..eedc385
--- /dev/null
+++ b/VA/support/timer.h
@@ -0,0 +1,59 @@
+/*
+ * 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[4];
+ struct timeval stopTime[4];
+ double time[4];
+
+}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)); }