Skip to content
Permalink
Browse files
Switched to BLIS+reference LAPACK.
  • Loading branch information
ShadenSmith committed Mar 12, 2017
1 parent 6dfaed8 commit 6a4d62b
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 36 deletions.
@@ -28,6 +28,7 @@ include(cmake/lapack.cmake)
include(cmake/openmp.cmake)
include(cmake/mpi.cmake)
include(cmake/partition.cmake)
include(cmake/fortran.cmake)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

@@ -0,0 +1,24 @@

if (DEFINED USE_FORTRAN)
set(SPLATT_NOWARN ${USE_FORTRAN})

# Enable linking against Fortran
enable_language(Fortran)

# Link against a supplied Fortran library.
if (DEFINED USER_FORTRAN_LIB)
message(STATUS "Using user supplied Fortran library=${USER_FORTRAN_LIB}")
set(SPLATT_LIBS ${SPLATT_LIBS} ${USER_FORTRAN_LIB})

# Try popular ones.
else()

# TODO search better
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel")
set(SPLATT_LIBS ${SPLATT_LIBS} ifcore)
else()
set(SPLATT_LIBS ${SPLATT_LIBS} gfortran)
endif()
endif()
endif()

@@ -7,23 +7,19 @@ else()
# BLAS/LAPACK
if (DEFINED DOWNLOAD_BLAS_LAPACK)

message(WARNING "Downloading generic BLAS/LAPACK libraries.")
message(WARNING " NOTE: performance may suffer.")
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/scripts/download-blas-lapack.sh ${CMAKE_BINARY_DIR})

# Enable linking against Fortran
enable_language(Fortran)

set(USER_LAPACK_LIB ${CMAKE_BINARY_DIR}/lapack/lib/liblapack.a)

# Link against generic BLAS and a Fortran library.
# TODO: Is there a better way to do this? The Fortran library must be added
# AFTER BLAS/LAPACK.
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel")
set(USER_BLAS_LIB ${CMAKE_BINARY_DIR}/lapack/lib/libblas.a ifcore)
else()
set(USER_BLAS_LIB ${CMAKE_BINARY_DIR}/lapack/lib/libblas.a gfortran)
endif()
message(STATUS "Building BLIS & reference LAPACK.")
execute_process(
COMMAND
${CMAKE_SOURCE_DIR}/scripts/download-blas-lapack.sh
${CMAKE_BINARY_DIR}/blis
${CONFIG_BLAS_INT}
)

set(USER_LAPACK_LIB ${CMAKE_BINARY_DIR}/blis/lib/liblapack.a)
set(USER_BLAS_LIB ${CMAKE_BINARY_DIR}/blis/lib/libblis.a)

# Force Fortran linking (due to reference LAPACK)
set(USE_FORTRAN 1)

# avoid annoying warning
set(SPLATT_NOWARN ${DOWNLOAD_BLAS_LAPACK})
@@ -2,7 +2,7 @@
# default widths
set(CONFIG_VAL_WIDTH 64)
set(CONFIG_IDX_WIDTH 64)
set(CONFIG_BLAS_INT int32_t)
set(CONFIG_BLAS_INT 32)

# check for user-defined widths
if (DEFINED USER_IDX_WIDTH)
@@ -32,9 +32,18 @@ endif()

if (DEFINED USER_BLAS_INT)
set(CONFIG_BLAS_INT ${USER_BLAS_INT})
message("Using type '${CONFIG_BLAS_INT}' for BLAS/LAPACK integers.")
if (${USER_BLAS_INT} STREQUAL "32")
set(CONFIG_BLAS_INT 32)
elseif (${USER_BLAS_INT} STREQUAL "64")
set(CONFIG_BLAS_INT 64)
else()
message(FATAL_ERROR "Width '${USER_BLAS_INT}' not recognized.\
Choose between {32 64}.")
endif()
message("Using ${CONFIG_BLAS_INT}-bit integers for BLAS/LAPACK.")
endif()


# Configure include/splatt/types.h to include specified type widths.
configure_file(${CMAKE_SOURCE_DIR}/include/splatt/types_config.h
${CMAKE_SOURCE_DIR}/include/splatt/types.h)
@@ -2,7 +2,7 @@

