Skip to content

Commit 7316c58

Browse files
committed
refactor: ClMatrix module
1 parent 23e5ed6 commit 7316c58

11 files changed

Lines changed: 154 additions & 154 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksEWiseAdd.fs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ open GraphBLAS.FSharp.Objects
1111
open GraphBLAS.FSharp.Backend.Objects
1212
open GraphBLAS.FSharp.Backend.Matrix.COO
1313
open GraphBLAS.FSharp.Backend.Matrix.CSR
14-
open GraphBLAS.FSharp.Backend.Common
1514

1615
type Config() =
1716
inherit ManualConfig()
@@ -198,7 +197,7 @@ type EWiseAddBenchmarksWithDataTransfer<'matrixT, 'elem when 'matrixT :> IDevice
198197
this.Processor.PostAndReply Msg.MsgNotifyMe
199198

200199
module M =
201-
let resultToHostCOO (resultMatrix: ClCOOMatrix<'a>) (processor :MailboxProcessor<_>) =
200+
let resultToHostCOO (resultMatrix: ClMatrix.COO<'a>) (processor :MailboxProcessor<_>) =
202201
let cols =
203202
let a = Array.zeroCreate resultMatrix.ColumnCount
204203
processor.Post(Msg.CreateToHostMsg<_>(resultMatrix.Columns,a))
@@ -222,7 +221,7 @@ module M =
222221

223222
type EWiseAddBenchmarks4Float32COOWithoutDataTransfer() =
224223

225-
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCOOMatrix<float32>,float32>(
224+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<float32>,float32>(
226225
(fun context wgSize -> COOMatrix.elementwise context ArithmeticOperations.float32Sum wgSize),
227226
float32,
228227
(fun _ -> Utils.nextSingle (System.Random())),
@@ -234,7 +233,7 @@ type EWiseAddBenchmarks4Float32COOWithoutDataTransfer() =
234233

235234
type EWiseAddBenchmarks4Float32COOWithDataTransfer() =
236235

237-
inherit EWiseAddBenchmarksWithDataTransfer<ClCOOMatrix<float32>,float32>(
236+
inherit EWiseAddBenchmarksWithDataTransfer<ClMatrix.COO<float32>,float32>(
238237
(fun context wgSize -> COOMatrix.elementwise context ArithmeticOperations.float32Sum wgSize),
239238
float32,
240239
(fun _ -> Utils.nextSingle (System.Random())),
@@ -248,7 +247,7 @@ type EWiseAddBenchmarks4Float32COOWithDataTransfer() =
248247

249248
type EWiseAddBenchmarks4BoolCOOWithoutDataTransfer() =
250249

251-
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCOOMatrix<bool>,bool>(
250+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<bool>,bool>(
252251
(fun context wgSize -> COOMatrix.elementwise context ArithmeticOperations.boolSum wgSize),
253252
(fun _ -> true),
254253
(fun _ -> true),
@@ -261,7 +260,7 @@ type EWiseAddBenchmarks4BoolCOOWithoutDataTransfer() =
261260

262261
type EWiseAddBenchmarks4Float32CSRWithoutDataTransfer() =
263262

264-
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCSRMatrix<float32>,float32>(
263+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<float32>,float32>(
265264
(fun context wgSize -> CSRMatrix.elementwise context ArithmeticOperations.float32Sum wgSize),
266265
float32,
267266
(fun _ -> Utils.nextSingle (System.Random())),
@@ -274,7 +273,7 @@ type EWiseAddBenchmarks4Float32CSRWithoutDataTransfer() =
274273

275274
type EWiseAddBenchmarks4BoolCSRWithoutDataTransfer() =
276275

277-
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCSRMatrix<bool>,bool>(
276+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<bool>,bool>(
278277
(fun context wgSize -> CSRMatrix.elementwise context ArithmeticOperations.boolSum wgSize),
279278
(fun _ -> true),
280279
(fun _ -> true),
@@ -288,7 +287,7 @@ type EWiseAddBenchmarks4BoolCSRWithoutDataTransfer() =
288287

289288
type EWiseAddAtLeastOneBenchmarks4BoolCOOWithoutDataTransfer() =
290289

291-
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCOOMatrix<bool>,bool>(
290+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<bool>,bool>(
292291
(fun context wgSize -> COOMatrix.elementwiseAtLeastOne context ArithmeticOperations.boolSumAtLeastOne wgSize),
293292
(fun _ -> true),
294293
(fun _ -> true),
@@ -300,7 +299,7 @@ type EWiseAddAtLeastOneBenchmarks4BoolCOOWithoutDataTransfer() =
300299

301300
type EWiseAddAtLeastOneBenchmarks4BoolCSRWithoutDataTransfer() =
302301

303-
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCSRMatrix<bool>,bool>(
302+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<bool>,bool>(
304303
(fun context wgSize -> CSRMatrix.elementwiseAtLeastOne context ArithmeticOperations.boolSumAtLeastOne wgSize),
305304
(fun _ -> true),
306305
(fun _ -> true),
@@ -312,7 +311,7 @@ type EWiseAddAtLeastOneBenchmarks4BoolCSRWithoutDataTransfer() =
312311

313312
type EWiseAddAtLeastOneBenchmarks4Float32COOWithoutDataTransfer() =
314313

315-
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCOOMatrix<float32>,float32>(
314+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<float32>,float32>(
316315
(fun context wgSize -> COOMatrix.elementwiseAtLeastOne context ArithmeticOperations.float32SumAtLeastOne wgSize),
317316
float32,
318317
(fun _ -> Utils.nextSingle (System.Random())),
@@ -324,7 +323,7 @@ type EWiseAddAtLeastOneBenchmarks4Float32COOWithoutDataTransfer() =
324323

325324
type EWiseAddAtLeastOneBenchmarks4Float32CSRWithoutDataTransfer() =
326325

327-
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCSRMatrix<float32>,float32>(
326+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<float32>,float32>(
328327
(fun context wgSize -> CSRMatrix.elementwiseAtLeastOne context ArithmeticOperations.float32SumAtLeastOne wgSize),
329328
float32,
330329
(fun _ -> Utils.nextSingle (System.Random())),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module BFS =
3535
let containsNonZero =
3636
ClArray.exists clContext workGroupSize Predicates.containsNonZero
3737

38-
fun (queue: MailboxProcessor<Msg>) (matrix: ClCSRMatrix<'a>) (source: int) ->
38+
fun (queue: MailboxProcessor<Msg>) (matrix: ClMatrix.CSR<'a>) (source: int) ->
3939
let vertexCount = matrix.RowCount
4040

4141
let levels = zeroCreate queue vertexCount

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open GraphBLAS.FSharp.Backend.Quotes
66
open Microsoft.FSharp.Quotations
77
open GraphBLAS.FSharp.Backend.Objects
88
open GraphBLAS.FSharp.Backend
9+
open GraphBLAS.FSharp.Backend.Objects.ClMatrix
910

1011
module COOMatrix =
1112
let private preparePositions<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
@@ -310,7 +311,7 @@ module COOMatrix =
310311
let setPositions =
311312
Matrix.Common.setPositions<'c> clContext workGroupSize
312313

313-
fun (queue: MailboxProcessor<_>) (matrixLeft: ClCOOMatrix<'a>) (matrixRight: ClCOOMatrix<'b>) ->
314+
fun (queue: MailboxProcessor<_>) (matrixLeft: ClMatrix.COO<'a>) (matrixRight: ClMatrix.COO<'b>) ->
314315

315316
let allRows, allColumns, leftMergedValues, rightMergedValues, isLeft =
316317
merge
@@ -350,7 +351,7 @@ module COOMatrix =
350351

351352
let copyData = ClArray.copy clContext workGroupSize
352353

353-
fun (processor: MailboxProcessor<_>) (matrix: ClCOOMatrix<'a>) ->
354+
fun (processor: MailboxProcessor<_>) (matrix: ClMatrix.COO<'a>) ->
354355

355356
let resultRows = copy processor matrix.Rows
356357

@@ -406,7 +407,7 @@ module COOMatrix =
406407
let copy = ClArray.copy clContext workGroupSize
407408
let copyData = ClArray.copy clContext workGroupSize
408409

409-
fun (processor: MailboxProcessor<_>) (matrix: ClCOOMatrix<'a>) ->
410+
fun (processor: MailboxProcessor<_>) (matrix: ClMatrix.COO<'a>) ->
410411
let rowPointers =
411412
prepare processor matrix.Rows matrix.RowCount
412413

@@ -423,7 +424,7 @@ module COOMatrix =
423424
let toCSRInplace (clContext: ClContext) workGroupSize =
424425
let prepare = compressRows clContext workGroupSize
425426

426-
fun (processor: MailboxProcessor<_>) (matrix: ClCOOMatrix<'a>) ->
427+
fun (processor: MailboxProcessor<_>) (matrix: ClMatrix.COO<'a>) ->
427428
let rowPointers =
428429
prepare processor matrix.Rows matrix.RowCount
429430

@@ -452,7 +453,7 @@ module COOMatrix =
452453
let sort =
453454
BitonicSort.sortKeyValuesInplace clContext workGroupSize
454455

455-
fun (queue: MailboxProcessor<_>) (matrix: ClCOOMatrix<'a>) ->
456+
fun (queue: MailboxProcessor<_>) (matrix: ClMatrix.COO<'a>) ->
456457
sort queue matrix.Columns matrix.Rows matrix.Values
457458

458459
{ Context = clContext
@@ -468,13 +469,12 @@ module COOMatrix =
468469
let copy = ClArray.copy clContext workGroupSize
469470
let copyData = ClArray.copy clContext workGroupSize
470471

471-
fun (queue: MailboxProcessor<_>) (matrix: ClCOOMatrix<'a>) ->
472-
let copiedMatrix =
473-
{ Context = clContext
474-
RowCount = matrix.RowCount
475-
ColumnCount = matrix.ColumnCount
476-
Rows = copy queue matrix.Rows
477-
Columns = copy queue matrix.Columns
478-
Values = copyData queue matrix.Values }
472+
fun (queue: MailboxProcessor<_>) (matrix: ClMatrix.COO<'a>) ->
479473

480-
transposeInplace queue copiedMatrix
474+
{ Context = clContext
475+
RowCount = matrix.RowCount
476+
ColumnCount = matrix.ColumnCount
477+
Rows = copy queue matrix.Rows
478+
Columns = copy queue matrix.Columns
479+
Values = copyData queue matrix.Values }
480+
|> transposeInplace queue

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open GraphBLAS.FSharp.Backend.Quotes
88
open Microsoft.FSharp.Quotations
99
open GraphBLAS.FSharp.Backend.Matrix.COO
1010
open GraphBLAS.FSharp.Backend.Objects
11+
open GraphBLAS.FSharp.Backend.Objects.ClMatrix
1112

1213
module CSRMatrix =
1314
let private expandRowPointers (clContext: ClContext) workGroupSize =
@@ -55,7 +56,7 @@ module CSRMatrix =
5556
let copy = ClArray.copy clContext workGroupSize
5657
let copyData = ClArray.copy clContext workGroupSize
5758

58-
fun (processor: MailboxProcessor<_>) (matrix: ClCSRMatrix<'a>) ->
59+
fun (processor: MailboxProcessor<_>) (matrix: ClMatrix.CSR<'a>) ->
5960
let rows =
6061
prepare processor matrix.RowPointers matrix.Columns.Length matrix.RowCount
6162

@@ -73,7 +74,7 @@ module CSRMatrix =
7374
let prepare =
7475
expandRowPointers clContext workGroupSize
7576

76-
fun (processor: MailboxProcessor<_>) (matrix: ClCSRMatrix<'a>) ->
77+
fun (processor: MailboxProcessor<_>) (matrix: ClMatrix.CSR<'a>) ->
7778
let rows =
7879
prepare processor matrix.RowPointers matrix.Columns.Length matrix.RowCount
7980

@@ -98,7 +99,7 @@ module CSRMatrix =
9899
let toCSRInplace =
99100
COOMatrix.toCSRInplace clContext workGroupSize
100101

101-
fun (processor: MailboxProcessor<_>) (m1: ClCSRMatrix<'a>) (m2: ClCSRMatrix<'b>) ->
102+
fun (processor: MailboxProcessor<_>) (m1: ClMatrix.CSR<'a>) (m2: ClMatrix.CSR<'b>) ->
102103
let m1COO =
103104
{ Context = clContext
104105
RowCount = m1.RowCount
@@ -141,7 +142,7 @@ module CSRMatrix =
141142
let toCSRInplace =
142143
COOMatrix.toCSRInplace clContext workGroupSize
143144

144-
fun (queue: MailboxProcessor<_>) (matrix: ClCSRMatrix<'a>) ->
145+
fun (queue: MailboxProcessor<_>) (matrix: ClMatrix.CSR<'a>) ->
145146
let coo = toCOOInplace queue matrix
146147
let transposedCoo = transposeInplace queue coo
147148
toCSRInplace queue transposedCoo
@@ -156,7 +157,7 @@ module CSRMatrix =
156157
let toCSRInplace =
157158
COOMatrix.toCSRInplace clContext workGroupSize
158159

159-
fun (queue: MailboxProcessor<_>) (matrix: ClCSRMatrix<'a>) ->
160+
fun (queue: MailboxProcessor<_>) (matrix: ClMatrix.CSR<'a>) ->
160161
let coo = toCOO queue matrix
161162
let transposedCoo = transposeInplace queue coo
162163
toCSRInplace queue transposedCoo
@@ -175,7 +176,7 @@ module CSRMatrix =
175176
let setPositions =
176177
Matrix.Common.setPositions<'c> clContext Utils.defaultWorkGroupSize
177178

178-
fun (queue: MailboxProcessor<_>) (matrixLeft: ClCSRMatrix<'a>) (matrixRight: ClCSRMatrix<'b>) ->
179+
fun (queue: MailboxProcessor<_>) (matrixLeft: ClMatrix.CSR<'a>) (matrixRight: ClMatrix.CSR<'b>) ->
179180

180181
let allRows, allColumns, leftMergedValues, rightMergedValues, isRowEnd, isLeft =
181182
merge
@@ -222,7 +223,7 @@ module CSRMatrix =
222223
let toCSRInplace =
223224
COOMatrix.toCSRInplace clContext Utils.defaultWorkGroupSize
224225

225-
fun (queue: MailboxProcessor<_>) (matrixLeft: ClCSRMatrix<'a>) (matrixRight: ClCSRMatrix<'b>) ->
226+
fun (queue: MailboxProcessor<_>) (matrixLeft: ClMatrix.CSR<'a>) (matrixRight: ClMatrix.CSR<'b>) ->
226227

227228
let cooRes =
228229
elementwiseToCOO queue matrixLeft matrixRight
@@ -255,6 +256,6 @@ module CSRMatrix =
255256
let run =
256257
SpGEMM.run clContext workGroupSize opAdd opMul
257258

258-
fun (queue: MailboxProcessor<_>) (matrixLeft: ClCSRMatrix<'a>) (matrixRight: ClCSCMatrix<'b>) (mask: ClMask2D) ->
259+
fun (queue: MailboxProcessor<_>) (matrixLeft: ClMatrix.CSR<'a>) (matrixRight: ClMatrix.CSC<'b>) (mask: ClMask2D) ->
259260

260261
run queue matrixLeft matrixRight mask

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ namespace GraphBLAS.FSharp.Backend.Matrix.CSR
33
open GraphBLAS.FSharp.Backend.Common
44
open Brahma.FSharp
55
open GraphBLAS.FSharp.Backend.Predefined
6-
open GraphBLAS.FSharp.Backend
76
open Microsoft.FSharp.Quotations
87
open GraphBLAS.FSharp.Backend.Objects
8+
open GraphBLAS.FSharp.Backend.Objects.ClMatrix
99

1010
module internal SpGEMM =
1111
let private calculate
@@ -106,7 +106,7 @@ module internal SpGEMM =
106106

107107
let program = context.Compile(run)
108108

109-
fun (queue: MailboxProcessor<_>) (matrixLeft: ClCSRMatrix<'a>) (matrixRight: ClCSCMatrix<'b>) (mask: ClMask2D) ->
109+
fun (queue: MailboxProcessor<_>) (matrixLeft: ClMatrix.CSR<'a>) (matrixRight: ClMatrix.CSC<'b>) (mask: ClMask2D) ->
110110

111111
let values =
112112
context.CreateClArray<'c>(
@@ -164,7 +164,7 @@ module internal SpGEMM =
164164
let scanInplace =
165165
PrefixSum.standardExcludeInplace context workGroupSize
166166

167-
fun (queue: MailboxProcessor<_>) (matrixLeft: ClCSRMatrix<'a>) (matrixRight: ClCSCMatrix<'b>) (mask: ClMask2D) ->
167+
fun (queue: MailboxProcessor<_>) (matrixLeft: ClMatrix.CSR<'a>) (matrixRight: ClMatrix.CSC<'b>) (mask: ClMask2D) ->
168168

169169
let values, bitmap =
170170
calculate queue matrixLeft matrixRight mask

0 commit comments

Comments
 (0)