Skip to content

Commit dbabc71

Browse files
committed
format
1 parent cbbdad3 commit dbabc71

File tree

11 files changed

+119
-114
lines changed

11 files changed

+119
-114
lines changed

benchmark/benchmarks.jl

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ BFS_RESULTS =
5656
DataFrame(operation = String[], size = Int[], implementation = String[], time = Real[])
5757

5858
for SIZE in SIZES
59-
SIZE2 = SIZE
60-
FILL = 0.001
59+
SIZE2 = SIZE
60+
FILL = 0.001
6161
print("Generating random sparse matrix of size $SIZE x $SIZE2 with fill $FILL\n")
6262
A_csc_cpu =
6363
convert(SparseMatrixCSC{MAIN_TYPE,INDEX_TYPE}, sprand(MAIN_TYPE, SIZE2, SIZE, FILL))
@@ -308,7 +308,7 @@ for i = 1:4
308308
KernelAbstractions.synchronize(BACKEND)
309309
end evals = 1 setup =
310310
(res_gpu = KernelAbstractions.zeros(BACKEND, ELTYPE_RES, $SIZE))
311-
311+
312312
SUITE2["mul!"]["GPU"]["GPUGraphsSELL"] = @benchmarkable begin
313313
for j = 1:10
314314
gpu_spmv!(res_gpu, $A_sell_gpu, $b_gpu; mul = MUL, add = ADD, accum = ACCUM)
@@ -324,46 +324,51 @@ for i = 1:4
324324
KernelAbstractions.synchronize(BACKEND)
325325
end evals = 1 setup =
326326
(res_gpu = KernelAbstractions.zeros(BACKEND, ELTYPE_RES, $SIZE))
327-
327+
328328

329329
graph = SimpleGraph(A_T)
330330
println("Built graph. ")
331331

332-
A_csr_cpu = transpose(convert(SparseMatrixCSC{BOOL_TYPE,INDEX_TYPE}, adjacency_matrix(graph, BOOL_TYPE; dir = :out)))
332+
A_csr_cpu = transpose(
333+
convert(
334+
SparseMatrixCSC{BOOL_TYPE,INDEX_TYPE},
335+
adjacency_matrix(graph, BOOL_TYPE; dir = :out),
336+
),
337+
)
333338
print("Converting to GPU-CSR format\n")
334339
A_csr_gpu = SparseGPUMatrixCSR(A_csr_cpu, BACKEND)
335340

336341
print("Converting to SELL format\n")
337342
A_sell_gpu = SparseGPUMatrixSELL(A_csr_cpu, 64, BACKEND)
338343

339-
SUITE2["bfs"]["CPU"]["SuiteSparseGraphBLAS"] = @benchmarkable begin
340-
bfs_BLAS!($A_ssGB, one(INDEX_TYPE), res_ssGB)
341-
end evals = 1 setup =
342-
(res_ssGB = GBVector{INDEX_TYPE}($SIZE, fill = zero(INDEX_TYPE)))
344+
SUITE2["bfs"]["CPU"]["SuiteSparseGraphBLAS"] = @benchmarkable begin
345+
bfs_BLAS!($A_ssGB, one(INDEX_TYPE), res_ssGB)
346+
end evals = 1 setup =
347+
(res_ssGB = GBVector{INDEX_TYPE}($SIZE, fill = zero(INDEX_TYPE)))
343348

344-
SUITE2["bfs"]["GPU"]["GPUGraphsCSR"] = @benchmarkable begin
345-
GPUGraphs.bfs_parents($A_csr_gpu, one(INDEX_TYPE))
346-
KernelAbstractions.synchronize(BACKEND)
347-
end evals = 1
349+
SUITE2["bfs"]["GPU"]["GPUGraphsCSR"] = @benchmarkable begin
350+
GPUGraphs.bfs_parents($A_csr_gpu, one(INDEX_TYPE))
351+
KernelAbstractions.synchronize(BACKEND)
352+
end evals = 1
348353

349-
end
354+
end
350355

351-
if i >= 2
356+
if i >= 2
352357

