Skip to content

Commit f20a75b

Browse files
committed
refactor: flag in Matrix, Vector
1 parent cd2df91 commit f20a75b

12 files changed

Lines changed: 198 additions & 364 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module BFS =
2525
let zeroCreate =
2626
ClArray.zeroCreate clContext workGroupSize CPUInterop
2727

28-
let ofList = Vector.ofList clContext workGroupSize
28+
let ofList = Vector.ofList clContext workGroupSize GPUOnly
2929

3030
let maskComplementedTo =
3131
DenseVector.elementWiseTo clContext Mask.complementedMaskOp workGroupSize
@@ -42,7 +42,7 @@ module BFS =
4242
let levels = zeroCreate queue vertexCount
4343

4444
let frontier =
45-
ofList queue Dense GPUOnly vertexCount [ source, 1 ]
45+
ofList queue Dense vertexCount [ source, 1 ]
4646

4747
match frontier with
4848
| ClVector.Dense front ->

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ module ClArray =
307307

308308
result
309309

310-
let map<'a, 'b> (clContext: ClContext) workGroupSize (op: Expr<'a -> 'b>) flag =
310+
let map<'a, 'b> (clContext: ClContext) workGroupSize flag (op: Expr<'a -> 'b>) =
311311

312312
let map =
313313
<@ fun (ndRange: Range1D) (lenght: int) (inputArray: ClArray<'a>) (result: ClArray<'b>) ->

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

Lines changed: 26 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open Microsoft.FSharp.Quotations
77
open GraphBLAS.FSharp.Backend.Objects
88
open GraphBLAS.FSharp.Backend
99
open GraphBLAS.FSharp.Backend.Objects.ClMatrix
10+
open GraphBLAS.FSharp.Backend.Objects.ClContext
1011

1112
module COOMatrix =
1213
let private preparePositions<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
@@ -57,18 +58,10 @@ module COOMatrix =
5758
Range1D.CreateValid(length, workGroupSize)
5859

5960
let rawPositionsGpu =
60-
clContext.CreateClArray<int>(
61-
length,
62-
hostAccessMode = HostAccessMode.NotAccessible,
63-
allocationMode = AllocationMode.Default
64-
)
61+
clContext.CreateClArrayWithFlag<int>(GPUOnly, length)
6562

6663
let allValues =
67-
clContext.CreateClArray<'c>(
68-
length,
69-
hostAccessMode = HostAccessMode.NotAccessible,
70-
allocationMode = AllocationMode.Default
71-
)
64+
clContext.CreateClArrayWithFlag<'c>(GPUOnly, length)
7265

7366
let kernel = kernel.GetKernel()
7467

@@ -225,44 +218,19 @@ module COOMatrix =
225218
let sumOfSides = firstSide + secondSide
226219

227220
let allRows =
228-
clContext.CreateClArray<int>(
229-
sumOfSides,
230-
deviceAccessMode = DeviceAccessMode.WriteOnly,
231-
hostAccessMode = HostAccessMode.NotAccessible,
232-
allocationMode = AllocationMode.Default
233-
)
221+
clContext.CreateClArrayWithFlag<int>(GPUOnly, sumOfSides)
234222

235223
let allColumns =
236-
clContext.CreateClArray<int>(
237-
sumOfSides,
238-
deviceAccessMode = DeviceAccessMode.WriteOnly,
239-
hostAccessMode = HostAccessMode.NotAccessible,
240-
allocationMode = AllocationMode.Default
241-
)
224+
clContext.CreateClArrayWithFlag<int>(GPUOnly, sumOfSides)
242225

243226
let leftMergedValues =
244-
clContext.CreateClArray<'a>(
245-
sumOfSides,
246-
deviceAccessMode = DeviceAccessMode.WriteOnly,
247-
hostAccessMode = HostAccessMode.NotAccessible,
248-
allocationMode = AllocationMode.Default
249-
)
227+
clContext.CreateClArrayWithFlag<'a>(GPUOnly, sumOfSides)
250228

