summarylogtreecommitdiffstats
path: root/cblas.patch
blob: c0cf0607a307d04478b2e38daaa9c1e6ab395e8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
commit 0c442318196389d653ee21eba65d8c4f7beb72a0
Author: Eli Schwartz <eschwartz@archlinux.org>
Date:   Fri Oct 5 15:52:17 2018 +0000

    Use a dedicated cblas library, that may or may not be in fact the blas one.

    Openblas can be built with statically compiled convenience copies of
    cblas, but if not, then the system libcblas.so should be used.

diff --git a/Make.inc b/Make.inc
index b00a41b356..7bc6cd69e8 100644
--- a/Make.inc
+++ b/Make.inc
@@ -886,6 +886,7 @@ endif
 ifeq ($(USE_SYSTEM_BLAS), 1)
 ifeq ($(OS), Darwin)
 USE_BLAS64 := 0
+USE_SYSTEM_CBLAS := 0
 USE_SYSTEM_LAPACK := 0
 LIBBLAS := -L$(build_libdir) -lgfortblas
 LIBBLASNAME := libgfortblas
@@ -898,12 +899,21 @@ LIBBLAS := -L$(build_shlibdir) -lopenblas
 LIBBLASNAME := libopenblas
 endif
 
-# OpenBLAS builds LAPACK as part of its build.
+# OpenBLAS builds cblas/LAPACK as part of its build.
 # We only need to build LAPACK if we are not using OpenBLAS.
 ifeq ($(USE_SYSTEM_BLAS), 0)
+LIBCBLAS := $(LIBBLAS)
+LIBCBLASNAME := $(LIBBLASNAME)
 LIBLAPACK := $(LIBBLAS)
 LIBLAPACKNAME := $(LIBBLASNAME)
 else
+ifeq ($(USE_SYSTEM_CBLAS), 1)
+LIBCBLAS ?= -lcblas
+LIBCBLASNAME ?= libcblas
+else
+LIBCBLAS := -L$(build_shlibdir) -lcblas $(LIBBLAS)
+LIBCBLASNAME := libcblas
+endif
 ifeq ($(USE_SYSTEM_LAPACK), 1)
 LIBLAPACK ?= -llapack
 LIBLAPACKNAME ?= liblapack
diff --git a/Makefile b/Makefile
index 6063e79ae9..7df60b8170 100644
--- a/Makefile
+++ b/Makefile
@@ -254,6 +254,9 @@ endif
 endif
 
 JL_PRIVATE_LIBS-$(USE_SYSTEM_BLAS) += $(LIBBLASNAME)
+ifneq ($(LIBCBLASNAME),$(LIBBLASNAME))
+JL_PRIVATE_LIBS-$(USE_SYSTEM_CBLAS) += $(LIBCBLASNAME)
+endif
 ifneq ($(LIBLAPACKNAME),$(LIBBLASNAME))
 JL_PRIVATE_LIBS-$(USE_SYSTEM_LAPACK) += $(LIBLAPACKNAME)
 endif
diff --git a/base/Makefile b/base/Makefile
index 70e6da933d..8ecfa6902b 100644
--- a/base/Makefile
+++ b/base/Makefile
@@ -42,6 +42,7 @@ else
 endif
 	@echo "const libm_name = \"$(LIBMNAME)\"" >> $@
 	@echo "const libblas_name = \"$(LIBBLASNAME)\"" >> $@
+	@echo "const libcblas_name = \"$(LIBCBLASNAME)\"" >> $@
 	@echo "const liblapack_name = \"$(LIBLAPACKNAME)\"" >> $@
 ifeq ($(USE_BLAS64), 1)
 	@echo "const USE_BLAS64 = true" >> $@
@@ -175,6 +176,9 @@ endif
 $(eval $(call symlink_system_library,libpcre2-8,PCRE))
 $(eval $(call symlink_system_library,libdSFMT,DSFMT))
 $(eval $(call symlink_system_library,$(LIBBLASNAME),BLAS))
+ifneq ($(LIBCBLASNAME),$(LIBBLASNAME))
+$(eval $(call symlink_system_library,$(LIBCBLASNAME),CBLAS))
+endif
 ifneq ($(LIBLAPACKNAME),$(LIBBLASNAME))
 $(eval $(call symlink_system_library,$(LIBLAPACKNAME),LAPACK))
 endif
diff --git a/stdlib/LinearAlgebra/src/blas.jl b/stdlib/LinearAlgebra/src/blas.jl
index fee8c9e74d..8c76d1acbf 100644
--- a/stdlib/LinearAlgebra/src/blas.jl
+++ b/stdlib/LinearAlgebra/src/blas.jl
@@ -62,6 +62,7 @@ export
 
 
 const libblas = Base.libblas_name
+const libcblas = Base.libcblas_name
 const liblapack = Base.liblapack_name
 
 import LinearAlgebra
@@ -103,6 +103,16 @@ else
     end
 end
 
+if libcblas == libblas
+     macro cblasfunc(x)
+        return @blasfunc(x)
+    end
+else
+    macro cblasfunc(x)
+        return Expr(:quote, x)
+    end
+end
+
 openblas_get_config() = strip(unsafe_string(ccall((@blasfunc(openblas_get_config), libblas), Ptr{UInt8}, () )))
 
 """
@@ -301,7 +312,7 @@ for (fname, elty) in ((:cblas_zdotc_sub,:ComplexF64),
                 #       DOUBLE PRECISION DX(*),DY(*)
         function dotc(n::Integer, DX::Union{Ptr{$elty},AbstractArray{$elty}}, incx::Integer, DY::Union{Ptr{$elty},AbstractArray{$elty}}, incy::Integer)
             result = Ref{$elty}()
-            ccall((@blasfunc($fname), libblas), Cvoid,
+            ccall((@cblasfunc($fname), libcblas), Cvoid,
                 (BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}),
                  n, DX, incx, DY, incy, result)
             result[]
@@ -319,7 +330,7 @@ for (fname, elty) in ((:cblas_zdotu_sub,:ComplexF64),
                 #       DOUBLE PRECISION DX(*),DY(*)
         function dotu(n::Integer, DX::Union{Ptr{$elty},AbstractArray{$elty}}, incx::Integer, DY::Union{Ptr{$elty},AbstractArray{$elty}}, incy::Integer)
             result = Ref{$elty}()
-            ccall((@blasfunc($fname), libblas), Cvoid,
+            ccall((@cblasfunc($fname), libcblas), Cvoid,
                 (BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}),
                  n, DX, incx, DY, incy, result)
             result[]