summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2023-05-17 14:49:41 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2023-05-17 14:49:41 +0200
commitce1e6a89d294507a21cc27bae1cba22a7af68a8c (patch)
tree5b7660a5217fd89be0414a0818558d15a8580746
parent8a285f9058eae3dd9d832c5f76b1045cbb457782 (diff)
port SCAN-SSA to dfatool
-rw-r--r--SCAN-SSA/Makefile48
-rw-r--r--SCAN-SSA/dpu/task.c12
-rw-r--r--SCAN-SSA/host/app.c89
-rwxr-xr-xSCAN-SSA/run.sh32
-rw-r--r--[-rwxr-xr-x]SCAN-SSA/support/common.h0
-rw-r--r--SCAN-SSA/support/params.h5
-rw-r--r--[-rwxr-xr-x]SCAN-SSA/support/timer.h7
7 files changed, 123 insertions, 70 deletions
diff --git a/SCAN-SSA/Makefile b/SCAN-SSA/Makefile
index 4930e70..00af65c 100644
--- a/SCAN-SSA/Makefile
+++ b/SCAN-SSA/Makefile
@@ -1,46 +1,36 @@
-DPU_DIR := dpu
-HOST_DIR := host
-BUILDDIR ?= bin
NR_DPUS ?= 1
NR_TASKLETS ?= 16
BL ?= 10
TYPE ?= INT64
ENERGY ?= 0
+UNROLL ?= 1
-define conf_filename
- ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3)_TYPE_$(4).conf
-endef
-CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL},${TYPE})
-
-HOST_TARGET := ${BUILDDIR}/host_code
-DPU_TARGET := ${BUILDDIR}/dpu_code
+HOST_SOURCES := $(wildcard host/*.c)
+DPU_SOURCES := $(wildcard dpu/*.c)
COMMON_INCLUDES := support
-HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c)
-DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c)
-
-.PHONY: all clean test
+COMMON_FLAGS = -Wall -Wextra -O2 -I${COMMON_INCLUDES} -DNR_DPUS=${NR_DPUS} -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${TYPE} -DUNROLL=${UNROLL}
+HOST_FLAGS = ${COMMON_FLAGS} -std=c11 `dpu-pkg-config --cflags --libs dpu`
+DPU_FLAGS = ${COMMON_FLAGS}
-__dirs := $(shell mkdir -p ${BUILDDIR})
+QUIET = @
-COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES}
-HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} -D${TYPE} -DENERGY=${ENERGY}
-DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${TYPE}
+ifdef verbose
+ QUIET =
+endif
-all: ${HOST_TARGET} ${DPU_TARGET}
+all: bin/dpu_code bin/host_code
-${CONF}:
- $(RM) $(call conf_filename,*,*)
- touch ${CONF}
+bin:
+ ${QUIET}mkdir -p bin
-${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF}
- $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS}
+bin/dpu_code: ${DPU_SOURCES}
+ ${QUIET}dpu-upmem-dpurte-clang ${DPU_FLAGS} ${DPU_SOURCES} -o $@
-${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF}
- dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES}
+bin/host_code: ${HOST_SOURCES}
+ ${QUIET}${CC} ${HOST_FLAGS} ${HOST_SOURCES} -o $@
clean:
- $(RM) -r $(BUILDDIR)
+ ${QUIET}${RM} -f bin/dpu_code bin/host_code
-test: all
- ./${HOST_TARGET}
+.PHONY: all clean
diff --git a/SCAN-SSA/dpu/task.c b/SCAN-SSA/dpu/task.c
index c6871f7..15411a4 100644
--- a/SCAN-SSA/dpu/task.c
+++ b/SCAN-SSA/dpu/task.c
@@ -23,10 +23,16 @@ T message_partial_count;
// Scan in each tasklet
static T scan(T *output, T *input){
output[0] = input[0];
+#if UNROLL
#pragma unroll
for(unsigned int j = 1; j < REGS; j++) {
output[j] = output[j - 1] + input[j];
}
+#else
+ for(unsigned int j = 1; j < REGS; j++) {
+ output[j] = output[j - 1] + input[j];
+ }
+#endif
return output[REGS - 1];
}
@@ -53,10 +59,16 @@ BARRIER_INIT(my_barrier, NR_TASKLETS);
// Add in each tasklet
static void add(T *output, T p_count){
+#if UNROLL
#pragma unroll
for(unsigned int j = 0; j < REGS; j++) {
output[j] += p_count;
}
+#else
+ for(unsigned int j = 0; j < REGS; j++) {
+ output[j] += p_count;
+ }
+#endif
}
extern int main_kernel1(void);
diff --git a/SCAN-SSA/host/app.c b/SCAN-SSA/host/app.c
index 2cc8af7..93650a8 100644
--- a/SCAN-SSA/host/app.c
+++ b/SCAN-SSA/host/app.c
@@ -22,6 +22,9 @@
#define DPU_BINARY "./bin/dpu_code"
#endif
+#define XSTR(x) STR(x)
+#define STR(x) #x
+
#if ENERGY
#include <dpu_probe.h>
#endif
@@ -51,6 +54,17 @@ static void scan_host(T* C, T* A, unsigned int nr_elements) {
}
}
+/*
+ * "SCAN" := [a1, a1, ..., an] -> [a1, a1 + a2, ..., a1 + a2 + ... + an]
+ * From the paper:
+ * SCAN-SSA has three steps:
+ * * (copy data to the DPU) (timer 1)
+ * * compute the partial scan operation locally inside each DPU (timer 2)
+ * * retrieve last element of each local scan from the DPUs, do a local (complete) scan on the last elements, and push them to the next DPU (timer 3)
+ * * finish the scan operation in each DPU (add sum [a1 ... ax] to a(x+1), ..., a(x+m) for DPU size m) (timer 4)
+ * * (retrieve results from DPU) (timer 5)
+ */
+
// Main of the Host Application
int main(int argc, char **argv) {
@@ -73,7 +87,7 @@ int main(int argc, char **argv) {
unsigned int i = 0;
T accum = 0;
- const unsigned int input_size = p.exp == 0 ? p.input_size * nr_of_dpus : p.input_size; // Total input size (weak or strong scaling)
+ const unsigned int input_size = p.input_size * nr_of_dpus; // Total input size (weak or strong scaling)
const unsigned int input_size_dpu_ = divceil(input_size, nr_of_dpus); // Input size per DPU (max.)
const unsigned int input_size_dpu_round =
(input_size_dpu_ % (NR_TASKLETS * REGS) != 0) ? roundup(input_size_dpu_, (NR_TASKLETS * REGS)) : input_size_dpu_; // Input size per DPU (max.), 8-byte aligned
@@ -98,14 +112,14 @@ int main(int argc, char **argv) {
// Compute output on CPU (performance comparison and verification purposes)
if(rep >= p.n_warmup)
- start(&timer, 0, rep - p.n_warmup);
+ start(&timer, 0, 0);
scan_host(C, A, input_size);
if(rep >= p.n_warmup)
stop(&timer, 0);
- printf("Load input data\n");
+ //printf("Load input data\n");
if(rep >= p.n_warmup)
- start(&timer, 1, rep - p.n_warmup);
+ start(&timer, 1, 0);
// Input arguments
const unsigned int input_size_dpu = input_size_dpu_round;
unsigned int kernel = 0;
@@ -123,10 +137,10 @@ int main(int argc, char **argv) {
if(rep >= p.n_warmup)
stop(&timer, 1);
- printf("Run program on DPU(s) \n");
+ //printf("Run program on DPU(s) \n");
// Run DPU kernel
if(rep >= p.n_warmup) {
- start(&timer, 2, rep - p.n_warmup);
+ start(&timer, 2, 0);
#if ENERGY
DPU_ASSERT(dpu_probe_start(&probe));
#endif
@@ -152,7 +166,7 @@ int main(int argc, char **argv) {
}
#endif
- printf("Retrieve results\n");
+ //printf("Retrieve results\n");
dpu_results_t results[nr_of_dpus];
T* results_scan = malloc(nr_of_dpus * sizeof(T));
i = 0;
@@ -162,7 +176,7 @@ int main(int argc, char **argv) {
dpu_results_t* results_retrieve[nr_of_dpus];
if(rep >= p.n_warmup)
- start(&timer, 3, rep - p.n_warmup);
+ start(&timer, 3, 0);
DPU_FOREACH(dpu_set, dpu, i) {
results_retrieve[i] = (dpu_results_t*)malloc(NR_TASKLETS * sizeof(dpu_results_t));
@@ -201,10 +215,10 @@ int main(int argc, char **argv) {
if(rep >= p.n_warmup)
stop(&timer, 3);
- printf("Run program on DPU(s) \n");
+ //printf("Run program on DPU(s) \n");
// Run DPU kernel
if(rep >= p.n_warmup) {
- start(&timer, 4, rep - p.n_warmup);
+ start(&timer, 4, 0);
#if ENERGY
DPU_ASSERT(dpu_probe_start(&probe));
#endif
@@ -229,9 +243,9 @@ int main(int argc, char **argv) {
}
#endif
- printf("Retrieve results\n");
+ //printf("Retrieve results\n");
if(rep >= p.n_warmup)
- start(&timer, 5, rep - p.n_warmup);
+ start(&timer, 5, 0);
i = 0;
// PARALLEL RETRIEVE TRANSFER
DPU_FOREACH(dpu_set, dpu, i) {
@@ -243,8 +257,40 @@ int main(int argc, char **argv) {
// Free memory
free(results_scan);
+
+ // Check output
+ bool status = true;
+ for (i = 0; i < input_size; i++) {
+ if(C[i] != bufferC[i]){
+ status = false;
+#if PRINT
+ printf("%d: %lu -- %lu\n", i, C[i], bufferC[i]);
+#endif
+ }
+ }
+ if (status) {
+ printf("[" ANSI_COLOR_GREEN "OK" ANSI_COLOR_RESET "] Outputs are equal\n");
+ printf("[::] n_dpus=%d n_tasklets=%d e_type=%s block_size_B=%d b_unroll=%d n_elements=%d "
+ "| throughput_cpu_MBps=%f throughput_pim_MBps=%f throughput_MBps=%f\n",
+ nr_of_dpus, NR_TASKLETS, XSTR(T), BLOCK_SIZE, UNROLL, input_size,
+ input_size * sizeof(T) / timer.time[0],
+ input_size * sizeof(T) / (timer.time[2] + timer.time[4]),
+ input_size * sizeof(T) / (timer.time[1] + timer.time[2] + timer.time[3] + timer.time[4]));
+ printf("[::] n_dpus=%d n_tasklets=%d e_type=%s block_size_B=%d b_unroll=%d n_elements=%d "
+ "| throughput_cpu_MOpps=%f throughput_pim_MOpps=%f throughput_MOpps=%f\n",
+ nr_of_dpus, NR_TASKLETS, XSTR(T), BLOCK_SIZE, UNROLL, input_size,
+ input_size / timer.time[0],
+ input_size / (timer.time[2] + timer.time[4]),
+ input_size / (timer.time[1] + timer.time[2] + timer.time[3] + timer.time[4]));
+ printf("[::] n_dpus=%d n_tasklets=%d e_type=%s block_size_B=%d b_unroll=%d n_elements=%d | ",
+ nr_of_dpus, NR_TASKLETS, XSTR(T), BLOCK_SIZE, UNROLL, input_size);
+ printall(&timer);
+ } else {
+ printf("[" ANSI_COLOR_RED "ERROR" ANSI_COLOR_RESET "] Outputs differ!\n");
+ }
}
+ /*
// Print timing results
printf("CPU ");
print(&timer, 0, p.n_reps);
@@ -258,6 +304,8 @@ int main(int argc, char **argv) {
print(&timer, 4, p.n_reps);
printf("DPU-CPU ");
print(&timer, 5, p.n_reps);
+ printf("\n");
+ */
#if ENERGY
double energy;
@@ -266,21 +314,6 @@ int main(int argc, char **argv) {
#endif
- // Check output
- bool status = true;
- for (i = 0; i < input_size; i++) {
- if(C[i] != bufferC[i]){
- status = false;
-#if PRINT
- printf("%d: %lu -- %lu\n", i, C[i], bufferC[i]);
-#endif
- }
- }
- if (status) {
- printf("[" ANSI_COLOR_GREEN "OK" ANSI_COLOR_RESET "] Outputs are equal\n");
- } else {
- printf("[" ANSI_COLOR_RED "ERROR" ANSI_COLOR_RESET "] Outputs differ!\n");
- }
// Deallocation
free(A);
@@ -288,5 +321,5 @@ int main(int argc, char **argv) {
free(C2);
DPU_ASSERT(dpu_free(dpu_set));
- return status ? 0 : -1;
+ return 0;
}
diff --git a/SCAN-SSA/run.sh b/SCAN-SSA/run.sh
index 8ea8457..10dee20 100755
--- a/SCAN-SSA/run.sh
+++ b/SCAN-SSA/run.sh
@@ -1,11 +1,27 @@
#!/bin/bash
-for i in 2048 4096 8192 16384 65536 262144 1048576 3932160
-do
- NR_DPUS=1 NR_TASKLETS=16 BL=10 make all
- wait
- ./bin/host_code -w 10 -e 100 -i ${i} > profile/out${i}_tl16_bl10_dpu11
- wait
- make clean
- wait
+set -e
+
+# BL: use 2^(BL) B blocks for MRAM <-> WRAM transfers on PIM module
+# T: data type
+# -w: number of un-timed warmup iterations
+# -e: number of timed iterations
+# -i: input size (number of elements, not number of bytes!)
+
+echo "prim-benchmarks SCAN-SSA (dfatool edition)"
+echo "Started at $(date)"
+echo "Revision $(git describe --always)"
+
+for nr_dpus in 1 2 4 8 16 32 64 128 256 512; do
+ for nr_tasklets in 1 2 3 4 6 8 10 12 16 20 24; do
+ for i in 2048 4096 8192 16384 65536 262144 1048576 3932160; do
+ for dt in UINT32 UINT64 INT32 INT64 FLOAT DOUBLE; do
+ echo
+ if make -B NR_DPUS=${nr_dpus} NR_TASKLETS=${nr_tasklets} BL=10 TYPE=${dt} UNROLL=1 \
+ || make -B NR_DPUS=${nr_dpus} NR_TASKLETS=${nr_tasklets} BL=10 TYPE=${dt} UNROLL=0; then
+ bin/host_code -w 0 -e 100 -i ${i} || true
+ fi
+ done
+ done
+ done
done
diff --git a/SCAN-SSA/support/common.h b/SCAN-SSA/support/common.h
index 1c419da..1c419da 100755..100644
--- a/SCAN-SSA/support/common.h
+++ b/SCAN-SSA/support/common.h
diff --git a/SCAN-SSA/support/params.h b/SCAN-SSA/support/params.h
index bb86211..cdc075d 100644
--- a/SCAN-SSA/support/params.h
+++ b/SCAN-SSA/support/params.h
@@ -7,7 +7,6 @@ typedef struct Params {
unsigned int input_size;
int n_warmup;
int n_reps;
- int exp;
}Params;
static void usage() {
@@ -30,10 +29,9 @@ struct Params input_params(int argc, char **argv) {
p.input_size = 3932160;
p.n_warmup = 1;
p.n_reps = 3;
- p.exp = 0;
int opt;
- while((opt = getopt(argc, argv, "hi:w:e:x:")) >= 0) {
+ while((opt = getopt(argc, argv, "hi:w:e:")) >= 0) {
switch(opt) {
case 'h':
usage();
@@ -42,7 +40,6 @@ struct Params input_params(int argc, char **argv) {
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();
diff --git a/SCAN-SSA/support/timer.h b/SCAN-SSA/support/timer.h
index b53d95f..194569f 100755..100644
--- a/SCAN-SSA/support/timer.h
+++ b/SCAN-SSA/support/timer.h
@@ -56,4 +56,9 @@ void stop(Timer *timer, int i) {
(timer->stopTime[i].tv_usec - timer->startTime[i].tv_usec);
}
-void print(Timer *timer, int i, int REP) { printf("Time (ms): %f\t", timer->time[i] / (1000 * REP)); }
+void printall(Timer *timer) {
+ for (int i = 0; i <= 5; i++) {
+ printf(" timer%d_us=%f", i, timer->time[i]);
+ }
+ printf("\n");
+}