Skip to content

Commit e80ef7e

Browse files
committed
Matrix.copy added and used in converters, Matrix.Dispose
1 parent 1c013e9 commit e80ef7e

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/GraphBLAS-sharp.Backend/Matrices.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ type Matrix<'a when 'a: struct> =
2323
| MatrixCSR matrix -> matrix.ColumnCount
2424
| MatrixCOO matrix -> matrix.ColumnCount
2525

26+
member this.Dispose() =
27+
match this with
28+
| MatrixCSR matrix -> (matrix :> IDeviceMemObject).Dispose()
29+
| MatrixCOO matrix -> (matrix :> IDeviceMemObject).Dispose()
30+
2631
and CSRMatrix<'elem when 'elem: struct> =
2732
{ Context: ClContext
2833
RowCount: int

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,49 @@ open Brahma.FSharp.OpenCL
44
open Microsoft.FSharp.Quotations
55

66
module Matrix =
7+
let copy (clContext: ClContext) =
8+
let copy = GraphBLAS.FSharp.Backend.ClArray.copy clContext
9+
let copyData = GraphBLAS.FSharp.Backend.ClArray.copy clContext
10+
11+
fun (processor: MailboxProcessor<_>) workGroupSize (matrix: Matrix<'a>) ->
12+
match matrix with
13+
| MatrixCOO m ->
14+
let res =
15+
{ Context = clContext
16+
RowCount = m.RowCount
17+
ColumnCount = m.ColumnCount
18+
Rows = copy processor workGroupSize m.Rows
19+
Columns = copy processor workGroupSize m.Columns
20+
Values = copyData processor workGroupSize m.Values
21+
}
22+
MatrixCOO res
23+
| MatrixCSR m ->
24+
let res =
25+
{ Context = clContext
26+
RowCount = m.RowCount
27+
ColumnCount = m.ColumnCount
28+
RowPointers = copy processor workGroupSize m.RowPointers
29+
Columns = copy processor workGroupSize m.Columns
30+
Values = copyData processor workGroupSize m.Values
31+
}
32+
MatrixCSR res
33+
734
let toCSR (clContext: ClContext) workGroupSize =
835
let toCSR = COOMatrix.toCSR clContext workGroupSize
36+
let copy = copy clContext
937

1038
fun (processor: MailboxProcessor<_>) (matrix: Matrix<'a>) ->
1139
match matrix with
1240
| MatrixCOO m -> toCSR processor m |> MatrixCSR
13-
| MatrixCSR _ -> matrix
41+
| MatrixCSR _ -> copy processor workGroupSize matrix
1442

1543
let toCOO (clContext: ClContext) workGroupSize =
1644
let toCOO = CSRMatrix.toCOO clContext
45+
let copy = copy clContext
1746

1847
fun (processor: MailboxProcessor<_>) (matrix: Matrix<'a>) ->
1948
match matrix with
20-
| MatrixCOO _ -> matrix
49+
| MatrixCOO _ -> copy processor workGroupSize matrix
2150
| MatrixCSR m -> toCOO workGroupSize processor m |> MatrixCOO
2251

2352
let eWiseAdd (clContext: ClContext) (opAdd: Expr<'a -> 'a -> 'a>) workGroupSize =

0 commit comments

Comments
 (0)