353-
SUITE2["mul!"]["GPU"]["GPUGraphsSELL"] = @benchmarkable begin
354-
for j = 1:10
355-
gpu_spmv!(res_gpu, $A_sell_gpu, $b_gpu; mul = MUL, add = ADD, accum = ACCUM)
356-
end
357-
KernelAbstractions.synchronize(BACKEND)
358-
end evals = 1 setup =
359-
(res_gpu = KernelAbstractions.zeros(BACKEND, ELTYPE_RES, $SIZE))
360-
361-
if MAIN_TYPE == Bool
362-
SUITE2["bfs"]["GPU"]["GPUGraphsSELL"] = @benchmarkable begin
363-
GPUGraphs.bfs_parents($A_sell_gpu, one(INDEX_TYPE))
364-
KernelAbstractions.synchronize(BACKEND)
365-
end evals = 1
358+
SUITE2["mul!"]["GPU"]["GPUGraphsSELL"] = @benchmarkable begin
359+
for j = 1:10
360+
gpu_spmv!(res_gpu, $A_sell_gpu, $b_gpu; mul = MUL, add = ADD, accum = ACCUM)
366361
end
362+
KernelAbstractions.synchronize(BACKEND)
363+
end evals = 1 setup =
364+
(res_gpu = KernelAbstractions.zeros(BACKEND, ELTYPE_RES, $SIZE))
365+
366+
if MAIN_TYPE == Bool
367+
SUITE2["bfs"]["GPU"]["GPUGraphsSELL"] = @benchmarkable begin
368+
GPUGraphs.bfs_parents($A_sell_gpu, one(INDEX_TYPE))
369+
KernelAbstractions.synchronize(BACKEND)
370+
end evals = 1
371+
end
367372

368373
println("Launching benchmarks\n")
369374
bench_res2 = run(SUITE2)

benchmark/plots.jl

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ savefig(p_bfs, "benchmark/out/plot_bfs_results.png")
5050
# Plot the speedup relative to the SuiteSparseGraphBLAS implementation
5151

5252
# Get the times
53-
ssgb_times = df[df.implementation.=="SuiteSparseGraphBLAS", :time]
54-
csr_gpu_times = df[df.implementation.=="GPUGraphsCSR", :time]
55-
ell_gpu_times = df[df.implementation.=="GPUGraphsELL", :time]
56-
cusparse_csr_times = df[df.implementation.=="CUSPARSE-CSR", :time]
57-
cusparse_csc_times = df[df.implementation.=="CUSPARSE-CSC", :time]
53+
ssgb_times = df[df.implementation .== "SuiteSparseGraphBLAS", :time]
54+
csr_gpu_times = df[df.implementation .== "GPUGraphsCSR", :time]
55+
ell_gpu_times = df[df.implementation .== "GPUGraphsELL", :time]
56+
cusparse_csr_times = df[df.implementation .== "CUSPARSE-CSR", :time]
57+
cusparse_csc_times = df[df.implementation .== "CUSPARSE-CSC", :time]
5858

5959

6060

@@ -83,9 +83,9 @@ savefig(speedup_plot, "benchmark/out/plot_spmv_speedup.png")
8383
# Get the times
8484
graphsjl_times = df_bfs[df_bfs.implementation .== "Graphs.jl", :time]
8585

86-
ssgb_times = df_bfs[df_bfs.implementation.=="SuiteSparseGraphBLAS", :time]
87-
csr_gpu_times = df_bfs[df_bfs.implementation.=="GPUGraphsCSR", :time]
88-
ell_gpu_times = df_bfs[df_bfs.implementation.=="GPUGraphsELL", :time]
86+
ssgb_times = df_bfs[df_bfs.implementation .== "SuiteSparseGraphBLAS", :time]
87+
csr_gpu_times = df_bfs[df_bfs.implementation .== "GPUGraphsCSR", :time]
88+
ell_gpu_times = df_bfs[df_bfs.implementation .== "GPUGraphsELL", :time]
8989

9090
# Calculate the speedup
9191
speedup_ssgb = graphsjl_times ./ ssgb_times
@@ -116,7 +116,7 @@ df2_bfs = DataFrame(CSV.File("benchmark/out/bfs_results_data.csv"))
116116
df2_bfs[!, :time] /= 1e9 # convert ns to s
117117

