Skip to content

Commit 989ad2c

Browse files
committed
2 parents 9aba30a + fca820e commit 989ad2c

File tree

6 files changed

+205
-30
lines changed

6 files changed

+205
-30
lines changed

benchmarks/Manifest.toml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ version = "0.1.6"
5353

5454
[[Compat]]
5555
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
56-
git-tree-sha1 = "96b0bc6c52df76506efc8a441c6cf1adcb1babc4"
56+
git-tree-sha1 = "b153278a25dd42c65abbf4e62344f9d22e59191b"
5757
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
58-
version = "3.42.0"
58+
version = "3.43.0"
5959

6060
[[CompilerSupportLibraries_jll]]
6161
deps = ["Artifacts", "Libdl"]
@@ -221,9 +221,9 @@ uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
221221

222222
[[LogExpFunctions]]
223223
deps = ["ChainRulesCore", "ChangesOfVariables", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"]
224-
git-tree-sha1 = "58f25e56b706f95125dcb796f39e1fb01d913a71"
224+
git-tree-sha1 = "a970d55c2ad8084ca317a4658ba6ce99b7523571"
225225
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
226-
version = "0.3.10"
226+
version = "0.3.12"
227227

228228
[[Logging]]
229229
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
@@ -416,6 +416,18 @@ version = "0.4.1"
416416
deps = ["LinearAlgebra", "SparseArrays"]
417417
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
418418

419+
[[StatsAPI]]
420+
deps = ["LinearAlgebra"]
421+
git-tree-sha1 = "8d7530a38dbd2c397be7ddd01a424e4f411dcc41"
422+
uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
423+
version = "1.2.2"
424+
425+
[[StatsBase]]
426+
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "LogExpFunctions", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"]
427+
git-tree-sha1 = "8977b17906b0a1cc74ab2e3a05faa16cf08a8291"
428+
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
429+
version = "0.33.16"
430+
419431
[[StorageOrders]]
420432
git-tree-sha1 = "365181758ec1084fecf147b72206f81a1310c8b7"
421433
uuid = "e9177fbf-8fde-426c-9425-4eed0f22262a"
@@ -433,7 +445,7 @@ uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
433445

434446
[[SuiteSparseGraphBLAS]]
435447
deps = ["ChainRulesCore", "HyperSparseMatrices", "Libdl", "LinearAlgebra", "MacroTools", "Preferences", "Random", "SSGraphBLAS_jll", "Serialization", "SparseArrays", "SpecialFunctions", "StorageOrders", "SuiteSparse"]
436-
git-tree-sha1 = "33576d2926608fdfe958334400eac5b73c58c7d1"
448+
git-tree-sha1 = "6f6472faf84bf1b93e44e4bc75b5904cd987c281"
437449
repo-rev = "master"
438450
repo-url = "https://github.com/JuliaSparse/SuiteSparseGraphBLAS.jl.git"
439451
uuid = "c2e53296-7b14-11e9-1210-bddfa8111e1d"

benchmarks/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
33
MKLSparse = "0c723cd3-b8cd-5d40-b370-ba682dde9aae"
44
SparseMatricesCSR = "a0a7dd2c-ebf4-11e9-1f05-cf50bc540ca1"
5+
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
56
StorageOrders = "e9177fbf-8fde-426c-9425-4eed0f22262a"
67
SuiteSparseGraphBLAS = "c2e53296-7b14-11e9-1210-bddfa8111e1d"
78
SuiteSparseMatrixCollection = "ac199af8-68bc-55b8-82c4-7abd6f96ed98"

benchmarks/bench_subassign.jl

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
println(stdout, "Opening Script")
2+
using Pkg
3+
Pkg.activate(".")
4+
Pkg.instantiate()
5+
using SuiteSparseMatrixCollection
6+
using SuiteSparseGraphBLAS
7+
using SparseArrays
8+
using LinearAlgebra
9+
using StorageOrders
10+
using StatsBase
11+
println(stdout, "Loaded Packages")
12+
13+
macro gbbench(ex)
14+
return quote
15+
gbset(:burble, true)
16+
$(esc(ex))
17+
gbset(:burble, false)
18+
local taccum = 0
19+
for i 1:3
20+
local t0 = time_ns()
21+
$(esc(ex))
22+
local t1 = time_ns()
23+
taccum += t1 - t0
24+
end
25+
taccum / 1e9
26+
end
27+
end
28+
29+
macro bench(ex)
30+
return quote
31+
$(esc(ex))
32+
local taccum = 0
33+
for i 1:3
34+
local t0 = time_ns()
35+
$(esc(ex))
36+
local t1 = time_ns()
37+
taccum += t1 - t0
38+
end
39+
taccum / 1e9
40+
end
41+
end
42+
43+
# Comment or uncomment this line to disable or enable MKLSparse respectively.
44+
# This will only work for SpMM and SpMV and only operates on CSC.
45+
#using MKLSparse
46+
47+
const threadlist = [1, 2, 16]
48+
49+
function idx(C, A, I, J)
50+
if C isa SuiteSparseGraphBLAS.AbstractGBArray
51+
Ao = storageorder(A) == ColMajor() ? "C" : "R"
52+
Co = storageorder(A) == ColMajor() ? "C" : "R"
53+
printstyled(stdout, "\nC::GBArray($(Co))[I, J] = A::GBArray($Ao, $(size(A)))\n")
54+
result = @gbbench begin
55+
C[I, J] = A
56+
wait(C)
57+
end
58+
println(stdout, result, "s")
59+
GC.gc()
60+
else
61+
printstyled(stdout, "\nC[I, J] = A::SparseMatrixCSC($(size(A)))\n")
62+
result = @bench C[I, J] = A
63+
println(stdout, result, "s")
64+
GC.gc()
65+
end
66+
flush(stdout)
67+
return result
68+
end
69+
70+
function runthreadedidx(C, A, I, J)
71+
v = []
72+
for t threadlist
73+
printstyled(stdout, "\nRunning GraphBLAS with $t threads\n"; bold=true)
74+
gbset(:nthreads, t)
75+
push!(v, idx(C, A, I, J))
76+
end
77+
return v
78+
end
79+
80+
function singlebench(szC, szA)
81+
gbresultsR = [0.0, 0.0, 0.0]
82+
gbresultsC = [0.0, 0.0, 0.0]
83+
SAresults = 0.0
84+
printstyled(stdout, "\nC($szC)[I, J] = A($szA))\n"; bold=true)
85+
println(stdout, "################################")
86+
for i 1:10
87+
C = SuiteSparseGraphBLAS.gbrand(Float64, szC[1:2]..., szC[3])
88+
A = SuiteSparseGraphBLAS.gbrand(Float64, szA[1:2]..., szA[3])
89+
wait(C)
90+
wait(A)
91+
I = sample(1:size(C, 1), size(A, 1), replace = false)
92+
J = sample(1:size(C, 2), size(A, 2), replace = false)
93+
94+
flush(stdout)
95+
gbset(A, :format, SuiteSparseGraphBLAS.BYROW)
96+
gbset(C, :format, SuiteSparseGraphBLAS.BYROW)
97+
SuiteSparseGraphBLAS.wait(A)
98+
gbresultsR .+= runthreadedidx(C, A, I, J)
99+
gbset(A, :format, SuiteSparseGraphBLAS.BYCOL)
100+
gbset(C, :format, SuiteSparseGraphBLAS.BYCOL)
101+
SuiteSparseGraphBLAS.wait(A)
102+
gbresultsC .+= runthreadedidx(C, A, I, J)
103+
A = SparseMatrixCSC(A)
104+
C = SparseMatrixCSC(C)
105+
SAresults += idx(C, A, I, J)
106+
end
107+
println(stdout, )
108+
printstyled(stdout, "\nRESULTS, C($szC)[I, J] = A($szA): \n"; bold=true, color=:green)
109+
println(stdout, "################################")
110+
println(stdout, "A by row (1, 2, 16 thread): $(gbresultsR ./ 30)")
111+
println(stdout, "A by col (1, 2, 16 thread): $(gbresultsC ./ 30)")
112+
println(stdout, "SparseArrays: $(SAresults / 30)")
113+
flush(stdout)
114+
return nothing
115+
end
116+
117+
singlebench((10_000, 10_000, 0.001), (2_000, 2_000, 0.1))
118+
#singlebench((1_000_000, 1_000_000, 0.01), (5_000, 5_000, 0.005))
119+
#singlebench((25_000_000, 25_000_000, 1e-7), (5_000, 5_000, 0.002))
120+
#singlebench((50_000_000, 50_000_000, 1e-7), (100_000, 100_000, 0.001))
121+
#
122+
#singlebench((50_000_000, 50_000_000, 1e-7), (1_000, 1_000, 1.0))

benchmarks/benchmarks2.jl

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ end
7373

7474
function tpose(A::SuiteSparseGraphBLAS.GBArray)
7575
Ao = storageorder(A) == ColMajor() ? "C" : "R"
76-
Bo = storageorder(B) == ColMajor() ? "C" : "R"
77-
printstyled(stdout, "\nC::GBArray = transpose(A::GBArray($Ao, $(size(A))))\n")
78-
result = @gbbench copy(transpose(A))
76+
C = similar(A)
77+
gbset(C, :format, storageorder(A) === ColMajor() ? SuiteSparseGraphBLAS.BYCOL : SuiteSparseGraphBLAS.BYROW)
78+
Co = storageorder(A) == ColMajor() ? "C" : "R"
79+
printstyled(stdout, "\nC::GBArray($(Co)) = transpose(A::GBArray($Ao, $(size(A))))\n")
80+
result = @gbbench SuiteSparseGraphBLAS.gbtranspose!(C, A)
7981
println(stdout, result, "s")
8082
GC.gc()
8183
flush(stdout)
@@ -91,7 +93,45 @@ function tpose(A::SparseMatrixCSC)
9193
return result
9294
end
9395

94-
function spdbench(A)
96+
function runthreadedt(A; accumdenseoutput=false)
97+
v = []
98+
for t threadlist
99+
printstyled(stdout, "\nRunning GraphBLAS with $t threads\n"; bold=true)
100+
gbset(:nthreads, t)
101+
push!(v, tpose(A))
102+
end
103+
return v
104+
end
105+
106+
function idx(C, A, I, J)
107+
if C isa SuiteSparseGraphBLAS.AbstractGBArray
108+
Ao = storageorder(A) == ColMajor() ? "C" : "R"
109+
Co = storageorder(A) == ColMajor() ? "C" : "R"
110+
printstyled(stdout, "\nC::GBArray($(Co))[I, J] = A::GBArray($Ao, $(size(A)))\n")
111+
result = @gbbench begin
112+
C[I, J] = A
113+
wait(C)
114+
end
115+
println(stdout, result, "s")
116+
GC.gc()
117+
else
118+
printstyled(stdout, "\nC[I, J] = A::SparseMatrixCSC($(size(A)))\n")
119+
result = @bench C[I, J] = A
120+
println(stdou, result, "s")
121+
GC.gc()
122+
end
123+
flush(stdout)
124+
return result
125+
end
126+
127+
function runthreadedidx(C, A, I, J)
128+
v = []
129+
for t threadlist
130+
printstyled(stdout, "\nRunning GraphBLAS with $t threads\n"; bold=true)
131+
gbset(:nthreads, t)
132+
push!(v, idx(C, A, I, J))
133+
end
134+
return v
95135
end
96136

97137
function singlebench(pathornum)
@@ -113,12 +153,13 @@ function singlebench(pathornum)
113153
printstyled(stdout, "\n#################################################################################\n"; bold=true, color=:green)
114154
printstyled(stdout, "Benchmarking $name:\n"; bold=true, color=:green)
115155
printstyled(stdout, "#################################################################################\n"; bold=true, color=:green)
156+
116157
printstyled(stdout, "\nSparse * Vec\n"; bold=true)
117158
println(stdout, "################################")
118159
flush(stdout)
119160
B = rand(eltype(A), size(A, 2))
120161
B = GBVector(B)
121-
162+
#
122163
gbresultsR = runthreaded(A, B; accumdenseoutput=true)
123164
gbset(A, :format, SuiteSparseGraphBLAS.BYCOL)
124165
diag(A)
@@ -130,7 +171,7 @@ function singlebench(pathornum)
130171
println(stdout, "A by col (1, 2, 16 thread): $gbresultsC")
131172
println(stdout, "SparseArrays: $SAresults")
132173
flush(stdout)
133-
174+
#
134175
printstyled(stdout, "\nSparse * (n x 2)\n"; bold=true)
135176
println(stdout, "################################")
136177
flush(stdout)
@@ -148,7 +189,7 @@ function singlebench(pathornum)
148189
println(stdout, "A by col (1, 2, 16 thread): $gbresultsC")
149190
println(stdout, "SparseArrays: $SAresults")
150191
flush(stdout)
151-
192+
#
152193
printstyled(stdout, "\nSparse * (n x 32)\n"; bold=true)
153194
println(stdout, "################################")
154195
flush(stdout)
@@ -166,7 +207,7 @@ function singlebench(pathornum)
166207
println(stdout, "A by col (1, 2, 16 thread): $gbresultsC")
167208
println(stdout, "SparseArrays: $SAresults")
168209
flush(stdout)
169-
210+
#
170211
printstyled(stdout, "\nSparse * Sparse'"; bold=true)
171212
println(stdout, "################################")
172213
flush(stdout)
@@ -179,32 +220,31 @@ function singlebench(pathornum)
179220
A2 = SparseMatrixCSC(A)
180221
SAresults = mxm(A2, transpose(A2))
181222
println(stdout, )
182-
printstyled(stdout, "\nRESULTS, Sparse * Sparse: \n"; bold=true, color=:green)
223+
printstyled(stdout, "\nRESULTS, Sparse * n x 32 Dense: \n"; bold=true, color=:green)
183224
println(stdout, "################################")
184225
println(stdout, "A by row (1, 2, 16 thread): $gbresultsR")
185226
println(stdout, "A by col (1, 2, 16 thread): $gbresultsC")
186227
println(stdout, "SparseArrays: $SAresults")
187228
flush(stdout)
188229

189-
printstyled(stdout, "\nSparse * Sparse'"; bold=true)
230+
printstyled(stdout, "\nC = copy(transpose(A))"; bold=true)
190231
println(stdout, "################################")
191232
flush(stdout)
192233
gbset(A, :format, SuiteSparseGraphBLAS.BYROW)
193234
diag(A)
194-
gbresultsR = runthreaded(A, transpose(A))
235+
gbresultsR = runthreadedt(A)
195236
gbset(A, :format, SuiteSparseGraphBLAS.BYCOL)
196237
diag(A)
197-
gbresultsC = runthreaded(A, transpose(A))
198-
A2 = SparseMatrixCSC(A)
199-
SAresults = mxm(A2, transpose(A2))
238+
gbresultsC = runthreadedt(A)
239+
A2 = SparseMatrixCSC(A)
240+
SAresults = tpose(A2)
200241
println(stdout, )
201-
printstyled(stdout, "\nRESULTS, Sparse * Sparse: \n"; bold=true, color=:green)
242+
printstyled(stdout, "\nRESULTS, C = copy(transpose(A)): \n"; bold=true, color=:green)
202243
println(stdout, "################################")
203244
println(stdout, "A by row (1, 2, 16 thread): $gbresultsR")
204245
println(stdout, "A by col (1, 2, 16 thread): $gbresultsC")
205246
println(stdout, "SparseArrays: $SAresults")
206247
flush(stdout)
207-
208248
return nothing
209249
end
210250

src/SuiteSparseGraphBLAS.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function __init__()
143143
# In the future this should hopefully allow us to do no-copy passing of arrays between Julia and SS:GrB.
144144
# In the meantime it helps Julia respond to memory pressure from SS:GrB and finalize things in a timely fashion.
145145
@wraperror LibGraphBLAS.GxB_init(LibGraphBLAS.GrB_NONBLOCKING, cglobal(:jl_malloc), cglobal(:jl_calloc), cglobal(:jl_realloc), cglobal(:jl_free))
146-
gbset(:nthreads, Sys.CPU_THREADS ÷ 2)
146+
gbset(:nthreads, BLAS.get_num_threads())
147147
# Eagerly load selectops constants.
148148
_loadselectops()
149149
ALL.p = load_global("GrB_ALL", LibGraphBLAS.GrB_Index)

src/wait.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
function Base.wait(A::AbstractGBArray)
22
waitmode = LibGraphBLAS.GrB_MATERIALIZE
33
@wraperror LibGraphBLAS.GrB_Matrix_wait(gbpointer(A), waitmode)
4-
return nothing
4+
return A
55
end
66

77
function Base.wait(A::LibGraphBLAS.GrB_UnaryOp)
88
waitmode = LibGraphBLAS.GrB_MATERIALIZE
99
@wraperror LibGraphBLAS.GrB_UnaryOp_wait(A, waitmode)
10-
return nothing
10+
return A
1111
end
1212

1313
function Base.wait(A::LibGraphBLAS.GrB_BinaryOp)
1414
waitmode = LibGraphBLAS.GrB_MATERIALIZE
1515
@wraperror LibGraphBLAS.GrB_BinaryOp_wait(A, waitmode)
16-
return nothing
16+
return A
1717
end
1818

1919
function Base.wait(A::LibGraphBLAS.GxB_SelectOp)
2020
waitmode = LibGraphBLAS.GrB_MATERIALIZE
2121
@wraperror LibGraphBLAS.GrB_SelectOp_wait(A, waitmode)
22-
return nothing
22+
return A
2323
end
2424

2525
function Base.wait(A::LibGraphBLAS.GrB_IndexUnaryOp)
2626
waitmode = LibGraphBLAS.GrB_MATERIALIZE
2727
@wraperror LibGraphBLAS.GrB_IndexUnaryOp_wait(A, waitmode)
28-
return nothing
28+
return A
2929
end
3030

3131
function Base.wait(A::LibGraphBLAS.GrB_Monoid)
3232
waitmode = LibGraphBLAS.GrB_MATERIALIZE
3333
@wraperror LibGraphBLAS.GrB_Monoid_wait(A, waitmode)
34-
return nothing
34+
return A
3535
end
3636

3737
function Base.wait(A::LibGraphBLAS.GrB_Semiring)
3838
waitmode = LibGraphBLAS.GrB_MATERIALIZE
3939
@wraperror LibGraphBLAS.GrB_Semiring_wait(A, waitmode)
40-
return nothing
40+
return A
4141
end
4242

4343
function Base.wait(A::GBScalar)
4444
waitmode = LibGraphBLAS.GrB_MATERIALIZE
4545
@wraperror LibGraphBLAS.GrB_Scalar_wait(A, waitmode)
46-
return nothing
46+
return A
4747
end

0 commit comments

Comments
 (0)