Skip to content

Commit 66c2711

Browse files
committed
refactor: wip
1 parent 6da457b commit 66c2711

4 files changed

Lines changed: 76 additions & 405 deletions

File tree

src/GraphBLAS-sharp.Backend/Common/ClArray.fs

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ open Microsoft.FSharp.Quotations
55
open GraphBLAS.FSharp.Backend.Objects.ClContext
66
open GraphBLAS.FSharp.Backend.Objects.ClCell
77
open GraphBLAS.FSharp.Backend.Quotes
8+
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
89

910
module ClArray =
1011
let init (clContext: ClContext) workGroupSize (initializer: Expr<int -> 'a>) =
@@ -33,30 +34,6 @@ module ClArray =
3334

3435
outputArray
3536

36-
let assignManyInit (clContext: ClContext) workGroupSize (initializer: Expr<int -> 'a>) =
37-
38-
let init =
39-
<@ fun (range: Range1D) indicesLength (indices: ClArray<int>) (outputBuffer: ClArray<'a>) ->
40-
41-
let gid = range.GlobalID0
42-
43-
if gid < indicesLength then
44-
let targetIndex = indices.[gid]
45-
46-
outputBuffer.[targetIndex] <- (%initializer) gid @>
47-
48-
let program = clContext.Compile(init)
49-
50-
fun (processor: MailboxProcessor<_>) (indices: ClArray<int>) (result: ClArray<'a>) ->
51-
52-
let kernel = program.GetKernel()
53-
54-
let ndRange =
55-
Range1D.CreateValid(indices.Length, workGroupSize)
56-
57-
processor.Post(Msg.MsgSetArguments(fun () -> kernel.KernelFunc ndRange indices.Length indices result))
58-
processor.Post(Msg.CreateRunMsg<_, _> kernel)
59-
6037
let create (clContext: ClContext) workGroupSize =
6138

6239
let create =
@@ -315,6 +292,24 @@ module ClArray =
315292

316293
resultArray
317294

295+
let getUniqueBitmap2<'a when 'a: equality> (clContext: ClContext) workGroupSize =
296+
297+
let map = map2 clContext workGroupSize <@ fun x y -> if x = 1 && y = 1 then 1 else 0 @>
298+
299+
let getUniqueBitmap = getUniqueBitmap clContext workGroupSize
300+
301+
fun (processor: MailboxProcessor<_>) allocationMode (firstArray: ClArray<'a>) (secondArray: ClArray<'a>) ->
302+
let firstBitmap = getUniqueBitmap processor DeviceOnly firstArray
303+
304+
let secondBitmap = getUniqueBitmap processor DeviceOnly secondArray
305+
306+
let result = map processor allocationMode firstBitmap secondBitmap
307+
308+
firstBitmap.Free processor
309+
secondBitmap.Free processor
310+
311+
result
312+
318313
let choose<'a, 'b> (clContext: ClContext) workGroupSize (predicate: Expr<'a -> 'b option>) =
319314
let getBitmap =
320315
map<'a, int> clContext workGroupSize
@@ -353,3 +348,14 @@ module ClArray =
353348
scatter processor positions values result
354349

355350
result
351+
352+
let iterate (clContext: ClContext) workGroupSize iterator =
353+
354+
let create = create clContext workGroupSize iterator
355+
356+
let scatter = Scatter.runInplace clContext workGroupSize
357+
358+
fun (processor: MailboxProcessor<_>) allocationMode (inputArray: ClArray<'a>) (resultArray: ClArray<'a>) ->
359+
360+
let positions = create processor allocationMode
361+

src/GraphBLAS-sharp.Backend/Matrix/CSRMatrix/Matrix.fs

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ open GraphBLAS.FSharp.Backend.Objects
99
open GraphBLAS.FSharp.Backend.Objects.ClMatrix
1010
open GraphBLAS.FSharp.Backend.Objects.ClContext
1111
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
12+
open GraphBLAS.FSharp.Backend.Objects.ClCell
1213

1314
module Matrix =
1415
let private expandRowPointers (clContext: ClContext) workGroupSize =
@@ -155,50 +156,3 @@ module Matrix =
155156

156157
run queue matrixLeft matrixRight mask
157158

158-
let spgemm
159-
(clContext: ClContext)
160-
workGroupSize
161-
(opAdd: Expr<'c -> 'c -> 'c>)
162-
(opMul: Expr<'a -> 'b -> 'c>)
163-
=
164-
165-
let expand = SpGEMM.Expand.run clContext workGroupSize opMul
166-
167-
let expandRowPointers = expandRowPointers clContext workGroupSize
168-
169-
let sortData = Sort.Radix.runByKeysStandard clContext workGroupSize
170-
171-
let sortKeys = Sort.Radix.runByKeysStandard clContext workGroupSize
172-
173-
let reduceByKey = Reduce.ByKey.segmentSequential clContext workGroupSize opAdd
174-
175-
fun (processor: MailboxProcessor<_>) (leftMatrix: ClMatrix.CSR<'a>) (rightMatrix: ClMatrix.CSR<'b>) ->
176-
let multiplicationResult, columns, rowPointers =
177-
expand processor leftMatrix rightMatrix
178-
179-
let rows =
180-
expandRowPointers processor DeviceOnly rowPointers columns.Length leftMatrix.RowCount
181-
182-
rowPointers.Free processor
183-
184-
// sorting
185-
let sortData = sortData processor
186-
let sortKeys = sortKeys processor
187-
188-
// by columns
189-
let valuesSortedByColumns = sortData columns multiplicationResult
190-
let byKeSortedRows = sortKeys columns rows
191-
192-
multiplicationResult.Free processor
193-
rows.Free processor
194-
195-
// by rows
196-
let values = sortData byKeSortedRows valuesSortedByColumns
197-
let columns = sortKeys byKeSortedRows columns
198-
199-
// reduce
200-
201-
202-
203-
()
204-

0 commit comments

Comments
 (0)