251229
let rightMergedValues =
252-
clContext.CreateClArray<'b>(
253-
sumOfSides,
254-
deviceAccessMode = DeviceAccessMode.WriteOnly,
255-
hostAccessMode = HostAccessMode.NotAccessible,
256-
allocationMode = AllocationMode.Default
257-
)
230+
clContext.CreateClArrayWithFlag<'b>(GPUOnly, sumOfSides)
258231

259232
let isLeft =
260-
clContext.CreateClArray<int>(
261-
sumOfSides,
262-
deviceAccessMode = DeviceAccessMode.WriteOnly,
263-
hostAccessMode = HostAccessMode.NotAccessible,
264-
allocationMode = AllocationMode.Default
265-
)
233+
clContext.CreateClArrayWithFlag<int>(GPUOnly, sumOfSides)
266234

267235
let ndRange =
268236
Range1D.CreateValid(sumOfSides, workGroupSize)
@@ -301,6 +269,7 @@ module COOMatrix =
301269
(clContext: ClContext)
302270
(opAdd: Expr<'a option -> 'b option -> 'c option>)
303271
workGroupSize
272+
flag
304273
=
305274

306275
let merge = merge clContext workGroupSize
@@ -309,7 +278,7 @@ module COOMatrix =
309278
preparePositions clContext opAdd workGroupSize
310279

311280
let setPositions =
312-
Matrix.Common.setPositions<'c> clContext workGroupSize
281+
Matrix.Common.setPositions<'c> clContext workGroupSize flag
313282

314283
fun (queue: MailboxProcessor<_>) (matrixLeft: ClMatrix.COO<'a>) (matrixRight: ClMatrix.COO<'b>) ->
315284

@@ -345,11 +314,11 @@ module COOMatrix =
345314
Columns = resultColumns
346315
Values = resultValues }
347316

348-
let getTuples (clContext: ClContext) workGroupSize =
317+
let getTuples (clContext: ClContext) workGroupSize flag =
349318

350-
let copy = ClArray.copy clContext workGroupSize
319+
let copy = ClArray.copy clContext workGroupSize flag
351320

352-
let copyData = ClArray.copy clContext workGroupSize
321+
let copyData = ClArray.copy clContext workGroupSize flag
353322

354323
fun (processor: MailboxProcessor<_>) (matrix: ClMatrix.COO<'a>) ->
355324

@@ -364,7 +333,7 @@ module COOMatrix =
364333
ColumnIndices = resultColumns
365334
Values = resultValues }
366335

367-
let private compressRows (clContext: ClContext) workGroupSize =
336+
let private compressRows (clContext: ClContext) workGroupSize flag =
368337

369338
let compressRows =
370339
<@ fun (ndRange: Range1D) (rows: ClArray<int>) (nnz: int) (rowPointers: ClArray<int>) ->
@@ -379,7 +348,7 @@ module COOMatrix =
379348

380349
let program = clContext.Compile(compressRows)
381350

382-
let create = ClArray.create clContext workGroupSize
351+
let create = ClArray.create clContext workGroupSize flag
383352

384353
let scan =
385354
ClArray.prefixSumBackwardsIncludeInplace <@ min @> clContext workGroupSize
@@ -401,11 +370,11 @@ module COOMatrix =
401370

402371
rowPointers
403372

404-
let toCSR (clContext: ClContext) workGroupSize =
405-
let prepare = compressRows clContext workGroupSize
373+
let toCSR (clContext: ClContext) workGroupSize flag =
374+
let prepare = compressRows clContext workGroupSize flag
406375

407-
let copy = ClArray.copy clContext workGroupSize
408-
let copyData = ClArray.copy clContext workGroupSize
376+
let copy = ClArray.copy clContext workGroupSize flag
377+
let copyData = ClArray.copy clContext workGroupSize flag
409378

410379
fun (processor: MailboxProcessor<_>) (matrix: ClMatrix.COO<'a>) ->
411380
let rowPointers =
@@ -421,8 +390,8 @@ module COOMatrix =
421390
Columns = cols
422391
Values = vals }
423392

424-
let toCSRInplace (clContext: ClContext) workGroupSize =
425-
let prepare = compressRows clContext workGroupSize
393+
let toCSRInplace (clContext: ClContext) workGroupSize flag =
394+
let prepare = compressRows clContext workGroupSize flag
426395

