Unverified Commit f9843075 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Add STREAM benchmark application

parent b7a118ff
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
/Kconfig
/include/config.h
/src/app/aemr/main.cc
/src/app/stream/log
/src/app/prototest/nanopb.pb.h
/src/app/prototest/nanopb.pb.cc
/src/app/prototest/nanopbbench.pb.h

src/app/stream/Kconfig

0 → 100644
+23 −0
Original line number Diff line number Diff line
# 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
+9 −0
Original line number Diff line number Diff line
# vim:ft=make
#
# Copyright 2020 Birte Kristina Friesel
#
# SPDX-License-Identifier: CC0-1.0

ifdef app
	override arch_drivers += ,counter
endif

src/app/stream/main.cc

0 → 100644
+119 −0
Original line number Diff line number Diff line
/*
 * 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;
}

src/app/stream/run.sh

0 → 100755
+22 −0
Original line number Diff line number Diff line
#!/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