Skip to content

Commit 805aa5f

Browse files
committed
Fix sync for MatrixTuples
1 parent dec5ba8 commit 805aa5f

5 files changed

Lines changed: 31 additions & 11 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open GraphBLAS.FSharp.Backend.Common
77
open Brahma.OpenCL
88

99
module internal Mxv =
10+
// not finished
1011
let pcsr (matrix: CSRMatrix<'a>) (vector: BitmapVector<'a>) mask (semiring: ISemiring<'a>) = opencl {
1112
let (ClosedBinaryOp plus) = semiring.Plus
1213
let (ClosedBinaryOp times) = semiring.Times

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module internal RemoveDuplicates =
77
let run (array: 'a[]) = opencl {
88
let inputLength = array.Length
99

10-
let isUniqueBitmap =
10+
let getUniqueBitmap =
1111
<@
1212
fun (ndRange: _1D)
1313
(inputArray: 'a[])
@@ -32,9 +32,9 @@ module internal RemoveDuplicates =
3232
@>
3333

3434
let bitmap = Array.create inputLength 1
35-
do! RunCommand isUniqueBitmap <| fun kernelPrepare ->
36-
let ndRange = _1D(Utils.workSize inputLength, Utils.workGroupSize)
37-
kernelPrepare ndRange array bitmap
35+
do! RunCommand getUniqueBitmap <| fun kernelPrepare ->
36+
let range = _1D(Utils.workSize inputLength, Utils.workGroupSize)
37+
kernelPrepare range array bitmap
3838

3939
let resultLength = Array.zeroCreate 1
4040
do! PrefixSum.runInplace bitmap resultLength
@@ -43,8 +43,8 @@ module internal RemoveDuplicates =
4343

4444
let outputArray = Array.zeroCreate resultLength
4545
do! RunCommand setPositions <| fun kernelPrepare ->
46-
let ndRange = _1D(Utils.workSize inputLength, Utils.workGroupSize)
47-
kernelPrepare ndRange array bitmap outputArray
46+
let range = _1D(Utils.workSize inputLength, Utils.workGroupSize)
47+
kernelPrepare range array bitmap outputArray
4848

4949
return outputArray
5050
}

src/GraphBLAS-sharp/Methods/Matrix.fs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module Matrix =
4848
let tuples (matrix: Matrix<'a>) : GraphblasEvaluation<MatrixTuples<'a>> =
4949
let matrixTuples =
5050
match matrix with
51-
| MatrixCOO coo -> COOMatrix.GetTuples.from coo
51+
| MatrixCOO matrix -> COOMatrix.GetTuples.from matrix
5252
| _ -> failwith "Not Implemented"
5353

5454
graphblas { return! EvalGB.fromCl matrixTuples }
@@ -200,9 +200,10 @@ module Matrix =
200200
module MatrixTuples =
201201
let synchronize (matrixTuples: MatrixTuples<'a>) =
202202
opencl {
203-
let! _ = ToHost matrixTuples.RowIndices
204-
let! _ = ToHost matrixTuples.ColumnIndices
205-
let! _ = ToHost matrixTuples.Values
203+
let! rows = if matrixTuples.RowIndices.Length = 0 then opencl { return [||] } else ToHost matrixTuples.RowIndices
204+
let! cols = if matrixTuples.ColumnIndices.Length = 0 then opencl { return [||] } else ToHost matrixTuples.ColumnIndices
205+
let! vals = if matrixTuples.Values.Length = 0 then opencl { return [||] } else ToHost matrixTuples.Values
206+
206207
return ()
207208
}
208209
|> EvalGB.fromCl

src/GraphBLAS-sharp/Objects/Matrix.fs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ and COOMatrix<'a> =
3030
Values: 'a[]
3131
}
3232

33+
override this.ToString() =
34+
[
35+
sprintf "COO Matrix %ix%i \n" this.RowCount this.ColumnCount
36+
sprintf "RowIndices: %A \n" this.Rows
37+
sprintf "ColumnIndices: %A \n" this.Columns
38+
sprintf "Values: %A \n" this.Values
39+
]
40+
|> String.concat ""
41+
3342
static member FromTuples(rowCount: int, columnCount: int, rows: int[], columns: int[], values: 'a[]) =
3443
{
3544
RowCount = rowCount
@@ -44,7 +53,7 @@ and COOMatrix<'a> =
4453
array
4554
|> Seq.cast<'a>
4655
|> Seq.mapi (fun idx v -> (idx / Array2D.length2 array, idx % Array2D.length2 array, v))
47-
|> Seq.filter (fun (i, j, v) -> not <| isZero v)
56+
|> Seq.filter (fun (_, _, v) -> not <| isZero v)
4857
|> Array.ofSeq
4958
|> Array.unzip3
5059

src/GraphBLAS-sharp/Objects/Vector.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ and COOVector<'a> =
1515
Values: 'a[]
1616
}
1717

18+
override this.ToString() =
19+
[
20+
sprintf "Sparse Vector\n"
21+
sprintf "Size: %i \n" this.Size
22+
sprintf "Indices: %A \n" this.Indices
23+
sprintf "Values: %A \n" this.Values
24+
]
25+
|> String.concat ""
26+
1827
and BitmapVector<'a> =
1928
{
2029
Bitmap: bool[]

0 commit comments

Comments
 (0)