@@ -3,33 +3,52 @@ Pkg.activate(".")
3
3
Pkg. instantiate ()
4
4
using SuiteSparseMatrixCollection
5
5
using SuiteSparseGraphBLAS
6
- using BenchmarkTools
7
6
using SparseArrays
8
7
using LinearAlgebra
9
8
using StorageOrders
10
9
11
- # OPTIONS SET 1:
12
- # Maximum number of samples taken for each benchmark
13
- BenchmarkTools. DEFAULT_PARAMETERS. samples = 3
14
- BenchmarkTools. DEFAULT_PARAMETERS. evals = 1
15
- # Total amount of time allowed for each benchmark, minimum of 1 sample taken.
16
- BenchmarkTools. DEFAULT_PARAMETERS. seconds = 180
10
+ macro gbbench (ex)
11
+ return quote
12
+ gbset (:burble , true )
13
+ $ (esc (ex))
14
+ gbset (:burble , false )
15
+ local taccum = 0
16
+ for i ∈ 1 : 3
17
+ local t0 = time_ns ()
18
+ $ (esc (ex))
19
+ local t1 = time_ns ()
20
+ taccum += t1 - t0
21
+ end
22
+ taccum / 1e9
23
+ end
24
+ end
25
+
26
+ macro bench (ex)
27
+ return quote
28
+ local taccum = 0
29
+ for i ∈ 1 : 3
30
+ local t0 = time_ns ()
31
+ $ (esc (ex))
32
+ local t1 = time_ns ()
33
+ taccum += t1 - t0
34
+ end
35
+ taccum / 1e9
36
+ end
37
+ end
17
38
18
39
# Comment or uncomment this line to disable or enable MKLSparse respectively.
19
40
# This will only work for SpMM and SpMV and only operates on CSC.
20
41
# using MKLSparse
21
42
22
- const threadlist = [1 , 16 ]
23
-
24
- const suite = BenchmarkGroup ()
43
+ const threadlist = [1 , 2 , 16 ]
25
44
const ssmc = ssmc_db ()
26
45
27
46
function mxm (A:: SparseMatrixCSC , B)
28
47
printstyled (stdout , " \n C = A::SparseMatrixCSC($(size (A)) ) * B::$(typeof (B)) ($(size (B)) )\n " )
29
- result = @benchmark $ A * $ B
30
- show (stdout , MIME ( " text/plain " ), result )
48
+ result = @bench A * B
49
+ println (stdout , result, " s " )
31
50
flush (stdout )
32
- return median ( result)
51
+ return result
33
52
end
34
53
35
54
function mxm (A:: SuiteSparseGraphBLAS.GBArray , B:: SuiteSparseGraphBLAS.GBArray ; accumdenseoutput= false )
@@ -38,22 +57,16 @@ function mxm(A::SuiteSparseGraphBLAS.GBArray, B::SuiteSparseGraphBLAS.GBArray; a
38
57
if ! accumdenseoutput
39
58
printstyled (stdout , " \n C::GBArray = A::GBArray($Ao , $(size (A)) ) * B::GBArray($Bo , $(size (B)) )\n " )
40
59
flush (stdout )
41
- gbset (:burble , true )
42
- mul (A, B)
43
- gbset (:burble , false )
44
- result = @benchmark mul ($ A, $ B)
60
+ result = @gbbench mul (A, B)
45
61
else
46
62
printstyled (stdout , " \n C::GBArray += A::GBArray($Ao , $(size (A)) ) * B::GBArray($Bo , $(size (B)) )\n " )
47
63
C = GBMatrix (zeros (eltype (A), size (A, 1 ), size (B, 2 )))
48
64
flush (stdout )
49
- gbset (:burble , true )
50
- mul! (C, A, B; accum= + )
51
- gbset (:burble , false )
52
- result = @benchmark mul! ($ C, $ A, $ B; accum= + )
65
+ result = @gbbench mul! (C, A, B; accum= + )
53
66
end
54
- show (stdout , MIME ( " text/plain " ), result )
67
+ println (stdout , result, " s " )
55
68
flush (stdout )
56
- return median ( result)
69
+ return result
57
70
end
58
71
59
72
function singlebench (pathornum)
@@ -71,7 +84,8 @@ function singlebench(pathornum)
71
84
printstyled (stdout , " \n #################################################################################\n " ; bold= true , color= :green )
72
85
printstyled (stdout , " Benchmarking $name :\n " ; bold= true , color= :green )
73
86
printstyled (stdout , " #################################################################################\n " ; bold= true , color= :green )
74
- printstyled (stdout , " Sparse * Vec\n " ; bold= true )
87
+ printstyled (stdout , " \n Sparse * Vec\n " ; bold= true )
88
+ println (stdout , " ################################" )
75
89
flush (stdout )
76
90
B = rand (eltype (A), size (A, 2 ))
77
91
B = GBVector (B)
@@ -81,12 +95,16 @@ function singlebench(pathornum)
81
95
diag (A)
82
96
gbresultsC = runthreaded (A, B; accumdenseoutput= true )
83
97
SAresults = mxm (SparseMatrixCSC (A), Vector (B))
84
- printstyled (stdout , " RESULTS, Sparse * DenseVec: \n " ; bold= true , color= :green )
85
- println (stdout , " A by row: $gbresultsR " )
86
- println (stdout , " A by col: $gbresultsC " )
98
+ printstyled (stdout , " \n RESULTS, Sparse * DenseVec: \n " ; bold= true , color= :green )
99
+ println (stdout , " ################################" )
100
+ println (stdout , " A by row (1, 2, 16 thread): $gbresultsR " )
101
+ println (stdout , " A by col (1, 2, 16 thread): $gbresultsC " )
87
102
println (stdout , " SparseArrays: $SAresults " )
88
103
flush (stdout )
89
104
105
+ printstyled (stdout , " \n Sparse * (n x 2)\n " ; bold= true )
106
+ println (stdout , " ################################" )
107
+ flush (stdout )
90
108
B = GBMatrix (rand (eltype (A), size (A, 2 ), 2 ))
91
109
gbset (A, :format , SuiteSparseGraphBLAS. BYROW)
92
110
diag (A)
@@ -95,12 +113,16 @@ function singlebench(pathornum)
95
113
diag (A)
96
114
gbresultsC = runthreaded (A, B; accumdenseoutput= true )
97
115
SAresults = mxm (SparseMatrixCSC (A), Matrix (B))
98
- printstyled (stdout , " RESULTS, Sparse * n x 2 Dense: \n " ; bold= true , color= :green )
99
- println (stdout , " A by row: $gbresultsR " )
100
- println (stdout , " A by col: $gbresultsC " )
116
+ printstyled (stdout , " \n RESULTS, Sparse * n x 2 Dense: \n " ; bold= true , color= :green )
117
+ println (stdout , " ################################" )
118
+ println (stdout , " A by row (1, 2, 16 thread): $gbresultsR " )
119
+ println (stdout , " A by col (1, 2, 16 thread): $gbresultsC " )
101
120
println (stdout , " SparseArrays: $SAresults " )
102
121
flush (stdout )
103
122
123
+ printstyled (stdout , " \n Sparse * (n x 32)\n " ; bold= true )
124
+ println (stdout , " ################################" )
125
+ flush (stdout )
104
126
B = GBMatrix (rand (eltype (A), size (A, 2 ), 32 ))
105
127
gbset (A, :format , SuiteSparseGraphBLAS. BYROW)
106
128
diag (A)
@@ -109,25 +131,29 @@ function singlebench(pathornum)
109
131
diag (A)
110
132
gbresultsC = runthreaded (A, B; accumdenseoutput= true )
111
133
SAresults = mxm (SparseMatrixCSC (A), Matrix (B))
112
- printstyled (stdout , " RESULTS, Sparse * n x 32 Dense: \n " ; bold= true , color= :green )
113
- println (stdout , " A by row: $gbresultsR " )
114
- println (stdout , " A by col: $gbresultsC " )
134
+ printstyled (stdout , " \n RESULTS, Sparse * n x 32 Dense: \n " ; bold= true , color= :green )
135
+ println (stdout , " ################################" )
136
+ println (stdout , " A by row (1, 2, 16 thread): $gbresultsR " )
137
+ println (stdout , " A by col (1, 2, 16 thread): $gbresultsC " )
115
138
println (stdout , " SparseArrays: $SAresults " )
116
139
flush (stdout )
117
140
118
-
141
+ printstyled (stdout , " \n Sparse * Sparse'" ; bold= true )
142
+ println (stdout , " ################################" )
143
+ flush (stdout )
119
144
gbset (A, :format , SuiteSparseGraphBLAS. BYROW)
120
145
diag (A)
121
146
gbresultsR = runthreaded (A, transpose (A))
122
147
gbset (A, :format , SuiteSparseGraphBLAS. BYCOL)
123
148
diag (A)
124
149
gbresultsC = runthreaded (A, transpose (A))
125
- A2 = SparseMatrixCSC (A)
150
+ A2 = SparseMatrixCSC (A)
126
151
SAresults = mxm (A2, transpose (A2))
127
152
println (stdout , )
128
- printstyled (stdout , " \n\n RESULTS, Sparse * Sparse: \n " ; bold= true , color= :green )
129
- println (stdout , " A by row: $gbresultsR " )
130
- println (stdout , " A by col: $gbresultsC " )
153
+ printstyled (stdout , " \n RESULTS, Sparse * Sparse: \n " ; bold= true , color= :green )
154
+ println (stdout , " ################################" )
155
+ println (stdout , " A by row (1, 2, 16 thread): $gbresultsR " )
156
+ println (stdout , " A by col (1, 2, 16 thread): $gbresultsC " )
131
157
println (stdout , " SparseArrays: $SAresults " )
132
158
flush (stdout )
133
159
return nothing
0 commit comments