118118
# For each dataset, normalize the time by the time of the SuiteSparseGraphBLAS implementation
119-
gb_times = df2[df2.implementation.=="CUSPARSE-CSR", :time]
119+
gb_times = df2[df2.implementation .== "CUSPARSE-CSR", :time]
120120
gb_times_column = repeat(gb_times, inner = 4)
121121
# Normalize the time by the SuiteSparseGraphBLAS time
122122
df2[!, :time] = julia_times_column ./ df2[!, :time]
@@ -136,16 +136,16 @@ p2 = @df df2 bar(
136136
)
137137
# Add the speedup
138138
speedups = df2[!, :time]
139-
if false
140-
annotate!(1, 0, text("$(round(speedups[1], digits = 2))x \n", :black, 8, :center))
141-
annotate!(2, 0, text("$(round(speedups[2], digits = 2))x \n", :black, 8, :center))
142-
annotate!(3, 0, text("$(round(speedups[3], digits = 2))x \n", :black, 8, :center))
143-
annotate!(4, 0, text("$(round(speedups[4], digits = 2))x \n", :black, 8, :center))
144-
annotate!(5, 0, text("$(round(speedups[5], digits = 2))x \n", :black, 8, :center))
145-
annotate!(6, 0, text("$(round(speedups[6], digits = 2))x \n", :black, 8, :center))
146-
annotate!(7, 0, text("$(round(speedups[7], digits = 2))x \n", :black, 8, :center))
147-
annotate!(8, 0, text("$(round(speedups[8], digits = 2))x \n", :black, 8, :center))
148-
annotate!(9, 0, text("$(round(speedups[9], digits = 2))x \n", :black, 8, :center))
139+
if false
140+
annotate!(1, 0, text("$(round(speedups[1], digits = 2))x \n", :black, 8, :center))
141+
annotate!(2, 0, text("$(round(speedups[2], digits = 2))x \n", :black, 8, :center))
142+
annotate!(3, 0, text("$(round(speedups[3], digits = 2))x \n", :black, 8, :center))
143+
annotate!(4, 0, text("$(round(speedups[4], digits = 2))x \n", :black, 8, :center))
144+
annotate!(5, 0, text("$(round(speedups[5], digits = 2))x \n", :black, 8, :center))
145+
annotate!(6, 0, text("$(round(speedups[6], digits = 2))x \n", :black, 8, :center))
146+
annotate!(7, 0, text("$(round(speedups[7], digits = 2))x \n", :black, 8, :center))
147+
annotate!(8, 0, text("$(round(speedups[8], digits = 2))x \n", :black, 8, :center))
148+
annotate!(9, 0, text("$(round(speedups[9], digits = 2))x \n", :black, 8, :center))
149149
end
150150
display(p2)
151151

@@ -168,7 +168,6 @@ p2_bfs = @df df2_bfs bar(
168168
legend = :topleft,
169169
title = "BFS",
170170
ylim = (0, 1),
171-
172171
)
173172
# Add the speedup
174173
speedups_bfs = 1 ./ df2_bfs[!, :time]

