Skip to content

Commit 5d04754

Browse files
ViralBShahsimonbyrneKristofferC
committed
Incorporate libblastrampoline (LBT)
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. Co-authored-by: Simon Byrne <[email protected]> Co-authored-by: Kristoffer Carlsson <[email protected]>
1 parent 2eeef2e commit 5d04754

File tree

21 files changed

+204
-141
lines changed

21 files changed

+204
-141
lines changed

Make.inc

+1-71
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,9 @@ USE_SYSTEM_P7ZIP:=0
6060
# Link to the LLVM shared library
6161
USE_LLVM_SHLIB := 1
6262

63-
## Settings for various Intel tools
64-
# Set to 1 to use MKL
65-
USE_INTEL_MKL ?= 0
66-
# Set to 1 to use Intel LIBM
67-
USE_INTEL_LIBM ?= 0
68-
# Set to 1 to enable profiling with Intel VTune Amplifier
69-
USE_INTEL_JITEVENTS ?= 0
70-
# Set to 1 to use Intel C, C++, and FORTRAN compilers
71-
USEICC ?= 0
72-
USEIFC ?= 0
73-
7463
# Enable threading with one thread
7564
JULIA_THREADS := 1
7665

77-
ifeq ($(USE_MKL), 1)
78-
$(warning "The julia make variable USE_MKL has been renamed to USE_INTEL_MKL")
79-
USE_INTEL_MKL := 1
80-
endif
81-
8266
# Set to 1 to enable profiling with OProfile
8367
USE_OPROFILE_JITEVENTS ?= 0
8468

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

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

1348-
1349-
# Intel libraries
1350-
1351-
ifeq ($(USE_INTEL_LIBM), 1)
1352-
USE_SYSTEM_LIBM := 1
1353-
LIBM := -L$(MKLROOT)/../compiler/lib/intel64 -limf
1354-
LIBMNAME := libimf
1355-
endif
1356-
1357-
ifeq ($(USE_INTEL_MKL), 1)
1358-
ifeq ($(USE_BLAS64), 1)
1359-
export MKL_INTERFACE_LAYER := ILP64
1360-
MKLLIB := $(MKLROOT)/lib/intel64
1361-
else
1362-
MKLLIB := $(MKLROOT)/lib/ia32
1363-
endif
1364-
USE_SYSTEM_BLAS:=1
1365-
USE_SYSTEM_LAPACK:=1
1366-
LIBBLASNAME := libmkl_rt
1367-
LIBLAPACKNAME := libmkl_rt
1368-
MKL_LDFLAGS := -L$(MKLLIB) -lmkl_rt
1369-
ifneq ($(strip $(MKLLIB)),)
1370-
ifeq ($(OS), Linux)
1371-
RPATH_MKL := -Wl,-rpath,$(MKLLIB)
1372-
RPATH += $(RPATH_MKL)
1373-
MKL_LDFLAGS += $(RPATH_MKL)
1374-
endif
1375-
endif
1376-
LIBBLAS := $(MKL_LDFLAGS)
1377-
LIBLAPACK := $(MKL_LDFLAGS)
1378-
endif
1379-
13801328
ifeq ($(HAVE_SSP),1)
13811329
JCPPFLAGS += -DHAVE_SSP=1
13821330
ifeq ($(USEGCC),1)
13831331
OSLIBS += -lssp
13841332
endif
13851333
endif
13861334

1387-
# ATLAS
1388-
1389-
# ATLAS must have been previously installed to usr/lib/libatlas
1390-
# (built as a shared library, for your platform, single threaded)
1391-
USE_ATLAS := 0
1392-
ATLAS_LIBDIR := $(build_libdir)
1393-
#or ATLAS_LIBDIR := /path/to/system/atlas/lib
1394-
1395-
ifeq ($(USE_ATLAS), 1)
1396-
USE_BLAS64 := 0
1397-
USE_SYSTEM_BLAS := 1
1398-
USE_SYSTEM_LAPACK := 1
1399-
LIBBLAS := -L$(ATLAS_LIBDIR) -lsatlas
1400-
LIBLAPACK := $(LIBBLAS)
1401-
LIBBLASNAME := libsatlas
1402-
LIBLAPACKNAME := $(LIBBLASNAME)
1403-
endif
1404-
14051335
# Renaming OpenBLAS symbols, see #4923 and #8734
14061336
ifeq ($(USE_SYSTEM_BLAS), 0)
14071337
ifeq ($(USE_BLAS64), 1)

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ JL_TARGETS += julia-debug
164164
endif
165165

