summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2023-05-31 16:14:31 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2023-05-31 16:14:31 +0200
commit0540fa9e26e2c8e7e11fcf3e5444e4981f811e1c (patch)
treea450f403c535ded297b8ffc4a0ea5675e780a3de
parent0f710b4f47dfc51e3f01473995dbb6ed5844eff1 (diff)
port TRNS to dfatool
-rw-r--r--TRNS/Makefile46
-rw-r--r--TRNS/baselines/cpu/Makefile26
-rw-r--r--TRNS/baselines/cpu/main.cpp26
-rwxr-xr-xTRNS/baselines/cpu/run-opti.sh11
-rw-r--r--TRNS/baselines/cpu/support/timer.h7
-rw-r--r--TRNS/host/app.c63
-rwxr-xr-xTRNS/run-paper-strong-rank.sh27
-rwxr-xr-xTRNS/run-paper-weak.sh23
-rwxr-xr-xTRNS/support/timer.h7
9 files changed, 172 insertions, 64 deletions
diff --git a/TRNS/Makefile b/TRNS/Makefile
index 8a6fd64..f58eb0c 100644
--- a/TRNS/Makefile
+++ b/TRNS/Makefile
@@ -1,44 +1,36 @@
-DPU_DIR := dpu
-HOST_DIR := host
-BUILDDIR ?= bin
NR_DPUS ?= 1
NR_TASKLETS ?= 16
ENERGY ?= 0
-define conf_filename
- ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2).conf
-endef
-CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS})
-
-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})
+HOST_SOURCES := $(wildcard host/*.c)
+DPU_SOURCES := $(wildcard dpu/*.c)
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} -DENERGY=${ENERGY}
DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS}
-all: ${HOST_TARGET} ${DPU_TARGET}
+QUIET = @
-${CONF}:
- $(RM) $(call conf_filename,*,*)
- touch ${CONF}
+ifdef verbose
+ QUIET =
+endif
-${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF}
- $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS}
+all: bin/host_code bin/dpu_code
-${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF}
- dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES}
+bin:
+ ${QUIET}mkdir -p bin
+
+bin/host_code: ${HOST_SOURCES} ${COMMON_INCLUDES} bin
+ ${QUIET}${CC} -o $@ ${HOST_SOURCES} ${HOST_FLAGS}
+
+bin/dpu_code: ${DPU_SOURCES} ${COMMON_INCLUDES} bin
+ ${QUIET}dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES}
clean:
- $(RM) -r $(BUILDDIR)
+ ${QUIET}rm -rf bin
test: all
- ./${HOST_TARGET}
+ ${QUIET}bin/host_code
+
+.PHONY: all clean test
diff --git a/TRNS/baselines/cpu/Makefile b/TRNS/baselines/cpu/Makefile
index cb2e264..781e2be 100644
--- a/TRNS/baselines/cpu/Makefile
+++ b/TRNS/baselines/cpu/Makefile
@@ -41,9 +41,29 @@ DEP=kernel.cpp kernel.h main.cpp support/common.h support/setup.h support/timer.
SRC=main.cpp kernel.cpp
EXE=trns
-all:
- $(CXX) $(CXX_FLAGS) $(SRC) $(LIB) -o $(EXE)
+all: trns
+
+trns: ${SRC}
+ $(CXX) -O2 $(CXX_FLAGS) $(SRC) $(LIB) -o $(EXE)
+
+trns_O0: ${SRC}
+ $(CXX) $(CXX_FLAGS) $(SRC) $(LIB) -o $(EXE)_O0
+
+trns_O2: ${SRC}
+ $(CXX) -O2 $(CXX_FLAGS) $(SRC) $(LIB) -o $(EXE)_O2
+
+run: trns
+ ./trns -w 0 -r 1 -m 16 -n 8 -o 4096 -p 2556
+
+# upstream uses -r 1
+
+run_O0: trns_O0
+ ./trns_O0 -w 0 -r 50 -m 16 -n 8 -o 4096 -p 2556
+
+run_O2: trns_O2
+ ./trns_O2 -w 0 -r 50 -m 16 -n 8 -o 4096 -p 2556
clean:
- rm -f $(EXE)
+ rm -f $(EXE) ${EXE}_O0 ${EXE}_O2
+.PHONY: all run run_O0 run_O2 clean
diff --git a/TRNS/baselines/cpu/main.cpp b/TRNS/baselines/cpu/main.cpp
index 2c3bdc3..2c481df 100644
--- a/TRNS/baselines/cpu/main.cpp
+++ b/TRNS/baselines/cpu/main.cpp
@@ -44,6 +44,9 @@
#include <string.h>
#include <assert.h>
+#define XSTR(x) STR(x)
+#define STR(x) #x
+
// Params ---------------------------------------------------------------------
struct Params {
@@ -138,7 +141,7 @@ int main(int argc, char **argv) {
T *h_in_backup = (T *)malloc(in_size * sizeof(T));
ALLOC_ERR(h_in_backup);
timer.stop("Allocation");
- timer.print("Allocation", 1);
+ //timer.print("Allocation", 1);
// Initialize
timer.start("Initialization");
@@ -147,7 +150,7 @@ int main(int argc, char **argv) {
for(int i = 0; i < N_; i++)
h_head[i].store(0);
timer.stop("Initialization");
- timer.print("Initialization", 1);
+ //timer.print("Initialization", 1);
memcpy(h_in_backup, h_in_out, in_size * sizeof(T)); // Backup for reuse across iterations
// Loop over main kernel
@@ -197,10 +200,21 @@ int main(int argc, char **argv) {
// end timer
if(rep >= p.n_warmup)
timer.stop("Step 3");
+
+ if (rep >= p.n_warmup) {
+ printf("[::] TRNS CPU | n_threads=%d e_type=%s n_elements=%d "
+ "| throughput_MBps=%f",
+ p.n_threads, XSTR(T), in_size,
+ in_size * sizeof(T) / (timer.get("Step 1") + timer.get("Step 2") + timer.get("Step 3")));
+ printf(" throughput_MOpps=%f",
+ in_size / (timer.get("Step 1") + timer.get("Step 2") + timer.get("Step 3")));
+ printf(" timer1_us=%f timer2_us=%f timer3_us=%f\n",
+ timer.get("Step 1"), timer.get("Step 2"), timer.get("Step 3"));
+ }
}
- timer.print("Step 1", p.n_reps);
- timer.print("Step 2", p.n_reps);
- timer.print("Step 3", p.n_reps);
+ //timer.print("Step 1", p.n_reps);
+ //timer.print("Step 2", p.n_reps);
+ //timer.print("Step 3", p.n_reps);
// Verify answer
//verify(h_in_out, h_in_backup, M_ * m, N_ * n, 1);
@@ -212,7 +226,7 @@ int main(int argc, char **argv) {
free(h_head);
free(h_in_backup);
timer.stop("Deallocation");
- timer.print("Deallocation", 1);
+ //timer.print("Deallocation", 1);
printf("Test Passed\n");
return 0;
diff --git a/TRNS/baselines/cpu/run-opti.sh b/TRNS/baselines/cpu/run-opti.sh
new file mode 100755
index 0000000..0a3a4a3
--- /dev/null
+++ b/TRNS/baselines/cpu/run-opti.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+HOST="$(hostname)"
+
+echo $HOST
+
+make clean
+
+make run_O0 | sed 's/CPU/CPU O0/' | tee "${HOST}-O0.txt"
+
+make run_O2 | sed 's/CPU/CPU O2/' | tee "${HOST}-O2.txt"
diff --git a/TRNS/baselines/cpu/support/timer.h b/TRNS/baselines/cpu/support/timer.h
index 70ee386..d8ef221 100644
--- a/TRNS/baselines/cpu/support/timer.h
+++ b/TRNS/baselines/cpu/support/timer.h
@@ -47,9 +47,7 @@ struct Timer {
map<string, double> time;
void start(string name) {
- if(!time.count(name)) {
- time[name] = 0.0;
- }
+ time[name] = 0.0;
gettimeofday(&startTime[name], NULL);
}
@@ -59,5 +57,6 @@ struct Timer {
(stopTime[name].tv_usec - startTime[name].tv_usec);
}
- void print(string name, int REP) { printf("%s Time (ms): %f\n", name.c_str(), time[name] / (1000 * REP)); }
+ void print(string name, int REP) { printf("%s Time (ms): %f\n", name.c_str(), time[name] / (1000 * REP)); }
+ double get(string name) { return time[name]; }
};
diff --git a/TRNS/host/app.c b/TRNS/host/app.c
index 1aa6392..77e58f2 100644
--- a/TRNS/host/app.c
+++ b/TRNS/host/app.c
@@ -18,6 +18,9 @@
#include "../support/timer.h"
#include "../support/params.h"
+#define XSTR(x) STR(x)
+#define STR(x) #x
+
// Define the DPU Binary path as DPU_BINARY here
#ifndef DPU_BINARY
#define DPU_BINARY "./bin/dpu_code"
@@ -97,11 +100,10 @@ int main(int argc, char **argv) {
// Loop over main kernel
for(int rep = 0; rep < p.n_warmup + p.n_reps; rep++) {
- int timer_fix = 0;
// Compute output on CPU (performance comparison and verification purposes)
memcpy(A_host, A_backup, M_ * m * N_ * n * sizeof(T));
if(rep >= p.n_warmup)
- start(&timer, 0, rep - p.n_warmup + timer_fix);
+ start(&timer, 0, 0);
trns_host(A_host, M_ * m, N_ * n, 1);
if(rep >= p.n_warmup)
stop(&timer, 0);
@@ -133,7 +135,7 @@ int main(int argc, char **argv) {
printf("Load input data (step 1)\n");
if(rep >= p.n_warmup)
- start(&timer, 1, rep - p.n_warmup + timer_fix);
+ start(&timer, 1, 0);
// Load input matrix (step 1)
for(unsigned int j = 0; j < M_ * m; j++){
unsigned int i = 0;
@@ -160,7 +162,7 @@ int main(int argc, char **argv) {
printf("Run step 2 on DPU(s) \n");
// Run DPU kernel
if(rep >= p.n_warmup){
- start(&timer, 2, rep - p.n_warmup + timer_fix);
+ start(&timer, 2, 0);
#if ENERGY
DPU_ASSERT(dpu_probe_start(&probe));
#endif
@@ -193,7 +195,7 @@ int main(int argc, char **argv) {
printf("Run step 3 on DPU(s) \n");
// Run DPU kernel
if(rep >= p.n_warmup){
- start(&timer, 3, rep - p.n_warmup + timer_fix);
+ start(&timer, 3, 0);
#if ENERGY
DPU_ASSERT(dpu_probe_start(&probe));
#endif
@@ -219,7 +221,7 @@ int main(int argc, char **argv) {
printf("Retrieve results\n");
if(rep >= p.n_warmup)
- start(&timer, 4, rep - p.n_warmup + timer_fix);
+ start(&timer, 4, 0);
DPU_FOREACH(dpu_set, dpu) {
DPU_ASSERT(dpu_prepare_xfer(dpu, (T*)(&A_result[curr_dpu * m * n * M_])));
curr_dpu++;
@@ -231,10 +233,39 @@ int main(int argc, char **argv) {
if(first_round){
first_round = 0;
}
- timer_fix++;
}
DPU_ASSERT(dpu_free(dpu_set));
+ // Check output
+ bool status = true;
+ for (i = 0; i < M_ * m * N_ * n; i++) {
+ if(A_host[i] != A_result[i]){
+ status = false;
+#if PRINT
+ printf("%d: %lu -- %lu\n", i, A_host[i], A_result[i]);
+#endif
+ }
+ }
+ if (status) {
+ printf("[" ANSI_COLOR_GREEN "OK" ANSI_COLOR_RESET "] Outputs are equal\n");
+ unsigned long input_size = M_ * m * N_ * n;
+ if (rep >= p.n_warmup) {
+ printf("[::] TRNS NMC | n_dpus=%d n_tasklets=%d e_type=%s n_elements=%lu "
+ "| throughput_cpu_MBps=%f throughput_pim_MBps=%f throughput_MBps=%f",
+ nr_of_dpus, NR_TASKLETS, XSTR(T), input_size,
+ input_size * sizeof(T) / timer.time[0],
+ input_size * sizeof(T) / (timer.time[2] + timer.time[3]),
+ input_size * sizeof(T) / (timer.time[1] + timer.time[2] + timer.time[3] + timer.time[4]));
+ printf(" throughput_cpu_MOpps=%f throughput_pim_MOpps=%f throughput_MOpps=%f",
+ input_size / timer.time[0],
+ input_size / (timer.time[2] + timer.time[3]),
+ input_size / (timer.time[1] + timer.time[2] + timer.time[3] + timer.time[4]));
+ printall(&timer, 4);
+ }
+ } else {
+ printf("[" ANSI_COLOR_RED "ERROR" ANSI_COLOR_RESET "] Outputs differ!\n");
+ }
+
}
// Print timing results
@@ -255,27 +286,11 @@ int main(int argc, char **argv) {
printf("DPU Energy (J): %f\t", energy);
#endif
- // Check output
- bool status = true;
- for (i = 0; i < M_ * m * N_ * n; i++) {
- if(A_host[i] != A_result[i]){
- status = false;
-#if PRINT
- printf("%d: %lu -- %lu\n", i, A_host[i], A_result[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_host);
free(A_backup);
free(A_result);
free(done_host);
- return status ? 0 : -1;
+ return 0;
}
diff --git a/TRNS/run-paper-strong-rank.sh b/TRNS/run-paper-strong-rank.sh
new file mode 100755
index 0000000..205eccb
--- /dev/null
+++ b/TRNS/run-paper-strong-rank.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+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; ignored, always uses 262144 elements
+
+(
+
+echo "prim-benchmarks BS strong-rank (dfatool edition)"
+echo "Started at $(date)"
+echo "Revision $(git describe --always)"
+
+# 256 and 512 are not part of upstream
+for nr_dpus in 512 256 1 4 16 64; do
+ for nr_tasklets in 1 2 4 8 16; do
+ echo
+ if make -B NR_DPUS=${nr_dpus} NR_TASKLETS=${nr_tasklets}; then
+ # upstream uses -p 64, but then the number of DPUs is always constant...
+ timeout --foreground -k 1m 60m bin/host_code -w 0 -e 100 -p $nr_dpus -o 12288 -x 1 || true
+ fi
+ done
+done
+)| tee log-paper-strong-rank.txt
diff --git a/TRNS/run-paper-weak.sh b/TRNS/run-paper-weak.sh
new file mode 100755
index 0000000..0840260
--- /dev/null
+++ b/TRNS/run-paper-weak.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+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; ignored, always uses 262144 elements
+
+echo "prim-benchmarks BS weak (dfatool edition)"
+echo "Started at $(date)"
+echo "Revision $(git describe --always)"
+
+# 256 and 512 are not part of upstream
+for nr_dpus in 256 512 1 4 16 64; do
+ for nr_tasklets in 1 2 4 8 16; do
+ echo
+ if make -B NR_DPUS=${nr_dpus} NR_TASKLETS=${nr_tasklets}; then
+ timeout --foreground -k 1m 30m bin/bs_host -w 0 -e 100 -p 1 -o 12288 -x 0 || true
+ fi
+ done
+done | tee log-paper-weak.txt
diff --git a/TRNS/support/timer.h b/TRNS/support/timer.h
index b53d95f..4d597b9 100755
--- a/TRNS/support/timer.h
+++ b/TRNS/support/timer.h
@@ -57,3 +57,10 @@ void stop(Timer *timer, int i) {
}
void print(Timer *timer, int i, int REP) { printf("Time (ms): %f\t", timer->time[i] / (1000 * REP)); }
+
+void printall(Timer *timer, int maxt) {
+ for (int i = 0; i <= maxt; i++) {
+ printf(" timer%d_us=%f", i, timer->time[i]);
+ }
+ printf("\n");
+}