Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incorporate libblastrampoline (LBT)
Browse files Browse the repository at this point in the history
All BLAS and LAPACK are now routed through LBT.
SuiteSparse is also linked against LBT.
OpenBLAS is still installed as before, and is
what LBT forwards to by default.
ViralBShah committed Feb 15, 2021
1 parent 2eeef2e commit 7da0a6b
Showing 21 changed files with 189 additions and 118 deletions.
72 changes: 1 addition & 71 deletions Make.inc
Original file line number Diff line number Diff line change
@@ -60,25 +60,9 @@ USE_SYSTEM_P7ZIP:=0
# Link to the LLVM shared library
USE_LLVM_SHLIB := 1

## Settings for various Intel tools
# Set to 1 to use MKL
USE_INTEL_MKL ?= 0
# Set to 1 to use Intel LIBM
USE_INTEL_LIBM ?= 0
# Set to 1 to enable profiling with Intel VTune Amplifier
USE_INTEL_JITEVENTS ?= 0
# Set to 1 to use Intel C, C++, and FORTRAN compilers
USEICC ?= 0
USEIFC ?= 0

# Enable threading with one thread
JULIA_THREADS := 1

ifeq ($(USE_MKL), 1)
$(warning "The julia make variable USE_MKL has been renamed to USE_INTEL_MKL")
USE_INTEL_MKL := 1
endif

# Set to 1 to enable profiling with OProfile
USE_OPROFILE_JITEVENTS ?= 0