# The MIT License (MIT)
#
# Copyright (c) 2014-2016, Dominique LaSalle and Shaden Smith
# Copyright (c) 2014-2017, Dominique LaSalle and Shaden Smith
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -97,9 +97,14 @@ show_help() {
echo " --with-lapack-lib=<lib>"
echo " Set the LAPACK library (e.g., /usr/.../liblapack.so)."
echo " --download-blas-lapack"
echo " Download generic BLAS/LAPACK libraries (possible performance loss)."
echo " Download BLIS & reference LAPACK (requires git & gfortran)."
echo " --blas-int={int32_t,int64_t,etc.}"
echo " Integer type for BLAS/LAPACK (default: int32_t)."
echo " --with-fortran"
echo " Link against a Fortran library. Some LAPACK libraries require."
echo " --with-fortran-lib=<lib>"
echo " Set the Fortran library (e.g., gfortran or ifort)."


# Metis
echo "";
@@ -186,6 +191,12 @@ for i in "${@}"; do
--max-modes=*)
CONFIG_FLAGS="${CONFIG_FLAGS} -DMAX_MODES=${i#*=}"
;;
--with-fortran)
CONFIG_FLAGS="${CONFIG_FLAGS} -DUSE_FORTRAN=TRUE"
;;
--with-fortran-lib=*)
CONFIG_FLAGS="${CONFIG_FLAGS} -DUSER_FORTRAN_LIB=${i#*=}"
;;


## LIBRARY OPTIONS
@@ -38,10 +38,10 @@
#define SPLATT_IDX_TYPEWIDTH @CONFIG_IDX_WIDTH@
#define SPLATT_VAL_TYPEWIDTH @CONFIG_VAL_WIDTH@


/* Type for BLAS/LAPACK integers. This is usually int32_t, but needs to be
* int64_t when linking against 64b BLAS (e.g., Matlab's MKL). */
typedef @CONFIG_BLAS_INT@ splatt_blas_int;
#define SPLATT_BLAS_INTWIDTH @CONFIG_BLAS_INT@



/* Set type constants based on width. */
@@ -80,6 +80,14 @@ typedef @CONFIG_BLAS_INT@ splatt_blas_int;
#endif


#if SPLATT_BLAS_INTWIDTH == 32
typedef int32_t splatt_blas_int;
#elif SPLATT_BLAS_INTWIDTH == 64
typedef int64_t splatt_blas_int;
#else
#error "*** Incorrect user-supplied value of SPLATT_BLAS_INTWIDTH ***"
#endif




@@ -1,24 +1,37 @@
#!/bin/bash

LAPACK_VERSION=3.6.1
LAPACK_LOC=http://www.netlib.org/lapack/lapack-${LAPACK_VERSION}.tgz

if [ "$#" -eq 0 ]; then
echo "usage: <build directory>";
echo "usage: <build directory> [int size]";
exit 1;
fi

wget ${LAPACK_LOC} --output-document=$1/lapack.tgz;

pushd $1/
tar xf lapack.tgz
rm lapack.tgz;
BUILD_DIR=$1
mkdir -p ${BUILD_DIR}

mv lapack-${LAPACK_VERSION} lapack
pushd lapack
cmake .
make -j
BISIZE=32
if [ "$#" -gt 1 ]; then
BISIZE=$2
fi

#
# Build BLIS for its BLAS interface.
#
git clone https://github.com/flame/blis.git ${BUILD_DIR}/blis
pushd $1/blis
CC=gcc ./configure -p .. --enable-threading=openmp --blas-int-size=${BISIZE} auto
make -j
make install
popd

#
# Build reference LAPACK implementation.
#
git clone https://github.com/Reference-LAPACK/lapack.git ${BUILD_DIR}/lapack
pushd ${BUILD_DIR}/lapack
# Setup LAPACK build to use BLIS.
BLIS_LIB=${BUILD_DIR}/lib/libblis.a
sed "s@../../librefblas.a@${BLIS_LIB}@" make.inc.example > make.inc
make -j lapacklib
mv liblapack.a ../lib/
popd

0 comments on commit 6a4d62b

Please sign in to comment.