Skip to content

Commit 8666552

Browse files
committed
Backend matrix generalization
1 parent 1805e3a commit 8666552

10 files changed

Lines changed: 64 additions & 12 deletions

File tree

src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@
99
<ItemGroup>
1010
<Compile Include="AssemblyInfo.fs" />
1111
<Compile Include="Common/Utils.fs" />
12-
<Compile Include="Common/ClArray.fs" />
12+
<Compile Include="Common/ClArray.fs" />
1313
<Compile Include="Common/Sum.fs" />
1414
<Compile Include="Common/BitonicSort.fs" />
1515
<Compile Include="Matrices.fs" />
16-
<Compile Include="COOMatrix/COOMatrix.fs" />
17-
<Compile Include="CSRMatrix/CSRMatrix.fs" />
16+
<Compile Include="Matrix/COOMatrix/COOMatrix.fs" />
17+
<Compile Include="Matrix/CSRMatrix/CSRMatrix.fs" />
18+
<Compile Include="Matrix/CSRMatrix/SpGEMM.fs" />
19+
<Compile Include="Matrix/CSRMatrix/SpMV.fs" />
20+
<Compile Include="Matrix/Matrix.fs" />
1821
<!--Compile Include="Backend/CSRMatrix/GetTuples.fs" /-->
19-
<Compile Include="CSRMatrix/SpGEMM.fs" />
2022
<!--Compile Include="Backend/CSRMatrix/SpMSpV.fs" /-->
21-
<Compile Include="CSRMatrix/SpMV.fs" />
2223
<!--Compile Include="Backend/CSRMatrix/Transpose.fs" /-->
2324
<!--Compile Include="Backend/COOVector/Utilities/SetPositions.fs" />
2425
<Compile Include="Backend/COOVector/Utilities/AssignSubVector/Intersect.fs" />

src/GraphBLAS-sharp.Backend/Matrices.fs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,39 @@ namespace GraphBLAS.FSharp.Backend
22

33
open Brahma.FSharp.OpenCL
44

5-
type CSRMatrix<'elem when 'elem: struct> =
5+
type MatrixFromat =
6+
| CSR
7+
| COO
8+
9+
type Matrix<'a when 'a: struct> =
10+
| MatrixCSR of CSRMatrix<'a>
11+
| MatrixCOO of COOMatrix<'a>
12+
13+
member this.RowCount =
14+
match this with
15+
| MatrixCSR matrix -> matrix.RowCount
16+
| MatrixCOO matrix -> matrix.RowCount
17+
18+
member this.ColumnCount =
19+
match this with
20+
| MatrixCSR matrix -> matrix.ColumnCount
21+
| MatrixCOO matrix -> matrix.ColumnCount
22+
23+
and CSRMatrix<'elem when 'elem: struct> =
624
{ RowCount: int
725
ColumnCount: int
826
RowPointers: ClArray<int>
927
Columns: ClArray<int>
1028
Values: ClArray<'elem> }
1129

12-
type TupleMatrix<'elem when 'elem: struct> =
13-
{ RowIndices: ClArray<int>
14-
ColumnIndices: ClArray<int>
15-
Values: ClArray<'elem> }
16-
17-
type COOMatrix<'elem when 'elem: struct> =
30+
and COOMatrix<'elem when 'elem: struct> =
1831
{ RowCount: int
1932
ColumnCount: int
2033
Rows: ClArray<int>
2134
Columns: ClArray<int>
2235
Values: ClArray<'elem> }
36+
37+
and TupleMatrix<'elem when 'elem: struct> =
38+
{ RowIndices: ClArray<int>
39+
ColumnIndices: ClArray<int>
40+
Values: ClArray<'elem> }

src/GraphBLAS-sharp.Backend/COOMatrix/COOMatrix.fs renamed to src/GraphBLAS-sharp.Backend/Matrix/COOMatrix/COOMatrix.fs

File renamed without changes.

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

File renamed without changes.

src/GraphBLAS-sharp.Backend/CSRMatrix/GetTuples.fs renamed to src/GraphBLAS-sharp.Backend/Matrix/CSRMatrix/GetTuples.fs

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/GraphBLAS-sharp.Backend/CSRMatrix/Transpose.fs renamed to src/GraphBLAS-sharp.Backend/Matrix/CSRMatrix/Transpose.fs

File renamed without changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace GraphBLAS.FSharp.Backend
2+
3+
open Brahma.FSharp.OpenCL
4+
open Microsoft.FSharp.Quotations
5+
6+
module Matrix =
7+
let toCSR (clContext: ClContext) workGroupSize processor matrix =
8+
let toCSR =
9+
COOMatrix.toCSR clContext workGroupSize processor
10+
11+
match matrix with
12+
| MatrixCOO m -> toCSR m |> MatrixCSR
13+
| MatrixCSR _ -> matrix
14+
15+
let toCOO (clContext: ClContext) workGroupSize processor matrix =
16+
let toCOO =
17+
CSRMatrix.toCOO clContext processor workGroupSize
18+
19+
match matrix with
20+
| MatrixCOO _ -> matrix
21+
| MatrixCSR m -> toCOO m |> MatrixCOO
22+
23+
let eWiseAdd (clContext: ClContext) (opAdd: Expr<'a -> 'a -> 'a>) workGroupSize processor matrix1 matrix2 =
24+
let COOeWiseAdd =
25+
COOMatrix.eWiseAdd clContext opAdd workGroupSize processor
26+
27+
let CSReWiseAdd =
28+
CSRMatrix.eWiseAdd clContext opAdd workGroupSize processor
29+
30+
match matrix1, matrix2 with
31+
| MatrixCOO m1, MatrixCOO m2 -> COOeWiseAdd m1 m2 |> MatrixCOO
32+
| MatrixCSR m1, MatrixCSR m2 -> CSReWiseAdd m1 m2 |> MatrixCSR
33+
| _ -> failwith "Matrix formats are not matching"

0 commit comments

Comments
 (0)