@@ -3,33 +3,52 @@ Pkg.activate(".")
33Pkg. instantiate ()
44using SuiteSparseMatrixCollection
55using SuiteSparseGraphBLAS
6- using BenchmarkTools
76using SparseArrays
87using LinearAlgebra
98using StorageOrders
109
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
1738
1839# Comment or uncomment this line to disable or enable MKLSparse respectively.
1940# This will only work for SpMM and SpMV and only operates on CSC.
2041# using MKLSparse
2142
22- const threadlist = [1 , 16 ]
23-
24- const suite = BenchmarkGroup ()
43+ const threadlist = [1 , 2 , 16 ]
2544const ssmc = ssmc_db ()
2645
2746function mxm (A:: SparseMatrixCSC , B)
2847 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 " )
3150 flush (stdout )
32- return median ( result)
51+ return result
3352end
3453
3554function mxm (A:: SuiteSparseGraphBLAS.GBArray , B:: SuiteSparseGraphBLAS.GBArray ; accumdenseoutput= false )
@@ -38,22 +57,16 @@ function mxm(A::SuiteSparseGraphBLAS.GBArray, B::SuiteSparseGraphBLAS.GBArray; a
3857 if ! accumdenseoutput
3958 printstyled (stdout , " \n C::GBArray = A::GBArray($Ao , $(size (A)) ) * B::GBArray($Bo , $(size (B)) )\n " )
4059 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)
4561 else
4662 printstyled (stdout , " \n C::GBArray += A::GBArray($Ao , $(size (A)) ) * B::GBArray($Bo , $(size (B)) )\n " )
4763 C = GBMatrix (zeros (eltype (A), size (A, 1 ), size (B, 2 )))
4864 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= + )
5366 end
54- show (stdout , MIME ( " text/plain " ), result )
67+ println (stdout , result, " s " )
5568 flush (stdout )
56- return median ( result)
69+ return result
5770end
5871
5972function singlebench (pathornum)
@@ -71,7 +84,8 @@ function singlebench(pathornum)
7184 printstyled (stdout , " \n #################################################################################\n " ; bold= true , color= :green )
7285 printstyled (stdout , " Benchmarking $name :\n " ; bold= true , color= :green )
7386 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 , " ################################" )
7589 flush (stdout )
7690 B = rand (eltype (A), size (A, 2 ))
7791 B = GBVector (B)
@@ -81,12 +95,16 @@ function singlebench(pathornum)
8195 diag (A)
8296 gbresultsC = runthreaded (A, B; accumdenseoutput= true )
8397 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 " )
87102 println (stdout , " SparseArrays: $SAresults " )
88103 flush (stdout )
89104
105+ printstyled (stdout , " \n Sparse * (n x 2)\n " ; bold= true )
106+ println (stdout , " ################################" )
107+ flush (stdout )
90108 B = GBMatrix (rand (eltype (A), size (A, 2 ), 2 ))
91109 gbset (A, :format , SuiteSparseGraphBLAS. BYROW)
92110 diag (A)
@@ -95,12 +113,16 @@ function singlebench(pathornum)
95113 diag (A)
96114 gbresultsC = runthreaded (A, B; accumdenseoutput= true )
97115 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 " )
101120 println (stdout , " SparseArrays: $SAresults " )
102121 flush (stdout )
103122
123+ printstyled (stdout , " \n Sparse * (n x 32)\n " ; bold= true )
124+ println (stdout , " ################################" )
125+ flush (stdout )
104126 B = GBMatrix (rand (eltype (A), size (A, 2 ), 32 ))
105127 gbset (A, :format , SuiteSparseGraphBLAS. BYROW)
106128 diag (A)
@@ -109,25 +131,29 @@ function singlebench(pathornum)
109131 diag (A)
110132 gbresultsC = runthreaded (A, B; accumdenseoutput= true )
111133 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 " )
115138 println (stdout , " SparseArrays: $SAresults " )
116139 flush (stdout )
117140
118-
141+ printstyled (stdout , " \n Sparse * Sparse'" ; bold= true )
142+ println (stdout , " ################################" )
143+ flush (stdout )
119144 gbset (A, :format , SuiteSparseGraphBLAS. BYROW)
120145 diag (A)
121146 gbresultsR = runthreaded (A, transpose (A))
122147 gbset (A, :format , SuiteSparseGraphBLAS. BYCOL)
123148 diag (A)
124149 gbresultsC = runthreaded (A, transpose (A))
125- A2 = SparseMatrixCSC (A)
150+ A2 = SparseMatrixCSC (A)
126151 SAresults = mxm (A2, transpose (A2))
127152 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 " )
131157 println (stdout , " SparseArrays: $SAresults " )
132158 flush (stdout )
133159 return nothing
0 commit comments