Skip to content

Commit 8f77587

Browse files
committed
Revert "Addition and multiplication over sparse CuArrays (#1152)"
This reverts commit 7bf58da, fixing #1188.
1 parent 24e0934 commit 8f77587

File tree

5 files changed

+4
-242
lines changed

5 files changed

+4
-242
lines changed

lib/cusparse/CUSPARSE.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ include("management.jl")
3434
include("level1.jl")
3535
include("level2.jl")
3636
include("level3.jl")
37-
include("extra.jl")
3837
include("preconditioners.jl")
3938
include("conversions.jl")
4039
include("generic.jl")

lib/cusparse/array.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ mutable struct CuSparseMatrixCSC{Tv, Ti} <: AbstractCuSparseMatrix{Tv, Ti}
4545
end
4646
end
4747

48-
CuSparseMatrixCSC(A::CuSparseMatrixCSC) = A
49-
5048
function CUDA.unsafe_free!(xs::CuSparseMatrixCSC)
5149
unsafe_free!(xs.colPtr)
5250
unsafe_free!(rowvals(xs))
@@ -80,8 +78,6 @@ mutable struct CuSparseMatrixCSR{Tv, Ti} <: AbstractCuSparseMatrix{Tv, Ti}
8078
end
8179
end
8280

83-
CuSparseMatrixCSR(A::CuSparseMatrixCSR) = A
84-
8581
function CUDA.unsafe_free!(xs::CuSparseMatrixCSR)
8682
unsafe_free!(xs.rowPtr)
8783
unsafe_free!(xs.colVal)
@@ -110,8 +106,6 @@ mutable struct CuSparseMatrixBSR{Tv, Ti} <: AbstractCuSparseMatrix{Tv, Ti}
110106
end
111107
end
112108

113-
CuSparseMatrixBSR(A::CuSparseMatrixBSR) = A
114-
115109
function CUDA.unsafe_free!(xs::CuSparseMatrixBSR)
116110
unsafe_free!(xs.rowPtr)
117111
unsafe_free!(xs.colVal)
@@ -138,8 +132,6 @@ mutable struct CuSparseMatrixCOO{Tv, Ti} <: AbstractCuSparseMatrix{Tv, Ti}
138132
end
139133
end
140134

