Skip to content

Commit e78e50e

Browse files
committed
refactor: formatting
1 parent 1558c6d commit e78e50e

14 files changed

Lines changed: 176 additions & 110 deletions

File tree

src/GraphBLAS-sharp.Backend/Algorithms/MSBFS.fs

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@ open GraphBLAS.FSharp.Backend.Matrix.COO
1414
module internal MSBFS =
1515
let private frontExclude (clContext: ClContext) workGroupSize =
1616

17-
let excludeValues = ClArray.excludeElements clContext workGroupSize
17+
let excludeValues =
18+
ClArray.excludeElements clContext workGroupSize
1819

19-
let excludeIndices = ClArray.excludeElements clContext workGroupSize
20+
let excludeIndices =
21+
ClArray.excludeElements clContext workGroupSize
2022

2123
fun (queue: MailboxProcessor<_>) allocationMode (front: ClMatrix.COO<_>) (intersection: ClArray<int>) ->
2224

23-
let newRows = excludeIndices queue allocationMode intersection front.Rows
25+
let newRows =
26+
excludeIndices queue allocationMode intersection front.Rows
2427

25-
let newColumns = excludeIndices queue allocationMode intersection front.Columns
28+
let newColumns =
29+
excludeIndices queue allocationMode intersection front.Columns
2630

27-
let newValues = excludeValues queue allocationMode intersection front.Values
31+
let newValues =
32+
excludeValues queue allocationMode intersection front.Values
2833

2934
match newRows, newColumns, newValues with
3035
| Some rows, Some columns, Some values ->
@@ -42,17 +47,21 @@ module internal MSBFS =
4247

4348
let updateFront = frontExclude clContext workGroupSize
4449

45-
let mergeDisjoint = Matrix.mergeDisjoint clContext workGroupSize
50+
let mergeDisjoint =
51+
Matrix.mergeDisjoint clContext workGroupSize
4652

47-
let findIntersection = Intersect.findKeysIntersection clContext workGroupSize
53+
let findIntersection =
54+
Intersect.findKeysIntersection clContext workGroupSize
4855

4956
fun (queue: MailboxProcessor<_>) allocationMode (front: ClMatrix.COO<_>) (levels: ClMatrix.COO<_>) ->
5057

5158
// Find intersection of levels and front indices.
52-
let intersection = findIntersection queue DeviceOnly front levels
59+
let intersection =
60+
findIntersection queue DeviceOnly front levels
5361

5462
// Remove mutual elements
55-
let newFront = updateFront queue allocationMode front intersection
63+
let newFront =
64+
updateFront queue allocationMode front intersection
5665

5766
intersection.Free queue
5867

@@ -75,15 +84,15 @@ module internal MSBFS =
7584

7685
let copy = Matrix.copy clContext workGroupSize
7786

78-
let updateFrontAndLevels = updateFrontAndLevels clContext workGroupSize
87+
let updateFrontAndLevels =
88+
updateFrontAndLevels clContext workGroupSize
7989

