Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: continuing higher-level wrappers #32

Open
wants to merge 133 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
def834a
Fix two problems: wrong path to Dense.jl and lack of 'export magmaInit'
Jun 18, 2019
4f6750e
Change the "src/dense/Dense.jl" to "src/dense/dense.jl"
Jun 19, 2019
29a72ca
Fix the bug hidden in the svd.jl. Add the test for Cgesvd & Zgesvd
Jun 19, 2019
864363a
ADD the codes in JuliaGPU/MAGMA.jl to our current files
Jun 20, 2019
9a504f0
Try adding gpu interface but errored
Jun 21, 2019
9f09e5f
Correct the setmatrix, setvector and getvector
Jun 21, 2019
ba1c33e
Delete the trial of adding GPU interfaces for gesvd. There is no gpu …
Jun 22, 2019
dc208ae
Add gesdd, not finished yet
Jun 23, 2019
7fac92f
Continue
Jun 23, 2019
181c9b4
Edit gesdd
Jun 26, 2019
ecff1fd
Fix some bugs
Jun 26, 2019
3fbae75
Add 'export gesdd!' to MAGMA.jl
Jun 26, 2019
ad03663
Add test for gesdd!
Jun 26, 2019
6d52fb5
Add magma_malloc_pinned
Jun 28, 2019
7d8a230
Add a trial function for GPU gesdd
Jul 5, 2019
d07758f
Merge the judgment of A's type into the original wrapper
Jul 5, 2019
f2cea2d
The communication between CPU and GPU can be easily carried through s…
Jul 5, 2019
23f5277
Correct the naming convention for types
Jul 7, 2019
2e441b5
Delete some unnecessary things
Jul 7, 2019
b22ae4e
Polish some trivia
Jul 7, 2019
587a7ed
Fix some bugs
Jul 7, 2019
db829be
Add trial codes for GPU interface
Jul 7, 2019
7d27ce6
Tried some other ways but still bugs
Jul 7, 2019
5c15d63
Fixed
Jul 7, 2019
1f722a2
Simplify the process of converting in src
Jul 14, 2019
3314199
Add the same process of converting for gesvd along with the comments
Jul 14, 2019
31faa65
Delete useless codes
Jul 14, 2019
d765d30
Delete useless codes
Jul 14, 2019
3ced1db
Add GPU interface testing for gesvd
Jul 14, 2019
5a190d1
Furtherly polished the codes for testing and added some comments
Jul 16, 2019
86c3dda
Add some comments
Jul 16, 2019
f235236
Add some comments for gesdd!
Jul 16, 2019
00d4528
Merge branch 'master' into jerry/add_magma_malloc
Jul 16, 2019
194c43a
Simplify the testing procedure
Jul 18, 2019
648eadf
Add gebrd wrapper. Delete unnecessary parts.
Jul 18, 2019
d4a01a3
Fix gebrd wrapper and its testing
Jul 18, 2019
c758419
Delete something only for testing which actually do nothing
Jul 19, 2019
412c0c0
Fix a bug hidden in the testing codes. Trim some unnecessary parts.
Jul 19, 2019
8e616f3
Add linearsystemsolver.jl file
Aug 5, 2019
8f48cd7
Draft for linear solvers
Aug 5, 2019
c4d0cb6
Add a possibly useful build file for OpenBLAS
Aug 7, 2019
4ed5fbe
Test the workflow of deps/build.jl
Aug 7, 2019
fa1737c
WIP: debugging some problems
Aug 10, 2019
b9b54b1
Cleaned some bugs and now the CPU version works. Later comes the GPU …
Aug 10, 2019
4c12bb6
Add LinearAlgebra into the dependencies since we are gonna use some f…
Aug 11, 2019
eb9a601
Merge branch 'master' into jerry/add_magma_sgels
Roger-luo Aug 11, 2019
e2c9d10
WIP: Still have the problem "ReadOnlyMemoryError()" when ccall the gp…
Aug 12, 2019
3b7674e
Merge branch 'jerry/add_magma_sgels' of https://github.com/Roger-luo/…
Aug 12, 2019
ed2be06
WIP: debugging gels_gpu
Aug 12, 2019
02729ed
WIP: IDKY but that bug suddenly disappears when I write the ccall exp…
Aug 12, 2019
3d75045
Debugged. Now everything seems fine. Need to clean.
Aug 12, 2019
db49d05
Newly create a magmafunc_gpu function to create a gpu subroutine name…
Aug 13, 2019
db621ab
Simplify something
Aug 13, 2019
0f27099
Cleaned some redundant codes
Aug 13, 2019
a52f06b
WIP: testing gesv
Aug 14, 2019
cd28b7b
Finished the wrappers for gesv
Aug 14, 2019
7f3a1ad
Merge branch 'master' into jerry/add_magma_gesv
Aug 14, 2019
2b85e5a
Multidispatch gesvd! .Delete the cmplx-testing.
Aug 14, 2019
49aa810
Multidispatch gesdd. Add prefix 'magma_' to gesvd and gesdd
Aug 14, 2019
0f980f3
Fix bugs
Aug 15, 2019
6a5f677
Multidispatch gels
Aug 15, 2019
a78db12
Multipatch gesv
Aug 15, 2019
d5df7c1
Merge branch 'master' into jerry/polish_wrappers
Aug 15, 2019
3b3f61c
Testing codes for clang
Aug 18, 2019
499e683
Cleaned some repeated wrappers
Aug 18, 2019
b0c53ee
Merge branch 'master' into jerry/clang_wrappers
Aug 19, 2019
280c1f9
Add a simple README for src/clang/
Aug 20, 2019
81a98e3
Removed unnecessary file: enums.jl
Aug 24, 2019
c04d6c1
Exported magma_init
Aug 24, 2019
1aa16ad
Replaced magmaInit with magma_init, in test/dense/svd.jl
Aug 24, 2019
74d3873
Replaced in linearsystemsolver.jl
Aug 24, 2019
a7be96e
Removed the definition of magmaInit in MAGMA.jl
Aug 24, 2019
c0b8fd0
export magma_finalize
Aug 24, 2019
c7a7545
Replaced magmaFinalize with magma_finalize
Aug 24, 2019
ecc9a8e
Deleted magmaFinalize
Aug 24, 2019
0771b5b
Deleted unnecessary comments
Aug 24, 2019
9a598b1
Moved some 'using ***' to runtests.jl
Aug 24, 2019
b9fa5cc
Moved some 'using' to runtests.jl
Aug 24, 2019
b16b257
Deleted unnecessary file: libmagma_common.jl
Aug 24, 2019
838d22f
Renamed 'libmagma_common_v2.jl' as 'libmagma_common.jl'
Aug 24, 2019
22ab054
Deleted unnecessary comments
Aug 24, 2019
08eb7c3
Test the output of @magmafunc(gesvd)
JerryChen97 Aug 24, 2019
f732d10
Test passsed
JerryChen97 Aug 24, 2019
c8220dc
Edited tests for both gesvd and gesdd
JerryChen97 Aug 24, 2019
dd61a57
Edited for gebrd
JerryChen97 Aug 24, 2019
eaa0b31
Replaced all the Ptr with PtrOrCuPtr
JerryChen97 Aug 24, 2019
3d5dfaa
Deleted some unnecessary codes
JerryChen97 Aug 25, 2019
3b7280a
Constructed a type list for magma common usage
JerryChen97 Aug 25, 2019
fb6da0f
Changed the meta-prog into a more compact form
JerryChen97 Aug 25, 2019
7d2c595
Added the higher-level wrappers for getri with testing
JerryChen97 Aug 26, 2019
fcf9015
Cleaned some unnecessary things
JerryChen97 Aug 26, 2019
f108f75
Changed into more compact form
JerryChen97 Aug 26, 2019
1c58562
Debugging getrs
JerryChen97 Aug 26, 2019
570d8fa
Remained some bugs, but they seemed to be of MAGMA
JerryChen97 Aug 26, 2019
60784d9
Added the higher-level wrappers for getrf
JerryChen97 Aug 26, 2019
d8d5493
Add testing code for getrf individually
JerryChen97 Aug 26, 2019
8ddaf8b
Export getrf!
JerryChen97 Aug 26, 2019
3c9c84c
Changed the getrs testings into 'broken'
JerryChen97 Aug 26, 2019
34bc9c1
Improved the comments
JerryChen97 Aug 26, 2019
928f89d
Moved the func name eval to the outer side of for loop
JerryChen97 Aug 26, 2019
4321ac9
Fixed the bug of getrs
JerryChen97 Aug 26, 2019
aa77819
Merge branch 'master' into jerry/polish_before_more_wrappers
JerryChen97 Aug 26, 2019
875c441
Deleted some unnecessary sentences in linearsystemsolver.jl
JerryChen97 Aug 27, 2019
a6ec3c2
Deleted some unnecessary code
JerryChen97 Aug 27, 2019
974d9bc
Trimed more in the testing codes
JerryChen97 Aug 27, 2019
38af544
Add wrappers for getrf_gpu
JerryChen97 Aug 27, 2019
307ea66
Deleted two left 'isGPU' and add gerbt wrappers
JerryChen97 Aug 27, 2019
27c1e80
Modified the gerbt
JerryChen97 Aug 27, 2019
d2affb6
Edited the testing for gesv_rbt
JerryChen97 Aug 27, 2019
242586b
Corrected the gesv_rbt wrappers
JerryChen97 Aug 27, 2019
65f806e
Add wrappers for geqrsv
JerryChen97 Aug 28, 2019
cd1876b
Adding the posv wrappers
JerryChen97 Aug 28, 2019
6ded754
Add using require_one_based_indexing
JerryChen97 Aug 28, 2019
67f5a72
Add definition for require...
JerryChen97 Aug 28, 2019
4195cf0
Added the testing code from LAPACK
JerryChen97 Aug 28, 2019
6d584e0
Trimed the complex testing for gesv_rbt for convenience
JerryChen97 Aug 28, 2019
18836eb
Finished posv wrappers
JerryChen97 Aug 28, 2019
4e6981f
Adding hesv wrappers
JerryChen97 Aug 28, 2019
8abf713
Adding tests for hesv
JerryChen97 Aug 28, 2019
e7a19a5
Adding the sysv wrappers
JerryChen97 Aug 28, 2019
26f16cb
Added the tests for sysv
JerryChen97 Aug 28, 2019
573325b
Created factorization.jl
JerryChen97 Aug 29, 2019
e747109
Edited
JerryChen97 Aug 29, 2019
054d964
Added geqrf wrappers
JerryChen97 Aug 30, 2019
cd180a5
Added tests for geqrf
JerryChen97 Aug 30, 2019
a918026
Added several other wrappers of factorization
JerryChen97 Aug 30, 2019
d267458
Add the file for wrappers of eigenvalues subroutines
JerryChen97 Sep 1, 2019
c87163e
Set up the functions' name to wrap
JerryChen97 Sep 1, 2019
1982953
Added geev wrapper's src code
JerryChen97 Sep 1, 2019
44fe5a8
Added the testing code
JerryChen97 Sep 1, 2019
371a919
Fixed
JerryChen97 Sep 1, 2019
7283370
Added gehrd and fixed
JerryChen97 Sep 1, 2019
0a0c7f9
Deleted some unnecessary parts
JerryChen97 Sep 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/MAGMA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,32 @@ module MAGMA
using CUDAdrv, CUDAapi, CUDAnative, CuArrays
using CEnum

