Created
August 21, 2019 18:36
-
-
Save antoine-levitt/3e263dfe38a4435e02ac558e47a30fa9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import LinearAlgebra.BLAS | |
const libblas = Base.libblas_name | |
const liblapack = Base.liblapack_name | |
import LinearAlgebra | |
import LinearAlgebra: BlasReal, BlasComplex, BlasFloat, BlasInt, DimensionMismatch, checksquare, stride1, chkstride1, axpy! | |
import Libdl | |
function blas_transpose!(B,A) | |
ccall((BLAS.@blasfunc("domatcopy_"), libblas), Cvoid, (Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt}, Ref{Float64}, Ptr{Float64}, Ref{BlasInt}, Ptr{Float64}, | |
Ref{BlasInt}), | |
'C', | |
'T', | |
size(A,1), | |
size(A,2), | |
1.0, | |
A, | |
size(A,1), | |
B, | |
size(B,1)) | |
B | |
end | |
BLAS.set_num_threads(1) #does not seem to matter anyway | |
for i in 1:4 | |
N = rand(500:1000) | |
M = rand(500:1000) | |
# M = N #uncomment for square | |
println("$M $N") | |
A = randn(M,N) | |
B = zeros(N,M) | |
@btime blas_transpose!($B,$A) | |
C = copy(B) | |
B .= 0 | |
@btime transpose!($B,$A) | |
@assert norm(C-B) < 1e-10 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On a Haswell:
On a Sandybridge: