@@ -2,12 +2,32 @@ namespace GraphBLAS.FSharp.Backend.Common
22
33open Brahma.OpenCL
44open Brahma.FSharp .OpenCL .WorkflowBuilder .Basic
5- open Brahma.FSharp .OpenCL .WorkflowBuilder .Evaluation
65
7- // functions in mudule could be named run\get\if\it\t
8- // like mentioned here https://www.reddit.com/r/fsharp/comments/5kvsyk/modules_or_namespaces/dbt0zf7?utm_source=share&utm_medium=web2x&context=3
9- module internal PrefixSum =
10- let scan ( inputArray : int []) ( inputArrayLength : int ) ( vertices : int []) ( verticesLength : int ) ( totalSum : int []) = opencl {
6+ module internal rec PrefixSum =
7+ let runInplace ( inputArray : int []) ( totalSum : int []) = opencl {
8+ let workGroupSize = Utils.workGroupSize
9+
10+ let firstVertices = Array.zeroCreate <| ( inputArray.Length - 1 ) / workGroupSize + 1
11+ let secondVertices = Array.zeroCreate <| ( firstVertices.Length - 1 ) / workGroupSize + 1
12+ let mutable verticesArrays = firstVertices, secondVertices
13+ let swap ( a , b ) = ( b, a)
14+
15+ let mutable verticesLength = ( inputArray.Length - 1 ) / workGroupSize + 1
16+ let mutable bunchLength = workGroupSize
17+
18+ do ! scan inputArray inputArray.Length ( fst verticesArrays) verticesLength totalSum
19+ while verticesLength > 1 do
20+ let fstVertices = fst verticesArrays
21+ let sndVertices = snd verticesArrays
22+ do ! scan fstVertices verticesLength sndVertices (( verticesLength - 1 ) / workGroupSize + 1 ) totalSum
23+ do ! update inputArray inputArray.Length fstVertices bunchLength
24+
25+ bunchLength <- bunchLength * workGroupSize
26+ verticesArrays <- swap verticesArrays
27+ verticesLength <- ( verticesLength - 1 ) / workGroupSize + 1
28+ }
29+
30+ let private scan ( inputArray : int []) ( inputArrayLength : int ) ( vertices : int []) ( verticesLength : int ) ( totalSum : int []) = opencl {
1131 let workGroupSize = Utils.workGroupSize
1232
1333 let scan =
@@ -62,7 +82,7 @@ module internal PrefixSum =
6282 totalSum
6383 }
6484
65- let update ( inputArray : int []) ( inputArrayLength : int ) ( vertices : int []) ( bunchLength : int ) = opencl {
85+ let private update ( inputArray : int []) ( inputArrayLength : int ) ( vertices : int []) ( bunchLength : int ) = opencl {
6686 let workGroupSize = Utils.workGroupSize
6787
6888 let update =
@@ -83,30 +103,3 @@ module internal PrefixSum =
83103 inputArray
84104 vertices
85105 }
86-
87- // Changes received arrays
88- let run ( inputArray : int []) ( totalSum : int []) = opencl {
89- let workGroupSize = Utils.workGroupSize
90-
91- let firstVertices = Array.zeroCreate <| ( inputArray.Length - 1 ) / workGroupSize + 1
92- let secondVertices = Array.zeroCreate <| ( firstVertices.Length - 1 ) / workGroupSize + 1
93- let mutable verticesArrays = firstVertices, secondVertices
94- let swap ( a , b ) = ( b, a)
95-
96- let mutable verticesLength = ( inputArray.Length - 1 ) / workGroupSize + 1
97- let mutable bunchLength = workGroupSize
98-
99- do ! scan inputArray inputArray.Length ( fst verticesArrays) verticesLength totalSum
100- while verticesLength > 1 do
101- let fstVertices = fst verticesArrays
102- let sndVertices = snd verticesArrays
103- do ! scan fstVertices verticesLength sndVertices (( verticesLength - 1 ) / workGroupSize + 1 ) totalSum
104- do ! update inputArray inputArray.Length fstVertices bunchLength
105-
106- bunchLength <- bunchLength * workGroupSize
107- verticesArrays <- swap verticesArrays
108- verticesLength <- ( verticesLength - 1 ) / workGroupSize + 1
109- }
110-
111- // сделать не inplace prefixSum
112- // если функции вспомогательные, то лучше сделат их private
0 commit comments