# some useful functions from LinearAlgebra for some intermediate processes
using LinearAlgebra: triu, tril, dot, checksquare, chkstride1

# some useful const definitions or utility functions
export magmaTypeTuple, magmaTypeDict, magmaTypeList
export chkfinite

# export wrappers in svds
export magma_gels!, magma_gesvd!, magma_gesdd!, magmaInit, magmaFinalize, magma_gebrd!

# export wrappers in linearsystemsolver
export magma_gesv!, magma_getri!, magma_getrs!, magma_getrf!
export magma_gesv!, magma_getri!, magma_getrs!, magma_getrf!, magma_gerbt!, magma_gesv_rbt!, magma_geqrsv!
export magma_posv!, magma_hesv!, magma_sysv!

# export wrappers in factorization
export magma_geqrf!, magma_geqlf!, magma_gelqf!

# export wrappers in eigenvalues
export magma_geev!, magma_gehrd!

# export some wrappers in clang auto-generation
export magma_init, magma_finalize

#* some extra equipments
require_one_based_indexing(A...) = !has_offset_axes(A...) || throw(ArgumentError("offset arrays are not supported but got an array with index other than 1"))

include("clang/libmagma_common.jl")
include("clang/libmagma_api.jl")

Expand All @@ -34,11 +49,26 @@ macro magmafunc_nb(function_name)
return Expr(:quote, Symbol("magma_get_", function_name, "_nb"))
end

