From 9f876f789734c210bce241334fc5f400296dfc07 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Tue, 8 May 2018 15:04:41 +0100 Subject: [PATCH 1/2] c++ userland example --- kernel_module/user/Makefile | 10 +++++++--- kernel_module/user/README.adoc | 1 + kernel_module/user/hello_cpp.cpp | 5 +++++ 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 kernel_module/user/hello_cpp.cpp diff --git a/kernel_module/user/Makefile b/kernel_module/user/Makefile index b20328e..8ff2d59 100644 --- a/kernel_module/user/Makefile +++ b/kernel_module/user/Makefile @@ -1,11 +1,12 @@ .PHONY: all clean CFLAGS_EXTRA ?= -fopenmp -std=c99 -Wall -Werror -Wextra -IN_EXT ?= .c +IN_EXT_C ?= .c +IN_EXT_CXX ?= .cpp LIBS := OUT_EXT ?= .out -OUTS := $(addsuffix $(OUT_EXT), $(basename $(wildcard *$(IN_EXT)))) +OUTS := $(foreach IN_EXT,$(IN_EXT_C) $(IN_EXT_CXX),$(addsuffix $(OUT_EXT), $(basename $(wildcard *$(IN_EXT))))) ifeq ($(BR2_PACKAGE_OPENBLAS),y) LIBS += -lopenblas else @@ -14,8 +15,11 @@ endif all: $(OUTS) -%$(OUT_EXT): %$(IN_EXT) +%$(OUT_EXT): %$(IN_EXT_C) $(CC) $(CFLAGS) $(CFLAGS_EXTRA) -o '$@' '$<' $(LIBS) +%$(OUT_EXT): %$(IN_EXT_CXX) + $(CXX) $(CXXFLAGS) $(CXXFLAGS_EXTRA) -o '$@' '$<' $(LIBS) + clean: rm -f *'$(OUT_EXT)' diff --git a/kernel_module/user/README.adoc b/kernel_module/user/README.adoc index ce20135..c4f89c5 100644 --- a/kernel_module/user/README.adoc +++ b/kernel_module/user/README.adoc @@ -10,6 +10,7 @@ These programs can also be compiled and used on host. . Standalone .. link:hello.c[] +.. link:hello_cpp.cpp[] .. link:myinsmod.c[] .. link:myrmmod.c[] .. link:sched_getaffinity.c[] diff --git a/kernel_module/user/hello_cpp.cpp b/kernel_module/user/hello_cpp.cpp new file mode 100644 index 0000000..52e3b2e --- /dev/null +++ b/kernel_module/user/hello_cpp.cpp @@ -0,0 +1,5 @@ +#include + +int main() { + std::cout << "hello world" << std::endl; +} From a9a0b93d7c246348700455de734fe879836b0c66 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Tue, 8 May 2018 16:17:59 +0100 Subject: [PATCH 2/2] eigen: add hello world Mention openmp on readme --- README.adoc | 30 +++++++++++++++++++----------- kernel_module/external.mk | 7 ++++++- kernel_module/user/Makefile | 8 +++++++- kernel_module/user/README.adoc | 4 ++++ kernel_module/user/eigen.cpp | 14 ++++++++++++++ 5 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 kernel_module/user/eigen.cpp diff --git a/README.adoc b/README.adoc index f64437c..22cfcde 100644 --- a/README.adoc +++ b/README.adoc @@ -4164,7 +4164,6 @@ Buildroot built-in libraries, mostly under Libraries > Other: * Armadillo `C++`: linear algebra * fftw: Fourier transform -* Eigen: linear algebra * Flann * GSL: various * liblinear @@ -4174,21 +4173,21 @@ Buildroot built-in libraries, mostly under Libraries > Other: There are not yet enabled, but it should be easy to so, see: <> +===== OpenMP + +Implemented by GCC itself, so just a toolchain configuration, no external libs, and we enable it by default: + +.... +/openmp.out +.... + ===== BLAS Buildroot supports it, which makes everything just trivial: .... -./build \ - -a arm \ - -B 'BR2_PACKAGE_OPENBLAS=y' \ -; -.... - -and then inside the guest run our test program: - -.... -/openblas.out +./build -a arm -B 'BR2_PACKAGE_OPENBLAS=y' -k +./run -F '/openblas.out' .... For x86, you also need: @@ -4203,6 +4202,15 @@ to overcome this bug: https://bugs.busybox.net/show_bug.cgi?id=10856 sgemm_kernel.o: No such file or directory .... +===== Eigen + +Header only linear algebra library supported by Buildroot: + +.... +./build -B 'BR2_PACKAGE_EIGEN=y' -k +./run -F '/eigen.out' +.... + ===== 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. Some of the benchmarks were are segfaulting, they are documented in that repo. diff --git a/kernel_module/external.mk b/kernel_module/external.mk index 97bbe44..f322a0c 100644 --- a/kernel_module/external.mk +++ b/kernel_module/external.mk @@ -11,9 +11,14 @@ KERNEL_MODULE_SITE_METHOD = local ifeq ($(BR2_PACKAGE_OPENBLAS),y) KERNEL_MODULE_DEPENDENCIES += openblas endif +ifeq ($(BR2_PACKAGE_EIGEN),y) + KERNEL_MODULE_DEPENDENCIES += eigen +endif define KERNEL_MODULE_BUILD_CMDS - $(MAKE) -C '$(@D)/user' $(TARGET_CONFIGURE_OPTS) BR2_PACKAGE_OPENBLAS="$(BR2_PACKAGE_OPENBLAS)" + $(MAKE) -C '$(@D)/user' $(TARGET_CONFIGURE_OPTS) \ + BR2_PACKAGE_OPENBLAS="$(BR2_PACKAGE_OPENBLAS)" \ + BR2_PACKAGE_EIGEN="$(BR2_PACKAGE_EIGEN)" endef define KERNEL_MODULE_INSTALL_TARGET_CMDS diff --git a/kernel_module/user/Makefile b/kernel_module/user/Makefile index 8ff2d59..1da24cc 100644 --- a/kernel_module/user/Makefile +++ b/kernel_module/user/Makefile @@ -10,7 +10,13 @@ OUTS := $(foreach IN_EXT,$(IN_EXT_C) $(IN_EXT_CXX),$(addsuffix $(OUT_EXT), $(bas ifeq ($(BR2_PACKAGE_OPENBLAS),y) LIBS += -lopenblas else - OUTS := $(filter-out openblas.out,$(OUTS)) + OUTS := $(filter-out openblas$(OUT_EXT),$(OUTS)) +endif +ifeq ($(BR2_PACKAGE_EIGEN),y) + # Header only. + #LIBS += -leigen +else + OUTS := $(filter-out eigen%$(OUT_EXT),$(OUTS)) endif all: $(OUTS) diff --git a/kernel_module/user/README.adoc b/kernel_module/user/README.adoc index c4f89c5..420dfec 100644 --- a/kernel_module/user/README.adoc +++ b/kernel_module/user/README.adoc @@ -30,3 +30,7 @@ These programs can also be compiled and used on host. .. link:ioctl.c[] .. link:netlink.c[] .. link:poll.c[] +. Buildroot libraries +.. link:eigen.cpp[] +.. link:openmp.c[] +.. link:openblas.c[] diff --git a/kernel_module/user/eigen.cpp b/kernel_module/user/eigen.cpp new file mode 100644 index 0000000..a6837d6 --- /dev/null +++ b/kernel_module/user/eigen.cpp @@ -0,0 +1,14 @@ +/* Official hello world. */ + +#include +#include +using Eigen::MatrixXd; +int main() +{ + MatrixXd m(2,2); + m(0,0) = 3; + m(1,0) = 2.5; + m(0,1) = -1; + m(1,1) = m(1,0) + m(0,1); + std::cout << m << std::endl; +}