Skip to content

Commit

Permalink
Add blas library with lapack support (#46)
Browse files Browse the repository at this point in the history
blas and lapack integration unlocks accelerated mathematical operations on the grisp hardware.

Co-authored-by: tanguyl <[email protected]>
  • Loading branch information
ziopio and tanguyl authored Sep 1, 2023
1 parent a11b3b2 commit 6fc6019
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@
path = external/cryptoauthlib
url = https://github.com/grisp/cryptoauthlib
branch = GRiSP2
[submodule "external/lapack"]
path = external/lapack
url = https://github.com/Reference-LAPACK/lapack.git
39 changes: 38 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ SRC_BAREBOX = $(MAKEFILE_DIR)/external/barebox
SRC_OPENOCD = $(MAKEFILE_DIR)/external/openocd-code
SRC_IMX_USB_LOADER = $(MAKEFILE_DIR)/external/imx_usb_loader
SRC_CRYPTOAUTHLIB = $(MAKEFILE_DIR)/external/cryptoauthlib
SRC_BLAS = $(MAKEFILE_DIR)/external/lapack
BUILD_BSP = $(MAKEFILE_DIR)/build/b-$(BSP)
BUILD_BSP_GRISP1 = $(MAKEFILE_DIR)/build/b-$(BSP_GRISP1)
BUILD_LOGS = $(MAKEFILE_DIR)/build
Expand Down Expand Up @@ -82,7 +83,7 @@ help:

.PHONY: install
#H Build and install the complete toolchain, libraries, fdt and so on.
install: submodule-update toolchain toolchain-revision bootstrap bsp bsp-grisp1 libbsd fdt bsp.mk libgrisp libinih cryptoauthlib barebox-install
install: submodule-update toolchain toolchain-revision bootstrap bsp bsp-grisp1 libbsd fdt bsp.mk libgrisp libinih cryptoauthlib barebox-install blas

.PHONY: submodule-update
#H Update the submodules.
Expand All @@ -103,6 +104,7 @@ toolchain:
cd $(RSB)/rtems && ../source-builder/sb-set-builder \
--prefix=$(PREFIX) \
--log=$(BUILD_LOGS)/rsb-toolchain.log \
--with-fortran \
$(RTEMS_VERSION)/rtems-$(ARCH)
rm -rf $(RSB)/rtems/build

Expand Down Expand Up @@ -346,6 +348,41 @@ cryptoauthlib: cmake_toolchain_config
touch $(PREFIX)/$(TARGET)/$(BSP)/lib/include/cryptoauthlib/atca_start_config.h && \
touch $(PREFIX)/$(TARGET)/$(BSP)/lib/include/cryptoauthlib/atca_start_iface.h


BLAS_TOOLS=\
BLLIB='$(MAKEFILE_DIR)external/BLAS/CBLAS/lib/blas_ARM.a' \
CBLIB='$(MAKEFILE_DIR)external/BLAS/CBLAS/lib/cblas_ARM.a' \
CC='$(MAKEFILE_DIR)rtems/$(RTEMS_VERSION)/bin/$(ARCH)-rtems$(RTEMS_VERSION)-gcc' \
FC='$(MAKEFILE_DIR)rtems/$(RTEMS_VERSION)/bin/$(ARCH)-rtems$(RTEMS_VERSION)-gfortran' \
RANLIB='$(MAKEFILE_DIR)rtems/$(RTEMS_VERSION)/$(ARCH)-rtems$(RTEMS_VERSION)/bin/ranlib' \
AR='$(MAKEFILE_DIR)rtems/$(RTEMS_VERSION)/$(ARCH)-rtems$(RTEMS_VERSION)/bin/ar' \
ARCH=$(AR)


RANLIB=$(MAKEFILE_DIR)rtems/$(RTEMS_VERSION)/$(ARCH)-rtems$(RTEMS_VERSION)/bin/ranlib
AR='$(MAKEFILE_DIR)rtems/$(RTEMS_VERSION)/$(ARCH)-rtems$(RTEMS_VERSION)/bin/ar'

.PHONY: blas
#H Build the BLAS-LAPACKE library.
blas:
cp external/BLAS/make.inc $(SRC_BLAS)
cd $(SRC_BLAS) && make blaslib $(BLAS_TOOLS)
cd $(SRC_BLAS) && make cblaslib $(BLAS_TOOLS)
cd $(SRC_BLAS) && make lapacklib $(BLAS_TOOLS)
cd $(SRC_BLAS) && make lapackelib $(BLAS_TOOLS)
cd $(SRC_BLAS) &&\
$(AR) -x librefblas.a &&\
$(AR) -x libcblas.a &&\
$(AR) -x liblapack.a &&\
$(AR) -x liblapacke.a &&\
$(AR) -qc libblas.a *.o &&\
rm *.o &&\
$(RANLIB) libblas.a
cp $(SRC_BLAS)/libblas.a $(PREFIX)/$(TARGET)/$(BSP)/lib/libblas.a
cp $(SRC_BLAS)/CBLAS/include/cblas.h $(PREFIX)/$(TARGET)/$(BSP)/lib/include/cblas.h
cp $(SRC_BLAS)/CBLAS/include/cblas_mangling.h $(PREFIX)/$(TARGET)/$(BSP)/lib/include/cblas_mangling.h
cp $(SRC_BLAS)/LAPACKE/include/*.h $(PREFIX)/$(TARGET)/$(BSP)/lib/include/

.PHONY: demo
#H Build the demo application.
demo:
Expand Down
82 changes: 82 additions & 0 deletions external/BLAS/make.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
####################################################################
# LAPACK make include file. #
####################################################################

SHELL = /bin/sh

# CC is the C compiler, normally invoked with options CFLAGS.
#
CFLAGS = -O3 -march=armv7-a -mthumb -mfloat-abi=hard -mtune=cortex-a7 -mfpu=neon

# Modify the FC and FFLAGS definitions to the desired compiler
# and desired compiler options for your machine. NOOPT refers to
# the compiler options desired when NO OPTIMIZATION is selected.
#
# Note: During a regular execution, LAPACK might create NaN and Inf
# and handle these quantities appropriately. As a consequence, one
# should not compile LAPACK with flags such as -ffpe-trap=overflow.
#

FFLAGS = -O3 -march=armv7-a -mthumb -mfloat-abi=hard -mtune=cortex-a7 -mfpu=neon
FFLAGS_DRV = $(FFLAGS)
FFLAGS_NOOPT = -O0 -frecursive -march=armv7-a -mthumb -mfloat-abi=hard -mtune=cortex-a7 -mfpu=neon

# Define LDFLAGS to the desired linker options for your machine.
#
LDFLAGS =

# The archiver and the flag(s) to use when building an archive
# (library). If your system has no ranlib, set RANLIB = echo.
#

# Timer for the SECOND and DSECND routines
#
# Default: SECOND and DSECND will use a call to the
# EXTERNAL FUNCTION ETIME
#TIMER = EXT_ETIME
# For RS6K: SECOND and DSECND will use a call to the
# EXTERNAL FUNCTION ETIME_
#TIMER = EXT_ETIME_
# For gfortran compiler: SECOND and DSECND will use a call to the
# INTERNAL FUNCTION ETIME
TIMER = INT_ETIME
# If your Fortran compiler does not provide etime (like Nag Fortran
# Compiler, etc...) SECOND and DSECND will use a call to the
# INTERNAL FUNCTION CPU_TIME
#TIMER = INT_CPU_TIME
# If none of these work, you can use the NONE value.
# In that case, SECOND and DSECND will always return 0.
#TIMER = NONE

# Uncomment the following line to include deprecated routines in
# the LAPACK library.
#
BUILD_DEPRECATED = Yes

# LAPACKE has the interface to some routines from tmglib.
# If LAPACKE_WITH_TMG is defined, add those routines to LAPACKE.
#
#LAPACKE_WITH_TMG = Yes

# Location of the extended-precision BLAS (XBLAS) Fortran library
# used for building and testing extended-precision routines. The
# relevant routines will be compiled and XBLAS will be linked only
# if USEXBLAS is defined.
#
#USEXBLAS = Yes
#XBLASLIB = -lxblas

# The location of the libraries to which you will link. (The
# machine-specific, optimized BLAS library should be used whenever
# possible.)
#
BLASLIB = $(TOPSRCDIR)/librefblas.a
CBLASLIB = $(TOPSRCDIR)/libcblas.a
LAPACKLIB = $(TOPSRCDIR)/liblapack.a
TMGLIB = $(TOPSRCDIR)/libtmglib.a
LAPACKELIB = $(TOPSRCDIR)/liblapacke.a

# DOCUMENTATION DIRECTORY
# If you generate html pages (make html), documentation will be placed in $(DOCSDIR)/explore-html
# If you generate man pages (make man), documentation will be placed in $(DOCSDIR)/man
DOCSDIR = $(TOPSRCDIR)/DOCS
1 change: 1 addition & 0 deletions external/lapack
Submodule lapack added at 129637

0 comments on commit 6fc6019

Please sign in to comment.