diff --git a/.gitmodules b/.gitmodules index 6af50f5c731bd14511b4b786c7dd8cb746a16506..63cc18fe4c0e578ff4413a912c913ac56ccb96db 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "external/chibios-contrib"] path = external/chibios-contrib url = https://github.com/ChibiOS/ChibiOS-Contrib +[submodule "external/clapack"] + path = external/clapack + url = https://github.com/mniestroj/clapack diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index 94753e1fbe1129bf002dda55a3a21f5136ddc8a9..929b8e261b5051b2d784bf735a6062f52aeb403a 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -7,14 +7,18 @@ This file lists the third-party dependencies for this project and their individu The following dependencies are used: -| Project | License | URL | -|------------------|--------------------------------|--------------------------------------------| -| ChibiOS/HAL | APLv2.0 | http://www.chibios.org | -| ChibiOS/RT | GPLv3 | http://www.chibios.org | -| ChibiOS-Contrib* | APLv2.0 (components used here) | https://github.com/ChibiOS/ChibiOS-Contrib | -| newlib | Various FOSS licenses | https://sourceware.org/newlib | +| Project | License | URL | +|-------------------------------------|--------------------------------|--------------------------------------------| +| ChibiOS/HAL | APLv2.0 | http://www.chibios.org | +| ChibiOS/RT | GPLv3 | http://www.chibios.org | +| ChibiOS-Contrib* | APLv2.0 (components used here) | https://github.com/ChibiOS/ChibiOS-Contrib | +| clapack modified for ARM Cortex-M** | BSD | https://github.com/mniestroj/clapack | +| newlib | Various FOSS licenses | https://sourceware.org/newlib | * Components used: STM32F411_DISCOVERY board description files and black magic probe make targets +** The following patches are applied by this package: + - external/patches/clapack/disable_xerbla.patch: Calls to xerbla_ and xerblar_array_ return immediately with value 0. + - external/patches/clapack/spotrf_always_unblocked.patch: Skip querying block size using ilaenv_ and always use unblocked routine. ## Individual License Texts @@ -1115,6 +1119,46 @@ License file not included in git reposity and thus taken from https://www.apache > limitations under the License. +### clapack modified for ARM Cortex-M + +> Copyright (c) 1992-2008 The University of Tennessee. All rights reserved. +> +> $COPYRIGHT$ +> +> Additional copyrights may follow +> +> $HEADER$ +> +> Redistribution and use in source and binary forms, with or without +> modification, are permitted provided that the following conditions are +> met: +> +> - Redistributions of source code must retain the above copyright +> notice, this list of conditions and the following disclaimer. +> +> - Redistributions in binary form must reproduce the above copyright +> notice, this list of conditions and the following disclaimer listed +> in this license in the documentation and/or other materials +> provided with the distribution. +> +> - Neither the name of the copyright holders nor the names of its +> contributors may be used to endorse or promote products derived from +> this software without specific prior written permission. +> +> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +> "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +> LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +> A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +> OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +> SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +> LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +> DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +> THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +> (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +> OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +> + + ### newlib > The newlib subdirectory is a collection of software from several sources. diff --git a/Makefile b/Makefile index 6396f45488811e0f4741d78a1c7132c9c83e860c..a864180ca43e5ad0d8c45979c34b8f8356bcfba3 100644 --- a/Makefile +++ b/Makefile @@ -164,7 +164,7 @@ UINCDIR = $(EXTDDIR)/include $(SRCDIR) $(BUILDDIR)/config ULIBDIR = $(EXTDDIR)/lib # List all user libraries here -ULIBS = +ULIBS = -llapack -lblas -lf2c -lm # # End of user section @@ -207,10 +207,28 @@ $(BUILDDIR)/config/config.h: .FORCE echo "" >> $(BUILDDIR)/config/config.h echo "#endif // CONFIG_H" >> $(BUILDDIR)/config/config.h -PRE_MAKE_ALL_RULE_HOOK: $(BUILDDIR)/config/config.h +$(EXTDDIR)/clapack.done: + cd $(EXTDIR)/clapack; rm -fr build + cd $(EXTDIR)/clapack; git reset --hard HEAD + cd $(EXTDIR)/clapack; git apply ../patches/clapack/disable_xerbla.patch + cd $(EXTDIR)/clapack; git apply ../patches/clapack/spotrf_always_unblocked.patch + cd $(EXTDIR)/clapack; mkdir build + cd $(EXTDIR)/clapack/build; cmake .. -DCMAKE_TOOLCHAIN_FILE=../cm4.cmake -DCMAKE_BUILD_TYPE=Release + cd $(EXTDIR)/clapack/build; $(MAKE) + mkdir -p $(EXTDDIR)/lib + cp $(EXTDIR)/clapack/build/F2CLIBS/libf2c/libf2c.a $(EXTDDIR)/lib + cp $(EXTDIR)/clapack/build/BLAS/SRC/libblas.a $(EXTDDIR)/lib + cp $(EXTDIR)/clapack/build/SRC/liblapack.a $(EXTDDIR)/lib + cd $(EXTDIR)/clapack; rm -r build + cd $(EXTDIR)/clapack; git reset --hard HEAD + touch $(EXTDDIR)/clapack.done + +clapack: $(EXTDDIR)/clapack.done + +PRE_MAKE_ALL_RULE_HOOK: $(BUILDDIR)/config/config.h $(EXTDDIR)/clapack.done .FORCE: -.PHONY: doc dist-clean .FORCE +.PHONY: clapack doc dist-clean .FORCE # # Custom rules diff --git a/external/.gitignore b/external/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..f44b5eeb76295f6e2656edaa2f2bb930c947446a --- /dev/null +++ b/external/.gitignore @@ -0,0 +1 @@ +_dist diff --git a/external/clapack b/external/clapack new file mode 160000 index 0000000000000000000000000000000000000000..5cbab95a240fe77da65f58798d569853a67e7c5d --- /dev/null +++ b/external/clapack @@ -0,0 +1 @@ +Subproject commit 5cbab95a240fe77da65f58798d569853a67e7c5d diff --git a/external/patches/clapack/disable_xerbla.patch b/external/patches/clapack/disable_xerbla.patch new file mode 100644 index 0000000000000000000000000000000000000000..f067ef767cd50e040099ef9f16f27948efdea174 --- /dev/null +++ b/external/patches/clapack/disable_xerbla.patch @@ -0,0 +1,298 @@ +diff --git a/BLAS/SRC/xerbla.c b/BLAS/SRC/xerbla.c +index 2d7baf5..89e2c8f 100644 +--- a/BLAS/SRC/xerbla.c ++++ b/BLAS/SRC/xerbla.c +@@ -19,58 +19,5 @@ static integer c__1 = 1; + + /* Subroutine */ int xerbla_(char *srname, integer *info) + { +- /* Format strings */ +- static char fmt_9999[] = "(\002 ** On entry to \002,a,\002 parameter num" +- "ber \002,i2,\002 had \002,\002an illegal value\002)"; +- +- /* Builtin functions */ +- integer s_wsfe(cilist *), i_len_trim(char *, ftnlen), do_fio(integer *, +- char *, ftnlen), e_wsfe(void); +- /* Subroutine */ int s_stop(char *, ftnlen); +- +- /* Fortran I/O blocks */ +- static cilist io___1 = { 0, 6, 0, fmt_9999, 0 }; +- +- +- +-/* -- LAPACK auxiliary routine (preliminary version) -- */ +-/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ +-/* November 2006 */ +- +-/* .. Scalar Arguments .. */ +-/* .. */ +- +-/* Purpose */ +-/* ======= */ +- +-/* XERBLA is an error handler for the LAPACK routines. */ +-/* It is called by an LAPACK routine if an input parameter has an */ +-/* invalid value. A message is printed and execution stops. */ +- +-/* Installers may consider modifying the STOP statement in order to */ +-/* call system-specific exception-handling facilities. */ +- +-/* Arguments */ +-/* ========= */ +- +-/* SRNAME (input) CHARACTER*(*) */ +-/* The name of the routine which called XERBLA. */ +- +-/* INFO (input) INTEGER */ +-/* The position of the invalid parameter in the parameter list */ +-/* of the calling routine. */ +- +-/* ===================================================================== */ +- +-/* .. Intrinsic Functions .. */ +-/* .. */ +-/* .. Executable Statements .. */ +- +- printf("** On entry to %6s, parameter number %2i had an illegal value\n", +- srname, *info); +- +- +-/* End of XERBLA */ +- + return 0; + } /* xerbla_ */ +diff --git a/BLAS/SRC/xerbla_array.c b/BLAS/SRC/xerbla_array.c +index d4e4c24..0d8d6bb 100644 +--- a/BLAS/SRC/xerbla_array.c ++++ b/BLAS/SRC/xerbla_array.c +@@ -16,87 +16,5 @@ + /* Subroutine */ int xerbla_array__(char *srname_array__, integer * + srname_len__, integer *info, ftnlen srname_array_len) + { +- /* System generated locals */ +- integer i__1, i__2, i__3; +- +- /* Builtin functions */ +- /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen); +- integer i_len(char *, ftnlen); +- +- /* Local variables */ +- integer i__; +- extern /* Subroutine */ int xerbla_(char *, integer *); +- char srname[32]; +- +- +-/* -- LAPACK auxiliary routine (version 3.0) -- */ +-/* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */ +-/* September 19, 2006 */ +- +-/* .. Scalar Arguments .. */ +-/* .. */ +-/* .. Array Arguments .. */ +-/* .. */ +- +-/* Purpose */ +-/* ======= */ +- +-/* XERBLA_ARRAY assists other languages in calling XERBLA, the LAPACK */ +-/* and BLAS error handler. Rather than taking a Fortran string argument */ +-/* as the function's name, XERBLA_ARRAY takes an array of single */ +-/* characters along with the array's length. XERBLA_ARRAY then copies */ +-/* up to 32 characters of that array into a Fortran string and passes */ +-/* that to XERBLA. If called with a non-positive SRNAME_LEN, */ +-/* XERBLA_ARRAY will call XERBLA with a string of all blank characters. */ +- +-/* Say some macro or other device makes XERBLA_ARRAY available to C99 */ +-/* by a name lapack_xerbla and with a common Fortran calling convention. */ +-/* Then a C99 program could invoke XERBLA via: */ +-/* { */ +-/* int flen = strlen(__func__); */ +-/* lapack_xerbla(__func__, &flen, &info); */ +-/* } */ +- +-/* Providing XERBLA_ARRAY is not necessary for intercepting LAPACK */ +-/* errors. XERBLA_ARRAY calls XERBLA. */ +- +-/* Arguments */ +-/* ========= */ +- +-/* SRNAME_ARRAY (input) CHARACTER(1) array, dimension (SRNAME_LEN) */ +-/* The name of the routine which called XERBLA_ARRAY. */ +- +-/* SRNAME_LEN (input) INTEGER */ +-/* The length of the name in SRNAME_ARRAY. */ +- +-/* INFO (input) INTEGER */ +-/* The position of the invalid parameter in the parameter list */ +-/* of the calling routine. */ +- +-/* ===================================================================== */ +- +-/* .. */ +-/* .. Local Scalars .. */ +-/* .. */ +-/* .. Local Arrays .. */ +-/* .. */ +-/* .. Intrinsic Functions .. */ +-/* .. */ +-/* .. External Functions .. */ +-/* .. */ +-/* .. Executable Statements .. */ +- /* Parameter adjustments */ +- --srname_array__; +- +- /* Function Body */ +- s_copy(srname, "", (ftnlen)32, (ftnlen)0); +-/* Computing MIN */ +- i__2 = *srname_len__, i__3 = i_len(srname, (ftnlen)32); +- i__1 = min(i__2,i__3); +- for (i__ = 1; i__ <= i__1; ++i__) { +- *(unsigned char *)&srname[i__ - 1] = *(unsigned char *)& +- srname_array__[i__]; +- } +- xerbla_(srname, info); + return 0; + } /* xerbla_array__ */ +diff --git a/SRC/xerbla.c b/SRC/xerbla.c +index fb4a9d8..265414b 100644 +--- a/SRC/xerbla.c ++++ b/SRC/xerbla.c +@@ -20,46 +20,5 @@ static integer c__1 = 1; + + /* Subroutine */ int xerbla_(char *srname, integer *info) + { +- +- +-/* -- LAPACK auxiliary routine (version 3.2) -- */ +-/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ +-/* November 2006 */ +- +-/* .. Scalar Arguments .. */ +-/* .. */ +- +-/* Purpose */ +-/* ======= */ +- +-/* XERBLA is an error handler for the LAPACK routines. */ +-/* It is called by an LAPACK routine if an input parameter has an */ +-/* invalid value. A message is printed and execution stops. */ +- +-/* Installers may consider modifying the STOP statement in order to */ +-/* call system-specific exception-handling facilities. */ +- +-/* Arguments */ +-/* ========= */ +- +-/* SRNAME (input) CHARACTER*(*) */ +-/* The name of the routine which called XERBLA. */ +- +-/* INFO (input) INTEGER */ +-/* The position of the invalid parameter in the parameter list */ +-/* of the calling routine. */ +- +-/* ===================================================================== */ +- +-/* .. Intrinsic Functions .. */ +-/* .. */ +-/* .. Executable Statements .. */ +- +- printf("** On entry to %6s, parameter number %2i had an illegal value\n", +- srname, *info); +- +- +-/* End of XERBLA */ +- + return 0; + } /* xerbla_ */ +diff --git a/SRC/xerbla_array.c b/SRC/xerbla_array.c +index d4e4c24..0d8d6bb 100644 +--- a/SRC/xerbla_array.c ++++ b/SRC/xerbla_array.c +@@ -16,87 +16,5 @@ + /* Subroutine */ int xerbla_array__(char *srname_array__, integer * + srname_len__, integer *info, ftnlen srname_array_len) + { +- /* System generated locals */ +- integer i__1, i__2, i__3; +- +- /* Builtin functions */ +- /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen); +- integer i_len(char *, ftnlen); +- +- /* Local variables */ +- integer i__; +- extern /* Subroutine */ int xerbla_(char *, integer *); +- char srname[32]; +- +- +-/* -- LAPACK auxiliary routine (version 3.0) -- */ +-/* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */ +-/* September 19, 2006 */ +- +-/* .. Scalar Arguments .. */ +-/* .. */ +-/* .. Array Arguments .. */ +-/* .. */ +- +-/* Purpose */ +-/* ======= */ +- +-/* XERBLA_ARRAY assists other languages in calling XERBLA, the LAPACK */ +-/* and BLAS error handler. Rather than taking a Fortran string argument */ +-/* as the function's name, XERBLA_ARRAY takes an array of single */ +-/* characters along with the array's length. XERBLA_ARRAY then copies */ +-/* up to 32 characters of that array into a Fortran string and passes */ +-/* that to XERBLA. If called with a non-positive SRNAME_LEN, */ +-/* XERBLA_ARRAY will call XERBLA with a string of all blank characters. */ +- +-/* Say some macro or other device makes XERBLA_ARRAY available to C99 */ +-/* by a name lapack_xerbla and with a common Fortran calling convention. */ +-/* Then a C99 program could invoke XERBLA via: */ +-/* { */ +-/* int flen = strlen(__func__); */ +-/* lapack_xerbla(__func__, &flen, &info); */ +-/* } */ +- +-/* Providing XERBLA_ARRAY is not necessary for intercepting LAPACK */ +-/* errors. XERBLA_ARRAY calls XERBLA. */ +- +-/* Arguments */ +-/* ========= */ +- +-/* SRNAME_ARRAY (input) CHARACTER(1) array, dimension (SRNAME_LEN) */ +-/* The name of the routine which called XERBLA_ARRAY. */ +- +-/* SRNAME_LEN (input) INTEGER */ +-/* The length of the name in SRNAME_ARRAY. */ +- +-/* INFO (input) INTEGER */ +-/* The position of the invalid parameter in the parameter list */ +-/* of the calling routine. */ +- +-/* ===================================================================== */ +- +-/* .. */ +-/* .. Local Scalars .. */ +-/* .. */ +-/* .. Local Arrays .. */ +-/* .. */ +-/* .. Intrinsic Functions .. */ +-/* .. */ +-/* .. External Functions .. */ +-/* .. */ +-/* .. Executable Statements .. */ +- /* Parameter adjustments */ +- --srname_array__; +- +- /* Function Body */ +- s_copy(srname, "", (ftnlen)32, (ftnlen)0); +-/* Computing MIN */ +- i__2 = *srname_len__, i__3 = i_len(srname, (ftnlen)32); +- i__1 = min(i__2,i__3); +- for (i__ = 1; i__ <= i__1; ++i__) { +- *(unsigned char *)&srname[i__ - 1] = *(unsigned char *)& +- srname_array__[i__]; +- } +- xerbla_(srname, info); + return 0; + } /* xerbla_array__ */ diff --git a/external/patches/clapack/spotrf_always_unblocked.patch b/external/patches/clapack/spotrf_always_unblocked.patch new file mode 100644 index 0000000000000000000000000000000000000000..4ec1563d31e4bfae289a23dda7b826969ba095f1 --- /dev/null +++ b/external/patches/clapack/spotrf_always_unblocked.patch @@ -0,0 +1,22 @@ +diff --git a/SRC/spotrf.c b/SRC/spotrf.c +index ff33e9e..1d2db4c 100644 +--- a/SRC/spotrf.c ++++ b/SRC/spotrf.c +@@ -39,8 +39,6 @@ static real c_b14 = 1.f; + *, integer *, real *, real *, integer *, real *, real *, integer * + ), spotf2_(char *, integer *, real *, integer *, + integer *), xerbla_(char *, integer *); +- extern integer ilaenv_(integer *, char *, char *, integer *, integer *, +- integer *, integer *); + + + /* -- LAPACK routine (version 3.2) -- */ +@@ -142,7 +140,7 @@ static real c_b14 = 1.f; + + /* Determine the block size for this environment. */ + +- nb = ilaenv_(&c__1, "SPOTRF", uplo, n, &c_n1, &c_n1, &c_n1); ++ nb = 1; + if (nb <= 1 || nb >= *n) { + + /* Use unblocked code. */ diff --git a/src/lapack.h b/src/lapack.h new file mode 100644 index 0000000000000000000000000000000000000000..0fc0b76c9716b8afd9a3dbc6a124140f5fd201a9 --- /dev/null +++ b/src/lapack.h @@ -0,0 +1,42 @@ +// This file is part of the execution-time evaluation for the qronos observer abstractions. +// Copyright (C) 2022-2023 Tim Rheinfels <tim.rheinfels@fau.de> +// See https://gitlab.cs.fau.de/qronos-state-abstractions/execution-time +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +/// +/// @file lapack.h +/// +/// @brief Provides C wrapper for the LAPACK routines used +/// +/// @author Tim Rheinfels <tim.rheinfels@fau.de> +/// + +#ifndef LAPACK_H +#define LAPACK_H + +/// +/// @brief Wrapper for sposv +/// +/// @see https://netlib.org/lapack/explore-html/de/d80/group__real_p_osolve_gad46400c796afc8031a8c3ec5481af8c3.html#gad46400c796afc8031a8c3ec5481af8c3 +/// +inline int sposv(char UPLO, int N, int NRHS, float *A, int LDA, float *B, int LDB) +{ + extern void sposv_(const char *UPLO, const int *N, const int *NRHS, float *A, const int *LDA, float *B, const int *LDB, int *INFO); + int INFO; + sposv_(&UPLO, &N, &NRHS, A, &LDA, B, &LDB, &INFO); + return INFO; +} + +#endif // LAPACK_H