166166
# private libraries, that are installed in $(prefix)/lib/julia
167-
JL_PRIVATE_LIBS-0 := libccalltest libllvmcalltest libjulia-internal
167+
JL_PRIVATE_LIBS-0 := libccalltest libllvmcalltest libjulia-internal libblastrampoline
168168
ifeq ($(BUNDLE_DEBUG_LIBS),1)
169169
JL_PRIVATE_LIBS-0 += libjulia-internal-debug
170170
endif
@@ -360,7 +360,7 @@ endif
360360
$(call stringreplace,$${DEBUG_TARGET},sys-debug.$(SHLIB_EXT)$$,$(private_libdir_rel)/sys-debug.$(SHLIB_EXT)); \
361361
fi;
362362
endif
363-
363+
364364
# Set rpath for libjulia-internal, which is moving from `../lib` to `../lib/julia`. We only need to do this for Linux/FreeBSD
365365
ifneq (,$(findstring $(OS),Linux FreeBSD))
366366
$(PATCHELF) --set-rpath '$$ORIGIN:$$ORIGIN/$(reverse_private_libdir_rel)' $(DESTDIR)$(private_libdir)/libjulia-internal.$(SHLIB_EXT)

deps/Makefile

+7-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ BUILDDIR := $(BUILDDIR)$(MAYBE_HOST)
2424
# if you are adding a new target, it can help to copy an similar, existing target
2525
#
2626
# autoconf configure-driven scripts: pcre unwind gmp mpfr patchelf libuv curl
27-
# custom Makefile rules: openlibm dsfmt suitesparse-wrapper suitesparse lapack openblas utf8proc objconv osxunwind libwhich
27+
# custom Makefile rules: openlibm dsfmt suitesparse-wrapper suitesparse lapack blastrampoline openblas utf8proc objconv osxunwind libwhich
2828
# CMake libs: llvm libgit2 libssh2 mbedtls
2929
#
3030
# downloadable via git: llvm-svn, libuv, libopenlibm, utf8proc, libgit2, libssh2
@@ -39,6 +39,9 @@ unexport CONFIG_SITE
3939

4040
DEP_LIBS :=
4141

42+
# Always use libblastrampoline
43+
DEP_LIBS += blastrampoline
44+
4245
ifeq ($(USE_SYSTEM_CSL), 0)
4346
DEP_LIBS += csl
4447
endif
@@ -187,7 +190,7 @@ install: $(addprefix install-, $(DEP_LIBS))
187190
cleanall: $(addprefix clean-, $(DEP_LIBS))
188191
distcleanall: $(addprefix distclean-, $(DEP_LIBS))
189192
rm -rf $(build_prefix)
190-
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
193+
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
191194

192195
# If we're building for MacOS, no matter what, `getall` should include `osxunwind`
193196
ifeq ($(OS),Darwin)
@@ -206,7 +209,8 @@ include $(SRCDIR)/pcre.mk
206209
include $(SRCDIR)/openlibm.mk
207210
include $(SRCDIR)/dsfmt.mk
208211
include $(SRCDIR)/objconv.mk
209-
include $(SRCDIR)/blas.mk
212+
include $(SRCDIR)/blastrampoline.mk
213+
include $(SRCDIR)/openblas.mk
210214
include $(SRCDIR)/utf8proc.mk
211215
include $(SRCDIR)/suitesparse.mk
212216
include $(SRCDIR)/unwind.mk

deps/Versions.make

+5-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ OBJCONV_VER := 2.49.1
7070
OBJCONV_JLL_NAME := Objconv
7171
OBJCONV_JLL_VER := 2.49.1+0
7272

73+
# blastrampoline
74+
BLASTRAMPOLINE_VER := 2.0.0
75+
BLASTRAMPOLINE_JLL_NAME := libblastrampoline
76+
7377
# OpenBLAS
7478
OPENBLAS_VER := 0.3.10
7579
OPENBLAS_JLL_NAME := OpenBLAS
@@ -96,7 +100,7 @@ PCRE_JLL_NAME := PCRE2
96100

97101
# SuiteSparse
98102
SUITESPARSE_VER := 5.4.0
99-
SUITESPARSE_JLL_NAME := SuiteSparse
103+
SUITESPARSE_JLL_NAME := SuiteSparse_LBT
100104

101105
# unwind
102106
UNWIND_VER := 1.3.2