427396
fun (processor: MailboxProcessor<_>) (matrix: ClMatrix.COO<'a>) ->
428397
let rowPointers =
@@ -444,9 +413,10 @@ module COOMatrix =
444413
(clContext: ClContext)
445414
(opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>)
446415
workGroupSize
416+
flag
447417
=
448418

449-
elementwise clContext (Convert.atLeastOneToOption opAdd) workGroupSize
419+
elementwise clContext (Convert.atLeastOneToOption opAdd) workGroupSize flag
450420

451421
let transposeInplace (clContext: ClContext) workGroupSize =
452422

@@ -463,11 +433,11 @@ module COOMatrix =
463433
Columns = matrix.Rows
464434
Values = matrix.Values }
465435

466-
let transpose (clContext: ClContext) workGroupSize =
436+
let transpose (clContext: ClContext) workGroupSize flag =
467437

468438
let transposeInplace = transposeInplace clContext workGroupSize
469-
let copy = ClArray.copy clContext workGroupSize
470-
let copyData = ClArray.copy clContext workGroupSize
439+
let copy = ClArray.copy clContext workGroupSize flag
440+
let copyData = ClArray.copy clContext workGroupSize flag
471441

472442
fun (queue: MailboxProcessor<_>) (matrix: ClMatrix.COO<'a>) ->
473443

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

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ open GraphBLAS.FSharp.Backend.Objects
1111
open GraphBLAS.FSharp.Backend.Objects.ClMatrix
1212

1313
module CSRMatrix =
14-
let private expandRowPointers (clContext: ClContext) workGroupSize =
14+
let private expandRowPointers (clContext: ClContext) workGroupSize flag =
1515

1616
let expandRowPointers =
1717
<@ fun (ndRange: Range1D) (rowPointers: ClArray<int>) (rowCount: int) (rows: ClArray<int>) ->
@@ -26,7 +26,7 @@ module CSRMatrix =
2626

2727
let program = clContext.Compile(expandRowPointers)
2828

29-
let create = ClArray.create clContext workGroupSize
29+
let create = ClArray.create clContext workGroupSize flag
3030

3131
let scan =
3232
ClArray.prefixSumIncludeInplace <@ max @> clContext workGroupSize
@@ -49,12 +49,12 @@ module CSRMatrix =
4949

5050
rows
5151

52-
let toCOO (clContext: ClContext) workGroupSize =
52+
let toCOO (clContext: ClContext) workGroupSize flag =
5353
let prepare =
54-
expandRowPointers clContext workGroupSize
54+
expandRowPointers clContext workGroupSize flag
5555

56-
let copy = ClArray.copy clContext workGroupSize
57-
let copyData = ClArray.copy clContext workGroupSize
56+
let copy = ClArray.copy clContext workGroupSize flag
57+
let copyData = ClArray.copy clContext workGroupSize flag
5858

5959
fun (processor: MailboxProcessor<_>) (matrix: ClMatrix.CSR<'a>) ->
6060
let rows =
@@ -70,9 +70,9 @@ module CSRMatrix =
7070
Columns = cols
7171
Values = vals }
7272

73-
let toCOOInplace (clContext: ClContext) workGroupSize =
73+
let toCOOInplace (clContext: ClContext) workGroupSize flag =
7474
let prepare =
75-
expandRowPointers clContext workGroupSize
75+
expandRowPointers clContext workGroupSize flag
7676

7777
fun (processor: MailboxProcessor<_>) (matrix: ClMatrix.CSR<'a>) ->
7878
let rows =
@@ -88,16 +88,16 @@ module CSRMatrix =
8888
Values = matrix.Values }
8989

9090
///<remarks>Old version</remarks>
91-
let elementwiseWithCOO (clContext: ClContext) (opAdd: Expr<'a option -> 'b option -> 'c option>) workGroupSize =
91+
let elementwiseWithCOO (clContext: ClContext) (opAdd: Expr<'a option -> 'b option -> 'c option>) workGroupSize flag =
9292

9393
let prepareRows =
94-
expandRowPointers clContext workGroupSize
94+
expandRowPointers clContext workGroupSize flag
9595

9696
let eWiseCOO =
97-
COOMatrix.elementwise clContext opAdd workGroupSize
97+
COOMatrix.elementwise clContext opAdd workGroupSize flag
9898

9999
let toCSRInplace =
100-
COOMatrix.toCSRInplace clContext workGroupSize
100+
COOMatrix.toCSRInplace clContext workGroupSize flag
101101

102102
fun (processor: MailboxProcessor<_>) (m1: ClMatrix.CSR<'a>) (m2: ClMatrix.CSR<'b>) ->
103103
let m1COO =
@@ -128,34 +128,35 @@ module CSRMatrix =
128128
(clContext: ClContext)
129129
(opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>)
130130
workGroupSize
131+
flag
131132
=
132133

133-
elementwiseWithCOO clContext (Convert.atLeastOneToOption opAdd) workGroupSize
134+
elementwiseWithCOO clContext (Convert.atLeastOneToOption opAdd) workGroupSize flag
134135

135-
let transposeInplace (clContext: ClContext) workGroupSize =
136+
let transposeInplace (clContext: ClContext) workGroupSize flag =
136137

137-
let toCOOInplace = toCOOInplace clContext workGroupSize
138+
let toCOOInplace = toCOOInplace clContext workGroupSize flag
138139

139140
let transposeInplace =
140141
COOMatrix.transposeInplace clContext workGroupSize
141142

142143
let toCSRInplace =
143-
COOMatrix.toCSRInplace clContext workGroupSize
144+
COOMatrix.toCSRInplace clContext workGroupSize flag
144145

145146
fun (queue: MailboxProcessor<_>) (matrix: ClMatrix.CSR<'a>) ->
146147
let coo = toCOOInplace queue matrix
147148
let transposedCoo = transposeInplace queue coo
148149
toCSRInplace queue transposedCoo
149150

150-
let transpose (clContext: ClContext) workGroupSize =
151+
let transpose (clContext: ClContext) workGroupSize flag =
151152

152-
let toCOO = toCOO clContext workGroupSize
153+
let toCOO = toCOO clContext workGroupSize flag
153154

154155
let transposeInplace =
155156
COOMatrix.transposeInplace clContext workGroupSize
156157

157158
let toCSRInplace =
158-
COOMatrix.toCSRInplace clContext workGroupSize
159+
COOMatrix.toCSRInplace clContext workGroupSize flag
159160

160161
fun (queue: MailboxProcessor<_>) (matrix: ClMatrix.CSR<'a>) ->
161162
let coo = toCOO queue matrix
@@ -166,15 +167,16 @@ module CSRMatrix =
166167
(clContext: ClContext)
167168
(opAdd: Expr<'a option -> 'b option -> 'c option>)
168169
workGroupSize
170+
flag
169171
=
170172

171173
let merge = merge clContext workGroupSize
172174

173175
let preparePositions =
174-
preparePositions clContext opAdd Utils.defaultWorkGroupSize
176+
preparePositions clContext opAdd workGroupSize
175177

176178
let setPositions =
177-
Matrix.Common.setPositions<'c> clContext Utils.defaultWorkGroupSize
179+
Matrix.Common.setPositions<'c> clContext workGroupSize flag
178180

179181
fun (queue: MailboxProcessor<_>) (matrixLeft: ClMatrix.CSR<'a>) (matrixRight: ClMatrix.CSR<'b>) ->
180182

@@ -215,13 +217,14 @@ module CSRMatrix =
215217
(clContext: ClContext)
216218
(opAdd: Expr<'a option -> 'b option -> 'c option>)
217219
workGroupSize
220+
flag
218221
=
219222

220223
let elementwiseToCOO =
221-
elementwiseToCOO clContext opAdd workGroupSize
224+
elementwiseToCOO clContext opAdd workGroupSize flag
222225

223226
let toCSRInplace =
224-
COOMatrix.toCSRInplace clContext Utils.defaultWorkGroupSize
227+
COOMatrix.toCSRInplace clContext workGroupSize flag
225228

226229
fun (queue: MailboxProcessor<_>) (matrixLeft: ClMatrix.CSR<'a>) (matrixRight: ClMatrix.CSR<'b>) ->
227230

0 commit comments

Comments
 (0)