Skip to content

Commit b91a7a0

Browse files
committed
Merged branch dev from upstream repository
2 parents 10492e5 + e5c9ed5 commit b91a7a0

14 files changed

Lines changed: 227 additions & 157 deletions

File tree

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
<Authors>YaccConstructor</Authors>
1010
<RepositoryUrl>https://github.com/YaccConstructor/GraphBLAS-sharp</RepositoryUrl>
1111
<!-- owners is not supported in MSBuild -->
12+
<DisableFody>true</DisableFody>
1213
</PropertyGroup>
1314
</Project>

paket.dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ nuget System.CodeDom 4.7.0
1818
nuget FSharp.Quotations.Evaluator 2.1.0
1919
nuget FSharpx.Collections 2.1.3
2020
nuget FSharpx.Text.StructuredFormat 2.3.0
21-
nuget Brahma.FSharp.OpenCL.WorkflowBuilder
21+
nuget Brahma.FSharp.OpenCL.WorkflowBuilder 2.0.0-alpha4
2222
nuget BenchmarkDotNet
2323
nuget MathNet.Numerics.FSharp
2424

src/GraphBLAS-sharp/Abstracts.fs

Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
namespace GraphBLAS.FSharp
22

3+
<<<<<<< HEAD
34
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
5+
=======
6+
>>>>>>> e5c9ed5c70dc7da1eda621582663215739e51536
47
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
58

69
[<AbstractClass>]
@@ -10,6 +13,7 @@ type Matrix<'a when 'a : struct and 'a : equality>(nrow: int, ncol: int) =
1013
default this.RowCount = nrow
1114
default this.ColumnCount = ncol
1215

16+
<<<<<<< HEAD
1317
abstract Mask: Mask2D option
1418
abstract Complemented: Mask2D option
1519

