Skip to content

Commit ecb4b79

Browse files
committed
Fix merge 2
1 parent 1cf8c18 commit ecb4b79

8 files changed

Lines changed: 45 additions & 46 deletions

File tree

src/GraphBLAS-sharp/Algorithms/BFS.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module BFS =
1919
let! currentLevelScalar = Scalar.create currentLevel
2020

2121
let! frontierMask = Vector.mask frontier
22-
do! Vector.fillSubVector levels frontierMask currentLevelScalar
22+
do! Vector.fillSubVector levels frontierMask currentLevelScalar // v[q] = d
2323

2424
let! levelsComplemented = Vector.complemented levels
2525
do! Matrix.mxvWithMask AnyAll.bool levelsComplemented transposed frontier // q[!v] = (A' ||.&& q)' = q' ||.&& A -- replace + comp

src/GraphBLAS-sharp/Algorithms/TriangleCounting.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ module TriangleCounting =
1010
let! transposed = matrix' |> Matrix.transpose
1111

1212
let! lowerTriangularMask = lowerTriangular |> Matrix.mask
13-
let! result = (matrix', transposed) ||> Matrix.mxmWithMask AddMult.int lowerTriangularMask
14-
let! count = result |> Matrix.reduce Add.int
15-
16-
return! Scalar.exportValue count
13+
return!
14+
Matrix.mxmWithMask AddMult.int lowerTriangularMask matrix' transposed
15+
>>= Matrix.reduce Add.int
16+
>>= Scalar.exportValue
1717
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ module internal rec Replicate =
3131
do! RunCommand replicate <| fun kernelPrepare ->
3232
let ndRange = _1D(Utils.getDefaultGlobalSize outputArray.Length, Utils.defaultWorkGroupSize)
3333
kernelPrepare ndRange inputArray outputArray
34+
3435
return outputArray
3536
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ open Microsoft.FSharp.Quotations
77
module internal rec Sum =
88
let run (inputArray: 'a[]) (plus: Expr<'a -> 'a -> 'a>) (zero: 'a) =
99
if inputArray.Length = 0 then
10-
opencl { return [|zero|] }
10+
opencl { return [| zero |] }
1111
else
1212
runNotEmpty inputArray plus zero
1313

src/GraphBLAS-sharp/GraphBLAS-sharp.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
<Compile Include="Objects/Masks.fs" />
1818
<Compile Include="Backend/Common/Utils.fs" />
1919
<Compile Include="Backend/Common/Copy.fs" />
20-
<Compile Include="Backend/Common/Replicate.fs" />
2120
<Compile Include="Backend/Common/Sum.fs" />
2221
<Compile Include="Backend/Common/PrefixSum.fs" />
2322
<Compile Include="Backend/Common/BitonicSort.fs" />
23+
<Compile Include="Backend/Common/Replicate.fs" />
2424
<Compile Include="Backend/Common/RemoveDuplicates.fs" />
2525
<Compile Include="Backend/CSRMatrix/Convert.fs" />
2626
<Compile Include="Backend/CSRMatrix/GetTuples.fs" />
@@ -63,4 +63,4 @@
6363
</Content>
6464
</ItemGroup>
6565
<Import Project="..\..\.paket\Paket.Restore.targets" />
66-
</Project>
66+
</Project>

src/GraphBLAS-sharp/Objects/Vector.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ type VectorFormat =
66
type Vector<'a when 'a : struct> =
77
| VectorCOO of COOVector<'a>
88

9+
member this.Size =
10+
match this with
11+
| VectorCOO vector -> vector.Size
12+
913
and COOVector<'a> =
1014
{
1115
mutable Size: int

src/GraphBLAS-sharp/Operations/Scalar.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module Scalar =
2121
match scalar with
2222
| ScalarWrapped scalar -> opencl {
2323
let! _ = ToHost scalar.Value
24-
2524
return ()
2625
}
2726
|> EvalGB.fromCl
@@ -30,13 +29,14 @@ module Scalar =
3029
assignment and extraction
3130
*)
3231

33-
let exportValue (scalar: Scalar<'a>) : GraphblasEvaluation<'a> = graphblas {
34-
do! synchronize scalar
32+
let exportValue (scalar: Scalar<'a>) : GraphblasEvaluation<'a> =
33+
graphblas {
34+
do! synchronize scalar
3535

36-
match scalar with
37-
| ScalarWrapped scalar ->
38-
return scalar.Value.[0]
39-
}
36+
match scalar with
37+
| ScalarWrapped scalar ->
38+
return scalar.Value.[0]
39+
}
4040

4141
let assignValue (scalar: Scalar<'a>) (target: Scalar<'a>) : GraphblasEvaluation<unit> =
4242
failwith "Not Implemented yet"

src/GraphBLAS-sharp/Operations/Vector.fs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,20 @@ module Vector =
112112

113113
/// t.[mask] <- vec
114114
let assignSubVector (target: Vector<'a>) (mask: Mask1D) (source: Vector<'a>) : GraphblasEvaluation<unit> =
115-
match source, target with
116-
| VectorCOO s, VectorCOO t ->
117-
if t.Size <> mask.Size then
118-
invalidArg "mask" <| sprintf "The size of mask must be %A. Received: %A" t.Size mask.Size
119-
120-
if t.Size <> s.Size then
121-
invalidArg "source" <| sprintf "The size of source vector must be %A. Received: %A" t.Size s.Size
122-
123-
if mask.IsComplemented then
124-
failwith "Not Implemented yet"
125-
else
126-
opencl {
127-
let! (resultIndices, resultValues) = COOVector.AssignSubVector.run t.Indices t.Values s.Indices s.Values mask.Indices
128-
t.Indices <- resultIndices
129-
t.Values <- resultValues
130-
}
115+
if target.Size <> mask.Size then
116+
invalidArg "mask" <| sprintf "The size of mask must be %A. Received: %A" target.Size mask.Size
117+
118+
if target.Size <> source.Size then
119+
invalidArg "source" <| sprintf "The size of source vector must be %A. Received: %A" target.Size source.Size
120+
121+
match source, target, mask with
122+
| VectorCOO source, VectorCOO target, mask when not mask.IsComplemented ->
123+
opencl {
124+
let! (resultIndices, resultValues) = COOVector.AssignSubVector.run target.Indices target.Values source.Indices source.Values mask.Indices
125+
target.Indices <- resultIndices
126+
target.Values <- resultValues
127+
}
128+
| _ -> failwith "Not Implemented"
131129
|> EvalGB.fromCl
132130

133131
/// t.[idx] <- value
@@ -140,16 +138,14 @@ module Vector =
140138

141139
/// vec.[mask] <- value
142140
let fillSubVector (vector: Vector<'a>) (mask: Mask1D) (value: Scalar<'a>) : GraphblasEvaluation<unit> =
143-
match vector, value with
144-
| VectorCOO vector, ScalarWrapped scalar ->
145-
if mask.IsComplemented then
146-
failwith "Not Implemented yet"
147-
else
148-
opencl {
149-
let! (resultIndices, resultValues) = COOVector.FillSubVector.run vector.Indices vector.Values mask.Indices scalar.Value
150-
vector.Indices <- resultIndices
151-
vector.Values <- resultValues
152-
}
141+
match vector, value, mask with
142+
| VectorCOO vector, ScalarWrapped scalar, mask when not mask.IsComplemented ->
143+
opencl {
144+
let! (resultIndices, resultValues) = COOVector.FillSubVector.run vector.Indices vector.Values mask.Indices scalar.Value
145+
vector.Indices <- resultIndices
146+
vector.Values <- resultValues
147+
}
148+
| _ -> failwith "Not Implemented"
153149
|> EvalGB.fromCl
154150

155151
(*
@@ -162,14 +158,12 @@ module Vector =
162158
let select (predicate: UnaryOp<'a, bool>) (vector: Vector<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
163159

164160
let reduce (monoid: IMonoid<'a>) (vector: Vector<'a>) : GraphblasEvaluation<Scalar<'a>> =
161+
let (ClosedBinaryOp plus) = monoid.Plus
162+
165163
match vector with
166164
| VectorCOO vector ->
167165
opencl {
168-
let! result = opencl {
169-
let (ClosedBinaryOp plus) = monoid.Plus
170-
return! Sum.run vector.Values plus monoid.Zero
171-
}
172-
166+
let! result = Sum.run vector.Values plus monoid.Zero
173167
return ScalarWrapped { Value = result }
174168
}
175169
|> EvalGB.fromCl

0 commit comments

Comments
 (0)