You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Merge conversions.jl into conversion.jl (they tested overlapping
sparse↔sparse/dense format conversions under confusingly similar
names).
- Split the 461-line interfaces.jl into interfaces/{axpby,mul,ldiv,
misc}.jl. The old file had file-level m/k/n/nB constants shared
across five unrelated topics (axpby, mul!, ldiv!, misc linalg,
masked getindex).
- Move file-level m/n/k/p constants into the outer @testset in
bmm.jl, linalg.jl, reduce.jl. bmm.jl additionally had a silent
mid-file reassignment of those constants; each group now owns
its own.
- Add missing `using Adapt` to generic.jl (worked by accident when
included from the top-level CUDA.jl test runner).
- Switch runtests.jl to walkdir so every file is picked up. The old
hand-maintained include() list only covered 9 of the 16 test files
— bmm, broadcast, device, generic, linalg, reduce,
sparse_matrices_csr, and one of the two conversion files were
never exercised under Pkg.test(cuSPARSE).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: lib/cusparse/test/bmm.jl
+32-36Lines changed: 32 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -3,16 +3,16 @@ using CUDACore, cuSPARSE
3
3
using LinearAlgebra
4
4
using SparseArrays
5
5
6
-
m =5
7
-
n =15
8
-
# error when n == 1 and batchsize > 1 as cusparseSpMM fallsback to cusparseSpMV, which doesn't do batched computations.
9
-
# see https://docs.nvidia.com/cuda/cusparse/#cusparsespmm
10
-
k =25
11
-
p =0.5
12
-
13
6
@testset"Sparse-Dense $elty bmm!"for elty in (Float64, Float32, ComplexF64, ComplexF32)
14
-
α =rand(elty)
15
-
β =rand(elty)
7
+
m =5
8
+
n =15
9
+
# error when n == 1 and batchsize > 1 as cusparseSpMM fallsback to cusparseSpMV,
10
+
# which doesn't do batched computations. see https://docs.nvidia.com/cuda/cusparse/#cusparsespmm
11
+
k =25
12
+
p =0.5
13
+
14
+
α =rand(elty)
15
+
β =rand(elty)
16
16
17
17
@testset"Dimension checks"begin
18
18
A1 =CuSparseMatrixCSR{elty}(sprand(elty, m, k, p))
@@ -23,14 +23,14 @@ p = 0.5
23
23
B =CuArray(rand(elty, k, n, 2))
24
24
C =CuArray(rand(elty, m, n, 3))
25
25
26
-
@test_throwsArgumentError("C must have same batch-dimension as max(size(A,3)=$(size(A,3)), size(B,3)=$(size(B,3))), got $(size(C,3)).") cuSPARSE.bmm!('N', 'N', α, A, B, β, C, 'O')
27
-
26
+
@test_throwsArgumentError("C must have same batch-dimension as max(size(A,3)=$(size(A,3)), size(B,3)=$(size(B,3))), got $(size(C,3)).") cuSPARSE.bmm!('N', 'N', α, A, B, β, C, 'O')
27
+
28
28
C =CuArray(rand(elty, m, 1, 2))
29
-
@test_throwsArgumentError("bmm! does not work for n==1 and b>1 due to CUDA error.") cuSPARSE.bmm!('N', 'N', α, A, B, β, C, 'O')
29
+
@test_throwsArgumentError("bmm! does not work for n==1 and b>1 due to CUDA error.") cuSPARSE.bmm!('N', 'N', α, A, B, β, C, 'O')
30
30
31
31
C =CuArray(rand(elty, m, n, 2))
32
32
B =CuArray(rand(elty, k+1, n, 2))
33
-
@test_throwsDimensionMismatch("B has dimensions $(size(B)) but needs ($k,$n)") cuSPARSE.bmm!('N', 'N', α, A, B, β, C, 'O')
33
+
@test_throwsDimensionMismatch("B has dimensions $(size(B)) but needs ($k,$n)") cuSPARSE.bmm!('N', 'N', α, A, B, β, C, 'O')
34
34
end
35
35
36
36
@testset"C = αAB + βC"begin
@@ -43,7 +43,7 @@ p = 0.5
43
43
C =CuArray(rand(elty, m, n, 2))
44
44
D =copy(C)
45
45
46
-
cuSPARSE.bmm!('N', 'N', α, A, B, β, C, 'O')
46
+
cuSPARSE.bmm!('N', 'N', α, A, B, β, C, 'O')
47
47
48
48
D[:,:,1] = α * A1 * B[:,:,1] + β * D[:,:,1]
49
49
D[:,:,2] = α * A2 * B[:,:,2] + β * D[:,:,2]
@@ -61,15 +61,14 @@ p = 0.5
61
61
C =CuArray(rand(elty, m, n, 2))
62
62
D =copy(C)
63
63
64
-
cuSPARSE.bmm!('C', 'N', α, A, B, β, C, 'O')
64
+
cuSPARSE.bmm!('C', 'N', α, A, B, β, C, 'O')
65
65
66
66
D[:,:,1] = α * A1'* B[:,:,1] + β * D[:,:,1]
67
67
D[:,:,2] = α * A2'* B[:,:,2] + β * D[:,:,2]
68
68
69
69
@test D ≈ C
70
70
end
71
71
72
-
73
72
@testset"C = αABᵀ + βC"begin
74
73
A1 =CuSparseMatrixCSR{elty}(sprand(elty, m, k, p))
75
74
A2 =copy(A1)
@@ -80,15 +79,14 @@ p = 0.5
80
79
C =CuArray(rand(elty, m, n, 2))
81
80
D =copy(C)
82
81
83
-
cuSPARSE.bmm!('N', 'C', α, A, B, β, C, 'O')
82
+
cuSPARSE.bmm!('N', 'C', α, A, B, β, C, 'O')
84
83
85
84
D[:,:,1] = α * A1 * B[:,:,1]'+ β * D[:,:,1]
86
85
D[:,:,2] = α * A2 * B[:,:,2]'+ β * D[:,:,2]
87
86
88
87
@test D ≈ C
89
88
end
90
89
91
-
92
90
@testset"C = αAᵀBᵀ + βC"begin
93
91
A1 =CuSparseMatrixCSR{elty}(sprand(elty, k, m, p))
0 commit comments