From b1f82770b817d0558044d3cfb1ef4d36b4492055 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 23 May 2025 14:42:05 +0200 Subject: RED: support → include; fix runtime for NR_DPUS==1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RED/Makefile | 33 +++++++++++++++++----- RED/dpu/task.c | 4 +-- RED/host/app.c | 12 ++++---- RED/include/common.h | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ RED/include/cyclecount.h | 19 +++++++++++++ RED/include/params.h | 56 +++++++++++++++++++++++++++++++++++++ RED/include/timer.h | 66 +++++++++++++++++++++++++++++++++++++++++++ RED/support/common.h | 73 ------------------------------------------------ RED/support/cyclecount.h | 19 ------------- RED/support/params.h | 56 ------------------------------------- RED/support/timer.h | 66 ------------------------------------------- 11 files changed, 248 insertions(+), 229 deletions(-) create mode 100755 RED/include/common.h create mode 100644 RED/include/cyclecount.h create mode 100644 RED/include/params.h create mode 100755 RED/include/timer.h delete mode 100755 RED/support/common.h delete mode 100644 RED/support/cyclecount.h delete mode 100644 RED/support/params.h delete mode 100755 RED/support/timer.h diff --git a/RED/Makefile b/RED/Makefile index f20e1f7..c65df94 100644 --- a/RED/Makefile +++ b/RED/Makefile @@ -8,17 +8,34 @@ WITH_ALLOC_OVERHEAD ?= 0 WITH_LOAD_OVERHEAD ?= 0 WITH_FREE_OVERHEAD ?= 0 -COMMON_INCLUDES := support 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} -DBL=${BL} -D${TYPE} -DENERGY=${ENERGY} -DPERF=${PERF} -DWITH_ALLOC_OVERHEAD=${WITH_ALLOC_OVERHEAD} -DWITH_LOAD_OVERHEAD=${WITH_LOAD_OVERHEAD} -DWITH_FREE_OVERHEAD=${WITH_FREE_OVERHEAD} +aspectc ?= 0 +aspectc_timing ?= 0 +dfatool_timing ?= 1 + +HOST_CC := ${CC} + +COMMON_FLAGS := -Wall -Wextra -g -Iinclude +HOST_FLAGS := ${COMMON_FLAGS} -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} -D${TYPE} -DENERGY=${ENERGY} -DPERF=${PERF} -DWITH_ALLOC_OVERHEAD=${WITH_ALLOC_OVERHEAD} -DWITH_LOAD_OVERHEAD=${WITH_LOAD_OVERHEAD} -DWITH_FREE_OVERHEAD=${WITH_FREE_OVERHEAD} -DASPECTC=${aspectc} -DDFATOOL_TIMING=${dfatool_timing} DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${TYPE} -DPERF=${PERF} +ifeq (${aspectc_timing}, 1) + ASPECTC_HOST_FLAGS += -ainclude/dfatool_host_dpu.ah -ainclude/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 +ifeq (${verbose}, 1) QUIET = endif @@ -27,10 +44,12 @@ all: bin/host_code bin/dpu_code bin: ${QUIET}mkdir -p bin -bin/host_code: ${HOST_SOURCES} ${COMMON_INCLUDES} bin - ${QUIET}${CC} -o $@ ${HOST_SOURCES} ${HOST_FLAGS} +bin/host_code: ${HOST_SOURCES} include bin + ${QUIET}cp ../include/dfatool_host_dpu.ah include + ${QUIET}${HOST_CC} -o $@ ${HOST_SOURCES} ${HOST_FLAGS} + ${QUIET}rm -f include/dfatool_host_dpu.ah -bin/dpu_code: ${DPU_SOURCES} ${COMMON_INCLUDES} bin +bin/dpu_code: ${DPU_SOURCES} include bin ${QUIET}dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} clean: diff --git a/RED/dpu/task.c b/RED/dpu/task.c index 5536d4d..90386b2 100644 --- a/RED/dpu/task.c +++ b/RED/dpu/task.c @@ -11,8 +11,8 @@ #include #include -#include "../support/common.h" -#include "../support/cyclecount.h" +#include "common.h" +#include "cyclecount.h" __host dpu_arguments_t DPU_INPUT_ARGUMENTS; __host dpu_results_t DPU_RESULTS[NR_TASKLETS]; diff --git a/RED/host/app.c b/RED/host/app.c index 204f056..885ddb8 100644 --- a/RED/host/app.c +++ b/RED/host/app.c @@ -13,9 +13,9 @@ #include #include -#include "../support/common.h" -#include "../support/timer.h" -#include "../support/params.h" +#include "common.h" +#include "timer.h" +#include "params.h" // Define the DPU Binary path as DPU_BINARY here #ifndef DPU_BINARY @@ -168,9 +168,9 @@ int main(int argc, char **argv) { // Input arguments unsigned int kernel = 0; dpu_arguments_t input_arguments[NR_DPUS]; - for(i=0; i + +// 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/RED/include/params.h b/RED/include/params.h new file mode 100644 index 0000000..97bc50a --- /dev/null +++ b/RED/include/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 # of untimed warmup iterations (default=1)" + "\n -e # of timed repetition iterations (default=3)" + "\n -x Weak (0) or strong (1) scaling (default=0)" + "\n" + "\nBenchmark-specific options:" + "\n -i input size (default=6553600 elements)" + "\n"); +} + +struct Params input_params(int argc, char **argv) { + struct Params p; + p.input_size = 6553600; + 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/RED/include/timer.h b/RED/include/timer.h new file mode 100755 index 0000000..4d597b9 --- /dev/null +++ b/RED/include/timer.h @@ -0,0 +1,66 @@ +/* + * 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 + +typedef struct Timer{ + + struct timeval startTime[7]; + struct timeval stopTime[7]; + double time[7]; + +}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)); } + +void printall(Timer *timer, int maxt) { + for (int i = 0; i <= maxt; i++) { + printf(" timer%d_us=%f", i, timer->time[i]); + } + printf("\n"); +} diff --git a/RED/support/common.h b/RED/support/common.h deleted file mode 100755 index 121bf31..0000000 --- a/RED/support/common.h +++ /dev/null @@ -1,73 +0,0 @@ -#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 -#define DIV 2 // Shift right to divide by sizeof(T) -#elif UINT64 -#define T uint64_t -#define DIV 3 // Shift right to divide by sizeof(T) -#elif INT32 -#define T int32_t -#define DIV 2 // Shift right to divide by sizeof(T) -#elif INT64 -#define T int64_t -#define DIV 3 // Shift right to divide by sizeof(T) -#elif FLOAT -#define T float -#define DIV 2 // Shift right to divide by sizeof(T) -#elif DOUBLE -#define T double -#define DIV 3 // Shift right to divide by sizeof(T) -#elif CHAR -#define T char -#define DIV 0 // Shift right to divide by sizeof(T) -#elif SHORT -#define T short -#define DIV 1 // Shift right to divide by sizeof(T) -#endif - -// 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; - T t_count; -} dpu_arguments_t; - -typedef struct { - uint64_t cycles; - T t_count; -} dpu_results_t; - -#ifndef PERF -#define PERF 0 // Use perfcounters? -#endif -#ifndef PERF_SYNC -#define PERF_SYNC 0 // Use perfcounters to time sync primitives? -#endif -#ifndef ENERGY -#define ENERGY 0 -#endif -#define PRINT 0 - -#define ANSI_COLOR_RED "\x1b[31m" -#define ANSI_COLOR_GREEN "\x1b[32m" -#define ANSI_COLOR_RESET "\x1b[0m" - -#define divceil(n, m) (((n)-1) / (m) + 1) -#define roundup(n, m) ((n / m) * m + m) -#endif diff --git a/RED/support/cyclecount.h b/RED/support/cyclecount.h deleted file mode 100644 index c4247b5..0000000 --- a/RED/support/cyclecount.h +++ /dev/null @@ -1,19 +0,0 @@ -#include - -// 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/RED/support/params.h b/RED/support/params.h deleted file mode 100644 index 97bc50a..0000000 --- a/RED/support/params.h +++ /dev/null @@ -1,56 +0,0 @@ -#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 # of untimed warmup iterations (default=1)" - "\n -e # of timed repetition iterations (default=3)" - "\n -x Weak (0) or strong (1) scaling (default=0)" - "\n" - "\nBenchmark-specific options:" - "\n -i input size (default=6553600 elements)" - "\n"); -} - -struct Params input_params(int argc, char **argv) { - struct Params p; - p.input_size = 6553600; - 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/RED/support/timer.h b/RED/support/timer.h deleted file mode 100755 index 4d597b9..0000000 --- a/RED/support/timer.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 - -typedef struct Timer{ - - struct timeval startTime[7]; - struct timeval stopTime[7]; - double time[7]; - -}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)); } - -void printall(Timer *timer, int maxt) { - for (int i = 0; i <= maxt; i++) { - printf(" timer%d_us=%f", i, timer->time[i]); - } - printf("\n"); -} -- cgit v1.2.3