From 039b8a498c87de4ee68759672918cc4f58dc9fcd Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Wed, 14 Mar 2018 12:25:51 +0000 Subject: [PATCH] OpenBLAS Also don't add br2_local by default, default params are insane. --- README.adoc | 34 ++++++++++++++++++++++++++++++++-- build | 3 --- kernel_module/external.mk | 6 +++++- kernel_module/user/Makefile | 8 +++++++- kernel_module/user/openblas.c | 18 ++++++++++++++++++ run | 1 + 6 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 kernel_module/user/openblas.c diff --git a/README.adoc b/README.adoc index 29dade4..7eba441 100644 --- a/README.adoc +++ b/README.adoc @@ -2015,6 +2015,34 @@ External open source benchmarks. We will try to create Buildroot packages for th * http://parsec.cs.princeton.edu/ Mentioned on docs: http://gem5.org/PARSEC_benchmarks * http://www.m5sim.org/Splash_benchmarks +===== BLAS + +Buildroot supports it, which makes everything just trivial: + +.... +printf 'BR2_PACKAGE_OPENBLAS=y\n' >> br2_local +printf 'BR2_TARGET_ROOTFS_EXT2_SIZE="128M"\n' >> br2_local +./build -a arm -g -i br2_local -- kernel_module-reconfigure +.... + +and then inside the guest run our test program: + +.... +/openblas.out +.... + +For x86, you also need: + +.... +printf 'BR2_PACKAGE_OPENBLAS_TARGET="NEHALEM"\n' >> br2_local +.... + +to overcome this bug: https://bugs.busybox.net/show_bug.cgi?id=10856 + +.... +sgemm_kernel.o: No such file or directory +.... + ===== PARSEC benchmark We have ported parts of the link:http://parsec.cs.princeton.edu[PARSEC benchmark] for cross compilation at: https://github.com/cirosantilli/parsec-benchmark See the documentation on that repo to find out which benchmarks have been ported. Furthermore, some of the benchmarks were are segfaulting, see link:parsec-benchmark/test.sh[] @@ -2541,12 +2569,14 @@ dmesg We provide the following mechanisms: -* `br2_local`: a gitignored file that gets appended to the `.config`. Get started with: +* `./build -i br2_local`: append the file `br2_local` to a single build. Must be passed every time you run `./build`. ++ +For convenience, we already gitignore `br2_local` for you. + .... cp br2_local.off br2_local .... -* `./build -i somefile`: append `somefile` to a single build. Must be passed every time you run `./build`. ++ * `./build -c 'BR2_SOM_OPTION="myval"'`: append a single option to a single build. === ccache diff --git a/build b/build index bf077fd..b5677c8 100755 --- a/build +++ b/build @@ -57,9 +57,6 @@ while getopts 'a:c:Cgj:i:kK:lp:qS:v' OPT; do done shift $(($OPTIND - 1)) extra_make_args="$extra_make_args $@" -if [ -f br2_local ]; then - config_fragments="$config_fragments br2_local" -fi case "$arch" in x86_64) defconfig=qemu_x86_64_defconfig diff --git a/kernel_module/external.mk b/kernel_module/external.mk index 0db8306..539782d 100644 --- a/kernel_module/external.mk +++ b/kernel_module/external.mk @@ -8,8 +8,12 @@ KERNEL_MODULE_VERSION = 1.0 KERNEL_MODULE_SITE = $(BR2_EXTERNAL_KERNEL_MODULE_PATH) KERNEL_MODULE_SITE_METHOD = local +ifeq ($(BR2_PACKAGE_OPENBLAS),y) + KERNEL_MODULE_DEPENDENCIES += openblas +endif + define KERNEL_MODULE_BUILD_CMDS - $(MAKE) -C '$(@D)/user' CC="$(TARGET_CC)" LD="$(TARGET_LD)" + $(MAKE) -C '$(@D)/user' BR2_PACKAGE_OPENBLAS="$(BR2_PACKAGE_OPENBLAS)" CC="$(TARGET_CC)" LD="$(TARGET_LD)" endef define KERNEL_MODULE_INSTALL_TARGET_CMDS diff --git a/kernel_module/user/Makefile b/kernel_module/user/Makefile index 5376b06..6345391 100644 --- a/kernel_module/user/Makefile +++ b/kernel_module/user/Makefile @@ -2,14 +2,20 @@ CFLAGS_EXTRA ?= -ggdb3 -fopenmp -O0 -std=c99 -Wall -Werror -Wextra IN_EXT ?= .c +LIBS := OUT_EXT ?= .out OUTS := $(addsuffix $(OUT_EXT), $(basename $(wildcard *$(IN_EXT)))) +ifeq ($(BR2_PACKAGE_OPENBLAS),y) + LIBS += -lopenblas +else + OUTS := $(filter-out openblas.out,$(OUTS)) +endif all: $(OUTS) %$(OUT_EXT): %$(IN_EXT) - $(CC) $(CFLAGS) $(CFLAGS_EXTRA) -o '$@' '$<' + $(CC) $(CFLAGS) $(CFLAGS_EXTRA) -o '$@' '$<' $(LIBS) clean: rm -f *'$(OUT_EXT)' diff --git a/kernel_module/user/openblas.c b/kernel_module/user/openblas.c new file mode 100644 index 0000000..98ef52e --- /dev/null +++ b/kernel_module/user/openblas.c @@ -0,0 +1,18 @@ +/* +OpenBLAS hello world, initially adapted from: +https://stackoverflow.com/questions/49227682/gem5-can-not-simulate-my-program-that-calls-openblas-functions-with-an-fatal-err +*/ + +#include +#include + +int main() { + size_t i = 0; + double A[6] = {1.0,2.0,1.0,-3.0,4.0,-1.0}; + double B[6] = {1.0,2.0,1.0,-3.0,4.0,-1.0}; + double C[9] = {.5,.5,.5,.5,.5,.5,.5,.5,.5}; + cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans,3,3,2,1,A, 3, B, 3,2,C,3); + for(i = 0; i < 9; i++) + printf("%f ", C[i]); + printf("\n"); +} diff --git a/run b/run index 2290f7c..504445e 100755 --- a/run +++ b/run @@ -70,6 +70,7 @@ fi root_dir="$(pwd)" buildroot_dir="${root_dir}/buildroot" out_dir="${root_dir}/buildroot/output.${arch_dir}~" +images_dir="${out_dir}/images" if "$gem5"; then build_dir="${out_dir}/build/gem5-1.0"