@@ -3,6 +3,7 @@ namespace GraphBLAS.FSharp.Backend
33open Brahma.FSharp
44open GraphBLAS.FSharp .Backend
55open GraphBLAS.FSharp .Backend .Common
6+ open GraphBLAS.FSharp .Backend .Elementwise
67open Microsoft.FSharp .Quotations
78
89module CSRMatrix =
@@ -79,12 +80,13 @@ module CSRMatrix =
7980 Columns = matrix.Columns
8081 Values = matrix.Values }
8182
82- let eWiseAdd ( clContext : ClContext ) ( opAdd : Expr < 'a option -> 'b option -> 'c option >) workGroupSize =
83+ ///<remarks >Old version</remarks >
84+ let elementwiseWithCOO ( clContext : ClContext ) ( opAdd : Expr < 'a option -> 'b option -> 'c option >) workGroupSize =
8385
8486 let prepareRows = prepareRows clContext workGroupSize
8587
8688 let eWiseCOO =
87- COOMatrix.eWiseAdd clContext opAdd workGroupSize
89+ COOMatrix.elementwise clContext opAdd workGroupSize
8890
8991 let toCSRInplace =
9092 COOMatrix.toCSRInplace clContext workGroupSize
@@ -113,12 +115,17 @@ module CSRMatrix =
113115
114116 toCSRInplace processor m3COO
115117
116- let eWiseAddAtLeastOne ( clContext : ClContext ) ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'c option >) workGroupSize =
118+ ///<remarks >Old version</remarks >
119+ let elementwiseAtLeastOneWithCOO
120+ ( clContext : ClContext )
121+ ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'c option >)
122+ workGroupSize
123+ =
117124
118125 let prepareRows = prepareRows clContext workGroupSize
119126
120127 let eWiseCOO =
121- COOMatrix.eWiseAddAtLeastOne clContext opAdd workGroupSize
128+ COOMatrix.elementwiseAtLeastOne clContext opAdd workGroupSize
122129
123130 let toCSRInplace =
124131 COOMatrix.toCSRInplace clContext workGroupSize
@@ -177,3 +184,139 @@ module CSRMatrix =
177184 let coo = toCOO queue matrix
178185 let transposedCoo = transposeInplace queue coo
179186 toCSRInplace queue transposedCoo
187+
188+ let elementwiseToCOO < 'a , 'b , 'c when 'a : struct and 'b : struct and 'c : struct and 'c : equality >
189+ ( clContext : ClContext )
190+ ( opAdd : Expr < 'a option -> 'b option -> 'c option >)
191+ workGroupSize
192+ =
193+
194+ let merge = merge clContext workGroupSize
195+
196+ let preparePositions =
197+ preparePositions clContext opAdd Utils.defaultWorkGroupSize
198+
199+ let setPositions =
200+ setPositions< 'c> clContext Utils.defaultWorkGroupSize
201+
202+ fun ( queue : MailboxProcessor < _ >) ( matrixLeft : CSRMatrix < 'a >) ( matrixRight : CSRMatrix < 'b >) ->
203+
204+ let allRows , allColumns , leftMergedValues , rightMergedValues , isRowEnd , isLeft =
205+ merge
206+ queue
207+ matrixLeft.RowPointers
208+ matrixLeft.Columns
209+ matrixLeft.Values
210+ matrixRight.RowPointers
211+ matrixRight.Columns
212+ matrixRight.Values
213+
214+ let positions , allValues =
215+ preparePositions queue allColumns leftMergedValues rightMergedValues isRowEnd isLeft
216+
217+ queue.Post( Msg.CreateFreeMsg<_>( leftMergedValues))
218+ queue.Post( Msg.CreateFreeMsg<_>( rightMergedValues))
219+
220+ let resultRows , resultColumns , resultValues , positions , positionsSum =
221+ setPositions queue allRows allColumns allValues positions
222+
223+ queue.Post( Msg.CreateFreeMsg<_>( allRows))
224+ queue.Post( Msg.CreateFreeMsg<_>( isLeft))
225+ queue.Post( Msg.CreateFreeMsg<_>( isRowEnd))
226+ queue.Post( Msg.CreateFreeMsg<_>( positions))
227+ queue.Post( Msg.CreateFreeMsg<_>( allColumns))
228+ queue.Post( Msg.CreateFreeMsg<_>( allValues))
229+
230+ { Context = clContext
231+ RowCount = matrixLeft.RowCount
232+ ColumnCount = matrixLeft.ColumnCount
233+ Rows = resultRows
234+ Columns = resultColumns
235+ Values = resultValues }
236+
237+ let elementwise < 'a , 'b , 'c when 'a : struct and 'b : struct and 'c : struct and 'c : equality >
238+ ( clContext : ClContext )
239+ ( opAdd : Expr < 'a option -> 'b option -> 'c option >)
240+ workGroupSize
241+ =
242+
243+ let elementwiseToCOO =
244+ elementwiseToCOO clContext opAdd workGroupSize
245+
246+ let toCSRInplace =
247+ COOMatrix.toCSRInplace clContext Utils.defaultWorkGroupSize
248+
249+ fun ( queue : MailboxProcessor < _ >) ( matrixLeft : CSRMatrix < 'a >) ( matrixRight : CSRMatrix < 'b >) ->
250+
251+ let cooRes =
252+ elementwiseToCOO queue matrixLeft matrixRight
253+
254+ toCSRInplace queue cooRes
255+
256+ let elementwiseAtLeastOneToCOO < 'a , 'b , 'c when 'a : struct and 'b : struct and 'c : struct and 'c : equality >
257+ ( clContext : ClContext )
258+ ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'c option >)
259+ workGroupSize
260+ =
261+
262+ let merge = merge clContext workGroupSize
263+
264+ let preparePositions =
265+ preparePositionsAtLeastOne clContext opAdd Utils.defaultWorkGroupSize
266+
267+ let setPositions =
268+ setPositions< 'c> clContext Utils.defaultWorkGroupSize
269+
270+ fun ( queue : MailboxProcessor < _ >) ( matrixLeft : CSRMatrix < 'a >) ( matrixRight : CSRMatrix < 'b >) ->
271+
272+ let allRows , allColumns , leftMergedValues , rightMergedValues , isRowEnd , isLeft =
273+ merge
274+ queue
275+ matrixLeft.RowPointers
276+ matrixLeft.Columns
277+ matrixLeft.Values
278+ matrixRight.RowPointers
279+ matrixRight.Columns
280+ matrixRight.Values
281+
282+ let positions , allValues =
283+ preparePositions queue allColumns leftMergedValues rightMergedValues isRowEnd isLeft
284+
285+ queue.Post( Msg.CreateFreeMsg<_>( leftMergedValues))
286+ queue.Post( Msg.CreateFreeMsg<_>( rightMergedValues))
287+
288+ let resultRows , resultColumns , resultValues , positions , positionsSum =
289+ setPositions queue allRows allColumns allValues positions
290+
291+ queue.Post( Msg.CreateFreeMsg<_>( allRows))
292+ queue.Post( Msg.CreateFreeMsg<_>( isLeft))
293+ queue.Post( Msg.CreateFreeMsg<_>( isRowEnd))
294+ queue.Post( Msg.CreateFreeMsg<_>( positions))
295+ queue.Post( Msg.CreateFreeMsg<_>( allColumns))
296+ queue.Post( Msg.CreateFreeMsg<_>( allValues))
297+
298+ { Context = clContext
299+ RowCount = matrixLeft.RowCount
300+ ColumnCount = matrixLeft.ColumnCount
301+ Rows = resultRows
302+ Columns = resultColumns
303+ Values = resultValues }
304+
305+ let elementwiseAtLeastOne < 'a , 'b , 'c when 'a : struct and 'b : struct and 'c : struct and 'c : equality >
306+ ( clContext : ClContext )
307+ ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'c option >)
308+ workGroupSize
309+ =
310+
311+ let elementwiseAtLeastOneToCOO =
312+ elementwiseAtLeastOneToCOO clContext opAdd workGroupSize
313+
314+ let toCSRInplace =
315+ COOMatrix.toCSRInplace clContext Utils.defaultWorkGroupSize
316+
317+ fun ( queue : MailboxProcessor < _ >) ( matrixLeft : CSRMatrix < 'a >) ( matrixRight : CSRMatrix < 'b >) ->
318+
319+ let cooRes =
320+ elementwiseAtLeastOneToCOO queue matrixLeft matrixRight
321+
322+ toCSRInplace queue cooRes
0 commit comments