src/algorithms/shortest_path.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function shortest_path!(
5757
while true
5858

5959
iter += one(Ti)
60-
60+
6161
gpu_spmv!(
6262
next,
6363
A_T,
@@ -74,7 +74,7 @@ function shortest_path!(
7474
return nothing
7575
end
7676
end
77-
77+
7878
# Update the dist array
7979
dist .= next
8080

src/spmm/CSC.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#TODO
1+
#TODO

src/spmm/spmm.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
include("CSR.jl")
33
include("CSC.jl")
4-
include("SELL.jl")
4+
include("SELL.jl")

src/spmv/CSC.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ function gpu_spmv!(
5858
accum;
5959
ndrange = size(A, 1),
6060
)
61-
end
61+
end

src/spmv/SELL.jl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ function gpu_spmv!(
66
mul::Function = GPUGraphs_mul,
77
add::Function = GPUGraphs_add,
88
accum::Function = GPUGraphs_second,
9-
range::Union{Nothing, UnitRange} = nothing,
10-
mask::Union{Nothing, AbstractVector} = nothing,
9+
range::Union{Nothing,UnitRange} = nothing,
10+
mask::Union{Nothing,AbstractVector} = nothing,
1111
) where {
1212
Tv,
1313
Ti<:Integer,
@@ -20,9 +20,9 @@ function gpu_spmv!(
2020
if mask === nothing && range === nothing
2121
_simple_gpu_spmv!(C, A, B, mul, add, accum)
2222
elseif mask !== nothing && range === nothing
23-
_dense_mask_gpu_spmv!(C, A, B, mul, add, accum, mask)
23+
_dense_mask_gpu_spmv!(C, A, B, mul, add, accum, mask)
2424
elseif mask === nothing && range !== nothing
25-
_range_gpu_spmv!(C, A, B,mul, add, accum, range)
25+
_range_gpu_spmv!(C, A, B, mul, add, accum, range)
2626
else
2727
_range_mask_gpu_spmv!(C, A, B, mul, add, accum, mask, range)
2828
end
@@ -123,7 +123,7 @@ end
123123
acc = monoid_neutral_element
124124
for i = (a_slice_ptr[slice]+offset):slice_size:(a_slice_ptr[slice+1]-1)
125125
col = a_col_val[i]
126-
if col == -1
126+
if col == -1
127127
break
128128
end
129129
acc = add(acc, mul(a_nz_val[i], b[col], row, col, col, 1), row, col, col, 1)
@@ -273,7 +273,7 @@ end
273273
acc = monoid_neutral_element
274274
for i = (a_slice_ptr[slice]+offset):slice_size:(a_slice_ptr[slice+1]-1)
275275
col = a_col_val[i]
276-
if col == -1
276+
if col == -1
277277
break
278278
end
279279
acc = add(acc, mul(a_nz_val[i], b[col], row, col, col, 1), row, col, col, 1)
@@ -342,22 +342,26 @@ function _validate_args(
342342
MaskVec<:AbstractVector{Tmask},
343343
}
344344
# Check dimensions
345-
if size(A, 2) != length(B)
345+
if size(A, 2) != length(B)
346346
throw(DimensionMismatch("Matrix dimensions must agree"))
347347
end
348348
if size(C, 1) != size(A, 1)
349349
throw(DimensionMismatch("Matrix dimensions must agree"))
350350
end
351351
# Check types
352352
if !(promote_type(Tv, InputType) <: ResType)
353-
throw(ArgumentError("Result type must be able to hold the result of the multiplication"))
353+
throw(
354+
ArgumentError(
355+
"Result type must be able to hold the result of the multiplication",
356+
),
357+
)
354358
end
355359
# Check backends
356360
backend = get_backend(A)
357361
if get_backend(B) != backend || get_backend(C) != backend
358362
throw(ArgumentError("All inputs must be on the same backend"))
359363
end
360-
# Check mask if provided
364+
# Check mask if provided
361365
if mask !== nothing
362366
# Check mask type
363367
if !(typeof(mask) <: AbstractVector{Tmask})
@@ -372,4 +376,4 @@ function _validate_args(
372376
throw(ArgumentError("Mask must be on the same backend as A"))
373377
end
374378
end
375-
end
379+
end

src/storage/CSR.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,3 @@ sprand_gpu(::Type{Tv}, m::Int, n::Int, p::Real, backend::Backend) where {Tv} =
187187

188188
# KA functions
189189
KernelAbstractions.get_backend(A::SparseGPUMatrixCSR) = get_backend(A.nzval)
190-

src/storage/GPUGraphsMatrix.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"
44
Abstract type for a GPU compatible sparse matrix
55
"
6-
abstract type AbstractSparseGPUMatrix{Tv,Ti<:Integer} <: SparseArrays.AbstractSparseMatrix{Tv,Ti}
7-
end
6+
abstract type AbstractSparseGPUMatrix{Tv,Ti<:Integer} <:
7+
SparseArrays.AbstractSparseMatrix{Tv,Ti} end
88

99
include("CSC.jl")
1010
include("CSR.jl")
11-
include("SELL.jl")
11+
include("SELL.jl")

src/storage/SELL.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function SparseGPUMatrixSELL(
152152

153153

154154
end
155-
155+
156156
# Reshape the sub-matrix to make it column-major vector and copy it to final storage
157157

158158
colval_padded[slice_ptr[slice]:(slice_ptr[slice+1]-1)] =
@@ -245,4 +245,3 @@ SparseArrays.nnz(A::SparseGPUMatrixSELL) = A.nnz
245245

246246
# KA functions
247247
KernelAbstractions.get_backend(A::SparseGPUMatrixSELL) = get_backend(A.nzval)
248-

0 commit comments

Comments
 (0)