Skip to content

Commit b29f5b2

Browse files
committed
Add sync functions for tuples
1 parent f5e8e28 commit b29f5b2

8 files changed

Lines changed: 34 additions & 31 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) : GraphblasEvaluation<Vector<int>> =
1212
let vertexCount = Matrix.rowCount matrix
13-
let levels = Vector.ofArray <| Array.zeroCreate vertexCount <| (=) 0
14-
let frontier = Vector.ofTuples vertexCount [source, true]
13+
let levels = Vector.ofArray <| (=) 0 <| Array.zeroCreate vertexCount
14+
let frontier = Vector.ofList vertexCount [source, true]
1515

1616
graphblas {
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) : GraphblasEvaluation<Vector<float>> =
1111
let vertexCount = Matrix.rowCount matrix
12-
let distance = Vector.ofTuples vertexCount [source, 0.]
12+
let distance = Vector.ofList vertexCount [source, 0.]
1313

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

src/GraphBLAS-sharp/GraphblasEvaluation.fs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ module EvalGB =
2424
let x = run env reader
2525
run env (f x)
2626

27-
let ret x =
27+
let return' x =
2828
EvalGB <| fun _ -> x
2929

30-
// EvalGB.liftCl x === liftM EvalGB x
31-
let liftCl clEvaluation =
30+
let fromCl clEvaluation =
3231
EvalGB <| fun env ->
3332
runCl env.ClContext clEvaluation
3433

@@ -37,11 +36,11 @@ module EvalGB =
3736

3837
type GraphblasBuilder() =
3938
member this.Bind(x, f) = EvalGB.bind f x
40-
member this.Return x = EvalGB.ret x
39+
member this.Return x = EvalGB.return' x
4140
member this.ReturnFrom x = x
4241

4342
member this.Zero() =
44-
EvalGB.ret ()
43+
EvalGB.return' ()
4544

4645
member this.Combine(m1, m2) =
4746
EvalGB <| fun env ->

src/GraphBLAS-sharp/Methods/Matrix.fs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ type MatrixTuples<'a> =
1111
Values: 'a[]
1212
}
1313