macro magmafunc_generic(function_name, str)
return Expr(:quote, Symbol(function_name, str))
end

const magmaTypeTuple= (Float32, Float64, ComplexF32, ComplexF64)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is sufficient. you don't need to parse strings manually.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is sufficient. you don't need to parse strings manually.

Ah cool. There is some improvisation made by me a long time ago for convenience. Thank you for your careful checking and improvement.

const magmaTypeList = ["Float32", "Float64", "ComplexF32", "ComplexF64"]
const magmaTypeList_real = ["Float32", "Float64"]
const magmaTypeList_complex = ["ComplexF32", "ComplexF64"]
const magmaTypeDict = Dict(Float32=>"s", Float64=>"d", ComplexF32=>"c", ComplexF64=>"z",
"Float32"=>"s", "Float64"=>"d", "ComplexF32"=>"c", "ComplexF64"=>"z",)

function chkfinite(A::AbstractMatrix)
for a in A
if !isfinite(a)
throw(ArgumentError("matrix contains Infs or NaNs"))
end
end
return true
end

# include the files of subroutines
include("dense/dense.jl")

Expand Down
2 changes: 2 additions & 0 deletions src/dense/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ subsetrows(X::AbstractMatrix, Y::AbstractArray, k) = Y[1:k, :]

include("svd.jl")
include("linearsystemsolver.jl")
include("factorization.jl")
include("eigenvalues.jl")
141 changes: 141 additions & 0 deletions src/dense/eigenvalues.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
const function_list_eigenvalues = ("geev", "gehrd",
"heevx", "heevd", "heevdx", "heevr", "hetrd",
"hegvx", "hegvd", "hegvdx", "hegvr")
macro char_to_vec(op)
return op == 'V' ? MagmaVec : MagmaNoVec
end
macro type_to_rtype(type)
return type == Float64 || type == ComplexF64 ? Float64 : Float32
end

