@@ -2,21 +2,74 @@ module GraphBLAS.FSharp.Backend.Matrix
22
33open Brahma.FSharp
44open GraphBLAS.FSharp .Backend .Common
5- open GraphBLAS.FSharp .Backend .Matrix
6- open GraphBLAS.FSharp .Backend .Quotes
7- open Microsoft.FSharp .Quotations
85open GraphBLAS.FSharp .Backend .Objects
96open GraphBLAS.FSharp .Backend .Objects .ClMatrix
10- open GraphBLAS.FSharp .Backend .Objects .ClContext
7+ open GraphBLAS.FSharp .Backend .Objects .ArraysExtensions
8+
9+ // type lazy matrix ???
1110
1211module Split =
13- let toCOO ( clContext : ClContext ) workGroupSize =
12+ module ByChunk =
13+ let runCOOLazy ( clContext : ClContext ) workGroupSize =
14+
15+ let chunkBySizeValues = ClArray.lazyChunkBySize clContext workGroupSize
16+
17+ let chunkBySizeIndices = ClArray.lazyChunkBySize clContext workGroupSize
18+
19+ fun ( processor : MailboxProcessor < _ >) allocationMode chunkSize ( matrix : ClMatrix.COO < 'a >) ->
20+
21+ let createSubMatrixLazy ( values : Lazy < _ >) ( columns : Lazy < _ >) ( rows : Lazy < _ >) =
22+ lazy
23+ { Context = clContext
24+ RowCount = matrix.RowCount
25+ ColumnCount = matrix.ColumnCount
26+ Rows = rows.Value
27+ Columns = columns.Value
28+ Values = values.Value }
29+
30+ let values = chunkBySizeValues processor allocationMode chunkSize matrix.Values
31+ let columns = chunkBySizeIndices processor allocationMode chunkSize matrix.Columns
32+ let rows = chunkBySizeIndices processor allocationMode chunkSize matrix.Rows
33+
34+ Seq.map3 createSubMatrixLazy values columns rows
35+
36+ let runCOO ( clContext : ClContext ) workGroupSize =
37+
38+ let run = runCOOLazy clContext workGroupSize
39+
40+ fun ( processor : MailboxProcessor < _ >) allocationMode chunkSize ( matrix : ClMatrix.COO < 'a >) ->
41+ run processor allocationMode chunkSize matrix
42+ |> Seq.map ( fun lazyMatrix -> lazyMatrix.Value)
43+ |> Seq.toArray
44+
45+ module ByRow =
46+ let runCSRLazy ( clContext : ClContext ) workGroupSize =
47+
48+ let getChunkValues = ClArray.getChunk clContext workGroupSize
49+
50+ let getChunkIndices = ClArray.getChunk clContext workGroupSize
51+
52+ fun ( processor : MailboxProcessor < _ >) allocationMode ( matrix : ClMatrix.CSR < 'a >) ->
53+
54+ let getChunkValues = getChunkValues processor allocationMode matrix.Values
55+ let getChunkIndices = getChunkIndices processor allocationMode matrix.Columns
56+
57+ matrix.RowPointers.ToHost processor
58+ |> Seq.pairwise
59+ |> Seq.map ( fun ( first , second ) ->
60+ lazy
61+ if second - first > 0 then
62+ let values = getChunkValues first second
63+ let columns = getChunkIndices first second
1464
15- let copy = ClArray.copy clContext workGroupSize
65+ Some ( values, columns)
66+ else None)
1667
17- let copyData = ClArray.copy clContext workGroupSize
68+ let runCSR ( clContext : ClContext ) workGroupSize =
1869
19- // endIndex exclusive (for csr matrix row pointers interop), startIndex inclusive
20- fun ( processor : MailboxProcessor < _ >) allocationMode ( matrix : ClMatrix.CSR < 'a >) startIndex endIndex ->
70+ let runLazy = runCSRLazy clContext workGroupSize
2171
22- ()
72+ fun ( processor : MailboxProcessor < _ >) allocationMode ( matrix : ClMatrix.CSR < 'a >) ->
73+ runLazy processor allocationMode matrix
74+ |> Seq.map ( fun lazyValue -> lazyValue.Value)
75+ |> Seq.toArray
0 commit comments