Skip to content

Commit 971306e

Browse files
committed
refactor: separate quotes
1 parent 682c194 commit 971306e

28 files changed

Lines changed: 265 additions & 255 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksEWiseAdd.fs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace GraphBLAS.FSharp.Benchmarks
22

33
open System.IO
4+
open GraphBLAS.FSharp.Backend.Quotes
45
open GraphBLAS.FSharp.IO
56
open BenchmarkDotNet.Attributes
67
open BenchmarkDotNet.Configs
@@ -222,7 +223,7 @@ module M =
222223
type EWiseAddBenchmarks4Float32COOWithoutDataTransfer() =
223224

224225
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCOOMatrix<float32>,float32>(
225-
(fun context wgSize -> COOMatrix.elementwise context StandardOperations.float32Sum wgSize),
226+
(fun context wgSize -> COOMatrix.elementwise context ArithmeticOperations.float32Sum wgSize),
226227
float32,
227228
(fun _ -> Utils.nextSingle (System.Random())),
228229
COOMatrix<float32>.ToBackend
@@ -234,7 +235,7 @@ type EWiseAddBenchmarks4Float32COOWithoutDataTransfer() =
234235
type EWiseAddBenchmarks4Float32COOWithDataTransfer() =
235236

236237
inherit EWiseAddBenchmarksWithDataTransfer<ClCOOMatrix<float32>,float32>(
237-
(fun context wgSize -> COOMatrix.elementwise context StandardOperations.float32Sum wgSize),
238+
(fun context wgSize -> COOMatrix.elementwise context ArithmeticOperations.float32Sum wgSize),
238239
float32,
239240
(fun _ -> Utils.nextSingle (System.Random())),
240241
COOMatrix<float32>.ToBackend,
@@ -248,7 +249,7 @@ type EWiseAddBenchmarks4Float32COOWithDataTransfer() =
248249
type EWiseAddBenchmarks4BoolCOOWithoutDataTransfer() =
249250

250251
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCOOMatrix<bool>,bool>(
251-
(fun context wgSize -> COOMatrix.elementwise context StandardOperations.boolSum wgSize),
252+
(fun context wgSize -> COOMatrix.elementwise context ArithmeticOperations.boolSum wgSize),
252253
(fun _ -> true),
253254
(fun _ -> true),
254255
COOMatrix<bool>.ToBackend
@@ -261,7 +262,7 @@ type EWiseAddBenchmarks4BoolCOOWithoutDataTransfer() =
261262
type EWiseAddBenchmarks4Float32CSRWithoutDataTransfer() =
262263

263264
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCSRMatrix<float32>,float32>(
264-
(fun context wgSize -> CSRMatrix.elementwise context StandardOperations.float32Sum wgSize),
265+
(fun context wgSize -> CSRMatrix.elementwise context ArithmeticOperations.float32Sum wgSize),
265266
float32,
266267
(fun _ -> Utils.nextSingle (System.Random())),
267268
CSRMatrix<float32>.ToBackend
@@ -274,7 +275,7 @@ type EWiseAddBenchmarks4Float32CSRWithoutDataTransfer() =
274275
type EWiseAddBenchmarks4BoolCSRWithoutDataTransfer() =
275276

276277
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCSRMatrix<bool>,bool>(
277-
(fun context wgSize -> CSRMatrix.elementwise context StandardOperations.boolSum wgSize),
278+
(fun context wgSize -> CSRMatrix.elementwise context ArithmeticOperations.boolSum wgSize),
278279
(fun _ -> true),
279280
(fun _ -> true),
280281
CSRMatrix<bool>.ToBackend
@@ -288,7 +289,7 @@ type EWiseAddBenchmarks4BoolCSRWithoutDataTransfer() =
288289
type EWiseAddAtLeastOneBenchmarks4BoolCOOWithoutDataTransfer() =
289290

290291
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCOOMatrix<bool>,bool>(
291-
(fun context wgSize -> COOMatrix.elementwiseAtLeastOne context StandardOperations.boolSumAtLeastOne wgSize),
292+
(fun context wgSize -> COOMatrix.elementwiseAtLeastOne context ArithmeticOperations.boolSumAtLeastOne wgSize),
292293
(fun _ -> true),
293294
(fun _ -> true),
294295
COOMatrix<bool>.ToBackend
@@ -300,7 +301,7 @@ type EWiseAddAtLeastOneBenchmarks4BoolCOOWithoutDataTransfer() =
300301
type EWiseAddAtLeastOneBenchmarks4BoolCSRWithoutDataTransfer() =
301302

302303
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCSRMatrix<bool>,bool>(
303-
(fun context wgSize -> CSRMatrix.elementwiseAtLeastOne context StandardOperations.boolSumAtLeastOne wgSize),
304+
(fun context wgSize -> CSRMatrix.elementwiseAtLeastOne context ArithmeticOperations.boolSumAtLeastOne wgSize),
304305
(fun _ -> true),
305306
(fun _ -> true),
306307
CSRMatrix<bool>.ToBackend
@@ -312,7 +313,7 @@ type EWiseAddAtLeastOneBenchmarks4BoolCSRWithoutDataTransfer() =
312313
type EWiseAddAtLeastOneBenchmarks4Float32COOWithoutDataTransfer() =
313314

314315
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCOOMatrix<float32>,float32>(
315-
(fun context wgSize -> COOMatrix.elementwiseAtLeastOne context StandardOperations.float32SumAtLeastOne wgSize),
316+
(fun context wgSize -> COOMatrix.elementwiseAtLeastOne context ArithmeticOperations.float32SumAtLeastOne wgSize),
316317
float32,
317318
(fun _ -> Utils.nextSingle (System.Random())),
318319
COOMatrix<float32>.ToBackend
@@ -324,7 +325,7 @@ type EWiseAddAtLeastOneBenchmarks4Float32COOWithoutDataTransfer() =
324325
type EWiseAddAtLeastOneBenchmarks4Float32CSRWithoutDataTransfer() =
325326

326327
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCSRMatrix<float32>,float32>(
327-
(fun context wgSize -> CSRMatrix.elementwiseAtLeastOne context StandardOperations.float32SumAtLeastOne wgSize),
328+
(fun context wgSize -> CSRMatrix.elementwiseAtLeastOne context ArithmeticOperations.float32SumAtLeastOne wgSize),
328329
float32,
329330
(fun _ -> Utils.nextSingle (System.Random())),
330331
CSRMatrix<float32>.ToBackend

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ open Brahma.FSharp
55
open FSharp.Quotations
66
open GraphBLAS.FSharp.Backend.Objects
77
open GraphBLAS.FSharp.Backend.Common
8+
open GraphBLAS.FSharp.Backend.Quotes
89
open GraphBLAS.FSharp.Backend.Vector
910
open GraphBLAS.FSharp.Backend.Vector.Dense
1011
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
@@ -26,13 +27,19 @@ module BFS =
2627
let ofList = Vector.ofList clContext Dense
2728

2829
let maskComplementedTo =
29-
DenseVector.elementWiseTo clContext StandardOperations.complementedMaskOp workGroupSize
30+
DenseVector.elementWiseTo clContext Mask.complementedMaskOp workGroupSize
3031

3132
let fillSubVectorTo =
3233
DenseVector.standardFillSubVectorTo<int, int> clContext workGroupSize
3334

3435
let containsNonZero =
35-
ClArray.exists clContext workGroupSize <@ fun (item: int option) -> match item with Some _ -> true | _ -> false @>
36+
ClArray.exists
37+
clContext
38+
workGroupSize
39+
<@ fun (item: int option) ->
40+
match item with
41+
| Some _ -> true
42+
| _ -> false @>
3643

3744
fun (queue: MailboxProcessor<Msg>) (matrix: ClCSRMatrix<'a>) (source: int) ->
3845
let vertexCount = matrix.RowCount

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ module ClArray =
261261
///<param name="inputArray">Should be sorted.</param>
262262
let removeDuplications (clContext: ClContext) workGroupSize =
263263

264-
let scatter = Scatter.runInplace clContext workGroupSize
264+
let scatter =
265+
Scatter.runInplace clContext workGroupSize
266+
265267
let getUniqueBitmap = getUniqueBitmap clContext
266268

267269
let prefixSumExclude =
@@ -303,8 +305,7 @@ module ClArray =
303305
if gid < length then
304306
let isExist = (%predicate) vector.[gid]
305307

306-
if isExist then
307-
result.Value <- true @>
308+
if isExist then result.Value <- true @>
308309

309310
let kernel = clContext.Compile exists
310311

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace GraphBLAS.FSharp.Backend.Common
22

33
open Brahma.FSharp
44
open FSharp.Quotations
5+
open GraphBLAS.FSharp.Backend.Quotes
56

67
module PrefixSum =
78
let private update (opAdd: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize =

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

Lines changed: 0 additions & 80 deletions
This file was deleted.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace GraphBLAS.FSharp.Backend.Common
22

33
open Brahma.FSharp
4+
open GraphBLAS.FSharp.Backend.Quotes
45
open Microsoft.FSharp.Control
56
open Microsoft.FSharp.Quotations
67

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace GraphBLAS.FSharp.Backend.Common
22

33
open Brahma.FSharp
44
open GraphBLAS.FSharp.Backend
5+
open GraphBLAS.FSharp.Backend.Quotes
56
open Microsoft.FSharp.Quotations
67

78
module internal Sum =

src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,28 @@
1111

1212
<ItemGroup>
1313
<Compile Include="AssemblyInfo.fs" />
14-
<Compile Include="Common\Quotes.fs" />
15-
<Compile Include="Common\Scatter.fs" />
14+
<Compile Include="Objects/Common.fs" />
15+
<Compile Include="Objects/ArraysExtentions.fs" />
16+
<Compile Include="Objects/Vector.fs" />
17+
<Compile Include="Objects/Matrix.fs" />
18+
<Compile Include="Objects/Masks.fs" />
19+
<Compile Include="Objects/AtLeastOne.fs" />
20+
<Compile Include="Quotes/SubReduce.fs" />
21+
<Compile Include="Quotes/Arithmetic.fs" />
22+
<Compile Include="Quotes/Convert.fs" />
23+
<Compile Include="Quotes/Mask.fs" />
24+
<Compile Include="Quotes/SubSum.fs" />
25+
<Compile Include="Quotes\PreparePositions.fs" />
26+
<Compile Include="Common/Scatter.fs" />
1627
<Compile Include="Common/Utils.fs" />
1728
<Compile Include="Common/Sum.fs" />
1829
<Compile Include="Common/PrefixSum.fs" />
1930
<Compile Include="Common/ClArray.fs" />
2031
<Compile Include="Common/BitonicSort.fs" />
21-
<Compile Include="Common/StandardOperations.fs" />
2232
<Compile Include="Common/Reduce.fs" />
2333
<Compile Include="Predefined/PrefixSum.fs" />
2434
<!--Compile Include="Matrices.fs" /-->
25-
<Compile Include="Objects/Common.fs" />
26-
<Compile Include="Objects/ArraysExtentions.fs" />
27-
<Compile Include="Objects/Vector.fs" />
28-
<Compile Include="Objects/Matrix.fs" />
29-
<Compile Include="Objects\Masks.fs" />
30-
<Compile Include="Matrix\Common.fs" />
35+
<Compile Include="Matrix/Common.fs" />
3136
<Compile Include="Matrix/COOMatrix/COOMatrix.fs" />
3237
<Compile Include="Matrix/CSRMatrix/Elementwise.fs" />
3338
<Compile Include="Matrix/CSRMatrix/SpGEMM.fs" />

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace GraphBLAS.FSharp.Backend.Matrix.COO
22

33
open Brahma.FSharp
44
open GraphBLAS.FSharp.Backend.Common
5+
open GraphBLAS.FSharp.Backend.Quotes
56
open Microsoft.FSharp.Quotations
67
open GraphBLAS.FSharp.Backend.Objects
78
open GraphBLAS.FSharp.Backend
@@ -306,7 +307,8 @@ module COOMatrix =
306307
let preparePositions =
307308
preparePositions clContext opAdd workGroupSize
308309

309-
let setPositions = Matrix.Common.setPositions<'c> clContext workGroupSize
310+
let setPositions =
311+
Matrix.Common.setPositions<'c> clContext workGroupSize
310312

311313
fun (queue: MailboxProcessor<_>) (matrixLeft: ClCOOMatrix<'a>) (matrixRight: ClCOOMatrix<'b>) ->
312314

@@ -443,7 +445,7 @@ module COOMatrix =
443445
workGroupSize
444446
=
445447

446-
elementwise clContext (StandardOperations.atLeastOneToOption opAdd) workGroupSize
448+
elementwise clContext (Convert.atLeastOneToOption opAdd) workGroupSize
447449

448450
let transposeInplace (clContext: ClContext) workGroupSize =
449451

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ open Brahma.FSharp
44
open GraphBLAS.FSharp.Backend.Common
55
open GraphBLAS.FSharp.Backend
66
open GraphBLAS.FSharp.Backend.Matrix.CSR.Elementwise
7+
open GraphBLAS.FSharp.Backend.Quotes
78
open Microsoft.FSharp.Quotations
89
open GraphBLAS.FSharp.Backend.Matrix.COO
910
open GraphBLAS.FSharp.Backend.Objects
@@ -128,7 +129,7 @@ module CSRMatrix =
128129
workGroupSize
129130
=
130131

131-
elementwiseWithCOO clContext (StandardOperations.atLeastOneToOption opAdd) workGroupSize
132+
elementwiseWithCOO clContext (Convert.atLeastOneToOption opAdd) workGroupSize
132133

133134
let transposeInplace (clContext: ClContext) workGroupSize =
134135

@@ -234,15 +235,15 @@ module CSRMatrix =
234235
workGroupSize
235236
=
236237

237-
elementwiseToCOO clContext (StandardOperations.atLeastOneToOption opAdd) workGroupSize
238+
elementwiseToCOO clContext (Convert.atLeastOneToOption opAdd) workGroupSize
238239

239240
let elementwiseAtLeastOne<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
240241
(clContext: ClContext)
241242
(opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>)
242243
workGroupSize
243244
=
244245

245-
elementwise clContext (StandardOperations.atLeastOneToOption opAdd) workGroupSize
246+
elementwise clContext (Convert.atLeastOneToOption opAdd) workGroupSize
246247

247248
let spgemmCSC
248249
(clContext: ClContext)

0 commit comments

Comments
 (0)