Skip to content

Commit 375918c

Browse files
committed
build pass locally
1 parent bba9fca commit 375918c

8 files changed

Lines changed: 131 additions & 141 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,9 @@ module ClArray =
486486

487487
let setPositions = setPositions clContext
488488
let getUniqueBitmap = getUniqueBitmap clContext
489-
let prefixSumExclude = prefixSumExclude <@ (+) @> clContext workGroupSize
489+
490+
let prefixSumExclude =
491+
prefixSumExclude <@ (+) @> clContext workGroupSize
490492

491493
fun (processor: MailboxProcessor<_>) (inputArray: ClArray<'a>) ->
492494

@@ -500,7 +502,9 @@ module ClArray =
500502
let resultLength =
501503
let a = [| 0 |]
502504

503-
processor.PostAndReply(fun ch -> Msg.CreateToHostMsg(sum, a, ch)) |> ignore
505+
processor.PostAndReply(fun ch -> Msg.CreateToHostMsg(sum, a, ch))
506+
|> ignore
507+
504508
processor.Post(Msg.CreateFreeMsg<_>(sum))
505509

506510
a.[0]

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

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,69 +4,60 @@ open Brahma.FSharp
44

55
module SubSum =
66
let private treeAccess<'a> opAdd =
7-
<@
8-
fun step lid wgSize (localBuffer: 'a []) ->
9-
let i = step * (lid + 1) - 1
7+
<@ fun step lid wgSize (localBuffer: 'a []) ->
8+
let i = step * (lid + 1) - 1
109

11-
let firstValue = localBuffer.[i - (step >>> 1)]
12-
let secondValue = localBuffer.[i]
10+
let firstValue = localBuffer.[i - (step >>> 1)]
11+
let secondValue = localBuffer.[i]
1312

14-
localBuffer.[i] <- (%opAdd) firstValue secondValue
15-
@>
13+
localBuffer.[i] <- (%opAdd) firstValue secondValue @>
1614

1715
let private sequentialAccess<'a> opAdd =
18-
<@
19-
fun step lid wgSize (localBuffer: 'a []) ->
20-
let firstValue = localBuffer.[lid]
21-
let secondValue = localBuffer.[lid + wgSize / step]
16+
<@ fun step lid wgSize (localBuffer: 'a []) ->
17+
let firstValue = localBuffer.[lid]
18+
let secondValue = localBuffer.[lid + wgSize / step]
2219

23-
localBuffer.[lid] <- (%opAdd) firstValue secondValue
24-
@>
20+
localBuffer.[lid] <- (%opAdd) firstValue secondValue @>
2521

2622
let private sumGeneral<'a> memoryAccess =
27-
<@
28-
fun wgSize lid (localBuffer: 'a []) ->
29-
let mutable step = 2
23+
<@ fun wgSize lid (localBuffer: 'a []) ->
24+
let mutable step = 2
3025

31-
while step <= wgSize do
32-
if lid < wgSize / step then
33-
(%memoryAccess) step lid wgSize localBuffer
26+
while step <= wgSize do
27+
if lid < wgSize / step then
28+
(%memoryAccess) step lid wgSize localBuffer
3429

35-
step <- step <<< 1
30+
step <- step <<< 1
3631

37-
barrierLocal ()
38-
@>
32+
barrierLocal () @>
3933

40-
let sequentialSum<'a> opAdd = sumGeneral<'a> <| sequentialAccess<'a> opAdd
34+
let sequentialSum<'a> opAdd =
35+
sumGeneral<'a> <| sequentialAccess<'a> opAdd
4136

4237
let treeSum<'a> opAdd = sumGeneral<'a> <| treeAccess<'a> opAdd
4338

4439
module PreparePositions =
4540
let both<'c> =
46-
<@
47-
fun index (result: 'c option) (rawPositionsBuffer: ClArray<int>) (allValuesBuffer: ClArray<'c>) ->
48-
rawPositionsBuffer.[index] <- 0
41+
<@ fun index (result: 'c option) (rawPositionsBuffer: ClArray<int>) (allValuesBuffer: ClArray<'c>) ->
42+
rawPositionsBuffer.[index] <- 0
4943

50-
match result with
51-
| Some v ->
52-
allValuesBuffer.[index + 1] <- v
53-
rawPositionsBuffer.[index + 1] <- 1
54-
| None -> rawPositionsBuffer.[index + 1] <- 0
55-
@>
44+
match result with
45+
| Some v ->
46+
allValuesBuffer.[index + 1] <- v
47+
rawPositionsBuffer.[index + 1] <- 1
48+
| None -> rawPositionsBuffer.[index + 1] <- 0 @>
5649

5750
let leftRight<'c> =
58-
<@
59-
fun index (leftResult: 'c option) (rightResult: 'c option) (isLeftBitmap: ClArray<int>) (allValuesBuffer: ClArray<'c>) (rawPositionsBuffer: ClArray<int>) ->
60-
if isLeftBitmap.[index] = 1 then
61-
match leftResult with
62-
| Some v ->
63-
allValuesBuffer.[index] <- v
64-
rawPositionsBuffer.[index] <- 1
65-
| None -> rawPositionsBuffer.[index] <- 0
66-
else
67-
match rightResult with
68-
| Some v ->
69-
allValuesBuffer.[index] <- v
70-
rawPositionsBuffer.[index] <- 1
71-
| None -> rawPositionsBuffer.[index] <- 0
72-
@>
51+
<@ fun index (leftResult: 'c option) (rightResult: 'c option) (isLeftBitmap: ClArray<int>) (allValuesBuffer: ClArray<'c>) (rawPositionsBuffer: ClArray<int>) ->
52+
if isLeftBitmap.[index] = 1 then
53+
match leftResult with
54+
| Some v ->
55+
allValuesBuffer.[index] <- v
56+
rawPositionsBuffer.[index] <- 1
57+
| None -> rawPositionsBuffer.[index] <- 0
58+
else
59+
match rightResult with
60+
| Some v ->
61+
allValuesBuffer.[index] <- v
62+
rawPositionsBuffer.[index] <- 1
63+
| None -> rawPositionsBuffer.[index] <- 0 @>

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

Lines changed: 43 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -5,132 +5,104 @@ open GraphBLAS.FSharp.Backend
55
open Microsoft.FSharp.Quotations
66

77
module internal Sum =
8-
let private scan
9-
(clContext: ClContext)
10-
(workGroupSize: int)
11-
(opAdd: Expr<'a -> 'a -> 'a>)
12-
zero
13-
=
8+
let private scan (clContext: ClContext) (workGroupSize: int) (opAdd: Expr<'a -> 'a -> 'a>) zero =
149

1510
let subSum = SubSum.sequentialSum opAdd
1611

1712
let scan =
18-
<@
19-
fun (ndRange: Range1D) length (inputArray: ClArray<'a>) (resultArray: ClArray<'a>) ->
13+
<@ fun (ndRange: Range1D) length (inputArray: ClArray<'a>) (resultArray: ClArray<'a>) ->
2014

21-
let gid = ndRange.GlobalID0
22-
let lid = ndRange.LocalID0
15+
let gid = ndRange.GlobalID0
16+
let lid = ndRange.LocalID0
2317

24-
let localValues = localArray<'a> workGroupSize
18+
let localValues = localArray<'a> workGroupSize
2519

26-
if gid < length then
27-
localValues[lid] <- inputArray[gid]
28-
else
29-
localValues[lid] <- zero
20+
if gid < length then
21+
localValues.[lid] <- inputArray.[gid]
22+
else
23+
localValues.[lid] <- zero
3024

31-
barrierLocal ()
25+
barrierLocal ()
3226

33-
(%subSum) workGroupSize lid localValues
27+
(%subSum) workGroupSize lid localValues
3428

35-
resultArray[gid / workGroupSize] <- localValues[0]
36-
@>
29+
resultArray.[gid / workGroupSize] <- localValues.[0] @>
3730

3831
let kernel = clContext.Compile(scan)
3932

4033
fun (processor: MailboxProcessor<_>) (valuesArray: ClArray<'a>) valuesLength (resultArray: ClArray<'a>) ->
41-
let ndRange = Range1D.CreateValid(valuesArray.Length, workGroupSize)
34+
let ndRange =
35+
Range1D.CreateValid(valuesArray.Length, workGroupSize)
4236

4337
let kernel = kernel.GetKernel()
4438

4539
processor.Post(
46-
Msg.MsgSetArguments(
47-
fun () ->
48-
kernel.KernelFunc
49-
ndRange
50-
valuesLength
51-
valuesArray
52-
resultArray)
53-
)
40+
Msg.MsgSetArguments(fun () -> kernel.KernelFunc ndRange valuesLength valuesArray resultArray)
41+
)
5442

5543
processor.Post(Msg.CreateRunMsg<_, _>(kernel))
5644

57-
let private scanToCell
58-
(clContext: ClContext)
59-
(workGroupSize: int)
60-
(opAdd: Expr<'a -> 'a -> 'a>)
61-
zero
62-
=
45+
let private scanToCell (clContext: ClContext) (workGroupSize: int) (opAdd: Expr<'a -> 'a -> 'a>) zero =
6346

6447
let subSum = SubSum.sequentialSum opAdd
6548

6649
let scan =
67-
<@
68-
fun (ndRange: Range1D) length (inputArray: ClArray<'a>) (resultCell: ClCell<'a>) ->
50+
<@ fun (ndRange: Range1D) length (inputArray: ClArray<'a>) (resultCell: ClCell<'a>) ->
6951

70-
let gid = ndRange.GlobalID0
71-
let lid = ndRange.LocalID0
52+
let gid = ndRange.GlobalID0
53+
let lid = ndRange.LocalID0
7254

73-
let localValues = localArray<'a> workGroupSize
55+
let localValues = localArray<'a> workGroupSize
7456

75-
if gid < length then
76-
localValues[lid] <- inputArray[gid]
77-
else
78-
localValues[lid] <- zero
57+
if gid < length then
58+
localValues.[lid] <- inputArray.[gid]
59+
else
60+
localValues.[lid] <- zero
7961

80-
barrierLocal ()
62+
barrierLocal ()
8163

82-
(%subSum) workGroupSize lid localValues
64+
(%subSum) workGroupSize lid localValues
8365

84-
resultCell.Value <- localValues[0]
85-
@>
66+
resultCell.Value <- localValues.[0] @>
8667

8768
let kernel = clContext.Compile(scan)
8869

89-
fun (processor: MailboxProcessor<_>) (valuesArray: ClArray<'a>) valuesLength ->
70+
fun (processor: MailboxProcessor<_>) (valuesArray: ClArray<'a>) valuesLength ->
9071

91-
let ndRange = Range1D.CreateValid(valuesArray.Length, workGroupSize)
72+
let ndRange =
73+
Range1D.CreateValid(valuesArray.Length, workGroupSize)
9274

9375
let resultCell = clContext.CreateClCell zero
9476

9577
let kernel = kernel.GetKernel()
9678

97-
processor.Post(
98-
Msg.MsgSetArguments(
99-
fun () ->
100-
kernel.KernelFunc
101-
ndRange
102-
valuesLength
103-
valuesArray
104-
resultCell)
105-
)
79+
processor.Post(Msg.MsgSetArguments(fun () -> kernel.KernelFunc ndRange valuesLength valuesArray resultCell))
10680

10781
processor.Post(Msg.CreateRunMsg<_, _>(kernel))
10882

10983
resultCell
11084

111-
let run
112-
(clContext: ClContext)
113-
(workGroupSize: int)
114-
(opAdd: Expr<'a -> 'a -> 'a>)
115-
(zero: 'a)
116-
=
85+
let run (clContext: ClContext) (workGroupSize: int) (opAdd: Expr<'a -> 'a -> 'a>) (zero: 'a) =
11786

11887
let scan = scan clContext workGroupSize opAdd zero
119-
let scanToCell = scanToCell clContext workGroupSize opAdd zero
88+
89+
let scanToCell =
90+
scanToCell clContext workGroupSize opAdd zero
12091

12192
fun (processor: MailboxProcessor<_>) (inputArray: ClArray<'a>) ->
12293

12394
let scan = scan processor
12495

125-
let firstLength = (inputArray.Length - 1) / workGroupSize + 1
96+
let firstLength =
97+
(inputArray.Length - 1) / workGroupSize + 1
12698

12799
let firstVerticesArray =
128100
clContext.CreateClArray(
129101
firstLength,
130102
hostAccessMode = HostAccessMode.NotAccessible,
131103
deviceAccessMode = DeviceAccessMode.ReadWrite,
132104
allocationMode = AllocationMode.Default
133-
)
105+
)
134106

135107
let secondLength = (firstLength - 1) / workGroupSize + 1
136108

@@ -140,7 +112,7 @@ module internal Sum =
140112
hostAccessMode = HostAccessMode.NotAccessible,
141113
deviceAccessMode = DeviceAccessMode.ReadWrite,
142114
allocationMode = AllocationMode.Default
143-
)
115+
)
144116

145117
let mutable verticesArrays = firstVerticesArray, secondVerticesArray
146118
let swap (a, b) = (b, a)
@@ -159,7 +131,9 @@ module internal Sum =
159131
verticesLength <- (verticesLength - 1) / workGroupSize + 1
160132

161133
let fstVertices = fst verticesArrays
162-
let result = scanToCell processor fstVertices verticesLength
134+
135+
let result =
136+
scanToCell processor fstVertices verticesLength
163137

164138
processor.Post(Msg.CreateFreeMsg(firstVerticesArray))
165139
processor.Post(Msg.CreateFreeMsg(secondVerticesArray))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<Compile Include="Common/CommonQuotes.fs" />
1515
<Compile Include="Common/Utils.fs" />
1616
<Compile Include="Common/Sum.fs" />
17-
<Compile Include="Common\ClArray.fs" />
17+
<Compile Include="Common/ClArray.fs" />
1818
<Compile Include="Common/BitonicSort.fs" />
1919
<Compile Include="Common/Scatter.fs" />
2020
<Compile Include="Common/StandardOperations.fs" />

0 commit comments

Comments
 (0)