-
Notifications
You must be signed in to change notification settings - Fork 7
MSBFS #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
MSBFS #90
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
1cacb79
Set dataset folder to default
kirillgarbar 2b23505
Merge pull request #87 from kirillgarbar/fix
gsvgit 01c35d3
SSSP return vector
kirillgarbar 83c860e
BFS sparse and push-pull on int32
kirillgarbar 735f064
PageRank
kirillgarbar 988672e
BFS, SSSP, PR benchmarks
kirillgarbar 78c7964
Vector.create
kirillgarbar 7e914f1
PageRank on ClMatrix and ClVector
kirillgarbar a38aa20
PageRank test case
kirillgarbar f1a6f24
Formatting
kirillgarbar edc5a73
Vector.create tests
kirillgarbar 6f6c629
Rename
kirillgarbar cadb104
Pass accurasy to PR
kirillgarbar baa0c0b
Private functiona and constants
kirillgarbar 15f415e
PageRank test property
kirillgarbar 39361c4
Fix formatting bug
kirillgarbar e548294
Benchmark rename
kirillgarbar 483b644
merge: kirillgarbar/dev branch into msbfs
artemiipatov 2199287
add: matrix intersect
artemiipatov 00bdd5a
add: msbfs levels
artemiipatov 97281a6
add: spgemm coo->csr->coo
artemiipatov 1538ad6
add: msbfs parents
artemiipatov cf10d92
fix: msbfs parents
artemiipatov 1558c6d
add: tests
artemiipatov e78e50e
refactor: formatting
artemiipatov 95941af
wip: tests and msbfs bug fix
artemiipatov 7b21b4f
fix: msbfs levels bug
artemiipatov f4016eb
fix: msbfs tests
artemiipatov 94fec78
fix: msbfs parents bug
artemiipatov 3d9654d
fix: msbfs parents, clarray.copyto bugs
artemiipatov e33db1a
fix: mergeDisjoint, msbfs, intersect tests bugs
artemiipatov 63a44e3
refactor: formatting
artemiipatov dacc3e1
merge dev
artemiipatov d6373cc
revert: kirill's changes comming with pagerank pr
artemiipatov 9a9b7f9
revert: benchmarks changes
artemiipatov a94fd07
revert: benchmarks configs
artemiipatov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
benchmarks/GraphBLAS-sharp.Benchmarks/Configs/WorkflowTargets.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
BFSBenchmark | ||
BFSWithoutTransfer |
2 changes: 1 addition & 1 deletion
2
benchmarks/GraphBLAS-sharp.Benchmarks/GraphBLAS-sharp.Benchmarks.fsproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,265 @@ | ||
namespace GraphBLAS.FSharp.Backend.Algorithms | ||
|
||
open Brahma.FSharp | ||
open FSharp.Quotations | ||
open GraphBLAS.FSharp | ||
open GraphBLAS.FSharp.Objects | ||
open GraphBLAS.FSharp.Common | ||
open GraphBLAS.FSharp.Objects.ClMatrix | ||
open GraphBLAS.FSharp.Objects.ArraysExtensions | ||
open GraphBLAS.FSharp.Objects.ClContextExtensions | ||
open GraphBLAS.FSharp.Objects.ClCellExtensions | ||
open GraphBLAS.FSharp.Backend.Quotes | ||
open GraphBLAS.FSharp.Backend.Matrix.LIL | ||
open GraphBLAS.FSharp.Backend.Matrix.COO | ||
|
||
module internal MSBFS = | ||
let private frontExclude (clContext: ClContext) workGroupSize = | ||
|
||
let invert = | ||
ClArray.mapInPlace ArithmeticOperations.intNotQ clContext workGroupSize | ||
|
||
let prefixSum = | ||
PrefixSum.standardExcludeInPlace clContext workGroupSize | ||
|
||
let scatterIndices = | ||
Scatter.lastOccurrence clContext workGroupSize | ||
|
||
let scatterValues = | ||
Scatter.lastOccurrence clContext workGroupSize | ||
|
||
fun (queue: MailboxProcessor<_>) allocationMode (front: ClMatrix.COO<_>) (intersection: ClArray<int>) -> | ||
|
||
invert queue intersection | ||
|
||
let length = | ||
(prefixSum queue intersection).ToHostAndFree queue | ||
|
||
if length = 0 then | ||
None | ||
else | ||
let rows = | ||
clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, length) | ||
|
||
let columns = | ||
clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, length) | ||
|
||
let values = | ||
clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, length) | ||
|
||
scatterIndices queue intersection front.Rows rows | ||
scatterIndices queue intersection front.Columns columns | ||
scatterValues queue intersection front.Values values | ||
|
||
{ Context = clContext | ||
Rows = rows | ||
Columns = columns | ||
Values = values | ||
RowCount = front.RowCount | ||
ColumnCount = front.ColumnCount } | ||
|> Some | ||
|
||
module Levels = | ||
let private updateFrontAndLevels (clContext: ClContext) workGroupSize = | ||
|
||
let updateFront = frontExclude clContext workGroupSize | ||
|
||
let mergeDisjoint = | ||
Matrix.mergeDisjoint clContext workGroupSize | ||
|
||
let setLevel = ClArray.fill clContext workGroupSize | ||
|
||
let findIntersection = | ||
Intersect.findKeysIntersection clContext workGroupSize | ||
|
||
fun (queue: MailboxProcessor<_>) allocationMode (level: int) (front: ClMatrix.COO<_>) (levels: ClMatrix.COO<_>) -> | ||
|
||
// Find intersection of levels and front indices. | ||
let intersection = | ||
findIntersection queue DeviceOnly front levels | ||
|
||
// Remove mutual elements | ||
let newFront = | ||
updateFront queue allocationMode front intersection | ||
|
||
intersection.Free queue | ||
|
||
match newFront with | ||
| Some f -> | ||
let levelClCell = clContext.CreateClCell level | ||
|
||
// Set current level value to all remaining front positions | ||
setLevel queue levelClCell 0 f.Values.Length f.Values | ||
|
||
levelClCell.Free queue | ||
|
||
// Update levels | ||
let newLevels = mergeDisjoint queue levels f | ||
|
||
newLevels, newFront | ||
| _ -> levels, None | ||
|
||
let run<'a when 'a: struct> | ||
(add: Expr<int -> int -> int option>) | ||
(mul: Expr<int -> 'a -> int option>) | ||
(clContext: ClContext) | ||
workGroupSize | ||
= | ||
|
||
let spGeMM = | ||
Operations.SpGeMM.COO.expand add mul clContext workGroupSize | ||
|
||
let copy = Matrix.copy clContext workGroupSize | ||
|
||
let updateFrontAndLevels = | ||
updateFrontAndLevels clContext workGroupSize | ||
|
||
fun (queue: MailboxProcessor<Msg>) (matrix: ClMatrix<'a>) (source: int list) -> | ||
let vertexCount = matrix.RowCount | ||
let sourceVertexCount = source.Length | ||
|
||
let source = source |> List.sort | ||
|
||
let startMatrix = | ||
source |> List.mapi (fun i vertex -> i, vertex, 1) | ||
|
||
let mutable levels = | ||
startMatrix | ||
|> Matrix.ofList clContext DeviceOnly sourceVertexCount vertexCount | ||
|
||
let mutable front = copy queue DeviceOnly levels | ||
|
||
let mutable level = 1 | ||
let mutable stop = false | ||
|
||
while not stop do | ||
level <- level + 1 | ||
|
||
//Getting new frontier | ||
match spGeMM queue DeviceOnly (ClMatrix.COO front) matrix with | ||
| None -> | ||
front.Dispose queue | ||
stop <- true | ||
|
||
| Some newFrontier -> | ||
front.Dispose queue | ||
|
||
//Filtering visited vertices | ||
match updateFrontAndLevels queue DeviceOnly level newFrontier levels with | ||
| l, Some f -> | ||
front <- f | ||
|
||
levels.Dispose queue | ||
|
||
levels <- l | ||
|
||
newFrontier.Dispose queue | ||
|
||
| _, None -> | ||
stop <- true | ||
newFrontier.Dispose queue | ||
|
||
ClMatrix.COO levels | ||
|
||
module Parents = | ||
let private updateFrontAndParents (clContext: ClContext) workGroupSize = | ||
let frontExclude = frontExclude clContext workGroupSize | ||
|
||
let mergeDisjoint = | ||
Matrix.mergeDisjoint clContext workGroupSize | ||
|
||
let findIntersection = | ||
Intersect.findKeysIntersection clContext workGroupSize | ||
|
||
let copyIndices = ClArray.copyTo clContext workGroupSize | ||
|
||
fun (queue: MailboxProcessor<Msg>) allocationMode (front: ClMatrix.COO<_>) (parents: ClMatrix.COO<_>) -> | ||
|
||
// Find intersection of levels and front indices. | ||
let intersection = | ||
findIntersection queue DeviceOnly front parents | ||
|
||
// Remove mutual elements | ||
let newFront = | ||
frontExclude queue allocationMode front intersection | ||
|
||
intersection.Free queue | ||
|
||
match newFront with | ||
| Some f -> | ||
// Update parents | ||
let newParents = mergeDisjoint queue parents f | ||
|
||
copyIndices queue f.Columns f.Values | ||
|
||
newParents, Some f | ||
|
||
| _ -> parents, None | ||
|
||
let run<'a when 'a: struct> (clContext: ClContext) workGroupSize = | ||
|
||
let spGeMM = | ||
Operations.SpGeMM.COO.expand | ||
(ArithmeticOperations.min) | ||
(ArithmeticOperations.fst) | ||
clContext | ||
workGroupSize | ||
|
||
let updateFrontAndParents = | ||
updateFrontAndParents clContext workGroupSize | ||
|
||
fun (queue: MailboxProcessor<Msg>) (inputMatrix: ClMatrix<'a>) (source: int list) -> | ||
let vertexCount = inputMatrix.RowCount | ||
let sourceVertexCount = source.Length | ||
|
||
let source = source |> List.sort | ||
|
||
let matrix = | ||
match inputMatrix with | ||
| ClMatrix.CSR m -> | ||
{ Context = clContext | ||
RowPointers = m.RowPointers | ||
Columns = m.Columns | ||
Values = m.Columns | ||
RowCount = m.RowCount | ||
ColumnCount = m.ColumnCount } | ||
|> ClMatrix.CSR | ||
| _ -> failwith "Incorrect format" | ||
|
||
let mutable parents = | ||
source | ||
|> List.mapi (fun i vertex -> i, vertex, -1) | ||
|> Matrix.ofList clContext DeviceOnly sourceVertexCount vertexCount | ||
|
||
let mutable front = | ||
source | ||
|> List.mapi (fun i vertex -> i, vertex, vertex) | ||
|> Matrix.ofList clContext DeviceOnly sourceVertexCount vertexCount | ||
|
||
let mutable stop = false | ||
|
||
while not stop do | ||
//Getting new frontier | ||
match spGeMM queue DeviceOnly (ClMatrix.COO front) matrix with | ||
| None -> | ||
front.Dispose queue | ||
stop <- true | ||
|
||
| Some newFrontier -> | ||
front.Dispose queue | ||
|
||
//Filtering visited vertices | ||
match updateFrontAndParents queue DeviceOnly newFrontier parents with | ||
| p, Some f -> | ||
front <- f | ||
|
||
parents.Dispose queue | ||
parents <- p | ||
|
||
newFrontier.Dispose queue | ||
|
||
| _, None -> | ||
stop <- true | ||
newFrontier.Dispose queue | ||
|
||
ClMatrix.COO parents |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can BFS also be Parents and Leveles? Can unified interface be created?