8090
fun (queue: MailboxProcessor<Msg>) (matrix: ClMatrix<'a>) (source: int list) ->
8191
let vertexCount = matrix.RowCount
8292
let sourceVertexCount = source.Length
8393

8494
let startMatrix =
85-
source
86-
|> List.mapi (fun i vertex -> i, vertex, 1)
95+
source |> List.mapi (fun i vertex -> i, vertex, 1)
8796

8897
let mutable levels =
8998
startMatrix
@@ -124,50 +133,55 @@ module internal MSBFS =
124133
workGroupSize
125134
=
126135

127-
let SSBFS = BFS.singleSourceSparse add mul clContext workGroupSize
136+
let SSBFS =
137+
BFS.singleSourceSparse add mul clContext workGroupSize
128138

129139
fun (queue: MailboxProcessor<Msg>) (matrix: ClMatrix<'a>) (source: int list) ->
130-
source
131-
|> List.map (SSBFS queue matrix)
140+
source |> List.map (SSBFS queue matrix)
132141

133142
module Parents =
134143
let private updateFrontAndParents (clContext: ClContext) workGroupSize =
135144
// update parents same as levels
136145
// every front value should be equal to its column number
137146
let frontExclude = frontExclude clContext workGroupSize
138147

139-
let mergeDisjoint = Matrix.mergeDisjoint clContext workGroupSize
148+
let mergeDisjoint =
149+
Matrix.mergeDisjoint clContext workGroupSize
140150

141-
let findIntersection = Intersect.findKeysIntersection clContext workGroupSize
151+
let findIntersection =
152+
Intersect.findKeysIntersection clContext workGroupSize
142153

143154
fun (queue: MailboxProcessor<Msg>) allocationMode (front: ClMatrix.COO<_>) (parents: ClMatrix.COO<_>) ->
144155

145156
// Find intersection of levels and front indices.
146-
let intersection = findIntersection queue DeviceOnly front parents
157+
let intersection =
158+
findIntersection queue DeviceOnly front parents
147159

148160
// Remove mutual elements
149-
let newFront = frontExclude queue allocationMode front intersection
161+
let newFront =
162+
frontExclude queue allocationMode front intersection
150163

151164
intersection.Free queue
152165

153166
match newFront with
154167
| Some f ->
155168
// Update levels
156-
let resultFront =
157-
{ f with Values = f.Columns }
169+
let resultFront = { f with Values = f.Columns }
158170
let newLevels = mergeDisjoint queue parents f
159171
newLevels, Some resultFront
160172
| _ -> parents, None
161173

162-
let run<'a when 'a: struct>
163-
(clContext: ClContext)
164-
workGroupSize
165-
=
174+
let run<'a when 'a: struct> (clContext: ClContext) workGroupSize =
166175

167176
let spGeMM =
168-
Operations.SpGeMM.COO.expand (ArithmeticOperations.min -1) (ArithmeticOperations.fst -1) clContext workGroupSize
169-
170-
let updateFrontAndLevels = updateFrontAndParents clContext workGroupSize
177+
Operations.SpGeMM.COO.expand
178+
(ArithmeticOperations.min -1)
179+
(ArithmeticOperations.fst -1)
180+
clContext
181+
workGroupSize
182+
183+
let updateFrontAndLevels =
184+
updateFrontAndParents clContext workGroupSize
171185

172186
fun (queue: MailboxProcessor<Msg>) (inputMatrix: ClMatrix<'a>) (source: int list) ->
173187
let vertexCount = inputMatrix.RowCount

src/GraphBLAS-sharp.Backend/Common/ClArray.fs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ module ClArray =
146146

147147
let kernel = program.GetKernel()
148148

149-
processor.Post(
150-
Msg.MsgSetArguments(fun () -> kernel.KernelFunc ndRange source destination source.Length)
151-
)
149+
processor.Post(Msg.MsgSetArguments(fun () -> kernel.KernelFunc ndRange source destination source.Length))
152150

153151
processor.Post(Msg.CreateRunMsg<_, _> kernel)
154152

@@ -829,7 +827,8 @@ module ClArray =
829827
/// <param name="op">The function to transform elements of the array.</param>
830828
/// <param name="clContext">OpenCL context.</param>
831829
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
832-
let mapInPlace<'a> (op: Expr<'a -> 'a>) (clContext: ClContext) workGroupSize = Map.mapInPlace op clContext workGroupSize
830+
let mapInPlace<'a> (op: Expr<'a -> 'a>) (clContext: ClContext) workGroupSize =
831+
Map.mapInPlace op clContext workGroupSize
833832

834833
/// <summary>
835834
/// Builds a new array whose elements are the results of applying the given function
@@ -839,7 +838,8 @@ module ClArray =
839838
/// <param name="op">The function to transform elements of the array.</param>
840839
/// <param name="clContext">OpenCL context.</param>
841840
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
842-
let mapWithValue<'a, 'b, 'c> (clContext: ClContext) workGroupSize (op: Expr<'a -> 'b -> 'c>) = Map.mapWithValue clContext workGroupSize op
841+
let mapWithValue<'a, 'b, 'c> (clContext: ClContext) workGroupSize (op: Expr<'a -> 'b -> 'c>) =
842+
Map.mapWithValue clContext workGroupSize op
843843

844844
/// <summary>
845845
/// Builds a new array whose elements are the results of applying the given function
@@ -851,7 +851,8 @@ module ClArray =
851851
/// <param name="map">The function to transform the pairs of the input elements.</param>
852852
/// <param name="clContext">OpenCL context.</param>
853853
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
854-
let map2<'a, 'b, 'c> (map: Expr<'a -> 'b -> 'c>) (clContext: ClContext) workGroupSize = Map.map2 map clContext workGroupSize
854+
let map2<'a, 'b, 'c> (map: Expr<'a -> 'b -> 'c>) (clContext: ClContext) workGroupSize =
855+
Map.map2 map clContext workGroupSize
855856

856857
/// <summary>
857858
/// Fills the third given array with the results of applying the given function
@@ -863,7 +864,8 @@ module ClArray =
863864
/// <param name="map">The function to transform the pairs of the input elements.</param>
864865
/// <param name="clContext">OpenCL context.</param>
865866
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
866-
let map2InPlace<'a, 'b, 'c> (map: Expr<'a -> 'b -> 'c>) (clContext: ClContext) workGroupSize = Map.map2InPlace map clContext workGroupSize
867+
let map2InPlace<'a, 'b, 'c> (map: Expr<'a -> 'b -> 'c>) (clContext: ClContext) workGroupSize =
868+
Map.map2InPlace map clContext workGroupSize
867869