deps/blastrampoline.mk

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## blastrampoline ##
2+
3+
ifneq ($(USE_BINARYBUILDER_BLASTRAMPOLINE),1)
4+
5+
BLASTRAMPOLINE_GIT_URL := git://github.com/staticfloat/libblastrampoline.git
6+
BLASTRAMPOLINE_TAR_URL = https://api.github.com/repos/staticfloat/libblastrampoline/tarball/$1
7+
$(eval $(call git-external,blastrampoline,BLASTRAMPOLINE,,,$(BUILDDIR)))
8+
9+
$(BUILDDIR)/$(BLASTRAMPOLINE_SRC_DIR)/build-configured: $(BUILDDIR)/$(BLASTRAMPOLINE_SRC_DIR)/source-extracted
10+
mkdir -p $(dir $@)
11+
echo 1 > $@
12+
13+
$(BUILDDIR)/$(BLASTRAMPOLINE_SRC_DIR)/build-compiled: $(BUILDDIR)/$(BLASTRAMPOLINE_SRC_DIR)/build-configured
14+
cd $(dir $@)/src && $(MAKE) $(MAKE_COMMON)
15+
echo 1 > $@
16+
17+
define BLASTRAMPOLINE_INSTALL
18+
$(MAKE) -C $(BUILDDIR)/$(BLASTRAMPOLINE_SRC_DIR)/src $(MAKE_COMMON) install
19+
endef
20+
$(eval $(call staged-install, \
21+
blastrampoline,$(BLASTRAMPOLINE_SRC_DIR), \
22+
BLASTRAMPOLINE_INSTALL,, \
23+
$$(BLASTRAMPOLINE_OBJ_TARGET), \
24+
$$(INSTALL_NAME_CMD)libblastrampoline.$$(SHLIB_EXT) $$(build_shlibdir)/libblastrampoline.$$(SHLIB_EXT)))
25+
26+
get-blastrampoline: $(BLASTRAMPOLINE_SRC_FILE)
27+
extract-blastrampoline: $(BUILDDIR)/$(BLASTRAMPOLINE_SRC_DIR)/source-extracted
28+
configure-blastrampoline: extract-blastrampoline
29+
compile-blastrampoline: $(BUILDDIR)/$(BLASTRAMPOLINE_SRC_DIR)/build-compiled
30+
fastcheck-blastrampoline: check-blastrampoline
31+
check-blastrampoline: compile-blastrampoline
32+
33+
else
34+
35+
$(eval $(call bb-install,blastrampoline,BLASTRAMPOLINE,false))
36+
37+
endif # USE_BINARYBUILDER_BLASTRAMPOLINE

deps/blastrampoline.version

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BLASTRAMPOLINE_BRANCH=main
2+
BLASTRAMPOLINE_SHA1=ff674f952e55896d6db73331154cec84b54cb841
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
30edb3916c34dfb577f0d3f69f1fafff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ce716f97eda04ebf121d52faded2b7128635b3ca8cc21f61af5fa87fcef24adc480f912c3940b9361ac6b0175d81fb012c8634c2c3d9023fc0d86dcf73bf50e1

deps/blas.mk deps/openblas.mk

File renamed without changes.

deps/suitesparse.mk

+5-11
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ ifeq ($(USE_BLAS64), 1)
44
UMFPACK_CONFIG := -DLONGBLAS='long long'
55
CHOLMOD_CONFIG := -DLONGBLAS='long long'
66
SPQR_CONFIG := -DLONGBLAS='long long'
7-
ifeq ($(OPENBLAS_SYMBOLSUFFIX), 64_)
87
UMFPACK_CONFIG += -DSUN64
98
CHOLMOD_CONFIG += -DSUN64
109
SPQR_CONFIG += -DSUN64
1110
endif
12-
endif
1311

14-
# Disable trying to link against libmetis
12+
# Disable linking to libmetis
1513
CHOLMOD_CONFIG += -DNPARTITION
1614

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

56-
ifeq ($(USE_SYSTEM_BLAS), 0)
57-
$(BUILDDIR)/SuiteSparse-$(SUITESPARSE_VER)/build-compiled: | $(build_prefix)/manifest/openblas
58-
else ifeq ($(USE_SYSTEM_LAPACK), 0)
59-
$(BUILDDIR)/SuiteSparse-$(SUITESPARSE_VER)/build-compiled: | $(build_prefix)/manifest/lapack
60-
endif
54+
$(BUILDDIR)/SuiteSparse-$(SUITESPARSE_VER)/build-compiled: | $(build_prefix)/manifest/blastrampoline
6155

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

