diff options
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/stream/Kconfig | 23 | ||||
-rw-r--r-- | src/app/stream/Makefile.inc | 9 | ||||
-rw-r--r-- | src/app/stream/main.cc | 119 | ||||
-rwxr-xr-x | src/app/stream/run.sh | 22 |
4 files changed, 173 insertions, 0 deletions
diff --git a/src/app/stream/Kconfig b/src/app/stream/Kconfig new file mode 100644 index 0000000..ca5893c --- /dev/null +++ b/src/app/stream/Kconfig @@ -0,0 +1,23 @@ +# Copyright 2020 Birte Kristina Friesel +# +# SPDX-License-Identifier: CC0-1.0 + +prompt "STREAM Benchmark" +depends on meta_driver_counter && !loop && !wakeup + +config app_stream_type +string "Type" +depends on app_stream +default "unsigned int" + +config app_stream_n_elements +int "# Elements" +depends on app_stream +default 128 if arch_arduino_nano +default 8192 if arch_rm46l8lp +default 8192 if arch_stm32f746zg_nucleo + +config app_stream_stride +int "Stride" +depends on app_stream +default 1 diff --git a/src/app/stream/Makefile.inc b/src/app/stream/Makefile.inc new file mode 100644 index 0000000..7f4c0cc --- /dev/null +++ b/src/app/stream/Makefile.inc @@ -0,0 +1,9 @@ +# vim:ft=make +# +# Copyright 2020 Birte Kristina Friesel +# +# SPDX-License-Identifier: CC0-1.0 + +ifdef app + override arch_drivers += ,counter +endif diff --git a/src/app/stream/main.cc b/src/app/stream/main.cc new file mode 100644 index 0000000..6fe99bc --- /dev/null +++ b/src/app/stream/main.cc @@ -0,0 +1,119 @@ +/* + * Copyright 2020 Birte Kristina Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#include "arch.h" +#include "driver/gpio.h" +#include "driver/stdout.h" +#include "driver/counter.h" +#include <stdlib.h> + +#define XSTR(x) STR(x) +#define STR(x) #x + +static const auto input_size = CONFIG_app_stream_n_elements; +static const auto stride = CONFIG_app_stream_stride; +typedef CONFIG_app_stream_type T; +static T A[input_size]; +static T B[input_size]; +static T scale; +static T X[input_size]; +static T check; + +int main(void) +{ + uint16_t i; + arch.setup(); + gpio.setup(); + kout.setup(); + + scale = rand(); + for (i = 0; i < input_size; i++) { + A[i] = (T)rand(); + B[i] = (T)rand(); + X[i] = (T)0; + } + + while (1) { + check = 0; + /* + * Copy + */ + counter.start(); + for (i = 0; i < input_size; i += stride) { + X[i] = A[i]; + } + counter.stop(); + + kout << "[::] STREAM COPY"; + kout << " | n_elements=" << input_size << " e_type=" << XSTR(CONFIG_app_stream_type) << " elem_B=" << sizeof(T) << " n_stride=" << stride; + kout << " | latency_us=" << counter.value << "/" << counter.overflow; + kout << endl; + + for (i = 0; i < input_size; i++) { + check = (uint16_t)check ^ (uint16_t)X[i]; + } + + /* + * Scale + */ + counter.start(); + for (i = 0; i < input_size; i += stride) { + X[i] = scale * A[i]; + } + counter.stop(); + + kout << "[::] STREAM SCALE"; + kout << " | n_elements=" << input_size << " e_type=" << XSTR(CONFIG_app_stream_type) << " elem_B=" << sizeof(T) << " n_stride=" << stride; + kout << " | latency_us=" << counter.value << "/" << counter.overflow; + kout << endl; + + for (i = 0; i < input_size; i++) { + check = (uint16_t)check ^ (uint16_t)X[i]; + } + + /* + * Add + */ + counter.start(); + for (i = 0; i < input_size; i += stride) { + X[i] = A[i] + B[i]; + } + counter.stop(); + + kout << "[::] STREAM ADD"; + kout << " | n_elements=" << input_size << " e_type=" << XSTR(CONFIG_app_stream_type) << " elem_B=" << sizeof(T) << " n_stride=" << stride; + kout << " | latency_us=" << counter.value << "/" << counter.overflow; + kout << endl; + + for (i = 0; i < input_size; i++) { + check = (uint16_t)check ^ (uint16_t)X[i]; + } + + /* + * Triad + */ + counter.start(); + for (i = 0; i < input_size; i += stride) { + X[i] = A[i] + scale * B[i]; + } + counter.stop(); + + kout << "[::] STREAM TRIAD"; + kout << " | n_elements=" << input_size << " e_type=" << XSTR(CONFIG_app_stream_type) << " elem_B=" << sizeof(T) << " n_stride=" << stride; + kout << " | latency_us=" << counter.value << "/" << counter.overflow; + kout << endl; + + for (i = 0; i < input_size; i++) { + check = (uint16_t)check ^ (uint16_t)X[i]; + } + + /* + * Avoid optimizations + */ + kout << "// " << check << endl; + } + + return 0; +} diff --git a/src/app/stream/run.sh b/src/app/stream/run.sh new file mode 100755 index 0000000..8cc3da2 --- /dev/null +++ b/src/app/stream/run.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +cd "$(git rev-parse --show-toplevel)" + +target="$(grep '^CONFIG_arch=' .config | cut -d '"' -f 2)" + +mkdir -p src/app/stream/log +: > src/app/stream/log/${target}.txt + +for stride in 1 2 4 8 16 32 64; do + for type in uint8_t uint16_t uint32_t uint64_t float double; do + kconfig-tweak --keep-case --set-str app_stream_stride $stride + kconfig-tweak --keep-case --set-str app_stream_type $type + + echo + echo "stride: ${stride}" + echo "type : ${type}" + echo + + ./mp && make cat >> src/app/stream/log/${target}.txt + done +done |