868870
/// <summary>
869871
/// Excludes elements, pointed by the bitmap.
@@ -872,22 +874,28 @@ module ClArray =
872874
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
873875
let excludeElements (clContext: ClContext) workGroupSize =
874876

875-
let invert = mapInPlace ArithmeticOperations.intNotQ clContext workGroupSize
877+
let invert =
878+
mapInPlace ArithmeticOperations.intNotQ clContext workGroupSize
876879

877-
let prefixSum = PrefixSum.standardExcludeInPlace clContext workGroupSize
880+
let prefixSum =
881+
PrefixSum.standardExcludeInPlace clContext workGroupSize
878882

879-
let scatter = Scatter.lastOccurrence clContext workGroupSize
883+
let scatter =
884+
Scatter.lastOccurrence clContext workGroupSize
880885

881886
fun (queue: MailboxProcessor<_>) allocationMode (excludeBitmap: ClArray<int>) (inputArray: ClArray<'a>) ->
882887

883888
invert queue excludeBitmap
884889

885-
let length = (prefixSum queue excludeBitmap).ToHostAndFree queue
890+
let length =
891+
(prefixSum queue excludeBitmap)
892+
.ToHostAndFree queue
886893

887894
if length = 0 then
888895
None
889896
else
890-
let result = clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, length)
897+
let result =
898+
clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, length)
891899

892900
scatter queue excludeBitmap inputArray result
893901

src/GraphBLAS-sharp.Backend/Matrix/COO/Intersect.fs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,29 @@ module internal Intersect =
1616

1717
if gid < bitmapSize then
1818

19-
let index: uint64 = ((uint64 leftRows.[gid]) <<< 32) ||| (uint64 leftColumns.[gid])
19+
let index: uint64 =
20+
((uint64 leftRows.[gid]) <<< 32)
21+
||| (uint64 leftColumns.[gid])
2022

21-
let intersect = (%Search.Bin.existsByKey2D) bitmapSize index rightRows rightColumns
23+
let intersect =
24+
(%Search.Bin.existsByKey2D) bitmapSize index rightRows rightColumns
2225

2326
if intersect then
2427
bitmap.[gid] <- 1
2528
else
2629
bitmap.[gid] <- 0 @>
2730

28-
let kernel =
29-
clContext.Compile <| findIntersection
31+
let kernel = clContext.Compile <| findIntersection
3032

3133
fun (processor: MailboxProcessor<_>) allocationMode (leftMatrix: ClMatrix.COO<'a>) (rightMatrix: ClMatrix.COO<'b>) ->
3234

3335
let bitmapSize = leftMatrix.NNZ
3436

35-
let bitmap = clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, bitmapSize)
37+
let bitmap =
38+
clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, bitmapSize)
3639

37-
let ndRange = Range1D.CreateValid(bitmapSize, workGroupSize)
40+
let ndRange =
41+
Range1D.CreateValid(bitmapSize, workGroupSize)
3842

3943
let kernel = kernel.GetKernel()
4044

src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ module Matrix =
255255
/// </remarks>
256256
/// <param name="clContext">OpenCL context.</param>
257257
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
258-
let mergeDisjoint (clContext: ClContext) workGroupSize = Merge.runDisjoint clContext workGroupSize
258+
let mergeDisjoint (clContext: ClContext) workGroupSize =
259+
Merge.runDisjoint clContext workGroupSize
259260