14-
member this.ToHost() =
14+
// ждём тайпклассов чтобы можно было вызывать synchronize для всех объектов,
15+
// для которых он реализован, не привязывая реализацию к классу (как стратегия)
16+
module MatrixTuples =
17+
let synchronize (matrixTuples: MatrixTuples<'a>) =
1518
opencl {
16-
let! _ = ToHost this.RowIndices
17-
let! _ = ToHost this.ColumnIndices
18-
let! _ = ToHost this.Values
19-
20-
return this
19+
let! _ = ToHost matrixTuples.RowIndices
20+
let! _ = ToHost matrixTuples.ColumnIndices
21+
let! _ = ToHost matrixTuples.Values
22+
return ()
2123
}
24+
|> EvalGB.fromCl
2225

2326
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
2427
module Matrix =
@@ -30,7 +33,7 @@ module Matrix =
3033
let build (rowCount: int) (columnCount: int) (rows: int[]) (columns: int[]) (values: 'a[]) : Matrix<'a> =
3134
failwith "Not Implemented yet"
3235

33-
let ofArray2D (array: 'a[,]) (isZero: 'a -> bool) : Matrix<'a> =
36+
let ofArray2D (isZero: 'a -> bool) (array: 'a[,]) : Matrix<'a> =
3437
failwith "Not Implemented yet"
3538

3639
let fromFile (pathToMatrix: string) : Matrix<'a> =
@@ -55,7 +58,7 @@ module Matrix =
5558
let tuples (matrix: Matrix<'a>) : GraphblasEvaluation<MatrixTuples<'a>> = failwith "Not Implemented yet"
5659
let mask (matrix: Matrix<'a>) : GraphblasEvaluation<Mask2D option> = failwith "Not Implemented yet"
5760
let complemented (matrix: Matrix<'a>) : GraphblasEvaluation<Mask2D option> = failwith "Not Implemented yet"
58-
// let finish \ eval \ toHost
61+
let synchronize (matrix: Matrix<'a>) : GraphblasEvaluation<unit> = failwith "Not Implemented yet"
5962

6063
(*
6164
assignment, extraction and filling
@@ -90,7 +93,7 @@ module Matrix =
9093
}
9194
| _ -> failwith "Not Implemented"
9295

93-
graphblas { return! EvalGB.liftCl operationResult }
96+
graphblas { return! EvalGB.fromCl operationResult }
9497

9598
let eWiseMult (semiring: ISemiring<'a>) (mask: Mask2D option) (leftMatrix: Matrix<'a>) (rightMatrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'a>> = failwith "Not Implemented yet"
9699
let apply (mapper: UnaryOp<'a, 'b>) (mask: Mask2D option) (matrix: Matrix<'a>) : GraphblasEvaluation<Matrix<'b>> = failwith "Not Implemented yet"

src/GraphBLAS-sharp/Methods/Vector.fs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ type VectorTuples<'a> =
1010
Values: 'a[]
1111
}
1212

13-
member this.ToHost() =
13+
module VectorTuples =
14+
let synchronize (vectorTuples: VectorTuples<'a>) =
1415
opencl {
15-
let! _ = ToHost this.Indices
16-
let! _ = ToHost this.Values
17-
18-
return this
16+
let! _ = ToHost vectorTuples.Indices
17+
let! _ = ToHost vectorTuples.Values
18+
return ()
1919
}
20+
|> EvalGB.fromCl
2021

2122
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
2223
module Vector =
@@ -28,20 +29,19 @@ module Vector =
2829
let build (size: int) (indices: int[]) (values: int[]) : Vector<'a> =
2930
failwith "Not Implemented yet"
3031

31-
// ambiguous name (tuples = коллекция троек или 3 коллекции)
32-
let ofTuples (size: int) (elements: (int * 'a) list) : Vector<'a> =
32+
let ofList (size: int) (elements: (int * 'a) list) : Vector<'a> =
3333
failwith "Not Implemented yet"
3434

35-
let ofArray (array: 'a[]) (isZero: 'a -> bool) : Vector<'a> =
35+
let ofArray (isZero: 'a -> bool) (array: 'a[]) : Vector<'a> =
3636
failwith "Not Implemented yet"
3737

3838
let init (size: int) (initializer: int -> 'a) : Vector<'a> =
3939
failwith "Not Implemented yet"
4040

41+
// обоснован ли этот метод или можно просто create x использовать
4142
let zeroCreate (size: int) : Vector<'a> =
4243
failwith "Not Implemented yet"
4344

44-
4545
(*
4646
methods
4747
*)
@@ -52,9 +52,10 @@ module Vector =
5252
let resize (size: int) (vector: Vector<'a>) : GraphblasEvaluation<Vector<'a>> = failwith "Not Implemented yet"
5353
let nnz (vector: Vector<'a>) : GraphblasEvaluation<int> = failwith "Not Implemented yet"
5454
let tuples (vector: Vector<'a>) : GraphblasEvaluation<VectorTuples<'a>> = failwith "Not Implemented yet"
55+
// возвращается option, чтобы потом можно было бы сразу передавать её в методы (тк они option принимают)
5556
let mask (vector: Vector<'a>) : GraphblasEvaluation<Mask1D option> = failwith "Not Implemented yet"
5657
let complemented (vector: Vector<'a>) : GraphblasEvaluation<Mask1D option> = failwith "Not Implemented yet"
57-
// let finish \ eval \ toHost
58+
let synchronize (vector: Vector<'a>) : GraphblasEvaluation<unit> = failwith "Not Implemented yet"
5859

5960
(*
6061
assignment, extraction and filling

src/GraphBLAS-sharp/Predefined/Monoids/Add.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module Add =
1717

1818
let float32 =
1919
{ new IMonoid<float32> with
20-
member this.Zero = 0f
20+
member this.Zero = 0.f
2121
member this.Plus = ClosedBinaryOp <@ (+) @>
2222
}
2323

tests/GraphBLAS-sharp.Tests/OperationsTests/EWiseAddTests.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ let checkCorrectnessGeneric<'a when 'a : struct and 'a : equality>
147147
graphblas {
148148
let! result = Matrix.eWiseAdd semiring None left right
149149
let! tuples = Matrix.tuples result
150-
return! EvalGB.liftCl <| tuples.ToHost()
150+
do! MatrixTuples.synchronize tuples
151+
return tuples
151152
}
152153
|> EvalGB.runWithClContext oclContext
153154

tests/GraphBLAS-sharp.Tests/Program.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ let allTests =
66
testList "All tests" [
77
EWiseAdd.tests
88
]
9+
|> testSequenced
910

10-
// sequenced test?
1111
[<EntryPoint>]
1212
let main argv =
1313
allTests
14-
|> testSequenced
1514
|> runTestsWithCLIArgs [] argv

0 commit comments

Comments
 (0)