@@ -13,17 +13,54 @@ open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
1313
1414
1515module Matrix =
16+ let expandRowPointers ( clContext : ClContext ) workGroupSize =
17+
18+ let kernel =
19+ <@ fun ( ndRange : Range1D ) columnsLength pointersLength ( pointers : ClArray < int >) ( results : ClArray < int >) ->
20+
21+ let gid = ndRange.GlobalID0
22+
23+ if gid < columnsLength then
24+ let result =
25+ (% Search.Bin.lowerBound 0 ) pointersLength gid pointers
26+
27+ results.[ gid] <- result - 1 @>
28+
29+ let program = clContext.Compile kernel
30+
31+ fun ( processor : MailboxProcessor < _ >) allocationMode ( matrix : ClMatrix.CSR < 'a >) ->
32+
33+ let rows =
34+ clContext.CreateClArrayWithSpecificAllocationMode( allocationMode, matrix.Columns.Length)
35+
36+ let kernel = program.GetKernel()
37+
38+ let ndRange =
39+ Range1D.CreateValid( matrix.Columns.Length, workGroupSize)
40+
41+ processor.Post( Msg.MsgSetArguments(
42+ fun () ->
43+ kernel.KernelFunc
44+ ndRange
45+ matrix.Columns.Length
46+ matrix.RowPointers.Length
47+ matrix.RowPointers
48+ rows))
49+
50+ processor.Post( Msg.CreateRunMsg<_, _> kernel)
51+
52+ rows
53+
1654 let toCOO ( clContext : ClContext ) workGroupSize =
17- let prepare =
18- Common.expandRowPointers clContext workGroupSize
55+ let prepare = expandRowPointers clContext workGroupSize
1956
2057 let copy = ClArray.copy clContext workGroupSize
2158
2259 let copyData = ClArray.copy clContext workGroupSize
2360
2461 fun ( processor : MailboxProcessor < _ >) allocationMode ( matrix : ClMatrix.CSR < 'a >) ->
2562 let rows =
26- prepare processor allocationMode matrix.RowPointers matrix.Columns.Length matrix.RowCount
63+ prepare processor allocationMode matrix
2764
2865 let cols =
2966 copy processor allocationMode matrix.Columns
@@ -39,12 +76,11 @@ module Matrix =
3976 Values = values }
4077
4178 let toCOOInPlace ( clContext : ClContext ) workGroupSize =
42- let prepare =
43- Common.expandRowPointers clContext workGroupSize
79+ let prepare = expandRowPointers clContext workGroupSize
4480
4581 fun ( processor : MailboxProcessor < _ >) allocationMode ( matrix : ClMatrix.CSR < 'a >) ->
4682 let rows =
47- prepare processor allocationMode matrix.RowPointers matrix.Columns.Length matrix.RowCount
83+ prepare processor allocationMode matrix
4884
4985 processor.Post( Msg.CreateFreeMsg( matrix.RowPointers))
5086
@@ -92,7 +128,6 @@ module Matrix =
92128 let toCSRInPlace =
93129 COO.Matrix.toCSRInPlace clContext workGroupSize
94130
95-
96131 fun ( queue : MailboxProcessor < _ >) allocationMode ( matrix : ClMatrix.CSR < 'a >) ->
97132 toCOO queue allocationMode matrix
98133 |> transposeInPlace queue
0 commit comments