@@ -30,57 +34,109 @@ type Matrix<'a when 'a : struct and 'a : equality>(nrow: int, ncol: int) =
3034
abstract ReduceOut: Mask1D option -> Monoid<'a> -> Vector<'a>
3135
abstract Reduce: Monoid<'a> -> Scalar<'a>
3236
abstract T: Matrix<'a>
37+
=======
38+
abstract Clear: unit -> OpenCLEvaluation<unit>
39+
abstract Copy: unit -> OpenCLEvaluation<Matrix<'a>>
40+
abstract Resize: int -> int -> OpenCLEvaluation<Matrix<'a>>
41+
abstract GetNNZ: unit -> OpenCLEvaluation<int>
42+
abstract GetTuples: unit -> OpenCLEvaluation<{| Rows: int[]; Columns: int[]; Values: 'a[] |}>
43+
abstract GetMask: ?isComplemented: bool -> OpenCLEvaluation<Mask2D option>
44+
45+
abstract Extract: Mask2D option -> OpenCLEvaluation<Matrix<'a>>
46+
abstract Extract: (Mask1D option * int) -> OpenCLEvaluation<Vector<'a>>
47+
abstract Extract: (int * Mask1D option) -> OpenCLEvaluation<Vector<'a>>
48+
abstract Extract: (int * int) -> OpenCLEvaluation<Scalar<'a>>
49+
abstract Assign: Mask2D option * Matrix<'a> -> OpenCLEvaluation<unit>
50+
abstract Assign: (Mask1D option * int) * Vector<'a> -> OpenCLEvaluation<unit>
51+
abstract Assign: (int * Mask1D option) * Vector<'a> -> OpenCLEvaluation<unit>
52+
abstract Assign: (int * int) * Scalar<'a> -> OpenCLEvaluation<unit>
53+
abstract Assign: Mask2D option * Scalar<'a> -> OpenCLEvaluation<unit>
54+
abstract Assign: (Mask1D option * int) * Scalar<'a> -> OpenCLEvaluation<unit>
55+
abstract Assign: (int * Mask1D option) * Scalar<'a> -> OpenCLEvaluation<unit>
56+
57+
abstract Mxm: Matrix<'a> -> Mask2D option -> Semiring<'a> -> OpenCLEvaluation<Matrix<'a>>
58+
abstract Mxv: Vector<'a> -> Mask1D option -> Semiring<'a> -> OpenCLEvaluation<Vector<'a>>
59+
abstract EWiseAdd: Matrix<'a> -> Mask2D option -> Semiring<'a> -> OpenCLEvaluation<Matrix<'a>>
60+
abstract EWiseMult: Matrix<'a> -> Mask2D option -> Semiring<'a> -> OpenCLEvaluation<Matrix<'a>>
61+
abstract Apply: Mask2D option -> UnaryOp<'a, 'b> -> OpenCLEvaluation<Matrix<'b>>
62+
abstract Prune: Mask2D option -> UnaryOp<'a, bool> -> OpenCLEvaluation<Matrix<'a>>
63+
abstract ReduceIn: Mask1D option -> Monoid<'a> -> OpenCLEvaluation<Vector<'a>>
64+
abstract ReduceOut: Mask1D option -> Monoid<'a> -> OpenCLEvaluation<Vector<'a>>
65+
abstract Reduce: Monoid<'a> -> OpenCLEvaluation<Scalar<'a>>
66+
abstract Transpose: unit -> OpenCLEvaluation<Matrix<'a>>
67+
abstract Kronecker: Matrix<'a> -> Mask2D option -> Semiring<'a> -> OpenCLEvaluation<Matrix<'a>>
68+
>>>>>>> e5c9ed5c70dc7da1eda621582663215739e51536
3369

3470
static member inline (+) (x: Matrix<'a>, y: Matrix<'a>) = x.EWiseAdd y
3571
static member inline (*) (x: Matrix<'a>, y: Matrix<'a>) = x.EWiseMult y
3672
static member inline (@.) (x: Matrix<'a>, y: Matrix<'a>) = x.Mxm y
3773
static member inline (@.) (x: Matrix<'a>, y: Vector<'a>) = x.Mxv y
3874

39-
and [<AbstractClass>] Vector<'a when 'a : struct and 'a : equality>(length: int) =
40-
abstract Length: int
41-
default this.Length = length
4275

43-
abstract AsArray: 'a[]
44-
abstract Clear: unit -> unit
76+
and [<AbstractClass>] Vector<'a when 'a : struct and 'a : equality>(size: int) =
77+
abstract Size: int
78+
default this.Size = size
4579

46-
abstract Mask: Mask1D option
47-
abstract Complemented: Mask1D option
80+
abstract Clear: unit -> OpenCLEvaluation<unit>
81+
abstract Copy: unit -> OpenCLEvaluation<Vector<'a>>
82+
abstract Resize: int -> OpenCLEvaluation<Vector<'a>>
83+
abstract GetNNZ: unit -> OpenCLEvaluation<int>
84+
abstract GetTuples: unit -> OpenCLEvaluation<{| Indices: int[]; Values: 'a[] |}>
85+
abstract GetMask: ?isComplemented: bool -> OpenCLEvaluation<Mask1D option>
4886

49-
abstract Item: Mask1D option -> Vector<'a> with get, set
50-
abstract Item: int -> Scalar<'a> with get, set
51-
abstract Fill: Mask1D option -> Scalar<'a> with set
87+
abstract Extract: Mask1D option -> OpenCLEvaluation<Vector<'a>>
88+
abstract Extract: int -> OpenCLEvaluation<Scalar<'a>>
89+
abstract Assign: Mask1D option * Vector<'a> -> OpenCLEvaluation<unit>
90+
abstract Assign: int * Scalar<'a> -> OpenCLEvaluation<unit>
91+
abstract Assign: Mask1D option * Scalar<'a> -> OpenCLEvaluation<unit>
5292

93+
<<<<<<< HEAD
5394
abstract Vxm: Matrix<'a> -> Mask1D option -> Semiring<'a> -> Vector<'a>
5495
abstract EWiseAdd: Vector<'a> -> Mask1D option -> Semiring<'a> -> Vector<'a>
5596
abstract EWiseMult: Vector<'a> -> Mask1D option -> Semiring<'a> -> Vector<'a>
5697
abstract Apply: Mask1D option -> UnaryOp<'a, 'b> -> Vector<'b>
5798
abstract Reduce: Monoid<'a> -> Scalar<'a>
99+
=======
100+
abstract Vxm: Matrix<'a> -> Mask1D option -> Semiring<'a> -> OpenCLEvaluation<Vector<'a>>
101+
abstract EWiseAdd: Vector<'a> -> Mask1D option -> Semiring<'a> -> OpenCLEvaluation<Vector<'a>>
102+
abstract EWiseMult: Vector<'a> -> Mask1D option -> Semiring<'a> -> OpenCLEvaluation<Vector<'a>>
103+
abstract Apply: Mask1D option -> UnaryOp<'a, 'b> -> OpenCLEvaluation<Vector<'b>>
104+
abstract Prune: Mask1D option -> UnaryOp<'a, bool> -> OpenCLEvaluation<Vector<'a>>
105+
abstract Reduce: Monoid<'a> -> OpenCLEvaluation<Scalar<'a>>
106+
>>>>>>> e5c9ed5c70dc7da1eda621582663215739e51536
58107

59108
static member inline (+) (x: Vector<'a>, y: Vector<'a>) = x.EWiseAdd y
60109
static member inline (*) (x: Vector<'a>, y: Vector<'a>) = x.EWiseMult y
61110
static member inline (@.) (x: Vector<'a>, y: Matrix<'a>) = x.Vxm y
62111

63-
and Mask1D(indices: int[], length: int, isComplemented: bool) =
112+
113+
and Mask1D(indices: int[], size: int, isComplemented: bool) =
64114
member this.Indices = indices
65-
member this.Length = length
115+
member this.Size = size
66116
member this.IsComplemented = isComplemented
67117

118+
<<<<<<< HEAD
68119
member this.Item
69120
with get (idx: int) : bool =
70121
this.Indices
71122
|> Array.contains idx
72123
|> (<>) this.IsComplemented
124+
=======
125+
>>>>>>> e5c9ed5c70dc7da1eda621582663215739e51536
73126

74-
and Mask2D(indices: (int * int)[], rowCount: int, columnCount: int, isComplemented: bool) =
75-
member this.Rows = indices |> Array.unzip |> fst
76-
member this.Columns = indices |> Array.unzip |> snd
127+
and Mask2D(rowIndices: int[], columnIndices: int[], rowCount: int, columnCount: int, isComplemented: bool) =
128+
member this.RowIndices = rowIndices
129+
member this.ColumnIndices = columnIndices
77130
member this.RowCount = rowCount
78131
member this.ColumnCount = columnCount
79132
member this.IsComplemented = isComplemented
133+
<<<<<<< HEAD
80134

81135
member this.Item
82136
with get (rowIdx: int, colIdx: int) : bool =
83137
(this.Rows, this.Columns)
84138
||> Array.zip
85139
|> Array.contains (rowIdx, colIdx)
86140
|> (<>) this.IsComplemented
141+
=======
142+
>>>>>>> e5c9ed5c70dc7da1eda621582663215739e51536

src/GraphBLAS-sharp/Algorithms/BFS.fs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@ namespace GraphBLAS.FSharp.Algorithms
33
open GraphBLAS.FSharp.Predefined
44
open GraphBLAS.FSharp.Helpers
55
open GraphBLAS.FSharp
6+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
7+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
68

79
[<AutoOpen>]
810
module BFS =
9-
let levelBFS (matrix: Matrix<bool>) (source: int) : Vector<int> =
11+
let levelBFS (matrix: Matrix<bool>) (source: int) : OpenCLEvaluation<Vector<int>> =
1012
let vertexCount = matrix.RowCount
11-
let levels = DenseVector(Array.zeroCreate vertexCount, IntegerMonoid.add)
12-
13-
let frontier = SparseVector(vertexCount, [source, true])
14-
15-
let mutable currentLevel = 1
16-
while !> (frontier.Reduce BooleanMonoid.any) && currentLevel < vertexCount do
17-
levels.Fill(frontier.Mask) <- Scalar currentLevel
18-
frontier.Clear()
19-
frontier.[levels.Complemented] <- (frontier @. matrix) levels.Complemented BooleanSemiring.anyAll
20-
currentLevel <- currentLevel + 1
21-
22-
upcast levels
13+
let levels = Vector.Dense(Array.zeroCreate vertexCount, IntegerMonoid.add)
14+
let frontier = Vector.Sparse(vertexCount, [source, true])
15+
16+
opencl {
17+
let mutable currentLevel = 1
18+
while currentLevel < vertexCount do
19+
let! frontierMask = frontier.GetMask()
20+
do! levels.Assign(frontierMask, Scalar currentLevel)
21+
let! levelsComplemented = levels.GetMask(isComplemented = true)
22+
let! frontier = (frontier @. matrix) levelsComplemented BooleanSemiring.anyAll
23+
currentLevel <- currentLevel + 1
24+
25+
return levels
26+
}
2327

2428
// let parentBFS (matrix: Matrix<bool>) (source: int) : Vector<int> =
2529
// let vertexCount = matrix.RowCount

src/GraphBLAS-sharp/Algorithms/SSSP.fs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ namespace GraphBLAS.FSharp.Algorithms
22

33
open GraphBLAS.FSharp.Predefined
44
open GraphBLAS.FSharp
5+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
6+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
57

68
[<AutoOpen>]
79
module SSSP =
8-
let SSSP (matrix: Matrix<float>) (source: int) : Vector<float> =
10+
let SSSP (matrix: Matrix<float>) (source: int) : OpenCLEvaluation<Vector<float>> =
911
let vertexCount = matrix.RowCount
10-
let distance = SparseVector(vertexCount, [source, 0.])
12+
let distance = Vector.Sparse(vertexCount, [source, 0.])
1113

12-
for _ in 1 .. vertexCount - 1 do
13-
distance.[None] <- (distance @. matrix) None FloatSemiring.minAdd
14+
opencl {
15+
for _ in 1 .. vertexCount - 1 do
16+
let! step = (distance @. matrix) None FloatSemiring.minAdd
17+
do! distance.Assign(None, step)
1418

15-
upcast distance
19+
return distance
20+
}

src/GraphBLAS-sharp/Algorithms/TriangleCounting.fs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ namespace GraphBLAS.FSharp.Algorithms
22

33
open GraphBLAS.FSharp.Predefined
44
open GraphBLAS.FSharp
5+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
6+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
57

68
[<AutoOpen>]
79
module TriangleCounting =
8-
let sandiaTriangleCount (lowerTriangular: Matrix<bool>) =
10+
// скорее всего, тут не скаляр возвращать нужно, а инт
11+
let sandiaTriangleCount (lowerTriangular: Matrix<bool>) : OpenCLEvaluation<Scalar<int>> =
912
let bool2int = function
1013
| true -> 1
1114
| false -> 0
12-
let convertedMatrix = lowerTriangular.Apply None (UnaryOp <@ bool2int @>)
13-
let result = (convertedMatrix @. convertedMatrix.T) lowerTriangular.Mask IntegerSemiring.addMult
14-
result.Reduce IntegerMonoid.add
15+
16+
opencl {
17+
let! convertedMatrix = lowerTriangular.Apply None (UnaryOp <@ bool2int @>)
18+
let! convertedTransposed = convertedMatrix.Transpose()
19+
let! lowerTriangularMask = lowerTriangular.GetMask()
20+
let! result = (convertedMatrix @. convertedTransposed) lowerTriangularMask IntegerSemiring.addMult
21+
return! result.Reduce IntegerMonoid.add
22+
}

src/GraphBLAS-sharp/FodyWeavers.xml

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/GraphBLAS-sharp/FodyWeavers.xsd

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)