260261
let ofList (clContext: ClContext) allocationMode rowCount columnCount (elements: (int * int * 'a) list) =
261262
let rows, columns, values =
@@ -278,7 +279,8 @@ module Matrix =
278279
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
279280
let subRows (clContext: ClContext) workGroupSize =
280281

281-
let upperBound = ClArray.upperBound clContext workGroupSize
282+
let upperBound =
283+
ClArray.upperBound clContext workGroupSize
282284

283285
let blit = ClArray.blit clContext workGroupSize
284286

@@ -298,8 +300,14 @@ module Matrix =
298300
let lastRowClCell = clContext.CreateClCell(startRow + count)
299301

300302
// extract rows
301-
let firstIndex = (upperBound processor matrix.Rows firstRowClCell).ToHostAndFree processor
302-
let lastIndex = (upperBound processor matrix.Rows lastRowClCell).ToHostAndFree processor - 1
303+
let firstIndex =
304+
(upperBound processor matrix.Rows firstRowClCell)
305+
.ToHostAndFree processor
306+
307+
let lastIndex =
308+
(upperBound processor matrix.Rows lastRowClCell)
309+
.ToHostAndFree processor
310+
- 1
303311

304312
firstRowClCell.Free processor
305313
lastRowClCell.Free processor

src/GraphBLAS-sharp.Backend/Matrix/COO/Merge.fs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,19 @@ module Merge =
201201

202202
fun (processor: MailboxProcessor<_>) (leftMatrix: ClMatrix.COO<'a>) (rightMatrix: ClMatrix.COO<'a>) ->
203203

204-
let length = leftMatrix.Columns.Length + rightMatrix.Columns.Length
204+
let length =
205+
leftMatrix.Columns.Length
206+
+ rightMatrix.Columns.Length
205207

206208
let rows, cols, leftValues, rightValues, isLeft = merge processor leftMatrix rightMatrix
207209

208-
let ndRange = Range1D.CreateValid(length, workGroupSize)
210+
let ndRange =
211+
Range1D.CreateValid(length, workGroupSize)
209212

210213
let mergeValuesKernel = mergeValuesKernel.GetKernel()
211214

212215
processor.Post(
213-
Msg.MsgSetArguments
214-
(fun () ->
215-
mergeValuesKernel.KernelFunc
216-
ndRange
217-
length
218-
leftValues
219-
rightValues
220-
isLeft)
216+
Msg.MsgSetArguments(fun () -> mergeValuesKernel.KernelFunc ndRange length leftValues rightValues isLeft)
221217
)
222218

223219
processor.Post(Msg.CreateRunMsg<_, _>(mergeValuesKernel))

src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ module Matrix =
7676
Sparse.Vector.copyTo clContext workGroupSize
7777

7878
fun (processor: MailboxProcessor<_>) (source: ClMatrix<'a>) (destination: ClMatrix<'a>) ->
79-
if source.NNZ <> destination.NNZ || source.RowCount <> destination.RowCount || source.ColumnCount <> destination.ColumnCount then
79+
if source.NNZ <> destination.NNZ
80+
|| source.RowCount <> destination.RowCount
81+
|| source.ColumnCount <> destination.ColumnCount then
8082
failwith "Two matrices are not of the same size or they have different number of non-zero elements"
8183

8284
match source, destination with
@@ -93,10 +95,13 @@ module Matrix =
9395
copyTo processor s.ColumnPointers d.ColumnPointers
9496
copyDataTo processor s.Values d.Values
9597
| ClMatrix.LIL s, ClMatrix.LIL d ->
96-
List.iter2 (fun sourceVector destinationVector ->
97-
match sourceVector, destinationVector with
98-
| Some sv, Some dv -> vectorCopyTo processor sv dv
99-
| _ -> failwith "Vectors of LIL matrix are not of the same size") s.Rows d.Rows
98+
List.iter2
99+
(fun sourceVector destinationVector ->
100+
match sourceVector, destinationVector with
101+
| Some sv, Some dv -> vectorCopyTo processor sv dv
102+
| _ -> failwith "Vectors of LIL matrix are not of the same size")
103+
s.Rows
104+
d.Rows
100105
| _ -> failwith "Matrix formats are not matching"
101106

102107
/// <summary>

src/GraphBLAS-sharp.Backend/Objects/Matrix.fs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@ module ClMatrix =
9494
|> Seq.choose id
9595
|> Seq.iter (fun vector -> vector.Dispose q)
9696

97-
member this.NNZ = this.Rows |> List.fold (fun acc row -> match row with | Some r -> acc + r.NNZ | None -> acc) 0
97+
member this.NNZ =
98+
this.Rows
99+
|> List.fold
100+
(fun acc row ->
101+
match row with
102+
| Some r -> acc + r.NNZ
103+
| None -> acc)
104+
0
98105

99106
type Tuple<'elem when 'elem: struct> =
100107
{ Context: ClContext

src/GraphBLAS-sharp.Backend/Operations/Operations.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ module Operations =
133133

134134
fun (processor: MailboxProcessor<_>) (leftVector: ClVector<'a>) (rightVector: ClVector<'b>) (resultVector: ClVector<'c>) ->
135135
match leftVector, rightVector, resultVector with
136-
| ClVector.Dense left, ClVector.Dense right, ClVector.Dense result -> map2Dense processor left right result
136+
| ClVector.Dense left, ClVector.Dense right, ClVector.Dense result ->
137+
map2Dense processor left right result
137138
| _ -> failwith "Unsupported vector format"
138139

139140
/// <summary>

0 commit comments

Comments
 (0)