for type in magmaTypeList_real
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to create the symbols, just use type.

# create the symbols for element types
elty = Symbol(type)
relty= Symbol(@type_to_rtype(type))
# generate the symbol variables for our wrappers
for func_name in function_list_eigenvalues
@eval $(Symbol(func_name)) = (Symbol(magmaTypeDict[$type], $func_name))
end

@eval begin

function magma_geev!(jobvl::AbstractChar, jobvr::AbstractChar, A::AbstractMatrix{$elty})
magma_init()
chkstride1(A)
n = checksquare(A)
chkfinite(A) # balancing routines don't support NaNs and Infs
lvecs = jobvl == 'V'
rvecs = jobvr == 'V'
VL = similar(A, $elty, (n, lvecs ? n : 0))
VR = similar(A, $elty, (n, rvecs ? n : 0))
WR = similar(A, $elty, n)
WI = similar(A, $elty, n)
work = Vector{$elty}(undef, 1)
lwork = Cint(-1)
info = Ref{Cint}()
lda = max(1, stride(A, 2))

jobvl = @char_to_vec(jobvl)
jobvr = @char_to_vec(jobvr)
func = eval(@magmafunc($geev))
for i = 1:2 # first call returns lwork as work[1]
func(jobvl, jobvr, n, A, lda, WR, WI, VL, n,
VR, n, work, lwork, info)
if i == 1
lwork = ceil(Int, real(work[1]))
resize!(work, lwork)
end
end
magma_finalize()
(WR, WI, VL, VR)
end

