Skip to content

Commit 9978cb6

Browse files
author
Will Kimmerer
committed
wait returns object waited on
1 parent c440185 commit 9978cb6

File tree

5 files changed

+202
-20
lines changed

5 files changed

+202
-20
lines changed

benchmarks/Manifest.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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"

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

benchmarks/benchmarks2.jl

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function tpose(A::SparseMatrixCSC)
9393
return result
9494
end
9595

96-
function runthreadedt(A, B; accumdenseoutput=false)
96+
function runthreadedt(A; accumdenseoutput=false)
9797
v = []
9898
for t threadlist
9999
printstyled(stdout, "\nRunning GraphBLAS with $t threads\n"; bold=true)
@@ -103,6 +103,37 @@ function runthreadedt(A, B; accumdenseoutput=false)
103103
return v
104104
end
105105

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
135+
end
136+
106137
function singlebench(pathornum)
107138
x = tryparse(Int64, pathornum)
108139
if x !== nothing
@@ -114,14 +145,14 @@ function singlebench(pathornum)
114145
throw(ErrorException("Argument is not a path or SuiteSparseMatrixCollection ID number"))
115146
end
116147
name = basename(path)
117-
A = SuiteSparseGraphBLAS.mmread(path)
118-
if eltype(A) == Bool
119-
A = Int64.(A)
120-
end
121-
GC.gc()
122-
printstyled(stdout, "\n#################################################################################\n"; bold=true, color=:green)
123-
printstyled(stdout, "Benchmarking $name:\n"; bold=true, color=:green)
124-
printstyled(stdout, "#################################################################################\n"; bold=true, color=:green)
148+
# A = SuiteSparseGraphBLAS.mmread(path)
149+
# if eltype(A) == Bool
150+
# A = Int64.(A)
151+
# end
152+
# GC.gc()
153+
# printstyled(stdout, "\n#################################################################################\n"; bold=true, color=:green)
154+
# printstyled(stdout, "Benchmarking $name:\n"; bold=true, color=:green)
155+
# printstyled(stdout, "#################################################################################\n"; bold=true, color=:green)
125156

126157
# printstyled(stdout, "\nSparse * Vec\n"; bold=true)
127158
# println(stdout, "################################")
@@ -214,14 +245,41 @@ function singlebench(pathornum)
214245
# println(stdout, "A by col (1, 2, 16 thread): $gbresultsC")
215246
# println(stdout, "SparseArrays: $SAresults")
216247
# flush(stdout)
217-
printstyled(stdout, "\nC = copy(transpose(A))"; bold=true)
248+
# printstyled(stdout, "\nC = copy(transpose(A))"; bold=true)
249+
# println(stdout, "################################")
250+
# flush(stdout)
251+
# gbset(A, :format, SuiteSparseGraphBLAS.BYROW)
252+
# diag(A)
253+
# gbresultsR = runthreadedt(A)
254+
# gbset(A, :format, SuiteSparseGraphBLAS.BYCOL)
255+
# diag(A)
256+
# gbresultsC = runthreadedt(A)
257+
# A2 = SparseMatrixCSC(A)
258+
# SAresults = tpose(A2)
259+
# println(stdout, )
260+
# printstyled(stdout, "\nRESULTS, C = copy(transpose(A)): \n"; bold=true, color=:green)
261+
# println(stdout, "################################")
262+
# println(stdout, "A by row (1, 2, 16 thread): $gbresultsR")
263+
# println(stdout, "A by col (1, 2, 16 thread): $gbresultsC")
264+
# println(stdout, "SparseArrays: $SAresults")
265+
# flush(stdout)
266+
267+
268+
printstyled(stdout, "\nC[I, J] = A)"; bold=true)
218269
println(stdout, "################################")
270+
C = SuiteSparseGraphBLAS.wait(SuiteSparseGraphBLAS.gbrand(Float64, 25_000_000, 25_000_000, 5.76e-8))
271+
A = SuiteSparseGraphBLAS.wait(SuiteSparseGraphBLAS.gbrand(Float64, 5_000, 5_000, 0.002))
272+
I = rand(1:size(C, 1), size(A, 1))
273+
J = rand(1:size(C, 2), size(A, 2))
274+
219275
flush(stdout)
220276
gbset(A, :format, SuiteSparseGraphBLAS.BYROW)
221-
diag(A)
277+
gbset(C, :format, SuiteSparseGraphBLAS.BYROW)
278+
SuiteSparseGraphBLAS.wait(A)
222279
gbresultsR = runthreadedt(A, transpose(A))
223280
gbset(A, :format, SuiteSparseGraphBLAS.BYCOL)
224-
diag(A)
281+
gbset(C, :format, SuiteSparseGraphBLAS.BYCOL)
282+
SuiteSparseGraphBLAS.wait(A)
225283
gbresultsC = runthreadedt(A, transpose(A))
226284
A2 = SparseMatrixCSC(A)
227285
SAresults = tpose(A2)

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)