Skip to content

Commit 4e3fd25

Browse files
committed
Remove dense vector; change vector builders
1 parent beee153 commit 4e3fd25

5 files changed

Lines changed: 60 additions & 101 deletions

File tree

src/GraphBLAS-sharp/Algorithms/BFS.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
1010
module BFS =
1111
let levelBFS (matrix: Matrix<bool>) (source: int) : OpenCLEvaluation<Vector<int>> =
1212
let vertexCount = matrix.RowCount
13-
let levels = Vector.Dense(Array.zeroCreate vertexCount, IntegerMonoid.add)
14-
let frontier = Vector.Sparse(vertexCount, [source, true])
13+
let levels = Vector.ofArray <| Array.zeroCreate vertexCount <| (=) 0
14+
let frontier = Vector.ofTuples vertexCount [source, true]
1515

1616
opencl {
1717
let mutable currentLevel = 1

src/GraphBLAS-sharp/Algorithms/SSSP.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
99
module SSSP =
1010
let SSSP (matrix: Matrix<float>) (source: int) : OpenCLEvaluation<Vector<float>> =
1111
let vertexCount = matrix.RowCount
12-
let distance = Vector.Sparse(vertexCount, [source, 0.])
12+
let distance = Vector.ofTuples vertexCount [source, 0.]
1313

1414
opencl {
1515
for _ in 1 .. vertexCount - 1 do

src/GraphBLAS-sharp/Implementations.fs

Lines changed: 44 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -37,50 +37,50 @@ type CSRMatrix<'a when 'a : struct and 'a : equality>(csrTuples: CSRFormat<'a>)
3737
let rowCount = base.RowCount
3838
let columnCount = base.ColumnCount
3939

40-
let spMV (vector: DenseVector<'a>) (mask: Mask1D) (semiring: Semiring<'a>) : OpenCLEvaluation<Vector<'a>> =
41-
let csrMatrixRowCount = rowCount
42-
let csrMatrixColumnCount = columnCount
43-
let vectorLength = vector.Size
44-
if csrMatrixColumnCount <> vectorLength then
45-
invalidArg
46-
"vector"
47-
(sprintf "Argument has invalid dimension. Need %i, but given %i" csrMatrixColumnCount vectorLength)
48-
49-
let (BinaryOp plus) = semiring.PlusMonoid.Append
50-
let (BinaryOp mult) = semiring.Times
51-
52-
let resultVector = Array.zeroCreate<'a> csrMatrixRowCount
53-
let command =
54-
<@
55-
fun (ndRange: _1D)
56-
(resultBuffer: 'a[])
57-
(csrValuesBuffer: 'a[])
58-
(csrColumnsBuffer: int[])
59-
(csrRowPointersBuffer: int[])
60-
(vectorBuffer: 'a[]) ->
61-
62-
let i = ndRange.GlobalID0
63-
let mutable localResultBuffer = resultBuffer.[i]
64-
for k in csrRowPointersBuffer.[i] .. csrRowPointersBuffer.[i + 1] - 1 do
65-
localResultBuffer <- (%plus) localResultBuffer
66-
((%mult) csrValuesBuffer.[k] vectorBuffer.[csrColumnsBuffer.[k]])
67-
resultBuffer.[i] <- localResultBuffer
68-
@>
69-
70-
let ndRange = _1D(csrMatrixRowCount)
71-
let binder = fun kernelPrepare ->
72-
kernelPrepare
73-
ndRange
74-
resultVector
75-
csrTuples.Values
76-
csrTuples.ColumnIndices
77-
csrTuples.RowPointers
78-
vector.Values
79-
80-
opencl {
81-
do! RunCommand command binder
82-
return upcast DenseVector(resultVector, semiring.PlusMonoid)
83-
}
40+
// let spMV (vector: DenseVector<'a>) (mask: Mask1D) (semiring: Semiring<'a>) : OpenCLEvaluation<Vector<'a>> =
41+
// let csrMatrixRowCount = rowCount
42+
// let csrMatrixColumnCount = columnCount
43+
// let vectorLength = vector.Size
44+
// if csrMatrixColumnCount <> vectorLength then
45+
// invalidArg
46+
// "vector"
47+
// (sprintf "Argument has invalid dimension. Need %i, but given %i" csrMatrixColumnCount vectorLength)
48+
49+
// let (BinaryOp plus) = semiring.PlusMonoid.Append
50+
// let (BinaryOp mult) = semiring.Times
51+
52+
// let resultVector = Array.zeroCreate<'a> csrMatrixRowCount
53+
// let command =
54+
// <@
55+
// fun (ndRange: _1D)
56+
// (resultBuffer: 'a[])
57+
// (csrValuesBuffer: 'a[])
58+
// (csrColumnsBuffer: int[])
59+
// (csrRowPointersBuffer: int[])
60+
// (vectorBuffer: 'a[]) ->
61+
62+
// let i = ndRange.GlobalID0
63+
// let mutable localResultBuffer = resultBuffer.[i]
64+
// for k in csrRowPointersBuffer.[i] .. csrRowPointersBuffer.[i + 1] - 1 do
65+
// localResultBuffer <- (%plus) localResultBuffer
66+
// ((%mult) csrValuesBuffer.[k] vectorBuffer.[csrColumnsBuffer.[k]])
67+
// resultBuffer.[i] <- localResultBuffer
68+
// @>
69+
70+
// let ndRange = _1D(csrMatrixRowCount)
71+
// let binder = fun kernelPrepare ->
72+
// kernelPrepare
73+
// ndRange
74+
// resultVector
75+
// csrTuples.Values
76+
// csrTuples.ColumnIndices
77+
// csrTuples.RowPointers
78+
// vector.Values
79+
80+
// opencl {
81+
// do! RunCommand command binder
82+
// return upcast DenseVector(resultVector, semiring.PlusMonoid)
83+
// }
8484

8585
// Not Implemented
8686
new(rows: int[], columns: int[], values: 'a[]) = CSRMatrix(CSRFormat.CreateEmpty())
@@ -648,32 +648,3 @@ and SparseVector<'a when 'a : struct and 'a : equality>(size: int, indices: int[
648648
override this.Apply a b = failwith "Not Implemented"
649649
override this.Prune a b = failwith "Not Implemented"
650650
override this.Reduce (monoid: Monoid<'a>) = failwith "Not Implemented"
651-
652-
and DenseVector<'a when 'a : struct and 'a : equality>(vector: 'a[], monoid: Monoid<'a>) =
653-
inherit Vector<'a>(vector.Length)
654-
655-
member this.Monoid = monoid
656-
member this.Values: 'a[] = vector
657-
658-
override this.Clear () = failwith "Not Implemented"
659-
override this.Copy () = failwith "Not Implemented"
660-
override this.Resize a = failwith "Not Implemented"
661-
override this.GetNNZ () = failwith "Not Implemented"
662-
override this.GetTuples () = failwith "Not Implemented"
663-
override this.GetMask(?isComplemented: bool) =
664-
let isComplemented = defaultArg isComplemented false
665-
failwith "Not Implemented"
666-
override this.ToHost () = failwith "Not Implemented"
667-
668-
override this.Extract (mask: Mask1D option) : OpenCLEvaluation<Vector<'a>> = failwith "Not Implemented"
669-
override this.Extract (idx: int) : OpenCLEvaluation<Scalar<'a>> = failwith "Not Implemented"
670-
override this.Assign (mask: Mask1D option, vector: Vector<'a>) : OpenCLEvaluation<unit> = failwith "Not Implemented"
671-
override this.Assign (idx: int, Scalar (value: 'a)) : OpenCLEvaluation<unit> = failwith "Not Implemented"
672-
override this.Assign (mask: Mask1D option, Scalar (value: 'a)) : OpenCLEvaluation<unit> = failwith "Not Implemented"
673-
674-
override this.Vxm a b c = failwith "Not Implemented"
675-
override this.EWiseAdd a b c = failwith "Not Implemented"
676-
override this.EWiseMult a b c = failwith "Not Implemented"
677-
override this.Apply a b = failwith "Not Implemented"
678-
override this.Prune a b = failwith "Not Implemented"
679-
override this.Reduce (monoid: Monoid<'a>) = failwith "Not Implemented"

src/GraphBLAS-sharp/Vector.fs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
namespace GraphBLAS.FSharp
22

3-
[<AutoOpen>]
4-
module VectorExtensions =
5-
type Vector<'a when 'a : struct and 'a : equality> with
6-
static member Sparse(denseVector: 'T[], zero: 'T) : Vector<'T> =
7-
failwith "Not Implemented"
3+
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
4+
module Vector =
5+
let build (size: int) (indices: int[]) (values: int[]) : Vector<'a> =
6+
failwith "Not Implemented yet"
87

9-
static member Sparse(length: int, values: (int * 'T) list) : Vector<'T> =
10-
failwith "Not Implemented"
8+
// ambiguous name (tuples = коллекция троек или 3 коллекции)
9+
let ofTuples (size: int) (elements: (int * 'a) list) : Vector<'a> =
10+
failwith "Not Implemented yet"
1111

12-
static member Sparse(length: int, initializer: int -> 'T) : Vector<'T> =
13-
failwith "Not Implemented"
12+
let ofArray (array: 'a[]) (isZero: 'a -> bool) : Vector<'a> =
13+
failwith "Not Implemented yet"
1414

15-
static member ZeroSparse(length: int) : Vector<'T> =
16-
upcast SparseVector(length, Array.zeroCreate<int> 0, Array.zeroCreate<'T> 0)
15+
let init (size: int) (initializer: int -> 'a) : Vector<'a> =
16+
failwith "Not Implemented yet"
1717

18-
static member Dense(denseVector: 'T[], monoid: Monoid<'T>) : Vector<'T> =
19-
upcast DenseVector(denseVector, monoid)
20-
21-
static member Dense(length: int, initializer: int -> 'T, monoid: Monoid<'T>) : Vector<'T> =
22-
upcast DenseVector(Array.init length initializer, monoid)
23-
24-
static member ZeroDense(length: int, monoid: Monoid<'T>) : Vector<'T> =
25-
upcast DenseVector(Array.create length monoid.Zero, monoid)
26-
27-
// [<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
28-
// module Vector =
29-
// let ofArray (denseVector: 'a[]) (zero: 'a) (vectorFormat : VectorBackendFormat) : Vector<'a> =
30-
// failwith "Not Implemented"
18+
let zeroCreate (size: int) : Vector<'a> =
19+
failwith "Not Implemented yet"

tests/GraphBLAS-sharp.Tests/Common.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ type MatrixBackendFormat =
1212

1313
type VectorBackendFormat =
1414
| Sparse
15-
| Dense
1615

1716
type MaskType =
1817
| Regular

0 commit comments

Comments
 (0)