Skip to content

Commit fe2edc3

Browse files
committed
refactor: formattig
1 parent 39e8c0e commit fe2edc3

6 files changed

Lines changed: 127 additions & 105 deletions

File tree

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

Lines changed: 57 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,33 @@ module internal Map2 =
4040
let preparePositions (op: Expr<'a option -> 'b option -> 'c option>) =
4141
<@ fun (ndRange: Range1D) rowCount columnCount leftValuesLength rightValuesLength (leftValues: ClArray<'a>) (leftRows: ClArray<int>) (leftColumns: ClArray<int>) (rightValues: ClArray<'b>) (rightRows: ClArray<int>) (rightColumn: ClArray<int>) (resultBitmap: ClArray<int>) (resultValues: ClArray<'c>) (resultRows: ClArray<int>) (resultColumns: ClArray<int>) ->
4242

43-
let gid = ndRange.GlobalID0
43+
let gid = ndRange.GlobalID0
4444

45-
if gid < rowCount * columnCount then
45+
if gid < rowCount * columnCount then
4646

47-
let columnIndex = gid % columnCount
48-
let rowIndex = gid / columnCount
47+
let columnIndex = gid % columnCount
48+
let rowIndex = gid / columnCount
4949

50-
let index = (uint64 rowIndex <<< 32) ||| (uint64 columnIndex)
50+
let index =
51+
(uint64 rowIndex <<< 32) ||| (uint64 columnIndex)
5152

52-
let leftValue =
53-
(%binSearch) leftValuesLength index leftRows leftColumns leftValues
53+
let leftValue =
54+
(%binSearch) leftValuesLength index leftRows leftColumns leftValues
5455

55-
let rightValue =
56-
(%binSearch) rightValuesLength index rightRows rightColumn rightValues
56+
let rightValue =
57+
(%binSearch) rightValuesLength index rightRows rightColumn rightValues
5758

58-
match (%op) leftValue rightValue with
59-
| Some value ->
60-
resultValues.[gid] <- value
61-
resultRows.[gid] <- rowIndex
62-
resultColumns.[gid] <- columnIndex
59+
match (%op) leftValue rightValue with
60+
| Some value ->
61+
resultValues.[gid] <- value
62+
resultRows.[gid] <- rowIndex
63+
resultColumns.[gid] <- columnIndex
6364

64-
resultBitmap.[gid] <- 1
65-
| None ->
66-
resultBitmap.[gid] <- 0 @>
65+
resultBitmap.[gid] <- 1
66+
| None -> resultBitmap.[gid] <- 0 @>
6767

68-
let kernel = clContext.Compile <| preparePositions opAdd
68+
let kernel =
69+
clContext.Compile <| preparePositions opAdd
6970

7071
fun (processor: MailboxProcessor<_>) rowCount columnCount (leftValues: ClArray<'a>) (leftRows: ClArray<int>) (leftColumns: ClArray<int>) (rightValues: ClArray<'b>) (rightRows: ClArray<int>) (rightColumns: ClArray<int>) ->
7172

@@ -83,51 +84,64 @@ module internal Map2 =
8384
let resultValues =
8485
clContext.CreateClArrayWithSpecificAllocationMode<'c>(DeviceOnly, resultLength)
8586

86-
let ndRange = Range1D.CreateValid(resultLength, workGroupSize)
87+
let ndRange =
88+
Range1D.CreateValid(resultLength, workGroupSize)
8789

8890
let kernel = kernel.GetKernel()
8991

9092
processor.Post(
91-
Msg.MsgSetArguments(
92-
fun () ->
93-
kernel.KernelFunc
94-
ndRange
95-
rowCount
96-
columnCount
97-
leftValues.Length
98-
rightValues.Length
99-
leftValues
100-
leftRows
101-
leftColumns
102-
rightValues
103-
rightRows
104-
rightColumns
105-
resultBitmap
106-
resultValues
107-
resultRows
108-
resultColumns))
93+
Msg.MsgSetArguments
94+
(fun () ->
95+
kernel.KernelFunc
96+
ndRange
97+
rowCount
98+
columnCount
99+
leftValues.Length
100+
rightValues.Length
101+
leftValues
102+
leftRows
103+
leftColumns
104+
rightValues
105+
rightRows
106+
rightColumns
107+
resultBitmap
108+
resultValues
109+
resultRows
110+
resultColumns)
111+
)
109112

110113
processor.Post(Msg.CreateRunMsg<_, _> kernel)
111114

112115
resultBitmap, resultValues, resultRows, resultColumns
113116

114-
///<param name="clContext">.</param>
115-
///<param name="opAdd">.</param>
116-
///<param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
117+
///<param name="clContext">.</param>
118+
///<param name="opAdd">.</param>
119+
///<param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
117120
let run<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
118121
(clContext: ClContext)
119122
(opAdd: Expr<'a option -> 'b option -> 'c option>)
120123
workGroupSize
121124
=
122125

123-
let map2 = preparePositions clContext workGroupSize opAdd
126+
let map2 =
127+
preparePositions clContext workGroupSize opAdd
124128

125-
let setPositions = Common.setPositions<'c> clContext workGroupSize
129+
let setPositions =
130+
Common.setPositions<'c> clContext workGroupSize
126131

127132
fun (queue: MailboxProcessor<_>) allocationMode (matrixLeft: ClMatrix.COO<'a>) (matrixRight: ClMatrix.COO<'b>) ->
128133

129134
let bitmap, values, rows, columns =
130-
map2 queue matrixLeft.RowCount matrixLeft.ColumnCount matrixLeft.Values matrixLeft.Rows matrixLeft.Columns matrixRight.Values matrixRight.Rows matrixRight.Columns
135+
map2
136+
queue
137+
matrixLeft.RowCount
138+
matrixLeft.ColumnCount
139+
matrixLeft.Values
140+
matrixLeft.Rows
141+
matrixLeft.Columns
142+
matrixRight.Values
143+
matrixRight.Rows
144+
matrixRight.Columns
131145

132146
let resultRows, resultColumns, resultValues, _ =
133147
setPositions queue allocationMode rows columns values bitmap

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ module internal Map2AtLeastOne =
260260

261261
allRows, allColumns, leftMergedValues, rightMergedValues, isLeft
262262

263-
///<param name="clContext">.</param>
264-
///<param name="opAdd">.</param>
265-
///<param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
263+
///<param name="clContext">.</param>
264+
///<param name="opAdd">.</param>
265+
///<param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
266266
let run<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
267267
(clContext: ClContext)
268268
(opAdd: Expr<'a option -> 'b option -> 'c option>)

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ module Matrix =
2525

2626
let program = clContext.Compile(expandRowPointers)
2727

28-
let create = ClArray.zeroCreate clContext workGroupSize
28+
let create =
29+
ClArray.zeroCreate clContext workGroupSize
2930

3031
let scan =
3132
ClArray.prefixSumIncludeInplace <@ max @> clContext workGroupSize
@@ -99,14 +100,18 @@ module Matrix =
99100

100101
let secondToCOO = toCOO clContext workGroupSize
101102

102-
let COOMap2 = COO.Matrix.map2 clContext opAdd workGroupSize
103+
let COOMap2 =
104+
COO.Matrix.map2 clContext opAdd workGroupSize
103105

104-
let toCSR = COO.Matrix.toCSRInplace clContext workGroupSize
106+
let toCSR =
107+
COO.Matrix.toCSRInplace clContext workGroupSize
105108

106109
fun (processor: MailboxProcessor<_>) allocationMode (leftMatrix: ClMatrix.CSR<'a>) (rightMatrix: ClMatrix.CSR<'b>) ->
107-
let leftCOOMatrix = firstToCOO processor DeviceOnly leftMatrix
110+
let leftCOOMatrix =
111+
firstToCOO processor DeviceOnly leftMatrix
108112

109-
let rightCOOMatrix = secondToCOO processor DeviceOnly rightMatrix
113+
let rightCOOMatrix =
114+
secondToCOO processor DeviceOnly rightMatrix
110115

111116
COOMap2 processor DeviceOnly leftCOOMatrix rightCOOMatrix
112117
|> toCSR processor allocationMode
@@ -117,7 +122,7 @@ module Matrix =
117122
workGroupSize
118123
=
119124

120-
Map2AtLeastOne.runToCOO clContext (Convert.atLeastOneToOption opAdd) workGroupSize
125+
Map2AtLeastOne.runToCOO clContext (Convert.atLeastOneToOption opAdd) workGroupSize
121126

122127
let map2AtLeastOne<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
123128
(clContext: ClContext)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ module Matrix =
207207
map2CSR processor allocationMode m1 m2
208208
|> ClMatrix.CSR
209209
| ClMatrix.CSC m1, ClMatrix.CSC m2 ->
210-
(map2CSR processor allocationMode m1.ToCSR m2.ToCSR).ToCSC
210+
(map2CSR processor allocationMode m1.ToCSR m2.ToCSR)
211+
.ToCSC
211212
|> ClMatrix.CSC
212213
| _ -> failwith "Matrix formats are not matching"
213214

src/GraphBLAS-sharp.Backend/Vector/SparseVector/Map2.fs

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -54,74 +54,76 @@ module internal Map2 =
5454
resultBitmap.[gid] <- 1
5555
| None -> resultBitmap.[gid] <- 0 @>
5656

57-
let kernel = clContext.Compile <| preparePositions opAdd
57+
let kernel =
58+
clContext.Compile <| preparePositions opAdd
5859

5960
fun (processor: MailboxProcessor<_>) (vectorLenght: int) (leftValues: ClArray<'a>) (leftIndices: ClArray<int>) (rightValues: ClArray<'b>) (rightIndices: ClArray<int>) ->
6061

61-
let resultBitmap =
62-
clContext.CreateClArrayWithSpecificAllocationMode<int>(DeviceOnly, vectorLenght)
62+
let resultBitmap =
63+
clContext.CreateClArrayWithSpecificAllocationMode<int>(DeviceOnly, vectorLenght)
6364

64-
let resultIndices =
65-
clContext.CreateClArrayWithSpecificAllocationMode<int>(DeviceOnly, vectorLenght)
65+
let resultIndices =
66+
clContext.CreateClArrayWithSpecificAllocationMode<int>(DeviceOnly, vectorLenght)
6667

67-
let resultValues =
68-
clContext.CreateClArrayWithSpecificAllocationMode<'c>(DeviceOnly, vectorLenght)
68+
let resultValues =
69+
clContext.CreateClArrayWithSpecificAllocationMode<'c>(DeviceOnly, vectorLenght)
6970

70-
let ndRange =
71-
Range1D.CreateValid(vectorLenght, workGroupSize)
71+
let ndRange =
72+
Range1D.CreateValid(vectorLenght, workGroupSize)
7273

73-
let kernel = kernel.GetKernel()
74+
let kernel = kernel.GetKernel()
7475

75-
processor.Post(
76-
Msg.MsgSetArguments
77-
(fun () ->
78-
kernel.KernelFunc
79-
ndRange
80-
vectorLenght
81-
leftValues.Length
82-
rightValues.Length
83-
leftValues
84-
leftIndices
85-
rightValues
86-
rightIndices
87-
resultBitmap
88-
resultValues
89-
resultIndices)
90-
)
76+
processor.Post(
77+
Msg.MsgSetArguments
78+
(fun () ->
79+
kernel.KernelFunc
80+
ndRange
81+
vectorLenght
82+
leftValues.Length
83+
rightValues.Length
84+
leftValues
85+
leftIndices
86+
rightValues
87+
rightIndices
88+
resultBitmap
89+
resultValues
90+
resultIndices)
91+
)
9192

92-
processor.Post(Msg.CreateRunMsg<_, _> kernel)
93+
processor.Post(Msg.CreateRunMsg<_, _> kernel)
9394

94-
resultBitmap, resultValues, resultIndices
95+
resultBitmap, resultValues, resultIndices
9596

9697
let run<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct> (clContext: ClContext) op workGroupSize =
9798

9899
let prepare =
99-
preparePositions<'a, 'b, 'c> clContext workGroupSize op
100+
preparePositions<'a, 'b, 'c> clContext workGroupSize op
100101

101-
let setPositions = Common.setPositions clContext workGroupSize
102+
let setPositions =
103+
Common.setPositions clContext workGroupSize
102104

103105
fun (processor: MailboxProcessor<_>) allocationMode (leftVector: ClVector.Sparse<'a>) (rightVector: ClVector.Sparse<'b>) ->
104106

105-
let bitmap, allValues, allIndices =
106-
prepare
107-
processor
108-
leftVector.Size
109-
leftVector.Values
110-
leftVector.Indices
111-
rightVector.Values
112-
rightVector.Indices
107+
let bitmap, allValues, allIndices =
108+
prepare
109+
processor
110+
leftVector.Size
111+
leftVector.Values
112+
leftVector.Indices
113+
rightVector.Values
114+
rightVector.Indices
113115

114-
let resultValues, resultIndices =
115-
setPositions processor allocationMode allValues allIndices bitmap
116+
let resultValues, resultIndices =
117+
setPositions processor allocationMode allValues allIndices bitmap
116118

117-
processor.Post(Msg.CreateFreeMsg<_>(allIndices))
118-
processor.Post(Msg.CreateFreeMsg<_>(allValues))
119-
processor.Post(Msg.CreateFreeMsg<_>(bitmap))
119+
processor.Post(Msg.CreateFreeMsg<_>(allIndices))
120+
processor.Post(Msg.CreateFreeMsg<_>(allValues))
121+
processor.Post(Msg.CreateFreeMsg<_>(bitmap))
120122

121-
{ Context = clContext
122-
Values = resultValues
123-
Indices = resultIndices
124-
Size = max leftVector.Size rightVector.Size }
123+
{ Context = clContext
124+
Values = resultValues
125+
Indices = resultIndices
126+
Size = max leftVector.Size rightVector.Size }
125127

126128
let private preparePositionsAssignByMask<'a, 'b when 'a: struct and 'b: struct>
127129
(clContext: ClContext)
@@ -200,7 +202,8 @@ module internal Map2 =
200202
let prepare =
201203
preparePositionsAssignByMask clContext op workGroupSize
202204

203-
let setPositions = Common.setPositions clContext workGroupSize
205+
let setPositions =
206+
Common.setPositions clContext workGroupSize
204207

205208
fun (processor: MailboxProcessor<_>) allocationMode (leftVector: ClVector.Sparse<'a>) (rightVector: ClVector.Sparse<'b>) (value: ClCell<'a>) ->
206209

src/GraphBLAS-sharp.Backend/Vector/SparseVector/Map2AtLeastOne.fs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ module internal Map2AtLeastOne =
195195

196196
(%PreparePositions.leftRight) gid leftResult rightResult isLeft allValues positions @>
197197

198-
let kernel =
199-
clContext.Compile <| preparePositions op
198+
let kernel = clContext.Compile <| preparePositions op
200199

201200
fun (processor: MailboxProcessor<_>) (allIndices: ClArray<int>) (leftValues: ClArray<'a>) (rightValues: ClArray<'b>) (isLeft: ClArray<int>) ->
202201

@@ -233,7 +232,8 @@ module internal Map2AtLeastOne =
233232
let prepare =
234233
preparePositions<'a, 'b, 'c> clContext op workGroupSize
235234

236-
let setPositions = Common.setPositions clContext workGroupSize
235+
let setPositions =
236+
Common.setPositions clContext workGroupSize
237237

238238
fun (processor: MailboxProcessor<_>) allocationMode (leftVector: ClVector.Sparse<'a>) (rightVector: ClVector.Sparse<'b>) ->
239239

@@ -258,4 +258,3 @@ module internal Map2AtLeastOne =
258258
Values = resultValues
259259
Indices = resultIndices
260260
Size = max leftVector.Size rightVector.Size }
261-

0 commit comments

Comments
 (0)