33open Brahma.FSharp
44open FSharp.Quotations
55open GraphBLAS.FSharp .Backend
6+ open GraphBLAS.FSharp .Backend .Quotes
67open GraphBLAS.FSharp .Backend .Matrix
78open GraphBLAS.FSharp .Backend .Matrix .COO
89open GraphBLAS.FSharp .Backend .Objects
910open GraphBLAS.FSharp .Backend .Objects .ClMatrix
1011open GraphBLAS.FSharp .Backend .Objects .ClContext
1112
12- module Map =
13- let binSearch < 'a > =
14- <@ fun startIndex nnzInRow sourceColumn ( columnIndices : ClArray < int >) ( values : ClArray < 'a >) ->
15-
16- let mutable leftEdge = startIndex
17- let mutable rightEdge = startIndex + nnzInRow - 1
18-
19- let mutable result = None
20-
21- while leftEdge <= rightEdge do
22- let middleIdx = ( leftEdge + rightEdge) / 2
23-
24- let currentColumn = columnIndices.[ middleIdx]
25-
26- if sourceColumn = currentColumn then
27- result <- Some values.[ middleIdx]
28-
29- rightEdge <- - 1 // TODO() break
30- elif sourceColumn < currentColumn then
31- rightEdge <- middleIdx - 1
32- else
33- leftEdge <- middleIdx + 1
34-
35- result @>
36-
13+ module internal Map =
3714 let preparePositions < 'a , 'b > ( clContext : ClContext ) workGroupSize opAdd =
3815
3916 let preparePositions ( op : Expr < 'a option -> 'b option >) =
@@ -46,12 +23,11 @@ module Map =
4623 let columnIndex = gid % columnCount
4724 let rowIndex = gid / columnCount
4825
49- let nnzInRow =
50- rowPointers.[ rowIndex + 1 ]
51- - rowPointers.[ rowIndex]
26+ let startIndex = rowPointers.[ rowIndex]
27+ let lastIndex = rowPointers.[ rowIndex + 1 ] - 1
5228
5329 let value =
54- (% binSearch ) rowPointers .[ rowIndex ] nnzInRow columnIndex columns values
30+ (% BinSearch.searchInRange ) startIndex lastIndex columnIndex columns values
5531
5632 match (% op) value with
5733 | Some resultValue ->
@@ -106,7 +82,6 @@ module Map =
10682
10783 resultBitmap, resultValues, resultRows, resultColumns
10884
109-
11085 let runToCOO < 'a , 'b when 'a : struct and 'b : struct and 'b : equality >
11186 ( clContext : ClContext )
11287 ( opAdd : Expr < 'a option -> 'b option >)
@@ -145,11 +120,11 @@ module Map =
145120 workGroupSize
146121 =
147122
148- let elementwiseToCOO = runToCOO clContext opAdd workGroupSize
123+ let mapToCOO = runToCOO clContext opAdd workGroupSize
149124
150125 let toCSRInplace =
151126 Matrix.toCSRInplace clContext workGroupSize
152127
153128 fun ( queue : MailboxProcessor < _ >) allocationMode ( matrix : ClMatrix.CSR < 'a >) ->
154- elementwiseToCOO queue allocationMode matrix
129+ mapToCOO queue allocationMode matrix
155130 |> toCSRInplace queue allocationMode
0 commit comments