156-
# suitesparse depends on OpenBLAS
157-
compile-suitesparse: | $(build_prefix)/manifest/openblas
150+
# suitesparse depends on blastrampoline
151+
compile-suitesparse: | $(build_prefix)/manifest/blastrampoline
158152
endif

stdlib/LinearAlgebra/src/LinearAlgebra.jl

+48-13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Base: USE_BLAS64, abs, acos, acosh, acot, acoth, acsc, acsch, adjoint, as
1818
using Base: hvcat_fill, IndexLinear, promote_op, promote_typeof,
1919
@propagate_inbounds, @pure, reduce, typed_vcat, require_one_based_indexing
2020
using Base.Broadcast: Broadcasted, broadcasted
21+
import Libdl
2122

2223
export
2324
# Modules
@@ -433,21 +434,55 @@ function versioninfo(io::IO=stdout)
433434
println(io, "LAPACK: ",Base.liblapack_name)
434435
end
435436

436-
function __init__()
437-
try
438-
BLAS.check()
439-
if BLAS.vendor() === :mkl
440-
ccall((:MKL_Set_Interface_Layer, Base.libblas_name), Cvoid, (Cint,), USE_BLAS64 ? 1 : 0)
437+
function get_blas_lapack_path()
438+
shlib_ext = string(".", Libdl.dlext)
439+
libblas_path = joinpath(Sys.BINDIR, Base.LIBDIR, "julia", string(Base.libblas_name, shlib_ext))
440+
if !isfile(libblas_path)
441+
libblas_path = joinpath(Sys.BINDIR, Base.LIBDIR, string(Base.libblas_name, shlib_ext))
442+
if !isfile(libblas_path)
443+
libblas_path = joinpath(Sys.BINDIR, string(Base.libblas_name, shlib_ext))
444+
if !isfile(libblas_path)
445+
error("Cannot find BLAS at ", libblas_path)
446+
end
447+
end
448+
end
449+
liblapack_path = joinpath(Sys.BINDIR, Base.LIBDIR, "julia", string(Base.liblapack_name, shlib_ext))
450+
if !isfile(liblapack_path)
451+
liblapack_path = joinpath(Sys.BINDIR, Base.LIBDIR, string(Base.liblapack_name, shlib_ext))
452+
if !isfile(liblapack_path)
453+
liblapack_path = joinpath(Sys.BINDIR, string(Base.liblapack_name, shlib_ext))
454+
if !isfile(liblapack_path)
455+
error("Cannot find LAPACK at ", liblapack_path)
456+
end
441457
end
442-
Threads.resize_nthreads!(Abuf)
443-
Threads.resize_nthreads!(Bbuf)
444-
Threads.resize_nthreads!(Cbuf)
445-
catch ex
446-
Base.showerror_nostdio(ex,
447-
"WARNING: Error during initialization of module LinearAlgebra")
448458
end
449-
# register a hook to disable BLAS threading
450-
Base.at_disable_library_threading(() -> BLAS.set_num_threads(1))
459+
460+
return (libblas_path, liblapack_path)
461+
end
462+
463+
function set_blas_lapack_trampoline!(vendor, libblas_path, liblapack_path; verbose=0)
464+
BLAS.set_vendor!(vendor)
465+
ccall((:lbt_forward, "libblastrampoline"), Cvoid, (Cstring,Cint,Cint), libblas_path, 1, verbose)
466+
if liblapack_path != libblas_path
467+
ccall((:lbt_forward, "libblastrampoline"), Cvoid, (Cstring,Cint,Cint), liblapack_path, 0, verbose)
468+
end
469+
end
470+
471+
function __init__()
472+
try
473+
libblas_path, liblapack_path = get_blas_lapack_path()
474+
vendor = Base.USE_BLAS64 ? :openblas64 : :openblas
475+
set_blas_lapack_trampoline!(vendor, libblas_path, liblapack_path)
476+
BLAS.check()
477+
Threads.resize_nthreads!(Abuf)
478+
Threads.resize_nthreads!(Bbuf)
479+
Threads.resize_nthreads!(Cbuf)
480+
catch ex
481+
Base.showerror_nostdio(ex,
482+
"WARNING: Error during initialization of module LinearAlgebra")
483+
end
484+
# register a hook to disable BLAS threading
485+
Base.at_disable_library_threading(() -> BLAS.set_num_threads(1))
451486
end
452487

453488
end # module LinearAlgebra

0 commit comments

Comments
 (0)