summaryrefslogtreecommitdiff
path: root/Microbenchmarks
diff options
context:
space:
mode:
Diffstat (limited to 'Microbenchmarks')
-rw-r--r--Microbenchmarks/Arithmetic-Throughput/Makefile46
-rw-r--r--Microbenchmarks/Arithmetic-Throughput/dpu/task.c100
-rw-r--r--Microbenchmarks/Arithmetic-Throughput/host/app.c224
-rwxr-xr-xMicrobenchmarks/Arithmetic-Throughput/run.sh17
-rwxr-xr-xMicrobenchmarks/Arithmetic-Throughput/support/common.h48
-rw-r--r--Microbenchmarks/Arithmetic-Throughput/support/cyclecount.h20
-rw-r--r--Microbenchmarks/Arithmetic-Throughput/support/params.h56
-rwxr-xr-xMicrobenchmarks/Arithmetic-Throughput/support/timer.h59
-rw-r--r--Microbenchmarks/CPU-DPU/Makefile45
-rw-r--r--Microbenchmarks/CPU-DPU/dpu/task.c36
-rw-r--r--Microbenchmarks/CPU-DPU/host/app.c188
-rwxr-xr-xMicrobenchmarks/CPU-DPU/run.sh20
-rwxr-xr-xMicrobenchmarks/CPU-DPU/support/common.h31
-rw-r--r--Microbenchmarks/CPU-DPU/support/params.h56
-rwxr-xr-xMicrobenchmarks/CPU-DPU/support/timer.h59
-rw-r--r--Microbenchmarks/MRAM-Latency/Makefile46
-rw-r--r--Microbenchmarks/MRAM-Latency/dpu/copy.c84
-rw-r--r--Microbenchmarks/MRAM-Latency/host/app.c208
-rwxr-xr-xMicrobenchmarks/MRAM-Latency/run.sh21
-rwxr-xr-xMicrobenchmarks/MRAM-Latency/support/common.h36
-rw-r--r--Microbenchmarks/MRAM-Latency/support/cyclecount.h19
-rw-r--r--Microbenchmarks/MRAM-Latency/support/params.h56
-rwxr-xr-xMicrobenchmarks/MRAM-Latency/support/timer.h59
-rw-r--r--Microbenchmarks/Operational-Intensity/Makefile46
-rw-r--r--Microbenchmarks/Operational-Intensity/dpu/task.c99
-rw-r--r--Microbenchmarks/Operational-Intensity/host/app.c221
-rwxr-xr-xMicrobenchmarks/Operational-Intensity/run.sh20
-rwxr-xr-xMicrobenchmarks/Operational-Intensity/support/common.h55
-rw-r--r--Microbenchmarks/Operational-Intensity/support/cyclecount.h19
-rw-r--r--Microbenchmarks/Operational-Intensity/support/params.h60
-rwxr-xr-xMicrobenchmarks/Operational-Intensity/support/timer.h59
-rw-r--r--Microbenchmarks/Random-GUPS/Makefile44
-rw-r--r--Microbenchmarks/Random-GUPS/dpu/gups.c95
-rw-r--r--Microbenchmarks/Random-GUPS/host/app.c221
-rwxr-xr-xMicrobenchmarks/Random-GUPS/run.sh14
-rwxr-xr-xMicrobenchmarks/Random-GUPS/support/common.h76
-rw-r--r--Microbenchmarks/Random-GUPS/support/cyclecount.h20
-rw-r--r--Microbenchmarks/Random-GUPS/support/params.h56
-rwxr-xr-xMicrobenchmarks/Random-GUPS/support/timer.h59
-rw-r--r--Microbenchmarks/STREAM/Makefile46
-rw-r--r--Microbenchmarks/STREAM/dpu/add.c103
-rw-r--r--Microbenchmarks/STREAM/dpu/copy.c75
-rw-r--r--Microbenchmarks/STREAM/dpu/copyw.c101
-rw-r--r--Microbenchmarks/STREAM/dpu/scale.c103
-rw-r--r--Microbenchmarks/STREAM/dpu/triad.c105
-rw-r--r--Microbenchmarks/STREAM/host/app.c248
-rwxr-xr-xMicrobenchmarks/STREAM/run.sh35
-rwxr-xr-xMicrobenchmarks/STREAM/support/common.h36
-rw-r--r--Microbenchmarks/STREAM/support/cyclecount.h20
-rw-r--r--Microbenchmarks/STREAM/support/params.h56
-rwxr-xr-xMicrobenchmarks/STREAM/support/timer.h59
-rw-r--r--Microbenchmarks/STRIDED/Makefile45
-rw-r--r--Microbenchmarks/STRIDED/dpu/strided.c103
-rw-r--r--Microbenchmarks/STRIDED/host/app.c211
-rwxr-xr-xMicrobenchmarks/STRIDED/run.sh20
-rwxr-xr-xMicrobenchmarks/STRIDED/support/common.h37
-rw-r--r--Microbenchmarks/STRIDED/support/cyclecount.h20
-rw-r--r--Microbenchmarks/STRIDED/support/params.h60
-rwxr-xr-xMicrobenchmarks/STRIDED/support/timer.h59
-rw-r--r--Microbenchmarks/WRAM/Makefile47
-rw-r--r--Microbenchmarks/WRAM/dpu/task.c111
-rw-r--r--Microbenchmarks/WRAM/host/app.c232
-rwxr-xr-xMicrobenchmarks/WRAM/run.sh37
-rwxr-xr-xMicrobenchmarks/WRAM/support/common.h43
-rw-r--r--Microbenchmarks/WRAM/support/cyclecount.h19
-rw-r--r--Microbenchmarks/WRAM/support/params.h61
-rwxr-xr-xMicrobenchmarks/WRAM/support/timer.h59
67 files changed, 4849 insertions, 0 deletions
diff --git a/Microbenchmarks/Arithmetic-Throughput/Makefile b/Microbenchmarks/Arithmetic-Throughput/Makefile
new file mode 100644
index 0000000..137e7b5
--- /dev/null
+++ b/Microbenchmarks/Arithmetic-Throughput/Makefile
@@ -0,0 +1,46 @@
+DPU_DIR := dpu
+HOST_DIR := host
+BUILDDIR ?= bin
+NR_TASKLETS ?= 16
+BL ?= 10
+NR_DPUS ?= 1
+OP ?= ADD
+TYPE ?= INT32
+
+define conf_filename
+ ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3)_$(4)_$(5).conf
+endef
+CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL},${OP},${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${OP} -D${TYPE}
+DPU_FLAGS := ${COMMON_FLAGS} -O2 -flto -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${OP} -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/Microbenchmarks/Arithmetic-Throughput/dpu/task.c b/Microbenchmarks/Arithmetic-Throughput/dpu/task.c
new file mode 100644
index 0000000..2f538ff
--- /dev/null
+++ b/Microbenchmarks/Arithmetic-Throughput/dpu/task.c
@@ -0,0 +1,100 @@
+/*
+* Execution of arithmetic operations 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"
+#include "../support/cyclecount.h"
+
+__host dpu_arguments_t DPU_INPUT_ARGUMENTS;
+__host dpu_results_t DPU_RESULTS[NR_TASKLETS];
+
+// Arithmetic operation
+static void update(T *bufferA, T scalar) {
+ //#pragma unroll
+ for (unsigned int i = 0; i < BLOCK_SIZE / sizeof(T); i++){
+ // WRAM READ
+ T temp = bufferA[i];
+#ifdef ADD
+ temp += scalar; // ADD
+#elif SUB
+ temp -= scalar; // SUB
+#elif MUL
+ temp *= scalar; // MUL
+#elif DIV
+ temp /= scalar; // DIV
+#endif
+ // WRAM WRITE
+ bufferA[i] = temp;
+ }
+}
+
+// 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
+
+ perfcounter_config(COUNT_CYCLES, true);
+ }
+ // Barrier
+ barrier_wait(&my_barrier);
+ perfcounter_cycles cycles;
+
+ uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size / sizeof(T);
+ T scalar = (T)input_size_dpu; // Simply use this number as a scalar
+
+ dpu_results_t *result = &DPU_RESULTS[tasklet_id];
+ result->cycles = 0;
+
+ // Address of the current processing block in MRAM
+ uint32_t mram_base_addr_A = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2));
+ uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + input_size_dpu * sizeof(T));
+
+ // Initialize a local cache to store the MRAM block
+ T *cache_A = (T *) mem_alloc(BLOCK_SIZE);
+
+ for(unsigned int byte_index = 0; byte_index < input_size_dpu * sizeof(T); byte_index += BLOCK_SIZE * NR_TASKLETS){
+
+ // Load cache with current MRAM block
+ mram_read((__mram_ptr void const*)(mram_base_addr_A + byte_index), cache_A, BLOCK_SIZE);
+
+ // Barrier
+ barrier_wait(&my_barrier);
+ timer_start(&cycles); // START TIMER
+
+ // Update
+ update(cache_A, scalar);
+
+ result->cycles += timer_stop(&cycles); // STOP TIMER
+ // Barrier
+ barrier_wait(&my_barrier);
+
+ // Write cache to current MRAM block
+ mram_write(cache_A, (__mram_ptr void*)(mram_base_addr_B + byte_index), BLOCK_SIZE);
+ }
+
+ return 0;
+}
diff --git a/Microbenchmarks/Arithmetic-Throughput/host/app.c b/Microbenchmarks/Arithmetic-Throughput/host/app.c
new file mode 100644
index 0000000..5933d1d
--- /dev/null
+++ b/Microbenchmarks/Arithmetic-Throughput/host/app.c
@@ -0,0 +1,224 @@
+/**
+* app.c
+* Arithmetic Throughput 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
+
+// Pointer declaration
+static T* A;
+static T* B;
+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 update_host(T* C, T* A, unsigned int nr_elements) {
+ for (unsigned int i = 0; i < nr_elements; i++) {
+#if ADD
+ C[i] = A[i] + (nr_elements / NR_DPUS);
+#elif SUB
+ C[i] = A[i] - (nr_elements / NR_DPUS);
+#elif MUL
+ C[i] = A[i] * (nr_elements / NR_DPUS);
+#elif DIV
+ C[i] = A[i] / (nr_elements / NR_DPUS);
+#endif
+ }
+}
+
+// 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;
+
+ // 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;
+ double cc = 0;
+ double cc_min = 0;
+ const unsigned int input_size = p.exp == 0 ? p.input_size * nr_of_dpus : p.input_size;
+
+ // Input/output allocation
+ A = malloc(input_size * sizeof(T));
+ B = malloc(input_size * sizeof(T));
+ T *bufferA = A;
+ T *bufferB = B;
+ C2 = malloc(input_size * sizeof(T));
+
+ // 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);
+ update_host(C2, A, 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
+ const unsigned int input_size_dpu = input_size / nr_of_dpus;
+ unsigned int kernel = 0;
+ dpu_arguments_t input_arguments = {input_size_dpu * sizeof(T), kernel};
+ DPU_ASSERT(dpu_copy_to(dpu_set, "DPU_INPUT_ARGUMENTS", 0, (const void *)&input_arguments, sizeof(input_arguments)));
+ // Copy input arrays
+ i = 0;
+ DPU_FOREACH (dpu_set, dpu) {
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME, 0, bufferA + input_size_dpu * i, input_size_dpu * sizeof(T)));
+ i++;
+ }
+ 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);
+ DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS));
+ if(rep >= p.n_warmup)
+ stop(&timer, 2);
+
+#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);
+ dpu_results_t results[nr_of_dpus];
+ i = 0;
+ DPU_FOREACH (dpu_set, dpu) {
+ // Copy output array
+ DPU_ASSERT(dpu_copy_from(dpu, DPU_MRAM_HEAP_POINTER_NAME, input_size_dpu * sizeof(T), bufferB + input_size_dpu * i, input_size_dpu * sizeof(T)));
+
+#if PERF
+ results[i].cycles = 0;
+ // Retrieve tasklet timings
+ for (unsigned int each_tasklet = 0; each_tasklet < NR_TASKLETS; each_tasklet++) {
+ dpu_results_t result;
+ result.cycles = 0;
+ DPU_ASSERT(dpu_copy_from(dpu, "DPU_RESULTS", each_tasklet * sizeof(dpu_results_t), &result, sizeof(dpu_results_t)));
+ if (result.cycles > results[i].cycles)
+ results[i].cycles = result.cycles;
+ }
+#endif
+ i++;
+ }
+ if(rep >= p.n_warmup)
+ stop(&timer, 3);
+
+#if PERF
+ uint64_t max_cycles = 0;
+ uint64_t min_cycles = 0xFFFFFFFFFFFFFFFF;
+ // Print performance results
+ if(rep >= p.n_warmup){
+ i = 0;
+ DPU_FOREACH(dpu_set, dpu) {
+ if(results[i].cycles > max_cycles)
+ max_cycles = results[i].cycles;
+ if(results[i].cycles < min_cycles)
+ min_cycles = results[i].cycles;
+ i++;
+ }
+ cc += (double)max_cycles;
+ cc_min += (double)min_cycles;
+ }
+#endif
+
+ }
+#ifdef ADD
+ printf("ADD\n");
+#elif SUB
+ printf("SUB\n");
+#elif MUL
+ printf("MUL\n");
+#elif DIV
+ printf("DIV\n");
+#endif
+ printf("DPU cycles = %g cc\n", cc / p.n_reps);
+
+ // 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);
+
+ // Check output
+ bool status = true;
+ for (i = 0; i < input_size; i++) {
+ if(C2[i] != bufferB[i]){
+ status = false;
+#if PRINT
+ printf("%d: %u -- %u\n", i, C2[i], bufferB[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(C2);
+ DPU_ASSERT(dpu_free(dpu_set));
+
+ return status ? 0 : -1;
+}
diff --git a/Microbenchmarks/Arithmetic-Throughput/run.sh b/Microbenchmarks/Arithmetic-Throughput/run.sh
new file mode 100755
index 0000000..9200e54
--- /dev/null
+++ b/Microbenchmarks/Arithmetic-Throughput/run.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+for i in ADD SUB MUL DIV
+do
+ for j in INT32 FLOAT UINT32 INT64 DOUBLE UINT64
+ do
+ for k in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
+ do
+ NR_DPUS=1 NR_TASKLETS=$k BL=10 OP=$i TYPE=$j make all
+ wait
+ ./bin/host_code -w 0 -e 1 -i 1048576 > profile/${i}_${j}_tl${k}.txt
+ wait
+ make clean
+ wait
+ done
+ done
+done
diff --git a/Microbenchmarks/Arithmetic-Throughput/support/common.h b/Microbenchmarks/Arithmetic-Throughput/support/common.h
new file mode 100755
index 0000000..0d1cc8a
--- /dev/null
+++ b/Microbenchmarks/Arithmetic-Throughput/support/common.h
@@ -0,0 +1,48 @@
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+// Structures used by both the host and the dpu to communicate information
+typedef struct {
+ uint32_t size;
+ enum kernels {
+ kernel1 = 0,
+ nr_kernels = 1,
+ } kernel;
+} dpu_arguments_t;
+
+typedef struct {
+ uint64_t cycles;
+} dpu_results_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
+#elif UINT64
+#define T uint64_t
+#elif INT32
+#define T int32_t
+#elif INT64
+#define T int64_t
+#elif FLOAT
+#define T float
+#elif DOUBLE
+#define T double
+#endif
+
+#define PERF 1 // Use perfcounters?
+#define PRINT 0
+
+#define ANSI_COLOR_RED "\x1b[31m"
+#define ANSI_COLOR_GREEN "\x1b[32m"
+#define ANSI_COLOR_RESET "\x1b[0m"
+#endif
diff --git a/Microbenchmarks/Arithmetic-Throughput/support/cyclecount.h b/Microbenchmarks/Arithmetic-Throughput/support/cyclecount.h
new file mode 100644
index 0000000..4ef377e
--- /dev/null
+++ b/Microbenchmarks/Arithmetic-Throughput/support/cyclecount.h
@@ -0,0 +1,20 @@
+#include <perfcounter.h>
+
+// Timer
+typedef struct perfcounter_cycles{
+ perfcounter_t start;
+ perfcounter_t end;
+ perfcounter_t end2;
+
+}perfcounter_cycles;
+
+void timer_start(perfcounter_cycles *cycles){
+ cycles->start = perfcounter_get(); // START TIMER
+}
+
+uint64_t timer_stop(perfcounter_cycles *cycles){
+ cycles->end = perfcounter_get(); // STOP TIMER
+ cycles->end2 = perfcounter_get(); // STOP TIMER
+ return(((uint64_t)((uint32_t)(((cycles->end >> 4) - (cycles->start >> 4)) - ((cycles->end2 >> 4) - (cycles->end >> 4))))) << 4);
+}
+
diff --git a/Microbenchmarks/Arithmetic-Throughput/support/params.h b/Microbenchmarks/Arithmetic-Throughput/support/params.h
new file mode 100644
index 0000000..4618411
--- /dev/null
+++ b/Microbenchmarks/Arithmetic-Throughput/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=8K elements)"
+ "\n");
+}
+
+struct Params input_params(int argc, char **argv) {
+ struct Params p;
+ p.input_size = 8 << 10;
+ 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/Microbenchmarks/Arithmetic-Throughput/support/timer.h b/Microbenchmarks/Arithmetic-Throughput/support/timer.h
new file mode 100755
index 0000000..eedc385
--- /dev/null
+++ b/Microbenchmarks/Arithmetic-Throughput/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)); }
diff --git a/Microbenchmarks/CPU-DPU/Makefile b/Microbenchmarks/CPU-DPU/Makefile
new file mode 100644
index 0000000..09d613a
--- /dev/null
+++ b/Microbenchmarks/CPU-DPU/Makefile
@@ -0,0 +1,45 @@
+DPU_DIR := dpu
+HOST_DIR := host
+BUILDDIR ?= bin
+NR_TASKLETS ?= 16
+BL ?= 8
+NR_DPUS ?= 1
+TRANSFER ?= PUSH
+
+define conf_filename
+ ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3)_TRANSFER_$(4).conf
+endef
+CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL},${TRANSFER})
+
+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${TRANSFER}
+DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${TRANSFER}
+
+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/Microbenchmarks/CPU-DPU/dpu/task.c b/Microbenchmarks/CPU-DPU/dpu/task.c
new file mode 100644
index 0000000..cb68b4c
--- /dev/null
+++ b/Microbenchmarks/CPU-DPU/dpu/task.c
@@ -0,0 +1,36 @@
+/*
+* Empty kernel 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;
+
+// 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() {
+#if PRINT
+ unsigned int tasklet_id = me();
+ printf("tasklet_id = %u\n", tasklet_id);
+#endif
+ return 0;
+}
diff --git a/Microbenchmarks/CPU-DPU/host/app.c b/Microbenchmarks/CPU-DPU/host/app.c
new file mode 100644
index 0000000..6b8ab53
--- /dev/null
+++ b/Microbenchmarks/CPU-DPU/host/app.c
@@ -0,0 +1,188 @@
+/**
+* app.c
+* CPU-DPU Communication 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
+
+// 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] = A[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;
+
+ // Allocate DPUs and load binary
+ DPU_ASSERT(dpu_alloc(NR_DPUS, "nrThreadPerPool=8", &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;
+ unsigned int input_size = p.exp == 0 ? p.input_size * nr_of_dpus : p.input_size;
+
+ // Input/output allocation
+ A = malloc(input_size * sizeof(T));
+ B = malloc(input_size * sizeof(T));
+ C = malloc(input_size * sizeof(T));
+ C2 = malloc(input_size * sizeof(T));
+ T *bufferA = A;
+ T *bufferC = C;
+
+ // 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++) {
+
+ printf("Load input data\n");
+ // Input arguments
+ const unsigned int input_size_dpu = input_size / nr_of_dpus;
+ // Copy input arrays
+ if(rep >= p.n_warmup)
+ start(&timer, 1, rep - p.n_warmup);
+ i = 0;
+#ifdef SERIAL
+ DPU_FOREACH (dpu_set, dpu) {
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME, 0, bufferA + input_size_dpu * i, input_size_dpu * sizeof(T)));
+ i++;
+ }
+#elif BROADCAST
+ DPU_ASSERT(dpu_broadcast_to(dpu_set, DPU_MRAM_HEAP_POINTER_NAME, 0, bufferA, input_size_dpu * sizeof(T), DPU_XFER_DEFAULT));
+#else
+ DPU_FOREACH(dpu_set, dpu, i) {
+ DPU_ASSERT(dpu_prepare_xfer(dpu, bufferA + input_size_dpu * i));
+ }
+ DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_TO_DPU, DPU_MRAM_HEAP_POINTER_NAME, 0, input_size_dpu * sizeof(T), DPU_XFER_DEFAULT));
+#endif
+ 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);
+ //DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS));
+ if(rep >= p.n_warmup)
+ stop(&timer, 2);
+
+#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;
+#ifdef SERIAL
+ DPU_FOREACH (dpu_set, dpu) {
+ DPU_ASSERT(dpu_copy_from(dpu, DPU_MRAM_HEAP_POINTER_NAME, 0, bufferC + input_size_dpu * i, input_size_dpu * sizeof(T)));
+ i++;
+ }
+#else
+ DPU_FOREACH(dpu_set, dpu, i) {
+ DPU_ASSERT(dpu_prepare_xfer(dpu, bufferC + input_size_dpu * i));
+ }
+ DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_FROM_DPU, DPU_MRAM_HEAP_POINTER_NAME, 0, input_size_dpu * sizeof(T), DPU_XFER_DEFAULT));
+#endif
+ if(rep >= p.n_warmup)
+ stop(&timer, 3);
+
+ }
+
+ // Print timing results
+ printf("CPU-DPU ");
+ print(&timer, 1, p.n_reps);
+ double time_load = timer.time[1] / (1000 * p.n_reps);
+ printf("CPU-DPU Bandwidth (GB/s): %f\n", (input_size * 8)/(time_load*1e6));
+ printf("DPU Kernel ");
+ print(&timer, 2, p.n_reps);
+ printf("\n");
+ printf("DPU-CPU ");
+ print(&timer, 3, p.n_reps);
+ double time_retrieve = timer.time[3] / (1000 * p.n_reps);
+ printf("DPU-CPU Bandwidth (GB/s): %f\n", (input_size * 8)/(time_retrieve*1e6));
+
+ // Check output
+ bool status = true;
+#ifdef BROADCAST
+ for (i = 0; i < input_size/nr_of_dpus; i++) {
+ if(B[i] != bufferC[i]){
+ status = false;
+#if PRINT
+ printf("%d: %u -- %u\n", i, B[i], bufferA[i]);
+#endif
+ }
+ }
+#else
+ for (i = 0; i < input_size; i++) {
+ if(B[i] != bufferC[i]){
+ status = false;
+#if PRINT
+ printf("%d: %u -- %u\n", i, B[i], bufferA[i]);
+#endif
+ }
+ }
+#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/Microbenchmarks/CPU-DPU/run.sh b/Microbenchmarks/CPU-DPU/run.sh
new file mode 100755
index 0000000..09cdd7a
--- /dev/null
+++ b/Microbenchmarks/CPU-DPU/run.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+for i in 1 2 4 8 16 32 64
+do
+ for j in 1
+ do
+ for k in SERIAL PUSH BROADCAST
+ do
+ for l in 1 4 16 64 256 1024 4096 16384 65536 262144 1048576 4194304
+ do
+ NR_DPUS=$i NR_TASKLETS=$j BL=10 TRANSFER=$k make all
+ wait
+ ./bin/host_code -w 5 -e 20 -i ${l} >& profile/${i}_tl${j}_TR${k}_i${l}.txt
+ wait
+ make clean
+ wait
+ done
+ done
+ done
+done
diff --git a/Microbenchmarks/CPU-DPU/support/common.h b/Microbenchmarks/CPU-DPU/support/common.h
new file mode 100755
index 0000000..3c3c6ae
--- /dev/null
+++ b/Microbenchmarks/CPU-DPU/support/common.h
@@ -0,0 +1,31 @@
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+// Structures used by both the host and the dpu to communicate information
+typedef struct {
+ uint32_t 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
+#define T uint64_t
+
+#define PRINT 0
+
+#define ANSI_COLOR_RED "\x1b[31m"
+#define ANSI_COLOR_GREEN "\x1b[32m"
+#define ANSI_COLOR_RESET "\x1b[0m"
+#endif
diff --git a/Microbenchmarks/CPU-DPU/support/params.h b/Microbenchmarks/CPU-DPU/support/params.h
new file mode 100644
index 0000000..4618411
--- /dev/null
+++ b/Microbenchmarks/CPU-DPU/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=8K elements)"
+ "\n");
+}
+
+struct Params input_params(int argc, char **argv) {
+ struct Params p;
+ p.input_size = 8 << 10;
+ 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/Microbenchmarks/CPU-DPU/support/timer.h b/Microbenchmarks/CPU-DPU/support/timer.h
new file mode 100755
index 0000000..eedc385
--- /dev/null
+++ b/Microbenchmarks/CPU-DPU/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)); }
diff --git a/Microbenchmarks/MRAM-Latency/Makefile b/Microbenchmarks/MRAM-Latency/Makefile
new file mode 100644
index 0000000..b8dc7e2
--- /dev/null
+++ b/Microbenchmarks/MRAM-Latency/Makefile
@@ -0,0 +1,46 @@
+DPU_DIR := dpu
+HOST_DIR := host
+BUILDDIR ?= bin
+NR_TASKLETS ?= 16
+BL ?= 8
+NR_DPUS ?= 1
+OP ?= READ
+MEM ?= MRAM
+
+define conf_filename
+ ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3)_$(4)_$(5).conf
+endef
+CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL},${OP},${MEM})
+
+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${OP} -D${MEM}
+DPU_FLAGS := ${COMMON_FLAGS} -O2 -flto -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${OP} -D${MEM}
+
+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/Microbenchmarks/MRAM-Latency/dpu/copy.c b/Microbenchmarks/MRAM-Latency/dpu/copy.c
new file mode 100644
index 0000000..5cfd141
--- /dev/null
+++ b/Microbenchmarks/MRAM-Latency/dpu/copy.c
@@ -0,0 +1,84 @@
+/*
+* MRAM-WRAM R/W Latency with multiple tasklets
+*
+*/
+#include <stdint.h>
+#include <stdio.h>
+#include <defs.h>
+#include <mram.h>
+#include <alloc.h>
+#include <barrier.h>
+
+#include "../support/common.h"
+#include "../support/cyclecount.h"
+
+__host dpu_arguments_t DPU_INPUT_ARGUMENTS;
+__host dpu_results_t DPU_RESULTS[NR_TASKLETS];
+
+// 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
+
+ perfcounter_config(COUNT_CYCLES, true);
+ }
+ perfcounter_cycles cycles;
+ // Barrier
+ barrier_wait(&my_barrier);
+
+ uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size / sizeof(T);
+
+ dpu_results_t *result = &DPU_RESULTS[tasklet_id];
+ result->cycles = 0;
+
+ // Address of the current processing block in MRAM
+ uint32_t mram_base_addr_A = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2));
+ uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + input_size_dpu * sizeof(T));
+
+ // Initialize a local cache to store the MRAM block
+ T *cache_A = (T *) mem_alloc(BLOCK_SIZE);
+
+ for(unsigned int byte_index = 0; byte_index < input_size_dpu * sizeof(T); byte_index += BLOCK_SIZE * NR_TASKLETS){
+ __mram_ptr void const* address_A = (__mram_ptr void const*)(mram_base_addr_A + byte_index);
+ __mram_ptr void* address_B = (__mram_ptr void*)(mram_base_addr_B + byte_index);
+#ifdef READ
+ // Barrier
+ timer_start(&cycles); // START TIMER
+#endif
+ // Load cache with current MRAM block
+ mram_read(address_A, cache_A, BLOCK_SIZE);
+#ifdef READ
+ // Barrier
+ result->cycles += timer_stop(&cycles); // STOP TIMER
+#endif
+
+#ifdef WRITE
+ // Barrier
+ timer_start(&cycles); // START TIMER
+#endif
+ // Write cache to current MRAM block
+ mram_write(cache_A, address_B, BLOCK_SIZE);
+#ifdef WRITE
+ // Barrier
+ result->cycles += timer_stop(&cycles); // STOP TIMER
+#endif
+ }
+
+ return 0;
+}
diff --git a/Microbenchmarks/MRAM-Latency/host/app.c b/Microbenchmarks/MRAM-Latency/host/app.c
new file mode 100644
index 0000000..c968749
--- /dev/null
+++ b/Microbenchmarks/MRAM-Latency/host/app.c
@@ -0,0 +1,208 @@
+/**
+* app.c
+* MRAM Latency 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
+
+// Pointer declaration
+static T* A;
+static T* B;
+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 stream_host(T* C, T* A, unsigned int nr_elements) {
+ for (unsigned int i = 0; i < nr_elements; i++) {
+ C[i] = A[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;
+
+ // 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;
+ double cc = 0;
+ double cc_min = 0;
+ const unsigned int input_size = p.exp == 0 ? p.input_size * nr_of_dpus : p.input_size;
+ assert(input_size % (nr_of_dpus * NR_TASKLETS) == 0 && "Input size!");
+
+ // Input/output allocation
+ A = malloc(input_size * sizeof(T));
+ B = malloc(input_size * sizeof(T));
+ T *bufferA = A;
+ T *bufferB = B;
+ C2 = malloc(input_size * sizeof(T));
+
+ // 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);
+ stream_host(C2, A, 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
+ const unsigned int input_size_dpu = input_size / nr_of_dpus;
+ unsigned int kernel = 0;
+ dpu_arguments_t input_arguments = {input_size_dpu * sizeof(T), kernel};
+ DPU_ASSERT(dpu_copy_to(dpu_set, "DPU_INPUT_ARGUMENTS", 0, (const void *)&input_arguments, sizeof(input_arguments)));
+ // Copy input arrays
+ i = 0;
+ DPU_FOREACH (dpu_set, dpu) {
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME, 0, bufferA + input_size_dpu * i, input_size_dpu * sizeof(T)));
+ i++;
+ }
+ 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);
+ DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS));
+ if(rep >= p.n_warmup)
+ stop(&timer, 2);
+
+#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);
+ dpu_results_t results[nr_of_dpus];
+ i = 0;
+ DPU_FOREACH (dpu_set, dpu) {
+ // Copy output array
+ DPU_ASSERT(dpu_copy_from(dpu, DPU_MRAM_HEAP_POINTER_NAME, input_size_dpu * sizeof(T), bufferB + input_size_dpu * i, input_size_dpu * sizeof(T)));
+
+#if PERF
+ results[i].cycles = 0;
+ // Retrieve tasklet timings
+ for (unsigned int each_tasklet = 0; each_tasklet < NR_TASKLETS; each_tasklet++) {
+ dpu_results_t result;
+ result.cycles = 0;
+ DPU_ASSERT(dpu_copy_from(dpu, "DPU_RESULTS", each_tasklet * sizeof(dpu_results_t), &result, sizeof(dpu_results_t)));
+ if (result.cycles > results[i].cycles)
+ results[i].cycles = result.cycles;
+ }
+#endif
+ i++;
+ }
+ if(rep >= p.n_warmup)
+ stop(&timer, 3);
+
+#if PERF
+ uint64_t max_cycles = 0;
+ uint64_t min_cycles = 0xFFFFFFFFFFFFFFFF;
+ // Print performance results
+ if(rep >= p.n_warmup){
+ i = 0;
+ DPU_FOREACH(dpu_set, dpu) {
+ if(results[i].cycles > max_cycles)
+ max_cycles = results[i].cycles;
+ if(results[i].cycles < min_cycles)
+ min_cycles = results[i].cycles;
+ i++;
+ }
+ cc += (double)max_cycles;
+ cc_min += (double)min_cycles;
+ }
+#endif
+
+ }
+ printf("DPU cycles = %g cc\n", cc / p.n_reps);
+
+ // 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);
+
+ // Check output
+ bool status = true;
+ for (i = 0; i < input_size; i++) {
+ if(C2[i] != bufferB[i]){
+ status = false;
+#if PRINT
+ printf("%d: %u -- %u\n", i, C2[i], bufferB[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(C2);
+ DPU_ASSERT(dpu_free(dpu_set));
+
+ return status ? 0 : -1;
+}
diff --git a/Microbenchmarks/MRAM-Latency/run.sh b/Microbenchmarks/MRAM-Latency/run.sh
new file mode 100755
index 0000000..2ae57bf
--- /dev/null
+++ b/Microbenchmarks/MRAM-Latency/run.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+for i in 3 4 5 6 7 8 9 10 11
+do
+ for j in 1
+ do
+ NR_DPUS=1 NR_TASKLETS=$j BL=$i OP=READ make all
+ wait
+ ./bin/host_code -w 0 -e 1 -i 2097152 > profile/read_tl${j}_bl${i}.txt
+ wait
+ make clean
+ wait
+
+ NR_DPUS=1 NR_TASKLETS=$j BL=$i OP=WRITE make all
+ wait
+ ./bin/host_code -w 0 -e 1 -i 2097152 > profile/write_tl${j}_bl${i}.txt
+ wait
+ make clean
+ wait
+ done
+done
diff --git a/Microbenchmarks/MRAM-Latency/support/common.h b/Microbenchmarks/MRAM-Latency/support/common.h
new file mode 100755
index 0000000..8e2e59b
--- /dev/null
+++ b/Microbenchmarks/MRAM-Latency/support/common.h
@@ -0,0 +1,36 @@
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+// Structures used by both the host and the dpu to communicate information
+typedef struct {
+ uint32_t size;
+ enum kernels {
+ kernel1 = 0,
+ nr_kernels = 1,
+ } kernel;
+} dpu_arguments_t;
+
+typedef struct {
+ uint64_t cycles;
+} dpu_results_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
+#define T uint64_t
+
+#define PERF 1 // Use perfcounters?
+#define PRINT 0
+
+#define ANSI_COLOR_RED "\x1b[31m"
+#define ANSI_COLOR_GREEN "\x1b[32m"
+#define ANSI_COLOR_RESET "\x1b[0m"
+#endif
diff --git a/Microbenchmarks/MRAM-Latency/support/cyclecount.h b/Microbenchmarks/MRAM-Latency/support/cyclecount.h
new file mode 100644
index 0000000..c4247b5
--- /dev/null
+++ b/Microbenchmarks/MRAM-Latency/support/cyclecount.h
@@ -0,0 +1,19 @@
+#include <perfcounter.h>
+
+// Timer
+typedef struct perfcounter_cycles{
+ perfcounter_t start;
+ perfcounter_t end;
+ perfcounter_t end2;
+
+}perfcounter_cycles;
+
+void timer_start(perfcounter_cycles *cycles){
+ cycles->start = perfcounter_get(); // START TIMER
+}
+
+uint64_t timer_stop(perfcounter_cycles *cycles){
+ cycles->end = perfcounter_get(); // STOP TIMER
+ cycles->end2 = perfcounter_get(); // STOP TIMER
+ return(((uint64_t)((uint32_t)(((cycles->end >> 4) - (cycles->start >> 4)) - ((cycles->end2 >> 4) - (cycles->end >> 4))))) << 4);
+}
diff --git a/Microbenchmarks/MRAM-Latency/support/params.h b/Microbenchmarks/MRAM-Latency/support/params.h
new file mode 100644
index 0000000..4618411
--- /dev/null
+++ b/Microbenchmarks/MRAM-Latency/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=8K elements)"
+ "\n");
+}
+
+struct Params input_params(int argc, char **argv) {
+ struct Params p;
+ p.input_size = 8 << 10;
+ 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/Microbenchmarks/MRAM-Latency/support/timer.h b/Microbenchmarks/MRAM-Latency/support/timer.h
new file mode 100755
index 0000000..eedc385
--- /dev/null
+++ b/Microbenchmarks/MRAM-Latency/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)); }
diff --git a/Microbenchmarks/Operational-Intensity/Makefile b/Microbenchmarks/Operational-Intensity/Makefile
new file mode 100644
index 0000000..0fcbd8c
--- /dev/null
+++ b/Microbenchmarks/Operational-Intensity/Makefile
@@ -0,0 +1,46 @@
+DPU_DIR := dpu
+HOST_DIR := host
+BUILDDIR ?= bin
+NR_TASKLETS ?= 16
+BL ?= 10
+NR_DPUS ?= 1
+TYPE ?= INT32
+OP ?= ADD
+
+define conf_filename
+ ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3)_$(4)_$(5).conf
+endef
+CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL},${TYPE},${OP})
+
+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} -D${OP}
+DPU_FLAGS := ${COMMON_FLAGS} -O2 -flto -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${TYPE} -D${OP}
+
+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/Microbenchmarks/Operational-Intensity/dpu/task.c b/Microbenchmarks/Operational-Intensity/dpu/task.c
new file mode 100644
index 0000000..ea40fb8
--- /dev/null
+++ b/Microbenchmarks/Operational-Intensity/dpu/task.c
@@ -0,0 +1,99 @@
+/*
+* Arithmetic Throughtput versus Operational Intensity
+*
+*/
+#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"
+#include "../support/cyclecount.h"
+
+__host dpu_arguments_t DPU_INPUT_ARGUMENTS;
+__host dpu_results_t DPU_RESULTS[NR_TASKLETS];
+
+// Update
+static void update(T* bufferA, T scalar, uint32_t rep, uint32_t str) {
+ for (unsigned int r = 0; r < rep; r++){
+ for (unsigned int i = 0; i < BLOCK_SIZE / sizeof(T); i+=str){
+#ifdef ADD
+ bufferA[i] += scalar; // ADD
+#elif SUB
+ bufferA[i] -= scalar; // SUB
+#elif MUL
+ bufferA[i] *= scalar; // MUL
+#elif DIV
+ bufferA[i] /= scalar; // DIV
+#endif
+ }
+ }
+}
+
+// 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
+
+ perfcounter_config(COUNT_CYCLES, true);
+ }
+ // Barrier
+ barrier_wait(&my_barrier);
+ perfcounter_cycles cycles;
+
+ uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size / sizeof(T);
+
+ uint32_t rep = DPU_INPUT_ARGUMENTS.repetitions;
+ uint32_t str = DPU_INPUT_ARGUMENTS.stride;
+ T scalar = DPU_INPUT_ARGUMENTS.scalar; // Simply use this number as a scalar
+
+ dpu_results_t *result = &DPU_RESULTS[tasklet_id];
+ result->cycles = 0;
+
+ // Address of the current processing block in MRAM
+ uint32_t mram_base_addr_A = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2));
+ uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + input_size_dpu * sizeof(T));
+
+ // Initialize a local cache to store the MRAM block
+ T *cache_A = (T *) mem_alloc(BLOCK_SIZE);
+
+ barrier_wait(&my_barrier);
+ timer_start(&cycles); // START TIMER
+
+ for(unsigned int byte_index = 0; byte_index < input_size_dpu * sizeof(T); byte_index += BLOCK_SIZE * NR_TASKLETS){
+
+ // Load cache with current MRAM block
+ mram_read((__mram_ptr void const*)(mram_base_addr_A + byte_index), cache_A, BLOCK_SIZE);
+
+ // Update
+ update(cache_A, scalar, rep, str);
+
+ // Write cache to current MRAM block
+ mram_write(cache_A, (__mram_ptr void*)(mram_base_addr_B + byte_index), BLOCK_SIZE);
+
+ }
+
+ result->cycles = timer_stop(&cycles); // STOP TIMER
+ barrier_wait(&my_barrier);
+
+ return 0;
+}
diff --git a/Microbenchmarks/Operational-Intensity/host/app.c b/Microbenchmarks/Operational-Intensity/host/app.c
new file mode 100644
index 0000000..1fc5f46
--- /dev/null
+++ b/Microbenchmarks/Operational-Intensity/host/app.c
@@ -0,0 +1,221 @@
+/**
+* app.c
+* Operational Intensity 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
+
+// Pointer declaration
+static T* A;
+static T* B;
+
+// Create input arrays
+static void read_input(T* A, 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());
+ }
+}
+
+// Compute output in the host
+static void update_host(T* A, T scalar, unsigned int nr_elements, unsigned int rep, unsigned int str) {
+ for (unsigned int j = 0; j < nr_elements; j+=(BLOCK_SIZE / sizeof(T))) {
+ for (unsigned int r = 0; r < rep; r++){
+ for (unsigned int i = 0; i < BLOCK_SIZE / sizeof(T); i+=str){
+#ifdef ADD
+ A[j + i] += scalar; // ADD
+#elif SUB
+ A[j + i] -= scalar; // SUB
+#elif MUL
+ A[j + i] *= scalar; // MUL
+#elif DIV
+ A[j + i] /= scalar; // DIV
+#endif
+ }
+ }
+ }
+}
+
+// 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;
+
+ // 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;
+ double cc = 0;
+ double cc_min = 0;
+ const unsigned int input_size = p.exp == 0 ? p.input_size * nr_of_dpus : p.input_size;
+
+ // Input/output allocation
+ A = malloc(input_size * sizeof(T));
+ B = malloc(input_size * sizeof(T));
+ T *bufferA = A;
+
+ // Create an input file with arbitrary data
+ read_input(A, input_size);
+ memcpy(B, A, input_size * sizeof(T));
+
+ // Timer declaration
+ Timer timer;
+
+ printf("NR_TASKLETS\t%d\tBL\t%d\n", NR_TASKLETS, BL);
+
+ unsigned int repetitions = p.repetitions >= 1.0 ? (unsigned int)p.repetitions : 1;
+ unsigned int stride = p.repetitions >= 1.0 ? 1 : (unsigned int)(1 / p.repetitions);
+
+ printf("p.repetitions\t%f\trepetitions\t%u\tstride\t%u\n", p.repetitions, repetitions, stride);
+
+ // 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);
+ update_host(B, (T)p.n_reps /*use as a scalar*/, input_size, repetitions, stride);
+ 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
+ const unsigned int input_size_dpu = input_size / nr_of_dpus;
+ unsigned int kernel = 0;
+ T scalar = (T)p.n_reps; // Just a scalar
+ dpu_arguments_t input_arguments = {input_size_dpu * sizeof(T), kernel, repetitions, stride, scalar};
+ DPU_ASSERT(dpu_copy_to(dpu_set, "DPU_INPUT_ARGUMENTS", 0, (const void *)&input_arguments, sizeof(input_arguments)));
+ // Copy input arrays
+ i = 0;
+ DPU_FOREACH (dpu_set, dpu) {
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME, 0, bufferA + input_size_dpu * i, input_size_dpu * sizeof(T)));
+ i++;
+ }
+ 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);
+ DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS));
+ if(rep >= p.n_warmup)
+ stop(&timer, 2);
+
+#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);
+ dpu_results_t results[nr_of_dpus];
+ i = 0;
+ DPU_FOREACH (dpu_set, dpu) {
+ // Copy output array
+ DPU_ASSERT(dpu_copy_from(dpu, DPU_MRAM_HEAP_POINTER_NAME, input_size_dpu * sizeof(T), bufferA + input_size_dpu * i, input_size_dpu * sizeof(T)));
+
+#if PERF
+ results[i].cycles = 0;
+ // Retrieve tasklet timings
+ for (unsigned int each_tasklet = 0; each_tasklet < NR_TASKLETS; each_tasklet++) {
+ dpu_results_t result;
+ result.cycles = 0;
+ DPU_ASSERT(dpu_copy_from(dpu, "DPU_RESULTS", each_tasklet * sizeof(dpu_results_t), &result, sizeof(dpu_results_t)));
+ if (result.cycles > results[i].cycles)
+ results[i].cycles = result.cycles;
+ }
+#endif
+ i++;
+ }
+ if(rep >= p.n_warmup)
+ stop(&timer, 3);
+
+#if PERF
+ uint64_t max_cycles = 0;
+ uint64_t min_cycles = 0xFFFFFFFFFFFFFFFF;
+ // Print performance results
+ if(rep >= p.n_warmup){
+ i = 0;
+ DPU_FOREACH(dpu_set, dpu) {
+ if(results[i].cycles > max_cycles)
+ max_cycles = results[i].cycles;
+ if(results[i].cycles < min_cycles)
+ min_cycles = results[i].cycles;
+ i++;
+ }
+ cc += (double)max_cycles;
+ cc_min += (double)min_cycles;
+ }
+#endif
+
+ }
+ printf("DPU cycles = %g cc\n", cc / p.n_reps);
+
+ // 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);
+
+ // Check output
+ bool status = true;
+ for (i = 0; i < input_size; i++) {
+ if(B[i] != bufferA[i]){
+ status = false;
+#if PRINT
+ printf("%d: %u -- %u\n", i, B[i], bufferA[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);
+ DPU_ASSERT(dpu_free(dpu_set));
+
+ return status ? 0 : -1;
+}
diff --git a/Microbenchmarks/Operational-Intensity/run.sh b/Microbenchmarks/Operational-Intensity/run.sh
new file mode 100755
index 0000000..a540154
--- /dev/null
+++ b/Microbenchmarks/Operational-Intensity/run.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+for i in ADD SUB MUL DIV
+do
+ for j in CHAR SHORT INT32 FLOAT INT64 DOUBLE
+ do
+ for k in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
+ do
+ for l in 0.001953125 0.00390625 0.0078125 0.015625 0.03125 0.0625 0.125 0.25 0.5 1 2 4 8 16 32 64 128 256 512
+ do
+ NR_DPUS=1 NR_TASKLETS=$k BL=10 OP=$i TYPE=$j make all
+ wait
+ ./bin/host_code -w 0 -e 1 -i 1048576 -p ${l} >& profile/${i}_${j}_tl${k}_p${l}.txt
+ wait
+ make clean
+ wait
+ done
+ done
+ done
+done
diff --git a/Microbenchmarks/Operational-Intensity/support/common.h b/Microbenchmarks/Operational-Intensity/support/common.h
new file mode 100755
index 0000000..aac3eed
--- /dev/null
+++ b/Microbenchmarks/Operational-Intensity/support/common.h
@@ -0,0 +1,55 @@
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+// 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
+#elif UINT64
+#define T uint64_t
+#elif INT32
+#define T int32_t
+#elif INT64
+#define T int64_t
+#elif FLOAT
+#define T float
+#elif DOUBLE
+#define T double
+#elif CHAR
+#define T char
+#elif SHORT
+#define T short
+#endif
+
+// Structures used by both the host and the dpu to communicate information
+typedef struct {
+ uint32_t size;
+ enum kernels {
+ kernel1 = 0,
+ nr_kernels = 1,
+ } kernel;
+ uint32_t repetitions;
+ uint32_t stride;
+ T scalar;
+} dpu_arguments_t;
+
+typedef struct {
+ uint64_t cycles;
+} dpu_results_t;
+
+#define PERF 1 // Use perfcounters?
+#define PRINT 0
+
+#define ANSI_COLOR_RED "\x1b[31m"
+#define ANSI_COLOR_GREEN "\x1b[32m"
+#define ANSI_COLOR_RESET "\x1b[0m"
+#endif
diff --git a/Microbenchmarks/Operational-Intensity/support/cyclecount.h b/Microbenchmarks/Operational-Intensity/support/cyclecount.h
new file mode 100644
index 0000000..c4247b5
--- /dev/null
+++ b/Microbenchmarks/Operational-Intensity/support/cyclecount.h
@@ -0,0 +1,19 @@
+#include <perfcounter.h>
+
+// Timer
+typedef struct perfcounter_cycles{
+ perfcounter_t start;
+ perfcounter_t end;
+ perfcounter_t end2;
+
+}perfcounter_cycles;
+
+void timer_start(perfcounter_cycles *cycles){
+ cycles->start = perfcounter_get(); // START TIMER
+}
+
+uint64_t timer_stop(perfcounter_cycles *cycles){
+ cycles->end = perfcounter_get(); // STOP TIMER
+ cycles->end2 = perfcounter_get(); // STOP TIMER
+ return(((uint64_t)((uint32_t)(((cycles->end >> 4) - (cycles->start >> 4)) - ((cycles->end2 >> 4) - (cycles->end >> 4))))) << 4);
+}
diff --git a/Microbenchmarks/Operational-Intensity/support/params.h b/Microbenchmarks/Operational-Intensity/support/params.h
new file mode 100644
index 0000000..485dae5
--- /dev/null
+++ b/Microbenchmarks/Operational-Intensity/support/params.h
@@ -0,0 +1,60 @@
+#ifndef _PARAMS_H_
+#define _PARAMS_H_
+
+#include "common.h"
+
+typedef struct Params {
+ unsigned int input_size;
+ float repetitions;
+ 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=2)"
+ "\n -e <E> # of timed repetition iterations (default=5)"
+ "\n -x <X> Weak (0) or strong (1) scaling (default=0)"
+ "\n"
+ "\nBenchmark-specific options:"
+ "\n -i <I> input size (default=8K elements)"
+ "\n -p <P> # of compute repetitions (default=2)"
+ "\n");
+}
+
+struct Params input_params(int argc, char **argv) {
+ struct Params p;
+ p.input_size = 8 << 10;
+ p.repetitions = 1.0;
+ p.n_warmup = 2;
+ p.n_reps = 5;
+ p.exp = 0;
+
+ int opt;
+ while((opt = getopt(argc, argv, "hi:p:w:e:")) >= 0) {
+ switch(opt) {
+ case 'h':
+ usage();
+ exit(0);
+ break;
+ case 'i': p.input_size = atoi(optarg); break;
+ case 'p': p.repetitions = atof(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/Microbenchmarks/Operational-Intensity/support/timer.h b/Microbenchmarks/Operational-Intensity/support/timer.h
new file mode 100755
index 0000000..eedc385
--- /dev/null
+++ b/Microbenchmarks/Operational-Intensity/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)); }
diff --git a/Microbenchmarks/Random-GUPS/Makefile b/Microbenchmarks/Random-GUPS/Makefile
new file mode 100644
index 0000000..d517fa7
--- /dev/null
+++ b/Microbenchmarks/Random-GUPS/Makefile
@@ -0,0 +1,44 @@
+DPU_DIR := dpu
+HOST_DIR := host
+BUILDDIR ?= bin
+NR_TASKLETS ?= 16
+BL ?= 8
+NR_DPUS ?= 1
+
+define conf_filename
+ ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3).conf
+endef
+CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL})
+
+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}
+DPU_FLAGS := ${COMMON_FLAGS} -O2 -flto -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL}
+
+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/Microbenchmarks/Random-GUPS/dpu/gups.c b/Microbenchmarks/Random-GUPS/dpu/gups.c
new file mode 100644
index 0000000..dadde35
--- /dev/null
+++ b/Microbenchmarks/Random-GUPS/dpu/gups.c
@@ -0,0 +1,95 @@
+/*
+* Random Access (GUPS) 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"
+#include "../support/cyclecount.h"
+
+__host dpu_arguments_t DPU_INPUT_ARGUMENTS;
+__host dpu_results_t DPU_RESULTS[NR_TASKLETS];
+
+
+T ran[128]; // Current random numbers
+
+// 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
+#if PERF
+ perfcounter_config(COUNT_CYCLES, true);
+#endif
+ }
+ // Barrier
+ barrier_wait(&my_barrier);
+#if PERF
+ perfcounter_cycles cycles;
+ timer_start(&cycles); // START TIMER
+ dpu_results_t *result = &DPU_RESULTS[tasklet_id];
+ result->cycles = 0;
+#endif
+
+ uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size / sizeof(T);
+
+ // Number of updates to table (suggested: 16x number of table entries)
+ int NUPDATE = 16 * input_size_dpu;
+
+ for(int j = tasklet_id; j < 128; j += NR_TASKLETS){
+ ran[j] = HPCC_starts((NUPDATE/128) * j);
+ }
+ // Barrier
+ barrier_wait(&my_barrier);
+
+ // Address of the current processing block in MRAM
+ uint32_t mram_base_addr_A = (uint32_t)DPU_MRAM_HEAP_POINTER;
+
+ // Initialize a local cache to store the MRAM block
+ T *cache_A = (T *) mem_alloc(sizeof(T));
+
+ for (int i = 0; i < NUPDATE/128; i++){
+ for (int j = tasklet_id; j < 128; j += NR_TASKLETS){
+
+ ran[j] = (ran[j] << 1) ^ ((S) ran[j] < 0 ? POLY : 0);
+
+ // Table[ran[j] & (TableSize-1)] ^= ran[j]; is computed as follows (3 steps)
+ // 1. Load cache
+ mram_read((__mram_ptr void const*)(mram_base_addr_A + (ran[j] & (input_size_dpu - 1)) * sizeof(T)), cache_A, sizeof(T));
+
+ // 2. Update
+ //*cache_A ^= ran[j];
+ *cache_A = ran[j] & (input_size_dpu - 1);
+
+ // 3. Write cache
+ mram_write(cache_A, (__mram_ptr void*)(mram_base_addr_A + (ran[j] & (input_size_dpu - 1)) * sizeof(T)), sizeof(T));
+ }
+ }
+
+#if PERF
+ result->cycles += timer_stop(&cycles); // STOP TIMER
+#endif
+
+ return 0;
+}
diff --git a/Microbenchmarks/Random-GUPS/host/app.c b/Microbenchmarks/Random-GUPS/host/app.c
new file mode 100644
index 0000000..74499be
--- /dev/null
+++ b/Microbenchmarks/Random-GUPS/host/app.c
@@ -0,0 +1,221 @@
+/**
+* app.c
+* Random Access (GUPS) 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
+
+// Pointer declaration
+static T* A;
+static T* B;
+
+// 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] = A[i];
+ }
+}
+
+// Compute output in the host
+static void gups_host(T* B, unsigned int nr_elements) {
+
+ // Number of updates to table (suggested: 16x number of table entries)
+ unsigned int NUPDATE = 16 * (nr_elements / NR_DPUS);
+
+ for (unsigned int d = 0; d < NR_DPUS; d++){
+
+ T ran[128]; // Current random numbers
+ for(unsigned int j = 0; j < 128; j++){
+ ran[j] = HPCC_starts((NUPDATE/128) * j);
+ }
+
+ for (unsigned int i = 0; i < NUPDATE/128; i++){
+ for (unsigned int j = 0; j < NR_TASKLETS; j++){
+ for (unsigned int k = j; k < 128; k += NR_TASKLETS){
+ ran[k] = (ran[k] << 1) ^ ((S) ran[k] < 0 ? POLY : 0);
+ //B[((nr_elements / NR_DPUS) * d) + (ran[k] & ((nr_elements / NR_DPUS) - 1))] ^= ran[k];
+ B[((nr_elements / NR_DPUS) * d) + (ran[k] & ((nr_elements / NR_DPUS) - 1))] = ran[k] & ((nr_elements / NR_DPUS) - 1);
+ }
+ }
+ }
+ }
+}
+
+// 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;
+
+ // 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;
+ double cc = 0;
+ double cc_min = 0;
+ const unsigned int input_size = p.exp == 0 ? p.input_size * nr_of_dpus : p.input_size;
+
+ // Input/output allocation
+ A = malloc(input_size * sizeof(T));
+ B = malloc(input_size * sizeof(T));
+ T *bufferA = A;
+
+ // 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);
+ gups_host(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
+ const unsigned int input_size_dpu = input_size / nr_of_dpus;
+ unsigned int kernel = 0;
+ dpu_arguments_t input_arguments = {input_size_dpu * sizeof(T), kernel};
+ DPU_ASSERT(dpu_copy_to(dpu_set, "DPU_INPUT_ARGUMENTS", 0, (const void *)&input_arguments, sizeof(input_arguments)));
+ // Copy input arrays
+ i = 0;
+ DPU_FOREACH (dpu_set, dpu) {
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME, 0, bufferA + input_size_dpu * i, input_size_dpu * sizeof(T)));
+ i++;
+ }
+ 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);
+ DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS));
+ if(rep >= p.n_warmup)
+ stop(&timer, 2);
+
+#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);
+ dpu_results_t results[nr_of_dpus];
+ i = 0;
+ DPU_FOREACH (dpu_set, dpu) {
+ // Copy output array
+ DPU_ASSERT(dpu_copy_from(dpu, DPU_MRAM_HEAP_POINTER_NAME, 0, bufferA + input_size_dpu * i, input_size_dpu * sizeof(T)));
+
+#if PERF
+ results[i].cycles = 0;
+ // Retrieve tasklet timings
+ for (unsigned int each_tasklet = 0; each_tasklet < NR_TASKLETS; each_tasklet++) {
+ dpu_results_t result;
+ result.cycles = 0;
+ DPU_ASSERT(dpu_copy_from(dpu, "DPU_RESULTS", each_tasklet * sizeof(dpu_results_t), &result, sizeof(dpu_results_t)));
+ if (result.cycles > results[i].cycles)
+ results[i].cycles = result.cycles;
+ }
+#endif
+ i++;
+ }
+ if(rep >= p.n_warmup)
+ stop(&timer, 3);
+
+#if PERF
+ uint64_t max_cycles = 0;
+ uint64_t min_cycles = 0xFFFFFFFFFFFFFFFF;
+ // Print performance results
+ if(rep >= p.n_warmup){
+ i = 0;
+ DPU_FOREACH(dpu_set, dpu) {
+ if(results[i].cycles > max_cycles)
+ max_cycles = results[i].cycles;
+ if(results[i].cycles < min_cycles)
+ min_cycles = results[i].cycles;
+ i++;
+ }
+ cc += (double)max_cycles;
+ cc_min += (double)min_cycles;
+ }
+#endif
+
+ }
+ printf("DPU cycles = %g cc\n", cc / p.n_reps);
+
+ // 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);
+
+ // Check output
+ bool status = true;
+ for (i = 0; i < input_size; i++) {
+ if(B[i] != bufferA[i]){
+ status = false;
+#if PRINT
+ printf("%d: %lu -- %lu\n", i, B[i], bufferA[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);
+ DPU_ASSERT(dpu_free(dpu_set));
+
+ return status ? 0 : -1;
+}
diff --git a/Microbenchmarks/Random-GUPS/run.sh b/Microbenchmarks/Random-GUPS/run.sh
new file mode 100755
index 0000000..8c33392
--- /dev/null
+++ b/Microbenchmarks/Random-GUPS/run.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+for i in 1
+do
+ for j in 1 2 4 8 12 16
+ do
+ NR_DPUS=$i NR_TASKLETS=$j BL=10 make all
+ wait
+ ./bin/host_code -w 0 -e 1 -i 2097152 >& profile/gups_${i}_tl${j}.txt
+ wait
+ make clean
+ wait
+ done
+done
diff --git a/Microbenchmarks/Random-GUPS/support/common.h b/Microbenchmarks/Random-GUPS/support/common.h
new file mode 100755
index 0000000..f4eb611
--- /dev/null
+++ b/Microbenchmarks/Random-GUPS/support/common.h
@@ -0,0 +1,76 @@
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+// Structures used by both the host and the dpu to communicate information
+typedef struct {
+ uint32_t size;
+ enum kernels {
+ kernel1 = 0,
+ nr_kernels = 1,
+ } kernel;
+} dpu_arguments_t;
+
+typedef struct {
+ uint64_t cycles;
+} dpu_results_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
+#define T uint64_t
+#define S int64_t
+
+// HPCC_starts function from HPCC benchmark (https://github.com/icl-utk-edu/hpcc/blob/main/RandomAccess/utility.c)
+#define POLY 7ULL
+#define PERIOD 1317624576693539401LL
+
+T HPCC_starts(S n) {
+ int i, j;
+ T m2[64];
+ T temp, ran;
+
+ while (n < 0) n += PERIOD;
+ while (n > PERIOD) n -= PERIOD;
+ if (n == 0) return 0x1;
+
+ temp = 0x1;
+ for (i=0; i<64; i++) {
+ m2[i] = temp;
+ temp = (temp << 1) ^ ((S) temp < 0 ? POLY : 0);
+ temp = (temp << 1) ^ ((S) temp < 0 ? POLY : 0);
+ }
+
+ for (i=62; i>=0; i--)
+ if ((n >> i) & 1)
+ break;
+
+ ran = 0x2;
+ while (i > 0) {
+ temp = 0;
+ for (j=0; j<64; j++)
+ if ((ran >> j) & 1)
+ temp ^= m2[j];
+ ran = temp;
+ i -= 1;
+ if ((n >> i) & 1)
+ ran = (ran << 1) ^ ((S) ran < 0 ? POLY : 0);
+ }
+
+ return ran;
+}
+
+#define PERF 1 // Use perfcounters?
+#define PRINT 0
+
+#define ANSI_COLOR_RED "\x1b[31m"
+#define ANSI_COLOR_GREEN "\x1b[32m"
+#define ANSI_COLOR_RESET "\x1b[0m"
+#endif
diff --git a/Microbenchmarks/Random-GUPS/support/cyclecount.h b/Microbenchmarks/Random-GUPS/support/cyclecount.h
new file mode 100644
index 0000000..4ef377e
--- /dev/null
+++ b/Microbenchmarks/Random-GUPS/support/cyclecount.h
@@ -0,0 +1,20 @@
+#include <perfcounter.h>
+
+// Timer
+typedef struct perfcounter_cycles{
+ perfcounter_t start;
+ perfcounter_t end;
+ perfcounter_t end2;
+
+}perfcounter_cycles;
+
+void timer_start(perfcounter_cycles *cycles){
+ cycles->start = perfcounter_get(); // START TIMER
+}
+
+uint64_t timer_stop(perfcounter_cycles *cycles){
+ cycles->end = perfcounter_get(); // STOP TIMER
+ cycles->end2 = perfcounter_get(); // STOP TIMER
+ return(((uint64_t)((uint32_t)(((cycles->end >> 4) - (cycles->start >> 4)) - ((cycles->end2 >> 4) - (cycles->end >> 4))))) << 4);
+}
+
diff --git a/Microbenchmarks/Random-GUPS/support/params.h b/Microbenchmarks/Random-GUPS/support/params.h
new file mode 100644
index 0000000..4618411
--- /dev/null
+++ b/Microbenchmarks/Random-GUPS/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=8K elements)"
+ "\n");
+}
+
+struct Params input_params(int argc, char **argv) {
+ struct Params p;
+ p.input_size = 8 << 10;
+ 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/Microbenchmarks/Random-GUPS/support/timer.h b/Microbenchmarks/Random-GUPS/support/timer.h
new file mode 100755
index 0000000..eedc385
--- /dev/null
+++ b/Microbenchmarks/Random-GUPS/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)); }
diff --git a/Microbenchmarks/STREAM/Makefile b/Microbenchmarks/STREAM/Makefile
new file mode 100644
index 0000000..c669857
--- /dev/null
+++ b/Microbenchmarks/STREAM/Makefile
@@ -0,0 +1,46 @@
+DPU_DIR := dpu
+HOST_DIR := host
+BUILDDIR ?= bin
+NR_TASKLETS ?= 16
+BL ?= 10
+NR_DPUS ?= 1
+OP ?= copy
+MEM ?= MRAM
+
+define conf_filename
+ ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3)_$(4)_$(5).conf
+endef
+CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL},${OP},${MEM})
+
+HOST_TARGET := ${BUILDDIR}/host_code
+DPU_TARGET := ${BUILDDIR}/dpu_code
+
+COMMON_INCLUDES := support
+HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c)
+DPU_SOURCES := $(wildcard ${DPU_DIR}/${OP}.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${OP} -D${MEM}
+DPU_FLAGS := ${COMMON_FLAGS} -O2 -flto -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${OP} -D${MEM}
+
+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/Microbenchmarks/STREAM/dpu/add.c b/Microbenchmarks/STREAM/dpu/add.c
new file mode 100644
index 0000000..faf6504
--- /dev/null
+++ b/Microbenchmarks/STREAM/dpu/add.c
@@ -0,0 +1,103 @@
+/*
+* STREAM Add
+*
+*/
+#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"
+#include "../support/cyclecount.h"
+
+__host dpu_arguments_t DPU_INPUT_ARGUMENTS;
+__host dpu_results_t DPU_RESULTS[NR_TASKLETS];
+
+// Add
+static void add_dpu(T *bufferC, T *bufferA, T *bufferB) {
+
+ #pragma unroll
+ for (unsigned int i = 0; i < BLOCK_SIZE / sizeof(T); i++){
+ bufferC[i] = bufferA[i] + bufferB[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
+
+ perfcounter_config(COUNT_CYCLES, true);
+ }
+ perfcounter_cycles cycles;
+ // Barrier
+ barrier_wait(&my_barrier);
+#ifndef WRAM
+ timer_start(&cycles); // START TIMER
+#endif
+
+ uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size / sizeof(T);
+
+ dpu_results_t *result = &DPU_RESULTS[tasklet_id];
+ result->cycles = 0;
+
+ // Address of the current processing block in MRAM
+ uint32_t mram_base_addr_A = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2));
+ uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + input_size_dpu * sizeof(T));
+ uint32_t mram_base_addr_C = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + 2 * input_size_dpu * sizeof(T));
+
+ // 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 = 0; byte_index < input_size_dpu * sizeof(T); byte_index += BLOCK_SIZE * NR_TASKLETS){
+
+ // Load cache with current MRAM block
+ mram_read((__mram_ptr void const*)(mram_base_addr_A + byte_index), cache_A, BLOCK_SIZE);
+ mram_read((__mram_ptr void const*)(mram_base_addr_B + byte_index), cache_B, BLOCK_SIZE);
+
+#ifdef WRAM
+ // Barrier
+ barrier_wait(&my_barrier);
+ timer_start(&cycles); // START TIMER
+#endif
+
+ // Add
+ add_dpu(cache_B, cache_A, cache_B);
+
+#ifdef WRAM
+ result->cycles += timer_stop(&cycles); // STOP TIMER
+ // Barrier
+ barrier_wait(&my_barrier);
+#endif
+
+ // Write cache to current MRAM block
+ mram_write(cache_B, (__mram_ptr void*)(mram_base_addr_C + byte_index), BLOCK_SIZE);
+
+ }
+
+#ifndef WRAM
+ result->cycles = timer_stop(&cycles); // STOP TIMER
+#endif
+ return 0;
+}
diff --git a/Microbenchmarks/STREAM/dpu/copy.c b/Microbenchmarks/STREAM/dpu/copy.c
new file mode 100644
index 0000000..ff4df42
--- /dev/null
+++ b/Microbenchmarks/STREAM/dpu/copy.c
@@ -0,0 +1,75 @@
+/*
+* STREAM Copy
+*
+*/
+#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"
+#include "../support/cyclecount.h"
+
+__host dpu_arguments_t DPU_INPUT_ARGUMENTS;
+__host dpu_results_t DPU_RESULTS[NR_TASKLETS];
+
+// 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
+
+ perfcounter_config(COUNT_CYCLES, true);
+ }
+ perfcounter_cycles cycles;
+ // Barrier
+ barrier_wait(&my_barrier);
+#ifndef WRAM
+ timer_start(&cycles); // START TIMER
+#endif
+
+ uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size / sizeof(T);
+
+ dpu_results_t *result = &DPU_RESULTS[tasklet_id];
+ result->cycles = 0;
+
+ // Address of the current processing block in MRAM
+ uint32_t mram_base_addr_A = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2));
+ uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + input_size_dpu * sizeof(T));
+
+ // Initialize a local cache to store the MRAM block
+ T *cache_A = (T *) mem_alloc(BLOCK_SIZE);
+
+ for(unsigned int byte_index = 0; byte_index < input_size_dpu * sizeof(T); byte_index += BLOCK_SIZE * NR_TASKLETS){
+
+ // Load cache with current MRAM block
+ mram_read((__mram_ptr void const*)(mram_base_addr_A + byte_index), cache_A, BLOCK_SIZE);
+
+ // Write cache to current MRAM block
+ mram_write(cache_A, (__mram_ptr void*)(mram_base_addr_B + byte_index), BLOCK_SIZE);
+
+ }
+
+#ifndef WRAM
+ result->cycles = timer_stop(&cycles); // STOP TIMER
+#endif
+ return 0;
+}
diff --git a/Microbenchmarks/STREAM/dpu/copyw.c b/Microbenchmarks/STREAM/dpu/copyw.c
new file mode 100644
index 0000000..eff7a3b
--- /dev/null
+++ b/Microbenchmarks/STREAM/dpu/copyw.c
@@ -0,0 +1,101 @@
+/*
+* STREAM Copy (WRAM)
+*
+*/
+#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"
+#include "../support/cyclecount.h"
+
+__host dpu_arguments_t DPU_INPUT_ARGUMENTS;
+__host dpu_results_t DPU_RESULTS[NR_TASKLETS];
+
+// Copy
+static void copyw_dpu(T *bufferB, T *bufferA) {
+
+ #pragma unroll
+ for (unsigned int i = 0; i < BLOCK_SIZE / sizeof(T); 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
+
+ perfcounter_config(COUNT_CYCLES, true);
+ }
+ perfcounter_cycles cycles;
+ // Barrier
+ barrier_wait(&my_barrier);
+#ifndef WRAM
+ timer_start(&cycles); // START TIMER
+#endif
+
+ uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size / sizeof(T);
+
+ dpu_results_t *result = &DPU_RESULTS[tasklet_id];
+ result->cycles = 0;
+
+ // Address of the current processing block in MRAM
+ uint32_t mram_base_addr_A = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2));
+ uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + input_size_dpu * sizeof(T));
+
+ // 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 = 0; byte_index < input_size_dpu * sizeof(T); byte_index += BLOCK_SIZE * NR_TASKLETS){
+
+ // Load cache with current MRAM block
+ mram_read((__mram_ptr void const*)(mram_base_addr_A + byte_index), cache_A, BLOCK_SIZE);
+
+#ifdef WRAM
+ // Barrier
+ barrier_wait(&my_barrier);
+ timer_start(&cycles); // START TIMER
+#endif
+
+ // Copy
+ copyw_dpu(cache_B, cache_A);
+
+#ifdef WRAM
+ result->cycles += timer_stop(&cycles); // STOP TIMER
+ // Barrier
+ barrier_wait(&my_barrier);
+#endif
+
+ // Write cache to current MRAM block
+ mram_write(cache_B, (__mram_ptr void*)(mram_base_addr_B + byte_index), BLOCK_SIZE);
+
+ }
+
+#ifndef WRAM
+ result->cycles = timer_stop(&cycles); // STOP TIMER
+#endif
+ return 0;
+}
diff --git a/Microbenchmarks/STREAM/dpu/scale.c b/Microbenchmarks/STREAM/dpu/scale.c
new file mode 100644
index 0000000..4247aac
--- /dev/null
+++ b/Microbenchmarks/STREAM/dpu/scale.c
@@ -0,0 +1,103 @@
+/*
+* STREAM Scale
+*
+*/
+#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"
+#include "../support/cyclecount.h"
+
+__host dpu_arguments_t DPU_INPUT_ARGUMENTS;
+__host dpu_results_t DPU_RESULTS[NR_TASKLETS];
+
+// Scale
+static void scale_dpu(T *bufferB, T *bufferA, T scalar) {
+
+ #pragma unroll
+ for (unsigned int i = 0; i < BLOCK_SIZE / sizeof(T); i++){
+ bufferB[i] = scalar * 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
+
+ perfcounter_config(COUNT_CYCLES, true);
+ }
+ perfcounter_cycles cycles;
+ // Barrier
+ barrier_wait(&my_barrier);
+#ifndef WRAM
+ timer_start(&cycles); // START TIMER
+#endif
+
+ uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size / sizeof(T);
+
+ T scalar = (T)input_size_dpu; // Simply use this number as a scalar
+
+ dpu_results_t *result = &DPU_RESULTS[tasklet_id];
+ result->cycles = 0;
+
+ // Address of the current processing block in MRAM
+ uint32_t mram_base_addr_A = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2));
+ uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + input_size_dpu * sizeof(T));
+
+ // 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 = 0; byte_index < input_size_dpu * sizeof(T); byte_index += BLOCK_SIZE * NR_TASKLETS){
+
+ // Load cache with current MRAM block
+ mram_read((__mram_ptr void const*)(mram_base_addr_A + byte_index), cache_A, BLOCK_SIZE);
+
+#ifdef WRAM
+ // Barrier
+ barrier_wait(&my_barrier);
+ timer_start(&cycles); // START TIMER
+#endif
+
+ // Scale
+ scale_dpu(cache_B, cache_A, scalar);
+
+#ifdef WRAM
+ result->cycles += timer_stop(&cycles); // STOP TIMER
+ // Barrier
+ barrier_wait(&my_barrier);
+#endif
+
+ // Write cache to current MRAM block
+ mram_write(cache_B, (__mram_ptr void*)(mram_base_addr_B + byte_index), BLOCK_SIZE);
+
+ }
+
+#ifndef WRAM
+ result->cycles = timer_stop(&cycles); // STOP TIMER
+#endif
+ return 0;
+}
diff --git a/Microbenchmarks/STREAM/dpu/triad.c b/Microbenchmarks/STREAM/dpu/triad.c
new file mode 100644
index 0000000..e81cb59
--- /dev/null
+++ b/Microbenchmarks/STREAM/dpu/triad.c
@@ -0,0 +1,105 @@
+/*
+* STREAM Triad
+*
+*/
+#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"
+#include "../support/cyclecount.h"
+
+__host dpu_arguments_t DPU_INPUT_ARGUMENTS;
+__host dpu_results_t DPU_RESULTS[NR_TASKLETS];
+
+// Triad
+static void triad_dpu(T *bufferC, T *bufferA, T *bufferB, T scalar) {
+
+ #pragma unroll
+ for (unsigned int i = 0; i < BLOCK_SIZE / sizeof(T); i++){
+ bufferC[i] = bufferA[i] + scalar * bufferB[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
+
+ perfcounter_config(COUNT_CYCLES, true);
+ }
+ perfcounter_cycles cycles;
+ // Barrier
+ barrier_wait(&my_barrier);
+#ifndef WRAM
+ timer_start(&cycles); // START TIMER
+#endif
+
+ uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size / sizeof(T);
+
+ T scalar = (T)input_size_dpu; // Simply use this number as a scalar
+
+ dpu_results_t *result = &DPU_RESULTS[tasklet_id];
+ result->cycles = 0;
+
+ // Address of the current processing block in MRAM
+ uint32_t mram_base_addr_A = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2));
+ uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + input_size_dpu * sizeof(T));
+ uint32_t mram_base_addr_C = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + 2 * input_size_dpu * sizeof(T));
+
+ // 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 = 0; byte_index < input_size_dpu * sizeof(T); byte_index += BLOCK_SIZE * NR_TASKLETS){
+
+ // Load cache with current MRAM block
+ mram_read((__mram_ptr void const*)(mram_base_addr_A + byte_index), cache_A, BLOCK_SIZE);
+ mram_read((__mram_ptr void const*)(mram_base_addr_B + byte_index), cache_B, BLOCK_SIZE);
+
+#ifdef WRAM
+ // Barrier
+ barrier_wait(&my_barrier);
+ timer_start(&cycles); // START TIMER
+#endif
+
+ // Triad
+ triad_dpu(cache_B, cache_A, cache_B, scalar);
+
+#ifdef WRAM
+ result->cycles += timer_stop(&cycles); // STOP TIMER
+ // Barrier
+ barrier_wait(&my_barrier);
+#endif
+
+ // Write cache to current MRAM block
+ mram_write(cache_B, (__mram_ptr void*)(mram_base_addr_C + byte_index), BLOCK_SIZE);
+
+ }
+
+#ifndef WRAM
+ result->cycles = timer_stop(&cycles); // STOP TIMER
+#endif
+ return 0;
+}
diff --git a/Microbenchmarks/STREAM/host/app.c b/Microbenchmarks/STREAM/host/app.c
new file mode 100644
index 0000000..4571e96
--- /dev/null
+++ b/Microbenchmarks/STREAM/host/app.c
@@ -0,0 +1,248 @@
+/**
+* app.c
+* STREAM 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
+
+// Pointer declaration
+static T* A;
+static T* B;
+#if defined(add) || defined(triad)
+static T* C;
+#endif
+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
+#if defined(add) || defined(triad)
+static void stream_host(T* C, T* B, T* A, unsigned int nr_elements) {
+#else
+static void stream_host(T* C, T* A, unsigned int nr_elements) {
+#endif
+ for (unsigned int i = 0; i < nr_elements; i++) {
+#ifdef scale
+ C[i] = (nr_elements / NR_DPUS) * A[i];
+#elif add
+ C[i] = A[i] + B[i];
+#elif triad
+ C[i] = A[i] + (nr_elements / NR_DPUS) * B[i];
+#else // copy
+ C[i] = A[i];
+#endif
+ }
+}
+
+// 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;
+
+ // 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;
+ double cc = 0;
+ double cc_min = 0;
+ const unsigned int input_size = p.exp == 0 ? p.input_size * nr_of_dpus : p.input_size;
+
+ // Input/output allocation
+ A = malloc(input_size * sizeof(T));
+ B = malloc(input_size * sizeof(T));
+ T *bufferA = A;
+ T *bufferB = B;
+#if defined(add) || defined(triad)
+ C = malloc(input_size * sizeof(T));
+ T *bufferC = C;
+#endif
+ C2 = malloc(input_size * sizeof(T));
+
+ // 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);
+#if defined(add) || defined(triad)
+ stream_host(C2, B, A, input_size);
+#else
+ stream_host(C2, A, input_size);
+#endif
+ 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
+ const unsigned int input_size_dpu = input_size / nr_of_dpus;
+ unsigned int kernel = 0;
+ dpu_arguments_t input_arguments = {input_size_dpu * sizeof(T), kernel};
+ DPU_ASSERT(dpu_copy_to(dpu_set, "DPU_INPUT_ARGUMENTS", 0, (const void *)&input_arguments, sizeof(input_arguments)));
+ // Copy input arrays
+ i = 0;
+ DPU_FOREACH (dpu_set, dpu) {
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME, 0, bufferA + input_size_dpu * i, input_size_dpu * sizeof(T)));
+#if defined(add) || defined(triad)
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME, input_size_dpu * sizeof(T), bufferB + input_size_dpu * i, input_size_dpu * sizeof(T)));
+#endif
+ i++;
+ }
+ 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);
+ DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS));
+ if(rep >= p.n_warmup)
+ stop(&timer, 2);
+
+#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);
+ dpu_results_t results[nr_of_dpus];
+ i = 0;
+ DPU_FOREACH (dpu_set, dpu) {
+ // Copy output array
+#if defined(add) || defined(triad)
+ DPU_ASSERT(dpu_copy_from(dpu, DPU_MRAM_HEAP_POINTER_NAME, 2 * input_size_dpu * sizeof(T), bufferC + input_size_dpu * i, input_size_dpu * sizeof(T)));
+#else
+ DPU_ASSERT(dpu_copy_from(dpu, DPU_MRAM_HEAP_POINTER_NAME, input_size_dpu * sizeof(T), bufferB + input_size_dpu * i, input_size_dpu * sizeof(T)));
+#endif
+
+#if PERF
+ results[i].cycles = 0;
+ // Retrieve tasklet timings
+ for (unsigned int each_tasklet = 0; each_tasklet < NR_TASKLETS; each_tasklet++) {
+ dpu_results_t result;
+ result.cycles = 0;
+ DPU_ASSERT(dpu_copy_from(dpu, "DPU_RESULTS", each_tasklet * sizeof(dpu_results_t), &result, sizeof(dpu_results_t)));
+ if (result.cycles > results[i].cycles)
+ results[i].cycles = result.cycles;
+ }
+#endif
+ i++;
+ }
+ if(rep >= p.n_warmup)
+ stop(&timer, 3);
+
+#if PERF
+ uint64_t max_cycles = 0;
+ uint64_t min_cycles = 0xFFFFFFFFFFFFFFFF;
+ // Print performance results
+ if(rep >= p.n_warmup){
+ i = 0;
+ DPU_FOREACH(dpu_set, dpu) {
+ if(results[i].cycles > max_cycles)
+ max_cycles = results[i].cycles;
+ if(results[i].cycles < min_cycles)
+ min_cycles = results[i].cycles;
+ i++;
+ }
+ cc += (double)max_cycles;
+ cc_min += (double)min_cycles;
+ }
+#endif
+
+ }
+ printf("DPU cycles = %g cc\n", cc / p.n_reps);
+
+ // 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);
+
+ // Check output
+ bool status = true;
+ for (i = 0; i < input_size; i++) {
+#if defined(add) || defined(triad)
+ if(C2[i] != bufferC[i]){
+#else
+ if(C2[i] != bufferB[i]){
+#endif
+ status = false;
+#if PRINT
+#if defined(add) || defined(triad)
+ printf("%d: %u -- %u\n", i, C2[i], bufferC[i]);
+#else
+ printf("%d: %u -- %u\n", i, C2[i], bufferB[i]);
+#endif
+#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);
+#if defined(add) || defined(triad)
+ free(C);
+#endif
+ free(C2);
+ DPU_ASSERT(dpu_free(dpu_set));
+
+ return status ? 0 : -1;
+}
diff --git a/Microbenchmarks/STREAM/run.sh b/Microbenchmarks/STREAM/run.sh
new file mode 100755
index 0000000..141b01c
--- /dev/null
+++ b/Microbenchmarks/STREAM/run.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+# MRAM
+for i in copy copyw add scale triad
+do
+ for j in 1
+ do
+ for k in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
+ do
+ NR_DPUS=$j NR_TASKLETS=$k BL=10 MEM=MRAM OP=$i make all
+ wait
+ ./bin/host_code -w 0 -e 1 -i 2097152 >& profile/${i}_${j}_tl${k}_MRAM.txt
+ wait
+ make clean
+ wait
+ done
+ done
+done
+
+# WRAM
+for i in copyw add scale triad
+do
+ for j in 1
+ do
+ for k in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
+ do
+ NR_DPUS=$j NR_TASKLETS=$k BL=10 MEM=WRAM OP=$i make all
+ wait
+ ./bin/host_code -w 0 -e 1 -i 2097152 >& profile/${i}_${j}_tl${k}_WRAM.txt
+ wait
+ make clean
+ wait
+ done
+ done
+done
diff --git a/Microbenchmarks/STREAM/support/common.h b/Microbenchmarks/STREAM/support/common.h
new file mode 100755
index 0000000..8e2e59b
--- /dev/null
+++ b/Microbenchmarks/STREAM/support/common.h
@@ -0,0 +1,36 @@
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+// Structures used by both the host and the dpu to communicate information
+typedef struct {
+ uint32_t size;
+ enum kernels {
+ kernel1 = 0,
+ nr_kernels = 1,
+ } kernel;
+} dpu_arguments_t;
+
+typedef struct {
+ uint64_t cycles;
+} dpu_results_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
+#define T uint64_t
+
+#define PERF 1 // Use perfcounters?
+#define PRINT 0
+
+#define ANSI_COLOR_RED "\x1b[31m"
+#define ANSI_COLOR_GREEN "\x1b[32m"
+#define ANSI_COLOR_RESET "\x1b[0m"
+#endif
diff --git a/Microbenchmarks/STREAM/support/cyclecount.h b/Microbenchmarks/STREAM/support/cyclecount.h
new file mode 100644
index 0000000..4ef377e
--- /dev/null
+++ b/Microbenchmarks/STREAM/support/cyclecount.h
@@ -0,0 +1,20 @@
+#include <perfcounter.h>
+
+// Timer
+typedef struct perfcounter_cycles{
+ perfcounter_t start;
+ perfcounter_t end;
+ perfcounter_t end2;
+
+}perfcounter_cycles;
+
+void timer_start(perfcounter_cycles *cycles){
+ cycles->start = perfcounter_get(); // START TIMER
+}
+
+uint64_t timer_stop(perfcounter_cycles *cycles){
+ cycles->end = perfcounter_get(); // STOP TIMER
+ cycles->end2 = perfcounter_get(); // STOP TIMER
+ return(((uint64_t)((uint32_t)(((cycles->end >> 4) - (cycles->start >> 4)) - ((cycles->end2 >> 4) - (cycles->end >> 4))))) << 4);
+}
+
diff --git a/Microbenchmarks/STREAM/support/params.h b/Microbenchmarks/STREAM/support/params.h
new file mode 100644
index 0000000..4618411
--- /dev/null
+++ b/Microbenchmarks/STREAM/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=8K elements)"
+ "\n");
+}
+
+struct Params input_params(int argc, char **argv) {
+ struct Params p;
+ p.input_size = 8 << 10;
+ 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/Microbenchmarks/STREAM/support/timer.h b/Microbenchmarks/STREAM/support/timer.h
new file mode 100755
index 0000000..eedc385
--- /dev/null
+++ b/Microbenchmarks/STREAM/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)); }
diff --git a/Microbenchmarks/STRIDED/Makefile b/Microbenchmarks/STRIDED/Makefile
new file mode 100644
index 0000000..c5f3071
--- /dev/null
+++ b/Microbenchmarks/STRIDED/Makefile
@@ -0,0 +1,45 @@
+DPU_DIR := dpu
+HOST_DIR := host
+BUILDDIR ?= bin
+NR_TASKLETS ?= 16
+BL ?= 8
+NR_DPUS ?= 1
+OP ?= COARSECOARSE
+
+define conf_filename
+ ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3)_$(4).conf
+endef
+CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL},${OP})
+
+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${OP}
+DPU_FLAGS := ${COMMON_FLAGS} -O2 -flto -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${OP}
+
+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/Microbenchmarks/STRIDED/dpu/strided.c b/Microbenchmarks/STRIDED/dpu/strided.c
new file mode 100644
index 0000000..273b57c
--- /dev/null
+++ b/Microbenchmarks/STRIDED/dpu/strided.c
@@ -0,0 +1,103 @@
+/*
+* Strided access 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"
+#include "../support/cyclecount.h"
+
+__host dpu_arguments_t DPU_INPUT_ARGUMENTS;
+__host dpu_results_t DPU_RESULTS[NR_TASKLETS];
+
+// 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
+
+ perfcounter_config(COUNT_CYCLES, true);
+ }
+ perfcounter_cycles cycles;
+ // Barrier
+ barrier_wait(&my_barrier);
+ timer_start(&cycles); // START TIMER
+ dpu_results_t *result = &DPU_RESULTS[tasklet_id];
+ result->cycles = 0;
+
+ uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size / sizeof(T);
+ uint32_t s = DPU_INPUT_ARGUMENTS.stride;
+
+ // Address of the current processing block in MRAM
+ uint32_t mram_base_addr_A = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id * (input_size_dpu * sizeof(T) / NR_TASKLETS)));
+ uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id * (input_size_dpu * sizeof(T) / NR_TASKLETS)) + input_size_dpu * sizeof(T));
+
+#ifdef COARSECOARSE
+ // BLOCK SIZE
+ uint32_t B_SIZE = BLOCK_SIZE / sizeof(T);
+ uint32_t ADDR = (input_size_dpu/NR_TASKLETS) * tasklet_id;
+ uint32_t j = 0;
+
+ // 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 = 0; byte_index < input_size_dpu * sizeof(T) / NR_TASKLETS; byte_index += BLOCK_SIZE){
+
+ // Load cache with current MRAM block
+ mram_read((__mram_ptr void const*)(mram_base_addr_A + byte_index), cache_A, BLOCK_SIZE);
+ mram_read((__mram_ptr void const*)(mram_base_addr_B + byte_index), cache_B, BLOCK_SIZE);
+
+ // Copy
+ if(((ADDR + j * B_SIZE) & (s - 1)) == 0){
+
+ for(unsigned int i = 0; i < B_SIZE; i += s){
+ cache_B[i] = cache_A[i];
+ }
+
+ }
+
+ // Write cache to current MRAM block
+ mram_write(cache_B, (__mram_ptr void*)(mram_base_addr_B + byte_index), BLOCK_SIZE);
+ j++;
+ }
+#else // FINEFINE
+ // Initialize a local cache to store the MRAM block
+ T *cache_A = (T *) mem_alloc(sizeof(T));
+ uint32_t stride = (uint32_t)(s * sizeof(T));
+
+ for(unsigned int byte_index = 0; byte_index < input_size_dpu * sizeof(T) / NR_TASKLETS; byte_index += stride){
+
+ // Load cache with current MRAM block
+ mram_read((__mram_ptr void const*)(mram_base_addr_A + byte_index), cache_A, sizeof(T));
+
+ // Write cache to current MRAM block
+ mram_write(cache_A, (__mram_ptr void*)(mram_base_addr_B + byte_index), sizeof(T));
+ }
+#endif
+
+ result->cycles = timer_stop(&cycles); // STOP TIMER
+
+ return 0;
+}
diff --git a/Microbenchmarks/STRIDED/host/app.c b/Microbenchmarks/STRIDED/host/app.c
new file mode 100644
index 0000000..e9d119a
--- /dev/null
+++ b/Microbenchmarks/STRIDED/host/app.c
@@ -0,0 +1,211 @@
+/**
+* app.c
+* Strided Access 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
+
+// Create input arrays
+static void read_input(T* A, T* B, T* C, 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] = A[i];
+ C[i] = A[i];
+ }
+}
+
+// Compute output in the host
+static void stride_host(T* B, T* A, unsigned int nr_elements, int s) {
+ for (unsigned int i = 0; i < nr_elements; i+=s){
+ B[i] = A[i];
+ }
+}
+
+// Pointer declaration
+static T* A;
+static T* B;
+static T* C;
+
+// 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;
+
+ // 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;
+ double cc = 0;
+ double cc_min = 0;
+ const unsigned int input_size = p.exp == 0 ? p.input_size * nr_of_dpus : p.input_size;
+
+ // Input/output allocation
+ A = malloc(input_size * sizeof(T));
+ B = malloc(input_size * sizeof(T));
+ C = malloc(input_size * sizeof(T));
+ T *bufferA = A;
+ T *bufferB = B;
+
+ // Create an input file with arbitrary data
+ read_input(A, B, C, 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);
+ stride_host(C, A, input_size, p.stride);
+ 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
+ const unsigned int input_size_dpu = input_size / nr_of_dpus;
+ unsigned int kernel = 0;
+ dpu_arguments_t input_arguments = {input_size_dpu * sizeof(T), p.stride, kernel};
+ DPU_ASSERT(dpu_copy_to(dpu_set, "DPU_INPUT_ARGUMENTS", 0, (const void *)&input_arguments, sizeof(input_arguments)));
+ // Copy input arrays
+ i = 0;
+ DPU_FOREACH (dpu_set, dpu) {
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME, 0, bufferA + input_size_dpu * i, input_size_dpu * sizeof(T)));
+#ifdef COARSECOARSE
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME, input_size_dpu * sizeof(T), bufferB + input_size_dpu * i, input_size_dpu * sizeof(T)));
+#endif
+ i++;
+ }
+ 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);
+ DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS));
+ if(rep >= p.n_warmup)
+ stop(&timer, 2);
+
+#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);
+ dpu_results_t results[nr_of_dpus];
+ i = 0;
+ DPU_FOREACH (dpu_set, dpu) {
+ // Copy output array
+ DPU_ASSERT(dpu_copy_from(dpu, DPU_MRAM_HEAP_POINTER_NAME, input_size_dpu * sizeof(T), bufferB + input_size_dpu * i, input_size_dpu * sizeof(T)));
+
+#if PERF
+ results[i].cycles = 0;
+ // Retrieve tasklet timings
+ for (unsigned int each_tasklet = 0; each_tasklet < NR_TASKLETS; each_tasklet++) {
+ dpu_results_t result;
+ result.cycles = 0;
+ DPU_ASSERT(dpu_copy_from(dpu, "DPU_RESULTS", each_tasklet * sizeof(dpu_results_t), &result, sizeof(dpu_results_t)));
+ if (result.cycles > results[i].cycles)
+ results[i].cycles = result.cycles;
+ }
+#endif
+ i++;
+ }
+ if(rep >= p.n_warmup)
+ stop(&timer, 3);
+
+#if PERF
+ uint64_t max_cycles = 0;
+ uint64_t min_cycles = 0xFFFFFFFFFFFFFFFF;
+ // Print performance results
+ if(rep >= p.n_warmup){
+ i = 0;
+ DPU_FOREACH(dpu_set, dpu) {
+ if(results[i].cycles > max_cycles)
+ max_cycles = results[i].cycles;
+ if(results[i].cycles < min_cycles)
+ min_cycles = results[i].cycles;
+ i++;
+ }
+ cc += (double)max_cycles;
+ cc_min += (double)min_cycles;
+ }
+#endif
+
+ }
+ printf("DPU cycles = %g cc\n", cc / p.n_reps);
+
+ // 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);
+
+ // Check output
+ bool status = true;
+ for (i = 0; i < input_size; i++) {
+ if(C[i] != bufferB[i]){
+ status = false;
+#if PRINT
+ printf("%d: %u -- %u\n", i, C[i], bufferB[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);
+ DPU_ASSERT(dpu_free(dpu_set));
+
+ return status ? 0 : -1;
+}
diff --git a/Microbenchmarks/STRIDED/run.sh b/Microbenchmarks/STRIDED/run.sh
new file mode 100755
index 0000000..153e633
--- /dev/null
+++ b/Microbenchmarks/STRIDED/run.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+for i in COARSECOARSE FINEFINE
+do
+ for j in 1
+ do
+ for k in 1 2 4 8 16
+ do
+ for l in 1 2 4 8 16 32 64 128 256 512 1024 2048 4096
+ do
+ NR_DPUS=$j NR_TASKLETS=$k BL=10 OP=$i make all
+ wait
+ ./bin/host_code -w 0 -e 1 -i 2097152 -s ${l} >& profile/${i}_${j}_tl${k}_s${l}.txt
+ wait
+ make clean
+ wait
+ done
+ done
+ done
+done
diff --git a/Microbenchmarks/STRIDED/support/common.h b/Microbenchmarks/STRIDED/support/common.h
new file mode 100755
index 0000000..c71f33a
--- /dev/null
+++ b/Microbenchmarks/STRIDED/support/common.h
@@ -0,0 +1,37 @@
+#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 stride;
+ enum kernels {
+ kernel1 = 0,
+ nr_kernels = 1,
+ } kernel;
+} dpu_arguments_t;
+
+typedef struct {
+ uint64_t cycles;
+} dpu_results_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
+#define T uint64_t
+
+#define PERF 1 // Use perfcounters?
+#define PRINT 0
+
+#define ANSI_COLOR_RED "\x1b[31m"
+#define ANSI_COLOR_GREEN "\x1b[32m"
+#define ANSI_COLOR_RESET "\x1b[0m"
+#endif
diff --git a/Microbenchmarks/STRIDED/support/cyclecount.h b/Microbenchmarks/STRIDED/support/cyclecount.h
new file mode 100644
index 0000000..4ef377e
--- /dev/null
+++ b/Microbenchmarks/STRIDED/support/cyclecount.h
@@ -0,0 +1,20 @@
+#include <perfcounter.h>
+
+// Timer
+typedef struct perfcounter_cycles{
+ perfcounter_t start;
+ perfcounter_t end;
+ perfcounter_t end2;
+
+}perfcounter_cycles;
+
+void timer_start(perfcounter_cycles *cycles){
+ cycles->start = perfcounter_get(); // START TIMER
+}
+
+uint64_t timer_stop(perfcounter_cycles *cycles){
+ cycles->end = perfcounter_get(); // STOP TIMER
+ cycles->end2 = perfcounter_get(); // STOP TIMER
+ return(((uint64_t)((uint32_t)(((cycles->end >> 4) - (cycles->start >> 4)) - ((cycles->end2 >> 4) - (cycles->end >> 4))))) << 4);
+}
+
diff --git a/Microbenchmarks/STRIDED/support/params.h b/Microbenchmarks/STRIDED/support/params.h
new file mode 100644
index 0000000..e49cc36
--- /dev/null
+++ b/Microbenchmarks/STRIDED/support/params.h
@@ -0,0 +1,60 @@
+#ifndef _PARAMS_H_
+#define _PARAMS_H_
+
+#include "common.h"
+
+typedef struct Params {
+ unsigned int input_size;
+ unsigned int stride;
+ 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=8K elements)"
+ "\n -s <S> stride (default=2)"
+ "\n");
+}
+
+struct Params input_params(int argc, char **argv) {
+ struct Params p;
+ p.input_size = 8 << 10;
+ p.stride = 2;
+ p.n_warmup = 1;
+ p.n_reps = 3;
+ p.exp = 0;
+
+ int opt;
+ while((opt = getopt(argc, argv, "hi:s:w:e:x:")) >= 0) {
+ switch(opt) {
+ case 'h':
+ usage();
+ exit(0);
+ break;
+ case 'i': p.input_size = atoi(optarg); break;
+ case 's': p.stride = 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/Microbenchmarks/STRIDED/support/timer.h b/Microbenchmarks/STRIDED/support/timer.h
new file mode 100755
index 0000000..eedc385
--- /dev/null
+++ b/Microbenchmarks/STRIDED/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)); }
diff --git a/Microbenchmarks/WRAM/Makefile b/Microbenchmarks/WRAM/Makefile
new file mode 100644
index 0000000..f824e41
--- /dev/null
+++ b/Microbenchmarks/WRAM/Makefile
@@ -0,0 +1,47 @@
+DPU_DIR := dpu
+HOST_DIR := host
+BUILDDIR ?= bin
+NR_TASKLETS ?= 16
+BL ?= 10
+NR_DPUS ?= 1
+OP ?= streaming
+MEM ?= WRAM
+TYPE ?= INT64
+
+define conf_filename
+ ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3)_$(4)_$(5).conf
+endef
+CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL},${OP},${MEM})
+
+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${OP} -D${MEM} -D${TYPE}
+DPU_FLAGS := ${COMMON_FLAGS} -O2 -flto -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${OP} -D${MEM} -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/Microbenchmarks/WRAM/dpu/task.c b/Microbenchmarks/WRAM/dpu/task.c
new file mode 100644
index 0000000..9ded3da
--- /dev/null
+++ b/Microbenchmarks/WRAM/dpu/task.c
@@ -0,0 +1,111 @@
+/*
+* WRAM Access
+*
+*/
+#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"
+#include "../support/cyclecount.h"
+
+__host dpu_arguments_t DPU_INPUT_ARGUMENTS;
+__host dpu_results_t DPU_RESULTS[NR_TASKLETS];
+
+// Copy
+static void copy_pattern_dpu(T *bufferC, T *bufferB, uint32_t *bufferA) {
+
+ #pragma unroll
+ for (unsigned int i = 0; i < (BLOCK_SIZE >> DIV); i++){
+
+ uint32_t address = bufferA[i];
+ bufferC[address] = bufferB[address];
+
+ }
+
+}
+
+// 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
+
+ perfcounter_config(COUNT_CYCLES, true);
+ }
+ perfcounter_cycles cycles;
+ // Barrier
+ barrier_wait(&my_barrier);
+#ifndef WRAM
+ timer_start(&cycles); // START TIMER
+#endif
+
+ uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size;
+
+ dpu_results_t *result = &DPU_RESULTS[tasklet_id];
+ result->cycles = 0;
+
+ const uint32_t A_SIZE = (BLOCK_SIZE >> DIV) << 2;
+ // Address of the current processing block in MRAM
+ uint32_t mram_base_addr_A = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id * A_SIZE));
+ uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + input_size_dpu * sizeof(uint32_t));
+ uint32_t mram_base_addr_C = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + input_size_dpu * (sizeof(uint32_t) + sizeof(T)));
+
+ // Initialize a local cache to store the MRAM block
+ uint32_t *cache_A = (uint32_t *) mem_alloc(A_SIZE);
+ T *cache_B = (T *) mem_alloc(BLOCK_SIZE);
+ T *cache_C = (T *) mem_alloc(BLOCK_SIZE);
+
+ uint32_t A_byte_index = 0;
+ for(unsigned int byte_index = 0; byte_index < (input_size_dpu << DIV); byte_index += BLOCK_SIZE * NR_TASKLETS){
+
+ // Load cache with current MRAM block
+ mram_read((__mram_ptr void const*)(mram_base_addr_A + A_byte_index), cache_A, A_SIZE);
+ mram_read((__mram_ptr void const*)(mram_base_addr_B + byte_index), cache_B, BLOCK_SIZE);
+ mram_read((__mram_ptr void const*)(mram_base_addr_C + byte_index), cache_C, BLOCK_SIZE); // Clean cache_C
+
+#ifdef WRAM
+ // Barrier
+ barrier_wait(&my_barrier);
+ timer_start(&cycles); // START TIMER
+#endif
+
+ // Copy
+ copy_pattern_dpu(cache_C, cache_B, cache_A);
+
+#ifdef WRAM
+ result->cycles += timer_stop(&cycles); // STOP TIMER
+ // Barrier
+ barrier_wait(&my_barrier);
+#endif
+
+ // Write cache to current MRAM block
+ mram_write(cache_C, (__mram_ptr void*)(mram_base_addr_C + byte_index), BLOCK_SIZE);
+
+ A_byte_index += A_SIZE * NR_TASKLETS;
+ }
+
+#ifndef WRAM
+ result->cycles = timer_stop(&cycles); // STOP TIMER
+#endif
+ return 0;
+}
diff --git a/Microbenchmarks/WRAM/host/app.c b/Microbenchmarks/WRAM/host/app.c
new file mode 100644
index 0000000..a0131da
--- /dev/null
+++ b/Microbenchmarks/WRAM/host/app.c
@@ -0,0 +1,232 @@
+/**
+* app.c
+* WRAM Access 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
+
+// Pointer declaration
+static unsigned int* A;
+static T* B;
+static T* C;
+static T* C2;
+
+// Create input arrays
+#ifdef strided
+static void read_input(unsigned int* A, T* B, unsigned int nr_elements, unsigned int stride) {
+#else
+static void read_input(unsigned int* A, T* B, unsigned int nr_elements) {
+#endif
+ srand(0);
+ printf("nr_elements\t%u\t", nr_elements);
+ for (unsigned int i = 0; i < nr_elements; i++) {
+#ifdef streaming
+ A[i] = i % (BLOCK_SIZE >> DIV);
+#elif strided
+ A[i] = ((i>0 ? A[i-1]:0) + stride) % (BLOCK_SIZE >> DIV);
+#else
+ A[i] = ((unsigned int)rand()) % (BLOCK_SIZE >> DIV);
+#endif
+ B[i] = (T)(rand());
+ C[i] = 0;
+ }
+}
+
+// Compute output in the host
+static void copy_host(T* C, T* B, unsigned int* A, unsigned int nr_elements) {
+ unsigned int wram_size = BLOCK_SIZE >> DIV;
+ for (unsigned int i = 0; i < nr_elements / wram_size; i++) {
+ for (unsigned int j = 0; j < wram_size; j++) {
+ unsigned int address = A[i * wram_size + j];
+ C[i * wram_size + address] = B[i * wram_size + address];
+ }
+ }
+}
+
+// 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;
+
+ // 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;
+ double cc = 0;
+ double cc_min = 0;
+ const unsigned int input_size = p.exp == 0 ? p.input_size * nr_of_dpus : p.input_size;
+
+ // Input/output allocation
+ A = malloc(input_size * sizeof(unsigned int));
+ unsigned int *bufferA = A;
+ B = malloc(input_size * sizeof(T));
+ T *bufferB = B;
+ C = malloc(input_size * sizeof(T));
+ T *bufferC = C;
+ C2 = malloc(input_size * sizeof(T));
+
+ // Create an input file with arbitrary data
+#ifdef strided
+ read_input(A, B, input_size, p.stride);
+#else
+ read_input(A, B, input_size);
+#endif
+
+ // 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);
+ copy_host(C2, B, A, 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
+ const unsigned int input_size_dpu = input_size / nr_of_dpus;
+ unsigned int kernel = 0;
+ dpu_arguments_t input_arguments = {input_size_dpu, kernel};
+ DPU_ASSERT(dpu_copy_to(dpu_set, "DPU_INPUT_ARGUMENTS", 0, (const void *)&input_arguments, sizeof(input_arguments)));
+ // Copy input arrays
+ i = 0;
+ DPU_FOREACH (dpu_set, dpu) {
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME, 0, bufferA + input_size_dpu * i, input_size_dpu * sizeof(unsigned int)));
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME, input_size_dpu * sizeof(unsigned int), bufferB + input_size_dpu * i, input_size_dpu * sizeof(T)));
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME, input_size_dpu * (sizeof(unsigned int) + sizeof(T)), bufferC + input_size_dpu * i, input_size_dpu * sizeof(T)));
+ i++;
+ }
+ 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);
+ DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS));
+ if(rep >= p.n_warmup)
+ stop(&timer, 2);
+
+#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);
+ dpu_results_t results[nr_of_dpus];
+ i = 0;
+ DPU_FOREACH (dpu_set, dpu) {
+ // Copy output array
+ DPU_ASSERT(dpu_copy_from(dpu, DPU_MRAM_HEAP_POINTER_NAME, input_size_dpu * (sizeof(unsigned int) + sizeof(T)), bufferC + input_size_dpu * i, input_size_dpu * sizeof(T)));
+
+#if PERF
+ results[i].cycles = 0;
+ // Retrieve tasklet timings
+ for (unsigned int each_tasklet = 0; each_tasklet < NR_TASKLETS; each_tasklet++) {
+ dpu_results_t result;
+ result.cycles = 0;
+ DPU_ASSERT(dpu_copy_from(dpu, "DPU_RESULTS", each_tasklet * sizeof(dpu_results_t), &result, sizeof(dpu_results_t)));
+ if (result.cycles > results[i].cycles)
+ results[i].cycles = result.cycles;
+ }
+#endif
+ i++;
+ }
+ if(rep >= p.n_warmup)
+ stop(&timer, 3);
+
+#if PERF
+ uint64_t max_cycles = 0;
+ uint64_t min_cycles = 0xFFFFFFFFFFFFFFFF;
+ // Print performance results
+ if(rep >= p.n_warmup){
+ i = 0;
+ DPU_FOREACH(dpu_set, dpu) {
+ if(results[i].cycles > max_cycles)
+ max_cycles = results[i].cycles;
+ if(results[i].cycles < min_cycles)
+ min_cycles = results[i].cycles;
+ i++;
+ }
+ cc += (double)max_cycles;
+ cc_min += (double)min_cycles;
+ }
+#endif
+
+ }
+ printf("DPU cycles = %g cc\n", cc / p.n_reps);
+
+ // 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);
+
+ // Check output
+ bool status = true;
+ for (i = 0; i < input_size; i++) {
+ if(C2[i] != bufferC[i]){
+ status = false;
+#if PRINT
+ printf("%d: %u -- %u\n", i, C2[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/Microbenchmarks/WRAM/run.sh b/Microbenchmarks/WRAM/run.sh
new file mode 100755
index 0000000..12fca6e
--- /dev/null
+++ b/Microbenchmarks/WRAM/run.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+# WRAM
+for i in streaming random
+do
+ for j in 1
+ do
+ for k in 1 2 4 8 16
+ do
+ NR_DPUS=$j NR_TASKLETS=$k BL=10 MEM=WRAM OP=$i make all
+ wait
+ ./bin/host_code -w 0 -e 1 -i 2097152 >& profile/${i}_${j}_tl${k}_s1_WRAM.txt
+ wait
+ make clean
+ wait
+ done
+ done
+done
+
+for i in strided
+do
+ for j in 1
+ do
+ for k in 1 2 4 8 16
+ do
+ for l in 1 2 4 8 16 32 64
+ do
+ NR_DPUS=$j NR_TASKLETS=$k BL=10 MEM=WRAM OP=$i make all
+ wait
+ ./bin/host_code -w 0 -e 1 -i 2097152 -s ${l} >& profile/${i}_${j}_tl${k}_s${l}_WRAM.txt
+ wait
+ make clean
+ wait
+ done
+ done
+ done
+done
diff --git a/Microbenchmarks/WRAM/support/common.h b/Microbenchmarks/WRAM/support/common.h
new file mode 100755
index 0000000..42914ac
--- /dev/null
+++ b/Microbenchmarks/WRAM/support/common.h
@@ -0,0 +1,43 @@
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+// Structures used by both the host and the dpu to communicate information
+typedef struct {
+ uint32_t size;
+ enum kernels {
+ kernel1 = 0,
+ nr_kernels = 1,
+ } kernel;
+} dpu_arguments_t;
+
+typedef struct {
+ uint64_t cycles;
+} dpu_results_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 INT32
+#define T int32_t
+#define DIV 2 // Shift right to divide by sizeof(T)
+#else
+#define T int64_t
+#define DIV 3 // Shift right to divide by sizeof(T)
+#endif
+
+#define PERF 1 // Use perfcounters?
+#define PRINT 0
+
+#define ANSI_COLOR_RED "\x1b[31m"
+#define ANSI_COLOR_GREEN "\x1b[32m"
+#define ANSI_COLOR_RESET "\x1b[0m"
+
+#endif
diff --git a/Microbenchmarks/WRAM/support/cyclecount.h b/Microbenchmarks/WRAM/support/cyclecount.h
new file mode 100644
index 0000000..c4247b5
--- /dev/null
+++ b/Microbenchmarks/WRAM/support/cyclecount.h
@@ -0,0 +1,19 @@
+#include <perfcounter.h>
+
+// Timer
+typedef struct perfcounter_cycles{
+ perfcounter_t start;
+ perfcounter_t end;
+ perfcounter_t end2;
+
+}perfcounter_cycles;
+
+void timer_start(perfcounter_cycles *cycles){
+ cycles->start = perfcounter_get(); // START TIMER
+}
+
+uint64_t timer_stop(perfcounter_cycles *cycles){
+ cycles->end = perfcounter_get(); // STOP TIMER
+ cycles->end2 = perfcounter_get(); // STOP TIMER
+ return(((uint64_t)((uint32_t)(((cycles->end >> 4) - (cycles->start >> 4)) - ((cycles->end2 >> 4) - (cycles->end >> 4))))) << 4);
+}
diff --git a/Microbenchmarks/WRAM/support/params.h b/Microbenchmarks/WRAM/support/params.h
new file mode 100644
index 0000000..bbc2a19
--- /dev/null
+++ b/Microbenchmarks/WRAM/support/params.h
@@ -0,0 +1,61 @@
+#ifndef _PARAMS_H_
+#define _PARAMS_H_
+
+#include "common.h"
+
+typedef struct Params {
+ unsigned int input_size;
+ unsigned int stride;
+ 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=8K elements)"
+ "\n -s <S> stride (default=2)"
+ "\n");
+}
+
+struct Params input_params(int argc, char **argv) {
+ struct Params p;
+ p.input_size = 8 << 10;
+ p.stride = 2;
+ p.n_warmup = 1;
+ p.n_reps = 3;
+ p.exp = 0;
+
+ int opt;
+ while((opt = getopt(argc, argv, "hi:w:e:x:s:")) >= 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;
+ case 's': p.stride = atoi(optarg); break;
+ default:
+ fprintf(stderr, "\nUnrecognized option!\n");
+ usage();
+ exit(0);
+ }
+ }
+ assert(NR_DPUS > 0 && "Invalid # of dpus!");
+ assert((NR_TASKLETS & (NR_TASKLETS - 1)) == 0 && "Use a power-of-two number of tasklets!");
+
+ return p;
+}
+#endif
diff --git a/Microbenchmarks/WRAM/support/timer.h b/Microbenchmarks/WRAM/support/timer.h
new file mode 100755
index 0000000..eedc385
--- /dev/null
+++ b/Microbenchmarks/WRAM/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)); }