@@ -1081,11 +1065,7 @@ endif
# Use ILP64 BLAS interface when building openblas from source on 64-bit architectures
ifeq ($(BINARY), 64)
ifeq ($(USE_SYSTEM_BLAS), 1)
ifeq ($(USE_INTEL_MKL), 1)
USE_BLAS64 ?= 1
else # non MKL system blas is most likely LP64
USE_BLAS64 ?= 0
endif
else
USE_BLAS64 ?= 1
endif
@@ -1181,7 +1161,7 @@ BB_TRIPLET_CXXABI := $(subst $(SPACE),-,$(filter-out libgfortran%,$(subst -,$(SP
BB_TRIPLET := $(subst $(SPACE),-,$(filter-out cxx%,$(filter-out libgfortran%,$(subst -,$(SPACE),$(BB_TRIPLET_LIBGFORTRAN_CXXABI)))))

# This is the set of projects that BinaryBuilder dependencies are hooked up for.
BB_PROJECTS := OPENBLAS LLVM SUITESPARSE OPENLIBM GMP MBEDTLS LIBSSH2 NGHTTP2 MPFR CURL LIBGIT2 PCRE LIBUV LIBUNWIND DSFMT OBJCONV ZLIB P7ZIP CSL
BB_PROJECTS := BLASTRAMPOLINE OPENBLAS LLVM SUITESPARSE OPENLIBM GMP MBEDTLS LIBSSH2 NGHTTP2 MPFR CURL LIBGIT2 PCRE LIBUV LIBUNWIND DSFMT OBJCONV ZLIB P7ZIP CSL
define SET_BB_DEFAULT
# First, check to see if BB is disabled on a global setting
ifeq ($$(USE_BINARYBUILDER),0)
@@ -1345,63 +1325,13 @@ ifeq ($(USE_PERF_JITEVENTS), 1)
JCPPFLAGS += -DJL_USE_PERF_JITEVENTS
endif


# Intel libraries

ifeq ($(USE_INTEL_LIBM), 1)
USE_SYSTEM_LIBM := 1
LIBM := -L$(MKLROOT)/../compiler/lib/intel64 -limf
LIBMNAME := libimf
endif

ifeq ($(USE_INTEL_MKL), 1)
ifeq ($(USE_BLAS64), 1)
export MKL_INTERFACE_LAYER := ILP64
MKLLIB := $(MKLROOT)/lib/intel64
else
MKLLIB := $(MKLROOT)/lib/ia32
endif
USE_SYSTEM_BLAS:=1
USE_SYSTEM_LAPACK:=1
LIBBLASNAME := libmkl_rt
LIBLAPACKNAME := libmkl_rt
MKL_LDFLAGS := -L$(MKLLIB) -lmkl_rt
ifneq ($(strip $(MKLLIB)),)
ifeq ($(OS), Linux)
RPATH_MKL := -Wl,-rpath,$(MKLLIB)
RPATH += $(RPATH_MKL)
MKL_LDFLAGS += $(RPATH_MKL)
endif
endif
LIBBLAS := $(MKL_LDFLAGS)
LIBLAPACK := $(MKL_LDFLAGS)
endif

ifeq ($(HAVE_SSP),1)
JCPPFLAGS += -DHAVE_SSP=1
ifeq ($(USEGCC),1)
OSLIBS += -lssp
endif
endif

# ATLAS

# ATLAS must have been previously installed to usr/lib/libatlas
# (built as a shared library, for your platform, single threaded)
USE_ATLAS := 0
ATLAS_LIBDIR := $(build_libdir)
#or ATLAS_LIBDIR := /path/to/system/atlas/lib

ifeq ($(USE_ATLAS), 1)
USE_BLAS64 := 0
USE_SYSTEM_BLAS := 1
USE_SYSTEM_LAPACK := 1
LIBBLAS := -L$(ATLAS_LIBDIR) -lsatlas
LIBLAPACK := $(LIBBLAS)
LIBBLASNAME := libsatlas
LIBLAPACKNAME := $(LIBBLASNAME)
endif

# Renaming OpenBLAS symbols, see #4923 and #8734
ifeq ($(USE_SYSTEM_BLAS), 0)
ifeq ($(USE_BLAS64), 1)
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -164,7 +164,7 @@ JL_TARGETS += julia-debug
endif

# private libraries, that are installed in $(prefix)/lib/julia
JL_PRIVATE_LIBS-0 := libccalltest libllvmcalltest libjulia-internal
JL_PRIVATE_LIBS-0 := libccalltest libllvmcalltest libjulia-internal libblastrampoline
ifeq ($(BUNDLE_DEBUG_LIBS),1)
JL_PRIVATE_LIBS-0 += libjulia-internal-debug
endif
@@ -360,7 +360,7 @@ endif
$(call stringreplace,$${DEBUG_TARGET},sys-debug.$(SHLIB_EXT)$$,$(private_libdir_rel)/sys-debug.$(SHLIB_EXT)); \
fi;
endif

# Set rpath for libjulia-internal, which is moving from `../lib` to `../lib/julia`. We only need to do this for Linux/FreeBSD
ifneq (,$(findstring $(OS),Linux FreeBSD))
$(PATCHELF) --set-rpath '$$ORIGIN:$$ORIGIN/$(reverse_private_libdir_rel)' $(DESTDIR)$(private_libdir)/libjulia-internal.$(SHLIB_EXT)
10 changes: 7 additions & 3 deletions deps/Makefile
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ BUILDDIR := $(BUILDDIR)$(MAYBE_HOST)
# if you are adding a new target, it can help to copy an similar, existing target
#
# autoconf configure-driven scripts: pcre unwind gmp mpfr patchelf libuv curl
# custom Makefile rules: openlibm dsfmt suitesparse-wrapper suitesparse lapack openblas utf8proc objconv osxunwind libwhich
# custom Makefile rules: openlibm dsfmt suitesparse-wrapper suitesparse lapack blastrampoline openblas utf8proc objconv osxunwind libwhich
# CMake libs: llvm libgit2 libssh2 mbedtls
#
# downloadable via git: llvm-svn, libuv, libopenlibm, utf8proc, libgit2, libssh2
@@ -39,6 +39,9 @@ unexport CONFIG_SITE

DEP_LIBS :=

# Always use libblastrampoline
DEP_LIBS += blastrampoline

ifeq ($(USE_SYSTEM_CSL), 0)
DEP_LIBS += csl
endif
@@ -187,7 +190,7 @@ install: $(addprefix install-, $(DEP_LIBS))
cleanall: $(addprefix clean-, $(DEP_LIBS))
distcleanall: $(addprefix distclean-, $(DEP_LIBS))
rm -rf $(build_prefix)
getall: get-llvm get-libuv get-pcre get-openlibm get-dsfmt get-openblas get-lapack get-suitesparse get-unwind get-gmp get-mpfr get-patchelf get-utf8proc get-objconv get-mbedtls get-libssh2 get-nghttp2 get-curl get-libgit2 get-libwhich get-zlib get-p7zip get-csl
getall: get-llvm get-libuv get-pcre get-openlibm get-dsfmt get-blastrampoline get-openblas get-lapack get-suitesparse get-unwind get-gmp get-mpfr get-patchelf get-utf8proc get-objconv get-mbedtls get-libssh2 get-nghttp2 get-curl get-libgit2 get-libwhich get-zlib get-p7zip get-csl

# If we're building for MacOS, no matter what, `getall` should include `osxunwind`
ifeq ($(OS),Darwin)
@@ -206,7 +209,8 @@ include $(SRCDIR)/pcre.mk
include $(SRCDIR)/openlibm.mk
include $(SRCDIR)/dsfmt.mk
include $(SRCDIR)/objconv.mk
include $(SRCDIR)/blas.mk
include $(SRCDIR)/blastrampoline.mk
include $(SRCDIR)/openblas.mk
include $(SRCDIR)/utf8proc.mk
include $(SRCDIR)/suitesparse.mk
include $(SRCDIR)/unwind.mk
6 changes: 5 additions & 1 deletion deps/Versions.make
Original file line number Diff line number Diff line change
@@ -70,6 +70,10 @@ OBJCONV_VER := 2.49.1
OBJCONV_JLL_NAME := Objconv
OBJCONV_JLL_VER := 2.49.1+0

# blastrampoline
BLASTRAMPOLINE_VER := 1.0.0
BLASTRAMPOLINE_JLL_NAME := libblastrampoline

# OpenBLAS
OPENBLAS_VER := 0.3.10
OPENBLAS_JLL_NAME := OpenBLAS
@@ -96,7 +100,7 @@ PCRE_JLL_NAME := PCRE2

# SuiteSparse
SUITESPARSE_VER := 5.4.0
SUITESPARSE_JLL_NAME := SuiteSparse
SUITESPARSE_JLL_NAME := SuiteSparse_LBT

# unwind
UNWIND_VER := 1.3.2
37 changes: 37 additions & 0 deletions deps/blastrampoline.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## blastrampoline ##

ifneq ($(USE_BINARYBUILDER_BLASTRAMPOLINE),1)

BLASTRAMPOLINE_GIT_URL := git://github.com/staticfloat/libblastrampoline.git
BLASTRAMPOLINE_TAR_URL = https://api.github.com/repos/staticfloat/libblastrampoline/tarball/$1
$(eval $(call git-external,blastrampoline,BLASTRAMPOLINE,,,$(BUILDDIR)))

$(BUILDDIR)/$(BLASTRAMPOLINE_SRC_DIR)/build-configured: $(BUILDDIR)/$(BLASTRAMPOLINE_SRC_DIR)/source-extracted
mkdir -p $(dir $@)
echo 1 > $@

$(BUILDDIR)/$(BLASTRAMPOLINE_SRC_DIR)/build-compiled: $(BUILDDIR)/$(BLASTRAMPOLINE_SRC_DIR)/build-configured
cd $(dir $@)/src && $(MAKE) $(MAKE_COMMON)
echo 1 > $@

define BLASTRAMPOLINE_INSTALL
$(MAKE) -C $(BUILDDIR)/$(BLASTRAMPOLINE_SRC_DIR)/src $(MAKE_COMMON) install
endef
$(eval $(call staged-install, \
blastrampoline,$(BLASTRAMPOLINE_SRC_DIR), \
BLASTRAMPOLINE_INSTALL,, \
$$(BLASTRAMPOLINE_OBJ_TARGET), \
$$(INSTALL_NAME_CMD)libblastrampoline.$$(SHLIB_EXT) $$(build_shlibdir)/libblastrampoline.$$(SHLIB_EXT)))

get-blastrampoline: $(BLASTRAMPOLINE_SRC_FILE)
extract-blastrampoline: $(BUILDDIR)/$(BLASTRAMPOLINE_SRC_DIR)/source-extracted
configure-blastrampoline: extract-blastrampoline
compile-blastrampoline: $(BUILDDIR)/$(BLASTRAMPOLINE_SRC_DIR)/build-compiled
fastcheck-blastrampoline: check-blastrampoline
check-blastrampoline: compile-blastrampoline

else

$(eval $(call bb-install,blastrampoline,BLASTRAMPOLINE,false))

endif # USE_BINARYBUILDER_BLASTRAMPOLINE
2 changes: 2 additions & 0 deletions deps/blastrampoline.version
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BLASTRAMPOLINE_BRANCH=main
BLASTRAMPOLINE_SHA1=0c723926f96ba431713c4873b46e81a5fd600d0c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
30edb3916c34dfb577f0d3f69f1fafff
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ce716f97eda04ebf121d52faded2b7128635b3ca8cc21f61af5fa87fcef24adc480f912c3940b9361ac6b0175d81fb012c8634c2c3d9023fc0d86dcf73bf50e1
File renamed without changes.
16 changes: 5 additions & 11 deletions deps/suitesparse.mk
Original file line number Diff line number Diff line change
@@ -4,14 +4,12 @@ ifeq ($(USE_BLAS64), 1)
UMFPACK_CONFIG := -DLONGBLAS='long long'
CHOLMOD_CONFIG := -DLONGBLAS='long long'
SPQR_CONFIG := -DLONGBLAS='long long'
ifeq ($(OPENBLAS_SYMBOLSUFFIX), 64_)
UMFPACK_CONFIG += -DSUN64
CHOLMOD_CONFIG += -DSUN64
SPQR_CONFIG += -DSUN64
endif
endif

# Disable trying to link against libmetis
# Disable linking to libmetis
CHOLMOD_CONFIG += -DNPARTITION

ifneq ($(USE_BINARYBUILDER_SUITESPARSE), 1)
@@ -23,7 +21,7 @@ SUITE_SPARSE_LIB := $(LDFLAGS) -L"$(abspath $(BUILDDIR))/SuiteSparse-$(SUITESPAR
ifeq ($(OS), Darwin)
SUITE_SPARSE_LIB += $(RPATH_ESCAPED_ORIGIN)
endif
SUITESPARSE_MFLAGS := CC="$(CC)" CXX="$(CXX)" F77="$(FC)" AR="$(AR)" RANLIB="$(RANLIB)" BLAS="$(LIBBLAS)" LAPACK="$(LIBLAPACK)" \
SUITESPARSE_MFLAGS := CC="$(CC)" CXX="$(CXX)" F77="$(FC)" AR="$(AR)" RANLIB="$(RANLIB)" BLAS="-L$(build_shlibdir) -lblastrampoline" LAPACK="-L$(build_shlibdir) -lblastrampoline" \
LDFLAGS="$(SUITE_SPARSE_LIB)" CFOPENMP="" CUDA=no CUDA_PATH="" \
UMFPACK_CONFIG="$(UMFPACK_CONFIG)" CHOLMOD_CONFIG="$(CHOLMOD_CONFIG)" SPQR_CONFIG="$(SPQR_CONFIG)"
ifeq ($(OS),WINNT)
@@ -53,11 +51,7 @@ $(BUILDDIR)/SuiteSparse-$(SUITESPARSE_VER)/SuiteSparse-shlib.patch-applied: $(BU
$(BUILDDIR)/SuiteSparse-$(SUITESPARSE_VER)/build-compiled: $(BUILDDIR)/SuiteSparse-$(SUITESPARSE_VER)/SuiteSparse-winclang.patch-applied
$(BUILDDIR)/SuiteSparse-$(SUITESPARSE_VER)/build-compiled: $(BUILDDIR)/SuiteSparse-$(SUITESPARSE_VER)/SuiteSparse-shlib.patch-applied

ifeq ($(USE_SYSTEM_BLAS), 0)
$(BUILDDIR)/SuiteSparse-$(SUITESPARSE_VER)/build-compiled: | $(build_prefix)/manifest/openblas
else ifeq ($(USE_SYSTEM_LAPACK), 0)
$(BUILDDIR)/SuiteSparse-$(SUITESPARSE_VER)/build-compiled: | $(build_prefix)/manifest/lapack
endif
$(BUILDDIR)/SuiteSparse-$(SUITESPARSE_VER)/build-compiled: | $(build_prefix)/manifest/blastrampoline

$(BUILDDIR)/SuiteSparse-$(SUITESPARSE_VER)/build-compiled: $(BUILDDIR)/SuiteSparse-$(SUITESPARSE_VER)/source-extracted
$(MAKE) -C $(dir $<)SuiteSparse_config library config $(SUITESPARSE_MFLAGS)
@@ -153,6 +147,6 @@ clean-suitesparse-wrapper: clean-suitesparse
distclean-suitesparse-wrapper: distclean-suitesparse
install-suitesparse-wrapper: install-suitesparse

# suitesparse depends on OpenBLAS
compile-suitesparse: | $(build_prefix)/manifest/openblas
# suitesparse depends on blastrampoline
compile-suitesparse: | $(build_prefix)/manifest/blastrampoline
endif
55 changes: 42 additions & 13 deletions stdlib/LinearAlgebra/src/LinearAlgebra.jl
Original file line number Diff line number Diff line change
@@ -433,21 +433,50 @@ function versioninfo(io::IO=stdout)
println(io, "LAPACK: ",Base.liblapack_name)
end

function __init__()
try
BLAS.check()
if BLAS.vendor() === :mkl
ccall((:MKL_Set_Interface_Layer, Base.libblas_name), Cvoid, (Cint,), USE_BLAS64 ? 1 : 0)
function get_blas_lapack_path()
shlib_ext = if Sys.iswindows()
".dll"
elseif Sys.isapple()
".dylib"
else
".so"
end
libblas_path = joinpath(Sys.BINDIR, Base.LIBDIR, "julia", string(Base.libblas_name, shlib_ext))
if !isfile(libblas_path)
libblas_path = joinpath(Sys.BINDIR, Base.LIBDIR, string(Base.libblas_name, shlib_ext))
if !isfile(libblas_path)
error("Cannot find BLAS at ", libblas_path)
end
end
liblapack_path = joinpath(Sys.BINDIR, Base.LIBDIR, "julia", string(Base.liblapack_name, shlib_ext))
if !isfile(liblapack_path)
liblapack_path = joinpath(Sys.BINDIR, Base.LIBDIR, string(Base.liblapack_name, shlib_ext))
if !isfile(liblapack_path)
error("Cannot find LAPACK at ", liblapack_path)
end
Threads.resize_nthreads!(Abuf)
Threads.resize_nthreads!(Bbuf)
Threads.resize_nthreads!(Cbuf)
catch ex
Base.showerror_nostdio(ex,
"WARNING: Error during initialization of module LinearAlgebra")
end
# register a hook to disable BLAS threading
Base.at_disable_library_threading(() -> BLAS.set_num_threads(1))

return (libblas_path, liblapack_path)
end

function __init__()
try
libblas_path, liblapack_path = get_blas_lapack_path()
ccall((:load_blas_funcs, "libblastrampoline"), Cvoid, (Cstring,Cint,Cint), libblas_path, 1, 0)
ccall((:load_blas_funcs, "libblastrampoline"), Cvoid, (Cstring,Cint,Cint), liblapack_path, 0, 0)
# BLAS.check()
# if BLAS.vendor() === :mkl
# ccall((:MKL_Set_Interface_Layer, Base.libblas_name), Cvoid, (Cint,), USE_BLAS64 ? 1 : 0)
# end
# Threads.resize_nthreads!(Abuf)
# Threads.resize_nthreads!(Bbuf)
# Threads.resize_nthreads!(Cbuf)
catch ex
Base.showerror_nostdio(ex,
"WARNING: Error during initialization of module LinearAlgebra")
end
# register a hook to disable BLAS threading
Base.at_disable_library_threading(() -> BLAS.set_num_threads(1))
end

end # module LinearAlgebra
8 changes: 4 additions & 4 deletions stdlib/LinearAlgebra/src/blas.jl
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ Interface to BLAS subroutines.
module BLAS

import ..axpy!, ..axpby!
import Base: copyto!
import Base: copyto!, USE_BLAS64
using Base: require_one_based_indexing

export
@@ -63,8 +63,8 @@ export
trsm


const libblas = Base.libblas_name
const liblapack = Base.liblapack_name
const libblas = "libblastrampoline"
const liblapack = "libblastrampoline"

import LinearAlgebra
import LinearAlgebra: BlasReal, BlasComplex, BlasFloat, BlasInt, DimensionMismatch, checksquare, stride1, chkstride1, axpy!
@@ -94,7 +94,7 @@ end
const _vendor = determine_vendor()
vendor() = _vendor

if vendor() === :openblas64
if USE_BLAS64
macro blasfunc(x)
return Expr(:quote, Symbol(x, "64_"))
end
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/lapack.jl
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ module LAPACK
Interfaces to LAPACK subroutines.
""" LAPACK

const liblapack = Base.liblapack_name
const liblapack = "libblastrampoline"

import ..LinearAlgebra.BLAS.@blasfunc

2 changes: 1 addition & 1 deletion stdlib/Makefile
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ $(build_datarootdir)/julia/stdlib/$(VERSDIR):
mkdir -p $@

JLLS = DSFMT GMP CURL LIBGIT2 LLVM LIBSSH2 LIBUV MBEDTLS MPFR NGHTTP2 \
OPENBLAS OPENLIBM P7ZIP PCRE SUITESPARSE ZLIB OSXUNWIND CSL \
BLASTRAMPOLINE OPENBLAS OPENLIBM P7ZIP PCRE SUITESPARSE ZLIB OSXUNWIND CSL \
UNWIND

# Initialize this with JLLs that aren't in deps/Versions.make
Loading

0 comments on commit 7da0a6b

Please sign in to comment.