end

end

for type in magmaTypeList_complex
# create the symbols for element types
elty = Symbol(type)
relty= Symbol(@type_to_rtype(type))
# generate the symbol variables for our wrappers
for func_name in function_list_eigenvalues
@eval $(Symbol(func_name)) = (Symbol(magmaTypeDict[$type], $func_name))
end

@eval begin

function magma_geev!(jobvl::AbstractChar, jobvr::AbstractChar, A::AbstractMatrix{$elty})
magma_init()
chkstride1(A)
n = checksquare(A)
chkfinite(A) # balancing routines don't support NaNs and Infs
lvecs = jobvl == 'V'
rvecs = jobvr == 'V'
VL = similar(A, $elty, (n, lvecs ? n : 0))
VR = similar(A, $elty, (n, rvecs ? n : 0))
W = similar(A, $elty, n)
rwork = similar(A, $relty, 2n)
work = Vector{$elty}(undef, 1)
lwork = Cint(-1)
info = Ref{Cint}()
lda = max(1, stride(A, 2))

jobvl = @char_to_vec(jobvl)
jobvr = @char_to_vec(jobvr)
func = eval(@magmafunc($geev))
for i = 1:2 # first call returns lwork as work[1]
func(jobvl, jobvr, n, A, lda, W, VL, n, VR, n,
work, lwork, rwork, info)
if i == 1
lwork = ceil(Int, real(work[1]))
resize!(work, lwork)
end
end
magma_finalize()
(W, VL, VR)
end

end

end

for type in magmaTypeList
# create the symbols for element types
elty = Symbol(type)
relty= Symbol(@type_to_rtype(type))
# generate the symbol variables for our wrappers
for func_name in function_list_eigenvalues
@eval $(Symbol(func_name)) = (Symbol(magmaTypeDict[$type], $func_name))
end

@eval begin

function magma_gehrd!(ilo::Integer, ihi::Integer, A::AbstractMatrix{$elty})
magma_init()
chkstride1(A)
n = checksquare(A)
chkfinite(A) # balancing routines don't support NaNs and Infs
tau = similar(A, $elty, max(0,n - 1))
work = Vector{$elty}(undef, 1)
lwork = Cint(-1)
info = Ref{Cint}()
func = eval(@magmafunc($gehrd))
nb = eval(@magmafunc_nb($gehrd))(n)
T = CuArray{$elty}(undef, nb*n)
for i = 1:2 # first call returns lwork as work[1]
func(n, ilo, ihi, A,
max(1, stride(A, 2)), tau, work, lwork, T,
info)
if i == 1
lwork = ceil(Int, real(work[1]))
resize!(work, lwork)
end
end
magma_finalize()
A, tau
end

end

end
157 changes: 157 additions & 0 deletions src/dense/factorization.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# wrappers for MAGMA factorization functions

const function_list_factorization = ("geqrf", "gerqf", "geqlf", "gelqf")
for type in magmaTypeList
# create the symbols for element types
elty = Symbol(type)
# generate the symbol variables for our wrappers
for func_name in function_list_factorization
@eval $(Symbol(func_name)) = (Symbol(magmaTypeDict[$type], $func_name))
end

@eval begin

