Skip to content

Commit bd9b63a

Browse files
committed
add blasfunc for appending suffix to all blas and lapack symbols
(manual backport of 02ff762)
1 parent 12797db commit bd9b63a

File tree

3 files changed

+159
-154
lines changed

3 files changed

+159
-154
lines changed

base/linalg/blas.jl

+40-39
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module BLAS
22

3-
import Base.copy!
3+
import Base: copy!, blasfunc
4+
45
export
56
# Level 1
67
asum,
@@ -43,14 +44,14 @@ import ..LinAlg: BlasReal, BlasComplex, BlasFloat, BlasChar, BlasInt, blas_int,
4344

4445
# Level 1
4546
## copy
46-
for (fname, elty) in ((:dcopy_,:Float64),
47+
for (fname, elty) in ((:dcopy_,:Float64),
4748
(:scopy_,:Float32),
48-
(:zcopy_,:Complex128),
49+
(:zcopy_,:Complex128),
4950
(:ccopy_,:Complex64))
5051
@eval begin
5152
# SUBROUTINE DCOPY(N,DX,INCX,DY,INCY)
5253
function blascopy!(n::Integer, DX::Union(Ptr{$elty},Array{$elty}), incx::Integer, DY::Union(Ptr{$elty},Array{$elty}), incy::Integer)
53-
ccall(($(string(fname)),libblas), Void,
54+
ccall(($(blasfunc(fname)), libblas), Void,
5455
(Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
5556
&n, DX, &incx, DY, &incy)
5657
DY
@@ -59,14 +60,14 @@ for (fname, elty) in ((:dcopy_,:Float64),
5960
end
6061

6162
## scal
62-
for (fname, elty) in ((:dscal_,:Float64),
63+
for (fname, elty) in ((:dscal_,:Float64),
6364
(:sscal_,:Float32),
64-
(:zscal_,:Complex128),
65+
(:zscal_,:Complex128),
6566
(:cscal_,:Complex64))
6667
@eval begin
6768
# SUBROUTINE DSCAL(N,DA,DX,INCX)
6869
function scal!(n::Integer, DA::$elty, DX::Union(Ptr{$elty},Array{$elty}), incx::Integer)
69-
ccall(($(string(fname)),libblas), Void,
70+
ccall(($(blasfunc(fname)), libblas), Void,
7071
(Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}),
7172
&n, &DA, DX, &incx)
7273
DX
@@ -79,7 +80,7 @@ for (fname, elty, celty) in ((:sscal_, :Float32, :Complex64),
7980
(:dscal_, :Float64, :Complex128))
8081
@eval begin
8182
function scal!(n::Integer, DA::$elty, DX::Union(Ptr{$celty},Array{$celty}), incx::Integer)
82-
ccall(($(string(fname)),libblas), Void,
83+
ccall(($(blasfunc(fname)), libblas), Void,
8384
(Ptr{BlasInt}, Ptr{$elty}, Ptr{$celty}, Ptr{BlasInt}),
8485
&(2*n), &DA, DX, &incx)
8586
DX
@@ -88,7 +89,7 @@ for (fname, elty, celty) in ((:sscal_, :Float32, :Complex64),
8889
end
8990

9091
## dot
91-
for (fname, elty) in ((:ddot_,:Float64),
92+
for (fname, elty) in ((:ddot_,:Float64),
9293
(:sdot_,:Float32))
9394
@eval begin
9495
# DOUBLE PRECISION FUNCTION DDOT(N,DX,INCX,DY,INCY)
@@ -98,7 +99,7 @@ for (fname, elty) in ((:ddot_,:Float64),
9899
# * .. Array Arguments ..
99100
# DOUBLE PRECISION DX(*),DY(*)
100101
function dot(n::Integer, DX::Union(Ptr{$elty},Array{$elty}), incx::Integer, DY::Union(Ptr{$elty},Array{$elty}), incy::Integer)
101-
ccall(($(string(fname)),libblas), $elty,
102+
ccall(($(blasfunc(fname)), libblas), $elty,
102103
(Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
103104
&n, DX, &incx, DY, &incy)
104105
end
@@ -115,7 +116,7 @@ for (fname, elty) in ((:cblas_zdotc_sub,:Complex128),
115116
# DOUBLE PRECISION DX(*),DY(*)
116117
function dotc(n::Integer, DX::Union(Ptr{$elty},Array{$elty}), incx::Integer, DY::Union(Ptr{$elty},Array{$elty}), incy::Integer)
117118
result = Array($elty, 1)
118-
ccall(($(string(fname)),libblas), $elty,
119+
ccall(($(blasfunc(fname)), libblas), $elty,
119120
(BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}),
120121
n, DX, incx, DY, incy, result)
121122
result[1]
@@ -133,7 +134,7 @@ for (fname, elty) in ((:cblas_zdotu_sub,:Complex128),
133134
# DOUBLE PRECISION DX(*),DY(*)
134135
function dotu(n::Integer, DX::Union(Ptr{$elty},Array{$elty}), incx::Integer, DY::Union(Ptr{$elty},Array{$elty}), incy::Integer)
135136
result = Array($elty, 1)
136-
ccall(($(string(fname)),libblas), $elty,
137+
ccall(($(blasfunc(fname)), libblas), $elty,
137138
(BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}),
138139
n, DX, incx, DY, incy, result)
139140
result[1]
@@ -164,7 +165,7 @@ for (fname, elty, ret_type) in ((:dnrm2_,:Float64,:Float64),
164165
@eval begin
165166
# SUBROUTINE DNRM2(N,X,INCX)
166167
function nrm2(n::Integer, X::Union(Ptr{$elty},StridedVector{$elty}), incx::Integer)
167-
ccall(($(string(fname)),libblas), $ret_type,
168+
ccall(($(blasfunc(fname)), libblas), $ret_type,
168169
(Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
169170
&n, X, &incx)
170171
end
@@ -181,7 +182,7 @@ for (fname, elty, ret_type) in ((:dasum_,:Float64,:Float64),
181182
@eval begin
182183
# SUBROUTINE ASUM(N, X, INCX)
183184
function asum(n::Integer, X::Union(Ptr{$elty},StridedVector{$elty}), incx::Integer)
184-
ccall(($(string(fname)),libblas), $ret_type,
185+
ccall(($(blasfunc(fname)), libblas), $ret_type,
185186
(Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
186187
&n, X, &incx)
187188
end
@@ -204,7 +205,7 @@ for (fname, elty) in ((:daxpy_,:Float64),
204205
#* .. Array Arguments ..
205206
# DOUBLE PRECISION DX(*),DY(*)
206207
function axpy!(n::Integer, alpha::($elty), dx::Union(Ptr{$elty},Array{$elty}), incx::Integer, dy::Union(Ptr{$elty},Array{$elty}), incy::Integer)
207-
ccall(($(string(fname)),libblas), Void,
208+
ccall(($(blasfunc(fname)), libblas), Void,
208209
(Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
209210
&n, &alpha, dx, &incx, dy, &incy)
210211
dy
@@ -235,7 +236,7 @@ for (fname, elty) in ((:idamax_,:Float64),
235236
(:icamax_,:Complex64))
236237
@eval begin
237238
function iamax(n::BlasInt, dx::Union(StridedVector{$elty}, Ptr{$elty}), incx::BlasInt)
238-
ccall(($(string(fname)), libblas),BlasInt,
239+
ccall(($(blasfunc(fname)), libblas),BlasInt,
239240
(Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
240241
&n, dx, &incx)
241242
end
@@ -261,7 +262,7 @@ for (fname, elty) in ((:dgemv_,:Float64),
261262
function gemv!(trans::BlasChar, alpha::($elty), A::StridedVecOrMat{$elty}, X::StridedVector{$elty}, beta::($elty), Y::StridedVector{$elty})
262263
m,n = size(A,1),size(A,2)
263264
length(X) == (trans == 'N' ? n : m) && length(Y) == (trans == 'N' ? m : n) || throw(DimensionMismatch(""))
264-
ccall(($(string(fname)),libblas), Void,
265+
ccall(($(blasfunc(fname)), libblas), Void,
265266
(Ptr{Uint8}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty},
266267
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
267268
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}),
@@ -280,9 +281,9 @@ for (fname, elty) in ((:dgemv_,:Float64),
280281
end
281282

282283
### (GB) general banded matrix-vector multiplication
283-
for (fname, elty) in ((:dgbmv_,:Float64),
284+
for (fname, elty) in ((:dgbmv_,:Float64),
284285
(:sgbmv_,:Float32),
285-
(:zgbmv_,:Complex128),
286+
(:zgbmv_,:Complex128),
286287
(:cgbmv_,:Complex64))
287288
@eval begin
288289
# SUBROUTINE DGBMV(TRANS,M,N,KL,KU,ALPHA,A,LDA,X,INCX,BETA,Y,INCY)
@@ -293,7 +294,7 @@ for (fname, elty) in ((:dgbmv_,:Float64),
293294
# * .. Array Arguments ..
294295
# DOUBLE PRECISION A(LDA,*),X(*),Y(*)
295296
function gbmv!(trans::BlasChar, m::Integer, kl::Integer, ku::Integer, alpha::($elty), A::StridedMatrix{$elty}, x::StridedVector{$elty}, beta::($elty), y::StridedVector{$elty})
296-
ccall(($(string(fname)),libblas), Void,
297+
ccall(($(blasfunc(fname)), libblas), Void,
297298
(Ptr{Uint8}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt},
298299
Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt},
299300
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty},
@@ -332,7 +333,7 @@ for (fname, elty) in ((:dsymv_,:Float64),
332333
m, n = size(A)
333334
if m != n throw(DimensionMismatch("Matrix A is $m by $n but must be square")) end
334335
if m != length(x) || m != length(y) throw(DimensionMismatch("")) end
335-
ccall(($(string(fname)),libblas), Void,
336+
ccall(($(blasfunc(fname)), libblas), Void,
336337
(Ptr{Uint8}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty},
337338
Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty},
338339
Ptr{$elty}, Ptr{BlasInt}),
@@ -351,9 +352,9 @@ for (fname, elty) in ((:dsymv_,:Float64),
351352
end
352353

353354
### sbmv, (SB) symmetric banded matrix-vector multiplication
354-
for (fname, elty) in ((:dsbmv_,:Float64),
355+
for (fname, elty) in ((:dsbmv_,:Float64),
355356
(:ssbmv_,:Float32),
356-
(:zsbmv_,:Complex128),
357+
(:zsbmv_,:Complex128),
357358
(:csbmv_,:Complex64))
358359
@eval begin
359360
# SUBROUTINE DSBMV(UPLO,N,K,ALPHA,A,LDA,X,INCX,BETA,Y,INCY)
@@ -364,7 +365,7 @@ for (fname, elty) in ((:dsbmv_,:Float64),
364365
# * .. Array Arguments ..
365366
# DOUBLE PRECISION A(LDA,*),X(*),Y(*)
366367
function sbmv!(uplo::BlasChar, k::Integer, alpha::($elty), A::StridedMatrix{$elty}, x::StridedVector{$elty}, beta::($elty), y::StridedVector{$elty})
367-
ccall(($(string(fname)),libblas), Void,
368+
ccall(($(blasfunc(fname)), libblas), Void,
368369
(Ptr{Uint8}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty},
369370
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
370371
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}),
@@ -400,7 +401,7 @@ for (fname, elty) in ((:dtrmv_,:Float64),
400401
if n != length(x)
401402
throw(DimensionMismatch("length(x)=$(length(x))does not match size(A)=$(size(A))"))
402403
end
403-
ccall(($(string(fname)), libblas), Void,
404+
ccall(($(blasfunc(fname)), libblas), Void,
404405
(Ptr{Uint8}, Ptr{Uint8}, Ptr{Uint8}, Ptr{BlasInt},
405406
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
406407
&uplo, &trans, &diag, &n,
@@ -427,7 +428,7 @@ for (fname, elty) in ((:dtrsv_,:Float64),
427428
function trsv!(uplo::Char, trans::Char, diag::Char, A::StridedMatrix{$elty}, x::StridedVector{$elty})
428429
n = chksquare(A)
429430
n==length(x) || throw(DimensionMismatch("size of A is $n != length(x) = $(length(x))"))
430-
ccall(($(string(fname)), libblas), Void,
431+
ccall(($(blasfunc(fname)), libblas), Void,
431432
(Ptr{Uint8}, Ptr{Uint8}, Ptr{Uint8}, Ptr{BlasInt},
432433
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
433434
&uplo, &trans, &diag, &n,
@@ -450,7 +451,7 @@ for (fname, elty) in ((:dger_,:Float64),
450451
m, n = size(A)
451452
m == length(x) || throw(DimensionMismatch(""))
452453
n == length(y) || throw(DimensionMismatch(""))
453-
ccall(($(string(fname)), libblas), Void,
454+
ccall(($(blasfunc(fname)), libblas), Void,
454455
(Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty},
455456
Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty},
456457
Ptr{BlasInt}),
@@ -471,7 +472,7 @@ for (fname, elty) in ((:dsyr_,:Float64),
471472
function syr!(uplo::Char, α::$elty, x::StridedVector{$elty}, A::StridedMatrix{$elty})
472473
n = chksquare(A)
473474
length(x) == n || throw(DimensionMismatch("Length of vector must be the same as the matrix dimensions"))
474-
ccall(($(string(fname)), libblas), Void,
475+
ccall(($(blasfunc(fname)), libblas), Void,
475476
(Ptr{Uint8}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty},
476477
Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
477478
&uplo, &n, &α, x,
@@ -488,7 +489,7 @@ for (fname, elty) in ((:zher_,:Complex128),
488489
function her!(uplo::Char, α::$elty, x::StridedVector{$elty}, A::StridedMatrix{$elty})
489490
n = chksquare(A)
490491
length(x) == A || throw(DimensionMismatch("Length of vector must be the same as the matrix dimensions"))
491-
ccall(($(string(fname)), libblas), Void,
492+
ccall(($(blasfunc(fname)), libblas), Void,
492493
(Ptr{Uint8}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty},
493494
Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
494495
&uplo, &n, &α, x,
@@ -523,7 +524,7 @@ for (gemm, elty) in
523524
if m != size(C,1) || n != size(C,2)
524525
throw(DimensionMismatch(""))
525526
end
526-
ccall(($(string(gemm)),libblas), Void,
527+
ccall(($(blasfunc(gemm)), libblas), Void,
527528
(Ptr{Uint8}, Ptr{Uint8}, Ptr{BlasInt}, Ptr{BlasInt},
528529
Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt},
529530
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty},
@@ -560,7 +561,7 @@ for (mfname, elty) in ((:dsymm_,:Float64),
560561
m, n = size(C)
561562
j = chksquare(A)
562563
if j != (side == 'L' ? m : n) || size(B,2) != n throw(DimensionMismatch("")) end
563-
ccall(($(string(mfname)),libblas), Void,
564+
ccall(($(blasfunc(mfname)), libblas), Void,
564565
(Ptr{Uint8}, Ptr{Uint8}, Ptr{BlasInt}, Ptr{BlasInt},
565566
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty},
566567
Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}),
@@ -598,7 +599,7 @@ for (fname, elty) in ((:dsyrk_,:Float64),
598599
nn = size(A, trans == 'N' ? 1 : 2)
599600
if nn != n throw(DimensionMismatch("syrk!")) end
600601
k = size(A, trans == 'N' ? 2 : 1)
601-
ccall(($(string(fname)),libblas), Void,
602+
ccall(($(blasfunc(fname)), libblas), Void,
602603
(Ptr{Uint8}, Ptr{Uint8}, Ptr{BlasInt}, Ptr{BlasInt},
603604
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty},
604605
Ptr{$elty}, Ptr{BlasInt}),
@@ -631,7 +632,7 @@ for (fname, elty) in ((:zherk_,:Complex128), (:cherk_,:Complex64))
631632
n = chksquare(C)
632633
n == size(A, trans == 'N' ? 1 : 2) || throw(DimensionMismatch("herk!"))
633634
k = size(A, trans == 'N' ? 2 : 1)
634-
ccall(($(string(fname)),libblas), Void,
635+
ccall(($(blasfunc(fname)), libblas), Void,
635636
(Ptr{Uint8}, Ptr{Uint8}, Ptr{BlasInt}, Ptr{BlasInt},
636637
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty},
637638
Ptr{$elty}, Ptr{BlasInt}),
@@ -670,7 +671,7 @@ for (fname, elty) in ((:dsyr2k_,:Float64),
670671
nn = size(A, trans == 'N' ? 1 : 2)
671672
if nn != n throw(DimensionMismatch("syr2k!")) end
672673
k = size(A, trans == 'N' ? 2 : 1)
673-
ccall(($(string(fname)),Base.libblas_name), Void,
674+
ccall(($(blasfunc(fname)),Base.libblas_name), Void,
674675
(Ptr{Uint8}, Ptr{Uint8}, Ptr{BlasInt}, Ptr{BlasInt},
675676
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty},
676677
Ptr{$elty}, Ptr{BlasInt}),
@@ -706,7 +707,7 @@ for (fname, elty1, elty2) in ((:zher2k_,:Complex128,:Float64), (:cher2k_,:Comple
706707
n = chksquare(C)
707708
n == size(A, trans == 'N' ? 1 : 2) || throw(DimensionMismatch("her2k!"))
708709
k = size(A, trans == 'N' ? 2 : 1)
709-
ccall(($(string(fname)),libblas), Void,
710+
ccall(($(blasfunc(fname)), libblas), Void,
710711
(Ptr{Uint8}, Ptr{Uint8}, Ptr{BlasInt}, Ptr{BlasInt},
711712
Ptr{$elty1}, Ptr{$elty1}, Ptr{BlasInt}, Ptr{$elty1}, Ptr{BlasInt},
712713
Ptr{$elty2}, Ptr{$elty1}, Ptr{BlasInt}),
@@ -737,7 +738,7 @@ for (fname, elty) in ((:dgbmv_,:Float64), (:sgbmv_,:Float32),
737738
function gbmv!(trans::BlasChar, m::Integer, kl::Integer, ku::Integer,
738739
alpha::($elty), A::StridedMatrix{$elty}, x::StridedVector{$elty},
739740
beta::($elty), y::StridedVector{$elty})
740-
ccall(($(string(fname)),libblas), Void,
741+
ccall(($(blasfunc(fname)), libblas), Void,
741742
(Ptr{Uint8}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt},
742743
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
743744
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}),
@@ -772,7 +773,7 @@ for (fname, elty) in ((:dsbmv_,:Float64), (:ssbmv_,:Float32),
772773
function sbmv!(uplo::BlasChar, k::Integer,
773774
alpha::($elty), A::StridedMatrix{$elty}, x::StridedVector{$elty},
774775
beta::($elty), y::StridedVector{$elty})
775-
ccall(($(string(fname)),libblas), Void,
776+
ccall(($(blasfunc(fname)), libblas), Void,
776777
(Ptr{Uint8}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt},
777778
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}),
778779
&uplo, &size(A,2), &k, &alpha, A, &max(1,stride(A,2)), x, &stride(x,1),
@@ -809,7 +810,7 @@ for (mmname, smname, elty) in
809810
m, n = size(B)
810811
nA = chksquare(A)
811812
if nA != (side == 'L' ? m : n) throw(DimensionMismatch("trmm!")) end
812-
ccall(($(string(mmname)), libblas), Void,
813+
ccall(($(blasfunc(mmname)), libblas), Void,
813814
(Ptr{Uint8}, Ptr{Uint8}, Ptr{Uint8}, Ptr{Uint8}, Ptr{BlasInt}, Ptr{BlasInt},
814815
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
815816
&side, &uplo, &transa, &diag, &m, &n,
@@ -832,7 +833,7 @@ for (mmname, smname, elty) in
832833
m, n = size(B)
833834
k = chksquare(A)
834835
k==(side == 'L' ? m : n) || throw(DimensionMismatch("size of A is $n, size(B)=($m,$n) and transa='$transa'"))
835-
ccall(($(string(smname)), libblas), Void,
836+
ccall(($(blasfunc(smname)), libblas), Void,
836837
(Ptr{Uint8}, Ptr{Uint8}, Ptr{Uint8}, Ptr{Uint8},
837838
Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty},
838839
Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),

0 commit comments

Comments
 (0)