diff options
-rw-r--r-- | TRNS/Makefile | 20 | ||||
-rw-r--r-- | TRNS/host/app.c | 45 | ||||
-rwxr-xr-x | TRNS/support/common.h | 12 | ||||
-rw-r--r-- | TRNS/support/dfatool_host.ah | 101 |
4 files changed, 156 insertions, 22 deletions
diff --git a/TRNS/Makefile b/TRNS/Makefile index 9d6a60b..427a332 100644 --- a/TRNS/Makefile +++ b/TRNS/Makefile @@ -6,12 +6,28 @@ COMMON_INCLUDES := support HOST_SOURCES := $(wildcard host/*.c) DPU_SOURCES := $(wildcard dpu/*.c) +aspectc ?= 0 +aspectc_timing ?= * dfatool_timing ?= 1 +HOST_CC := ${CC} + 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} -DDFATOOL_TIMING=${dfatool_timing} +HOST_FLAGS := ${COMMON_FLAGS} -O3 -march=native `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DENERGY=${ENERGY} -DDFATOOL_TIMING=${dfatool_timing} -DASPECTC=${aspectc} DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} +ifeq (${aspectc_timing}, 1) + ASPECTC_HOST_FLAGS += -a support/dfatool_host.ah +endif + +ASPECTC_HOST_FLAGS ?= -a0 + +ifeq (${aspectc}, 1) + HOST_CC = ag++ -r repo.acp -v 0 ${ASPECTC_HOST_FLAGS} --c_compiler ${UPMEM_HOME}/bin/clang++ -p . --Xcompiler +else + HOST_FLAGS += -std=c11 +endif + QUIET = @ ifdef verbose @@ -24,7 +40,7 @@ bin: ${QUIET}mkdir -p bin bin/host_code: ${HOST_SOURCES} ${COMMON_INCLUDES} bin - ${QUIET}${CC} -o $@ ${HOST_SOURCES} ${HOST_FLAGS} + ${QUIET}${HOST_CC} -o $@ ${HOST_SOURCES} ${HOST_FLAGS} bin/dpu_code: ${DPU_SOURCES} ${COMMON_INCLUDES} bin ${QUIET}dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} diff --git a/TRNS/host/app.c b/TRNS/host/app.c index 4ed69ec..735d2a9 100644 --- a/TRNS/host/app.c +++ b/TRNS/host/app.c @@ -7,8 +7,24 @@ #include <stdlib.h> #include <stdbool.h> #include <string.h> + +#if ASPECTC +extern "C" { +#endif + #include <dpu.h> #include <dpu_log.h> +#include <dpu_management.h> +#include <dpu_target_macros.h> + +#if ENERGY +#include <dpu_probe.h> +#endif + +#if ASPECTC +} +#endif + #include <unistd.h> #include <getopt.h> #include <assert.h> @@ -26,18 +42,14 @@ #define DPU_BINARY "./bin/dpu_code" #endif -#if ENERGY -#include <dpu_probe.h> -#endif - -#include <dpu_management.h> -#include <dpu_target_macros.h> - // Pointer declaration static T* A_host; static T* A_backup; static T* A_result; +struct Params p; +unsigned int kernel = 0; + // Create input arrays static void read_input(T* A, unsigned int nr_elements) { srand(0); @@ -65,7 +77,7 @@ static void trns_host(T* input, unsigned int A, unsigned int B, unsigned int b){ // Main of the Host Application int main(int argc, char **argv) { - struct Params p = input_params(argc, argv); + p = input_params(argc, argv); struct dpu_set_t dpu_set, dpu; uint32_t nr_of_dpus; @@ -84,10 +96,10 @@ int main(int argc, char **argv) { N_ = p.exp == 0 ? N_ * NR_DPUS : N_; // Input/output allocation - A_host = malloc(M_ * m * N_ * n * sizeof(T)); - A_backup = malloc(M_ * m * N_ * n * sizeof(T)); - A_result = malloc(M_ * m * N_ * n * sizeof(T)); - T* done_host = malloc(M_ * n); // Host array to reset done array of step 3 + A_host = (T*)malloc(M_ * m * N_ * n * sizeof(T)); + A_backup = (T*)malloc(M_ * m * N_ * n * sizeof(T)); + A_result = (T*)malloc(M_ * m * N_ * n * sizeof(T)); + T* done_host = (T*)malloc(M_ * n); // Host array to reset done array of step 3 memset(done_host, 0, M_ * n); // Create an input file with arbitrary data @@ -131,6 +143,7 @@ int main(int argc, char **argv) { DPU_ASSERT(dpu_load(dpu_set, DPU_BINARY, NULL)); stop(&timer, 2); DPU_ASSERT(dpu_get_nr_dpus(dpu_set, &nr_of_dpus)); + DPU_ASSERT(dpu_get_nr_ranks(dpu_set, &nr_of_ranks)); } else if (first_round){ start(&timer, 1, 0); DPU_ASSERT(dpu_alloc(active_dpus, NULL, &dpu_set)); @@ -174,8 +187,8 @@ int main(int argc, char **argv) { start(&timer, 5, !first_round); } - unsigned int kernel = 0; - dpu_arguments_t input_arguments = {m, n, M_, kernel}; + kernel = 0; + dpu_arguments_t input_arguments = {m, n, M_, (enum kernels)kernel}; // transfer control instructions to DPUs (run first program part) DPU_FOREACH(dpu_set, dpu, i) { DPU_ASSERT(dpu_prepare_xfer(dpu, &input_arguments)); @@ -215,7 +228,7 @@ int main(int argc, char **argv) { start(&timer, 7, !first_round); } kernel = 1; - dpu_arguments_t input_arguments2 = {m, n, M_, kernel}; + dpu_arguments_t input_arguments2 = {m, n, M_, (enum kernels)kernel}; DPU_FOREACH(dpu_set, dpu, i) { DPU_ASSERT(dpu_prepare_xfer(dpu, &input_arguments2)); } @@ -299,7 +312,9 @@ int main(int argc, char **argv) { } if (status) { printf("[" ANSI_COLOR_GREEN "OK" ANSI_COLOR_RESET "] Outputs are equal\n"); +#if DFATOOL_TIMING unsigned long input_size = M_ * m * N_ * n; +#endif if (rep >= p.n_warmup) { /* * timer 0: CPU version diff --git a/TRNS/support/common.h b/TRNS/support/common.h index 2ba56c5..6a94c62 100755 --- a/TRNS/support/common.h +++ b/TRNS/support/common.h @@ -14,16 +14,18 @@ // Data type #define T int64_t +enum kernels { + kernel1 = 0, + kernel2 = 1, + nr_kernels = 2, +}; + // Structures used by both the host and the dpu to communicate information typedef struct { uint32_t m; uint32_t n; uint32_t M_; - enum kernels { - kernel1 = 0, - kernel2 = 1, - nr_kernels = 2, - } kernel; + enum kernels kernel; } dpu_arguments_t; #ifndef ENERGY diff --git a/TRNS/support/dfatool_host.ah b/TRNS/support/dfatool_host.ah new file mode 100644 index 0000000..c884c9d --- /dev/null +++ b/TRNS/support/dfatool_host.ah @@ -0,0 +1,101 @@ +#pragma once + +#include <sys/time.h> + +aspect DfatoolHostTiming { + struct timeval starttime; + struct timeval stoptime; + uint32_t n_ranks = 0; + uint32_t n_dpus = 0; + + double const M_to_Mi = 1.048576; /* 2^20 / 1e6 */ + + advice call("% dpu_get_nr_dpus(...)") : after() { + n_dpus = **(tjp->arg<1>()); + } + + advice call("% dpu_get_nr_ranks(...)") : after() { + n_ranks = **(tjp->arg<1>()); + } + + advice call("% dpu_alloc(...)") : around() { + gettimeofday(&starttime, NULL); + tjp->proceed(); + gettimeofday(&stoptime, NULL); + n_dpus = *(tjp->arg<0>()); + printf("[::] dpu_alloc | n_dpus=%u | latency_us=%f\n", + n_dpus, + (stoptime.tv_sec - starttime.tv_sec) * 1000000.0 + (stoptime.tv_usec - starttime.tv_usec) + ); + } + + advice call("% dpu_alloc_ranks(...)") : around() { + gettimeofday(&starttime, NULL); + tjp->proceed(); + gettimeofday(&stoptime, NULL); + n_ranks = *(tjp->arg<0>()); + printf("[::] dpu_alloc_ranks | n_ranks=%u | latency_us=%f\n", + n_ranks, + (stoptime.tv_sec - starttime.tv_sec) * 1000000.0 + (stoptime.tv_usec - starttime.tv_usec) + ); + } + + advice call("% dpu_load(...)") : around() { + gettimeofday(&starttime, NULL); + tjp->proceed(); + gettimeofday(&stoptime, NULL); + printf("[::] dpu_load | n_dpus=%u n_ranks=%u | latency_us=%f\n", + n_dpus, n_ranks, + (stoptime.tv_sec - starttime.tv_sec) * 1000000.0 + (stoptime.tv_usec - starttime.tv_usec) + ); + } + + advice call("% dpu_free(...)") : around() { + gettimeofday(&starttime, NULL); + tjp->proceed(); + gettimeofday(&stoptime, NULL); + printf("[::] dpu_free | n_dpus=%u n_ranks=%u | latency_us=%f\n", + n_dpus, n_ranks, + (stoptime.tv_sec - starttime.tv_sec) * 1000000.0 + (stoptime.tv_usec - starttime.tv_usec) + ); + } + + advice call("% dpu_launch(...)") : around() { + gettimeofday(&starttime, NULL); + tjp->proceed(); + gettimeofday(&stoptime, NULL); + double latency_us = (stoptime.tv_sec - starttime.tv_sec) * 1000000.0 + (stoptime.tv_usec - starttime.tv_usec); + unsigned long input_size = p.M_ * p.m * p.N_ * p.n; + printf("[::] dpu_launch | n_dpus=%u n_ranks=%u e_kernel=kernel%d n_elements=%lu | latency_us=%f throughput_Mrps=%f throughput_MiBps=%f\n", + n_dpus, n_ranks, + kernel + 1, + input_size, + latency_us, + input_size / latency_us, + input_size * sizeof(T) / (latency_us * M_to_Mi) + ); + } + + advice call("% dpu_push_xfer(...)") : around() { + size_t payload_size = *(tjp->arg<4>()); + gettimeofday(&starttime, NULL); + tjp->proceed(); + gettimeofday(&stoptime, NULL); + double time_us = (stoptime.tv_sec - starttime.tv_sec) * 1000000.0 + (stoptime.tv_usec - starttime.tv_usec); + if (*(tjp->arg<1>()) == DPU_XFER_TO_DPU) { + printf("[::] dpu_push_to_dpu | n_dpus=%u n_ranks=%u total_payload_B=%lu dpu_payload_B=%lu | latency_us=%f throughput_MiBps=%f\n", + n_dpus, n_ranks, + payload_size * n_dpus, payload_size, + time_us, + payload_size * n_dpus / (time_us * M_to_Mi) + ); + } else if (*(tjp->arg<1>()) == DPU_XFER_FROM_DPU) { + printf("[::] dpu_push_from_dpu | n_dpus=%u n_ranks=%u total_payload_B=%lu dpu_payload_B=%lu | latency_us=%f throughput_MiBps=%f\n", + n_dpus, n_ranks, + payload_size * n_dpus, payload_size, + time_us, + payload_size * n_dpus / (time_us * M_to_Mi) + ); + } + } +}; |