function magma_geqrf!(A::Matrix{$elty})
m, n = size(A)
work = Vector{$elty}(undef, 1)
lwork = Cint(-1)
info = Ref{Cint}()
lda = max(1, m)
tau = similar(A, min(m, n))

func = eval(@magmafunc($geqrf))
magma_init()
for i = 1:2 #
func(m, n, A, lda, tau, work, lwork, info)
if i == 1
lwork = ceil(Int, real(work[1]))
resize!(work, lwork)
end
end
magma_finalize()
A, tau
end
function magma_geqrf!(A::CuMatrix{$elty})
magma_init()
m, n = size(A)
nb = (eval(@magmafunc_nb($geqrf)))( m, n )
info = Ref{Cint}()
lda = max(1, m)
tau = similar(Matrix(A), min(m, n))
T = similar(A, (2*min( m, n ) + ceil(Int, n/32)*32 )*nb)

func = eval(@magmafunc_gpu($geqrf))
func(m, n, A, lda, tau, T, info)
magma_finalize()
A, tau
end

# ! Strangely, it seems that MAGMA does not provide any API for gerqf
# function magma_gerqf!(A::Matrix{$elty})
# m, n = size(A)
# work = Vector{$elty}(undef, 1)
# lwork = Cint(-1)
# info = Ref{Cint}()
# lda = max(1, m)
# tau = similar(A, min(m, n))
# func = (eval(@magmafunc_generic($geqrf, "_error")))
# magma_init()
# for i = 1:2 #
# func(m, n, A, lda, tau, work, lwork, info)
# if i == 1
# lwork = ceil(Int, real(work[1]))
# resize!(work, lwork)
# end
# end
# magma_finalize()
# A, tau
# end
# function magma_gerqf!(A::CuMatrix{$elty})
# #! MAGMA does not provide direct GPU interface for gerqf
# A = Matrix(A)
# magma_gerqf!(A)
# end

function magma_geqlf!(A::Matrix{$elty})
m, n = size(A)
work = Vector{$elty}(undef, 1)
lwork = Cint(-1)
info = Ref{Cint}()
lda = max(1, m)
tau = similar(A, min(m, n))

func = eval(@magmafunc($geqlf))
magma_init()
for i = 1:2 #
func(m, n, A, lda, tau, work, lwork, info)
if i == 1
lwork = ceil(Int, real(work[1]))
resize!(work, lwork)
end
end
magma_finalize()
A, tau
end
function magma_geqlf!(A::CuMatrix{$elty})
A = Matrix(A)
magma_geqlf!(A)
end

function magma_gelqf!(A::Matrix{$elty})
m, n = size(A)
work = Vector{$elty}(undef, 1)
lwork = Cint(-1)
info = Ref{Cint}()
lda = max(1, m)
tau = similar(A, min(m, n))

func = eval(@magmafunc($gelqf))
magma_init()
for i = 1:2 #
func(m, n, A, lda, tau, work, lwork, info)
if i == 1
lwork = ceil(Int, real(work[1]))
resize!(work, lwork)
end
end
magma_finalize()
A, tau
end
function magma_gelqf!(A::CuMatrix{$elty})
m, n = size(A)
work = Vector{$elty}(undef, 1)
lwork = Cint(-1)
info = Ref{Cint}()
lda = max(1, m)
tau = similar(Matrix(A), min(m, n))

func = eval(@magmafunc_gpu($gelqf))
magma_init()
for i = 1:2 #
func(m, n, A, lda, tau, work, lwork, info)
if i == 1
lwork = ceil(Int, real(work[1]))
resize!(work, lwork)
end
end
magma_finalize()
A, tau
end

function magma_geqrs!(A::CuArray{$elty}, B::CuArray{$elty})
magma_init()

m, n = size(A)
nrhs = size(B, 2)
lda = max(1, m)
ldb = max(1, m)
tau = Array{$elty}(undef, n)


magma_finalize()
B, info[]
end

end

end
Loading