141-
CuSparseMatrixCOO(A::CuSparseMatrixCOO) = A
142-
143135
"""
144136
Utility union type of [`CuSparseMatrixCSC`](@ref), [`CuSparseMatrixCSR`](@ref),
145137
[`CuSparseMatrixBSR`](@ref), [`CuSparseMatrixCOO`](@ref).

lib/cusparse/extra.jl

Lines changed: 0 additions & 60 deletions
This file was deleted.

lib/cusparse/interfaces.jl

Lines changed: 4 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -79,87 +79,10 @@ for (taga, untaga) in tag_wrappers, (wrapa, transa, unwrapa) in op_wrappers
7979
end
8080
end
8181

82-
function LinearAlgebra.:(*)(A::Union{CuMatrix, CuSparseMatrix}, B::CuSparseMatrix{T}) where {T}
83-
return mul!(similar(CuMatrix{T}, (size(A,1), size(B,2))), A, CuArray(B))
84-
end
85-
86-
function LinearAlgebra.mul!(C::CuMatrix{T}, A::CuMatrix{T}, B::CuSparseMatrix{T}) where {T}
87-
mul!(C, B', A', one(T), zero(T))
88-
return C'
89-
end
90-
91-
Base.:(+)(A::CuSparseMatrixCSR, B::CuSparseMatrixCSR) = geam(one(eltype(A)), A, one(eltype(A)), B, 'O')
92-
Base.:(-)(A::CuSparseMatrixCSR, B::CuSparseMatrixCSR) = geam(one(eltype(A)), A, -one(eltype(A)), B, 'O')
93-
94-
Base.:(+)(A::CuSparseMatrixCSR, B::Adjoint{T,<:CuSparseMatrixCSR}) where {T} = A + Transpose(conj(B.parent))
95-
Base.:(-)(A::CuSparseMatrixCSR, B::Adjoint{T,<:CuSparseMatrixCSR}) where {T} = A - Transpose(conj(B.parent))
96-
Base.:(+)(A::Adjoint{T,<:CuSparseMatrixCSR}, B::CuSparseMatrixCSR) where {T} = Transpose(conj(A.parent)) + B
97-
Base.:(-)(A::Adjoint{T,<:CuSparseMatrixCSR}, B::CuSparseMatrixCSR) where {T} = Transpose(conj(A.parent)) - B
98-
Base.:(+)(A::Adjoint{T,<:CuSparseMatrixCSR}, B::Adjoint{T,<:CuSparseMatrixCSR}) where {T} =
99-
Transpose(conj(A.parent)) + B
100-
Base.:(-)(A::Adjoint{T,<:CuSparseMatrixCSR}, B::Adjoint{T,<:CuSparseMatrixCSR}) where {T} =
101-
Transpose(conj(A.parent)) - B
102-
103-
function Base.:(+)(A::CuSparseMatrixCSR, B::Transpose{T,<:CuSparseMatrixCSR}) where {T}
104-
cscB = CuSparseMatrixCSC(B.parent)
105-
transB = CuSparseMatrixCSR(cscB.colPtr, cscB.rowVal, cscB.nzVal, size(cscB))
106-
return geam(one(T), A, one(T), transB, 'O')
107-
end
108-
109-
function Base.:(-)(A::CuSparseMatrixCSR, B::Transpose{T,<:CuSparseMatrixCSR}) where {T}
110-
cscB = CuSparseMatrixCSC(B.parent)
111-
transB = CuSparseMatrixCSR(cscB.colPtr, cscB.rowVal, cscB.nzVal, size(cscB))
112-
return geam(one(T), A, -one(T), transB, 'O')
113-
end
114-
115-
function Base.:(+)(A::Transpose{T,<:CuSparseMatrixCSR}, B::CuSparseMatrixCSR) where {T}
116-
cscA = CuSparseMatrixCSC(A.parent)
117-
transA = CuSparseMatrixCSR(cscA.colPtr, cscA.rowVal, cscA.nzVal, size(cscA))
118-
geam(one(T), transA, one(T), B, 'O')
119-
end
120-
121-
function Base.:(-)(A::Transpose{T,<:CuSparseMatrixCSR}, B::CuSparseMatrixCSR) where {T}
122-
cscA = CuSparseMatrixCSC(A.parent)
123-
transA = CuSparseMatrixCSR(cscA.colPtr, cscA.rowVal, cscA.nzVal, size(cscA))
124-
geam(one(T), transA, -one(T), B, 'O')
125-
end
126-
127-
function Base.:(+)(A::Transpose{T,<:CuSparseMatrixCSR}, B::Transpose{T,<:CuSparseMatrixCSR}) where {T}
128-
C = geam(one(T), A.parent, one(T), B.parent, 'O')
129-
cscC = CuSparseMatrixCSC(C)
130-
return CuSparseMatrixCSR(cscC.colPtr, cscC.rowVal, cscC.nzVal, size(cscC))
131-
end
132-
133-
function Base.:(-)(A::Transpose{T,<:CuSparseMatrixCSR}, B::Transpose{T,<:CuSparseMatrixCSR}) where {T}
134-
C = geam(one(T), A.parent, -one(T), B.parent, 'O')
135-
cscC = CuSparseMatrixCSC(C)
136-
return CuSparseMatrixCSR(cscC.colPtr, cscC.rowVal, cscC.nzVal, size(cscC))
137-
end
138-
139-
function Base.:(+)(A::CuSparseMatrixCSR, B::CuSparseMatrix)
140-
csrB = CuSparseMatrixCSR(B)
141-
return geam(one(eltype(A)), A, one(eltype(A)), csrB, 'O')
142-
end
143-
144-
function Base.:(-)(A::CuSparseMatrixCSR, B::CuSparseMatrix)
145-
csrB = CuSparseMatrixCSR(B)
146-
return geam(one(eltype(A)), A, -one(eltype(A)), csrB, 'O')
147-
end
148-
149-
function Base.:(+)(A::CuSparseMatrix, B::CuSparseMatrixCSR)
150-
csrA = CuSparseMatrixCSR(A)
151-
return geam(one(eltype(A)), csrA, one(eltype(A)), B, 'O')
152-
end
153-
154-
function Base.:(-)(A::CuSparseMatrix, B::CuSparseMatrixCSR)
155-
csrA = CuSparseMatrixCSR(A)
156-
return geam(one(eltype(A)), csrA, -one(eltype(A)), B, 'O')
157-
end
158-
159-
Base.:(+)(A::CuSparseMatrix, B::CuMatrix) = CuArray(A) + B
160-
Base.:(-)(A::CuSparseMatrix, B::CuMatrix) = CuArray(A) - B
161-
Base.:(+)(A::CuMatrix, B::CuSparseMatrix) = A + CuArray(B)
162-
Base.:(-)(A::CuMatrix, B::CuSparseMatrix) = A - CuArray(B)
82+
Base.:(+)(A::Union{CuSparseMatrixCSR,CuSparseMatrixCSC},
83+
B::Union{CuSparseMatrixCSR,CuSparseMatrixCSC}) = geam(A,B,'O','O','O')
84+
Base.:(-)(A::Union{CuSparseMatrixCSR,CuSparseMatrixCSC},
85+
B::Union{CuSparseMatrixCSR,CuSparseMatrixCSC}) = geam(A,-one(eltype(A)),B,'O','O','O')
16386

16487
# triangular
16588

test/cusparse/interfaces.jl

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,6 @@ using CUDA.CUSPARSE
22
using LinearAlgebra, SparseArrays
33

44
@testset "LinearAlgebra" begin
5-
@testset "$f(A)±$h(B) $elty" for elty in [Float32, Float64, ComplexF32, ComplexF64],
6-
f in (identity, transpose), #adjoint),
7-
h in (identity, transpose)#, adjoint)
8-
# adjoint need the support of broadcast for `conj()` to work with `CuSparseMatrix`.
9-
n = 10
10-
alpha = rand()
11-
beta = rand()
12-
A = sprand(elty, n, n, rand())
13-
B = sprand(elty, n, n, rand())
14-
15-
dA = CuSparseMatrixCSR(A)
16-
dB = CuSparseMatrixCSR(B)
17-
18-
C = f(A) + h(B)
19-
dC = f(dA) + h(dB)
20-
@test C collect(dC)
21-
22-
C = f(A) - h(B)
23-
dC = f(dA) - h(dB)
24-
@test C collect(dC)
25-
end
26-
27-
@testset "$f(B) $elty" for elty in [Float32, Float64, ComplexF32, ComplexF64],
28-
f in (CuSparseMatrixCSR, CuSparseMatrixCSC, x->CuSparseMatrixBSR(x,1))
29-
n = 10
30-
A = sprand(elty, n, n, rand())
31-
B = sprand(elty, n, n, rand())
32-
33-
dA = CuSparseMatrixCSR(A)
34-
dB = CuSparseMatrixCSR(B)
35-
36-
C = A + B
37-
dC = dA + f(dB)
38-
@test C collect(dC)
39-
40-
C = B + A
41-
dC = f(dB) + dA
42-
@test C collect(dC)
43-
44-
C = A - B
45-
dC = dA - f(dB)
46-
@test C collect(dC)
47-
48-
C = B - A
49-
dC = f(dB) - dA
50-
@test C collect(dC)
51-
end
52-
53-
@testset "dense(A)$(op)sparse(B) $elty" for elty in [Float32, Float64, ComplexF32, ComplexF64],
54-
op in [+, -]
55-
n = 10
56-
A = rand(elty, n, n)
57-
B = sprand(elty, n, n, rand())
58-
59-
dA = CuArray(A)
60-
dB = CuSparseMatrixCSR(B)
61-
62-
C = op(A, B)
63-
dC = op(dA, dB)
64-
@test C collect(dC)
65-
@test dC isa CuMatrix{elty}
66-
67-
C = op(B, A)
68-
dC = op(dB, dA)
69-
@test C collect(dC)
70-
@test dC isa CuMatrix{elty}
71-
end
72-
735
@testset "$f(A)*b $elty" for elty in [Float32, Float64, ComplexF32, ComplexF64],
746
f in (identity, transpose, adjoint)
757
n = 10
@@ -135,30 +67,6 @@ using LinearAlgebra, SparseArrays
13567
@test C collect(dC)
13668
end
13769

138-
@testset "dense(A)*sparse(B) $elty" for elty in [Float32, Float64, ComplexF32, ComplexF64]
139-
n = 10
140-
A = rand(elty, n, n)
141-
B = sprand(elty, n, n, rand())
142-
143-
dA = CuArray(A)
144-
dB = CUSPARSE.CuSparseMatrixCSR(B)
145-
146-
C = A * B
147-
dC = dA * dB
148-
@test C collect(dC)
149-
@test dC isa CuMatrix{elty}
150-
151-
C = B * A
152-
dC = dB * dA
153-
@test C collect(dC)
154-
@test dC isa CuMatrix{elty}
155-
156-
C = B * B
157-
dC = dB * dB
158-
@test C collect(dC)
159-
@test dC isa CuMatrix{elty}
160-
end
161-
16270
@testset "issue #1095 ($elty)" for elty in [Float32, Float64, ComplexF32, ComplexF64]
16371
# Test non-square matrices
16472
n, m, p = 10, 20, 4

0 commit comments

Comments
 (0)