From 665cc63e16a1a5ac083c3a2df38236ae58025b64 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Thu, 15 May 2025 10:13:23 +0200 Subject: MLP: Add AspectC++ support --- MLP/Makefile | 64 +++++++++++++++++++++++------------------ MLP/dpu/task.c | 2 +- MLP/host/app.c | 36 +++++++++++------------ MLP/include/common.h | 45 +++++++++++++++++++++++++++++ MLP/include/dfatool_host.ah | 31 ++++++++++++++++++++ MLP/include/params.h | 65 ++++++++++++++++++++++++++++++++++++++++++ MLP/include/timer.h | 5 ++++ MLP/support/common.h | 45 ----------------------------- MLP/support/params.h | 65 ------------------------------------------ MLP/support/timer.h | 69 --------------------------------------------- README.md | 2 +- 11 files changed, 201 insertions(+), 228 deletions(-) create mode 100644 MLP/include/common.h create mode 100644 MLP/include/dfatool_host.ah create mode 100644 MLP/include/params.h create mode 100644 MLP/include/timer.h delete mode 100755 MLP/support/common.h delete mode 100644 MLP/support/params.h delete mode 100755 MLP/support/timer.h diff --git a/MLP/Makefile b/MLP/Makefile index 944b3ca..9d69752 100644 --- a/MLP/Makefile +++ b/MLP/Makefile @@ -1,44 +1,54 @@ -DPU_DIR := dpu -HOST_DIR := host -BUILDDIR ?= bin -NR_TASKLETS ?= 16 +NR_DPUS ?= 1 +NR_TASKLETS ?= 16 BL ?= 10 -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_SOURCES := $(wildcard host/*.c) +DPU_SOURCES := $(wildcard dpu/*.c) -HOST_TARGET := ${BUILDDIR}/mlp_host -DPU_TARGET := ${BUILDDIR}/mlp_dpu +aspectc ?= 0 +aspectc_timing ?= 0 -COMMON_INCLUDES := support -HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) -DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) +HOST_CC := ${CC} -.PHONY: all clean test +COMMON_FLAGS := -Wall -Wextra -g -Iinclude -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DBL=${BL} +HOST_FLAGS := ${COMMON_FLAGS} -O3 `dpu-pkg-config --cflags --libs dpu` -DASPECTC=${aspectc} +DPU_FLAGS := ${COMMON_FLAGS} -O2 + +ifeq (${aspectc_timing}, 1) + ASPECTC_HOST_FLAGS += -ainclude/dfatool_host_dpu.ah -ainclude/dfatool_host.ah +endif + +ASPECTC_HOST_FLAGS ?= -a0 -__dirs := $(shell mkdir -p ${BUILDDIR}) +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 -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 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} +QUIET = @ -all: ${HOST_TARGET} ${DPU_TARGET} +ifdef verbose + QUIET = +endif -${CONF}: - $(RM) $(call conf_filename,*,*) - touch ${CONF} +all: bin/mlp_dpu bin/mlp_host -${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} - $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} +bin: + ${QUIET}mkdir -p bin -${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} +bin/mlp_host: ${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/mlp_dpu: ${DPU_SOURCES} include bin dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} clean: $(RM) -r $(BUILDDIR) test: all - ./${HOST_TARGET} -m 1024 -n 1024 + bin/mlp_host -m 1024 -n 1024 + +.PHONY: all clean test diff --git a/MLP/dpu/task.c b/MLP/dpu/task.c index 4f85024..ae400ae 100644 --- a/MLP/dpu/task.c +++ b/MLP/dpu/task.c @@ -10,7 +10,7 @@ #include #include -#include "../support/common.h" +#include "common.h" __host dpu_arguments_t DPU_INPUT_ARGUMENTS; diff --git a/MLP/host/app.c b/MLP/host/app.c index 24243bf..9c32ab8 100644 --- a/MLP/host/app.c +++ b/MLP/host/app.c @@ -8,19 +8,28 @@ #include #include #include -#include -#include #include #include #include +#if ASPECTC +extern "C" { +#endif + +#include +#include + #if ENERGY #include #endif -#include "../support/common.h" -#include "../support/timer.h" -#include "../support/params.h" +#if ASPECTC +} +#endif + +#include "common.h" +#include "timer.h" +#include "params.h" // Define the DPU Binary path as DPU_BINARY here #ifndef DPU_BINARY @@ -159,8 +168,8 @@ int main(int argc, char **argv) B = (T *) malloc(n_size * sizeof(T)); B_host = (T *) malloc(n_size * sizeof(T)); C = (T *) malloc(m_size * sizeof(T)); - C_dpu = malloc(max_rows_per_dpu * nr_of_dpus * sizeof(T)); - B_tmp = malloc(max_rows_per_dpu * nr_of_dpus * sizeof(T)); + C_dpu = (T*)malloc(max_rows_per_dpu * nr_of_dpus * sizeof(T)); + B_tmp = (T*)malloc(max_rows_per_dpu * nr_of_dpus * sizeof(T)); init_data(A, B, B_host, m_size, n_size); @@ -331,22 +340,9 @@ int main(int argc, char **argv) DPU_ASSERT(dpu_probe_get(&probe, DPU_TIME, DPU_AVERAGE, &avg_time)); #endif - // Print timing results - printf("CPU Version Time (ms): "); - print(&timer, 0, 1); - printf("CPU-DPU Time (ms): "); - print(&timer, 1, p.n_reps); - printf("DPU Kernel Time (ms): "); - print(&timer, 2, p.n_reps); - printf("Inter-DPU Time (ms): "); - print(&timer, 4, p.n_reps); - printf("DPU-CPU Time (ms): "); - print(&timer, 3, p.n_reps); - #if ENERGY printf("Energy (J): %f J\t", avg_energy); #endif - printf("\n\n"); // Check output bool status = true; diff --git a/MLP/include/common.h b/MLP/include/common.h new file mode 100644 index 0000000..4b5031b --- /dev/null +++ b/MLP/include/common.h @@ -0,0 +1,45 @@ +#ifndef _COMMON_H_ +#define _COMMON_H_ + +// Structures used by both the host and the dpu to communicate information +typedef struct { + uint32_t n_size; + uint32_t n_size_pad; + uint32_t nr_rows; + uint32_t max_rows; +} dpu_arguments_t; + +// Specific information for each DPU +struct dpu_info_t { + uint32_t rows_per_dpu; + uint32_t rows_per_dpu_pad; + uint32_t prev_rows_dpu; +}; +struct dpu_info_t *dpu_info; + +#define NUM_LAYERS 3 +#define max(x, y) (x > y ? x : y) +#define min(x, y) (x < y ? x : y) + +// 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 int32_t + +#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" +#endif diff --git a/MLP/include/dfatool_host.ah b/MLP/include/dfatool_host.ah new file mode 100644 index 0000000..8cc4db5 --- /dev/null +++ b/MLP/include/dfatool_host.ah @@ -0,0 +1,31 @@ +#pragma once + +#include +#include "dfatool_host_dpu.ah" + +aspect DfatoolHostTiming : public DfatoolHostDPUTiming { + + unsigned int n_rows, n_cols; + unsigned int element_size; + + virtual int getKernel() { return 1; } + + DfatoolHostTiming() { + element_size = sizeof(uint32_t); + } + + advice call("% input_params(...)"): after() { + Params* p = tjp->result(); + n_rows = p->m_size; + n_cols = p->n_size; + printf("[>>] MLP | n_dpus=%u n_rows=%u n_cols=%u\n", NR_DPUS, n_rows, n_cols); + } + + advice call("% binarySearch(...)") : after() { + printf("[--] MLP | n_dpus=%u n_rows=%u n_cols=%u\n", NR_DPUS, n_rows, n_cols); + } + + advice execution("% main(...)") : after() { + printf("[<<] MLP | n_dpus=%u n_rows=%u n_cols=%u\n", NR_DPUS, n_rows, n_cols); + } +}; diff --git a/MLP/include/params.h b/MLP/include/params.h new file mode 100644 index 0000000..4bfc2fc --- /dev/null +++ b/MLP/include/params.h @@ -0,0 +1,65 @@ +#ifndef _PARAMS_H_ +#define _PARAMS_H_ + +#include "common.h" + +typedef struct Params { + unsigned int m_size; + unsigned int n_size; + unsigned int n_warmup; + unsigned int n_reps; +} 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" + "\nBenchmark-specific options:" + "\n -m m_size (default=2048 elements)" + "\n -n n_size (default=2048 elements)" "\n"); +} + +struct Params input_params(int argc, char **argv) +{ + struct Params p; + p.m_size = 163840; + p.n_size = 4096; + p.n_warmup = 1; + p.n_reps = 3; + + int opt; + while ((opt = getopt(argc, argv, "hm:n:w:e:")) >= 0) { + switch (opt) { + case 'h': + usage(); + exit(0); + break; + case 'm': + p.m_size = atoi(optarg); + break; + case 'n': + p.n_size = atoi(optarg); + break; + case 'w': + p.n_warmup = atoi(optarg); + break; + case 'e': + p.n_reps = 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/MLP/include/timer.h b/MLP/include/timer.h new file mode 100644 index 0000000..bff638d --- /dev/null +++ b/MLP/include/timer.h @@ -0,0 +1,5 @@ +#pragma once + +#define N_TIMERS 5 +#include "../../include/timer_base.h" +#undef N_TIMERS diff --git a/MLP/support/common.h b/MLP/support/common.h deleted file mode 100755 index 4b5031b..0000000 --- a/MLP/support/common.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef _COMMON_H_ -#define _COMMON_H_ - -// Structures used by both the host and the dpu to communicate information -typedef struct { - uint32_t n_size; - uint32_t n_size_pad; - uint32_t nr_rows; - uint32_t max_rows; -} dpu_arguments_t; - -// Specific information for each DPU -struct dpu_info_t { - uint32_t rows_per_dpu; - uint32_t rows_per_dpu_pad; - uint32_t prev_rows_dpu; -}; -struct dpu_info_t *dpu_info; - -#define NUM_LAYERS 3 -#define max(x, y) (x > y ? x : y) -#define min(x, y) (x < y ? x : y) - -// 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 int32_t - -#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" -#endif diff --git a/MLP/support/params.h b/MLP/support/params.h deleted file mode 100644 index 4bfc2fc..0000000 --- a/MLP/support/params.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef _PARAMS_H_ -#define _PARAMS_H_ - -#include "common.h" - -typedef struct Params { - unsigned int m_size; - unsigned int n_size; - unsigned int n_warmup; - unsigned int n_reps; -} 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" - "\nBenchmark-specific options:" - "\n -m m_size (default=2048 elements)" - "\n -n n_size (default=2048 elements)" "\n"); -} - -struct Params input_params(int argc, char **argv) -{ - struct Params p; - p.m_size = 163840; - p.n_size = 4096; - p.n_warmup = 1; - p.n_reps = 3; - - int opt; - while ((opt = getopt(argc, argv, "hm:n:w:e:")) >= 0) { - switch (opt) { - case 'h': - usage(); - exit(0); - break; - case 'm': - p.m_size = atoi(optarg); - break; - case 'n': - p.n_size = atoi(optarg); - break; - case 'w': - p.n_warmup = atoi(optarg); - break; - case 'e': - p.n_reps = 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/MLP/support/timer.h b/MLP/support/timer.h deleted file mode 100755 index 961ed11..0000000 --- a/MLP/support/timer.h +++ /dev/null @@ -1,69 +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[5]; - struct timeval stopTime[5]; - double time[5]; - -} 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); - //printf("Time (ms): %f\t",((timer->stopTime[i].tv_sec - timer->startTime[i].tv_sec) * 1000000.0 + - // (timer->stopTime[i].tv_usec - timer->startTime[i].tv_usec)) / 1000); - -} - -void print(Timer *timer, int i, int REP) -{ - printf("%f\t", timer->time[i] / (1000 * REP)); -} diff --git a/README.md b/README.md index 6100fc6..b77dbf3 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ CPU and DPU benchmarks in this repository have been adjusted as follows: * GEMV: ADLN * HST-L: AD * HST-S: DLN -* MLP: – +* MLP: A * NW: – * RED: DLN * SCAN-SSA: D -- cgit v1.2.3