Skip to content

Commit 29ef704

Browse files
committed
Update usage according to the modified interface. Change masks
1 parent 65f2d22 commit 29ef704

9 files changed

Lines changed: 95 additions & 120 deletions

File tree

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

paket.lock

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,34 @@ NUGET
2222
System.Threading.Tasks.Extensions (>= 4.5.2) - restriction: >= netstandard2.0
2323
System.ValueTuple (>= 4.5) - restriction: >= netstandard2.0
2424
BenchmarkDotNet.Annotations (0.12.1) - restriction: >= netstandard2.0
25-
Brahma.FSharp (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
26-
Brahma.FSharp.OpenCL.Printer (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
27-
Brahma.FSharp.OpenCL.Translator (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
25+
Brahma.FSharp (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
26+
Brahma.FSharp.OpenCL.Printer (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
27+
Brahma.FSharp.OpenCL.Translator (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
2828
FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netstandard2.1)
2929
FSharp.Quotations.Evaluator (>= 2.1) - restriction: || (>= net461) (>= netstandard2.1)
30-
YC.Brahma (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
31-
YC.Brahma.OpenCL (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
32-
YC.OpenCL.NET (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
33-
Brahma.FSharp.OpenCL.AST (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
30+
YC.Brahma (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
31+
YC.Brahma.OpenCL (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
32+
YC.OpenCL.NET (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
33+
Brahma.FSharp.OpenCL.AST (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
3434
FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netstandard2.1)
35-
Brahma.FSharp.OpenCL.Extensions (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
35+
Brahma.FSharp.OpenCL.Extensions (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
3636
FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netstandard2.1)
37-
YC.Brahma.OpenCL (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
38-
YC.OpenCL.NET (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
39-
Brahma.FSharp.OpenCL.Printer (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
40-
Brahma.FSharp.OpenCL.AST (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
41-
Brahma.FSharp.OpenCL.Translator (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
37+
YC.Brahma.OpenCL (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
38+
YC.OpenCL.NET (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
39+
Brahma.FSharp.OpenCL.Printer (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
40+
Brahma.FSharp.OpenCL.AST (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
41+
Brahma.FSharp.OpenCL.Translator (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
4242
FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netstandard2.1)
4343
FSharpx.Collections (>= 2.1.3) - restriction: || (>= net461) (>= netstandard2.1)
4444
FSharpx.Text.StructuredFormat (>= 2.3) - restriction: || (>= net461) (>= netstandard2.1)
45-
Brahma.FSharp.OpenCL.Translator (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
46-
Brahma.FSharp.OpenCL.AST (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
47-
Brahma.FSharp.OpenCL.Extensions (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
45+
Brahma.FSharp.OpenCL.Translator (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
46+
Brahma.FSharp.OpenCL.AST (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
47+
Brahma.FSharp.OpenCL.Extensions (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
4848
FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netstandard2.1)
4949
FSharpx.Collections (>= 2.1.3) - restriction: || (>= net461) (>= netstandard2.1)
50-
Brahma.FSharp.OpenCL.WorkflowBuilder (2.0.0-alpha3)
51-
Brahma.FSharp (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
52-
Brahma.FSharp.OpenCL.Extensions (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
50+
Brahma.FSharp.OpenCL.WorkflowBuilder (2.0.0-alpha4)
51+
Brahma.FSharp (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
52+
Brahma.FSharp.OpenCL.Extensions (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
5353
FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netstandard2.1)
5454
Chessie (0.6) - restriction: >= netcoreapp1.0
5555
FSharp.Core (>= 4.0.1.7-alpha) - restriction: >= netstandard1.6
@@ -521,7 +521,6 @@ NUGET
521521
System.Runtime.InteropServices (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (>= netstandard1.1) (< netstandard2.0) (< win8) (< wpa81) (< xamarintvos) (< xamarinwatchos)
522522
System.Net.Http (4.3.4) - restriction: || (&& (< net45) (>= net46) (< netstandard1.4) (>= netstandard1.6)) (&& (< net45) (< netstandard1.2) (>= netstandard1.6) (< win8)) (&& (< net45) (< netstandard1.3) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (< netstandard1.4) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (< netstandard1.5) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (>= netstandard1.6) (< netstandard2.0) (< win8) (< wpa81)) (&& (>= netcoreapp5.0) (< netstandard2.0)) (&& (< netstandard1.5) (>= netstandard1.6) (>= uap10.0))
523523
Microsoft.NETCore.Platforms (>= 1.1.1) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (>= netcoreapp5.0)
524-
Microsoft.Win32.Primitives (>= 4.3) - restriction: && (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)
525524
runtime.native.System (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (< netcoreapp5.0) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
526525
runtime.native.System.Net.Http (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (< netcoreapp5.0) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
527526
runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3.2) - restriction: && (< monoandroid) (< monotouch) (< net45) (< netcoreapp5.0) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
@@ -532,7 +531,6 @@ NUGET
532531
System.Globalization (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (>= netcoreapp5.0)
533532
System.Globalization.Extensions (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (< netcoreapp5.0) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
534533
System.IO (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.1) (< netstandard1.3) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (>= netcoreapp5.0)
535-
System.IO.Compression (>= 4.3) - restriction: && (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)
536534
System.IO.FileSystem (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (< netcoreapp5.0) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
537535
System.Net.Primitives (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.1) (< netstandard1.3) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (>= netcoreapp5.0)
538536
System.Resources.ResourceManager (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (>= netcoreapp5.0)
@@ -921,11 +919,11 @@ NUGET
921919
System.Threading (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.3) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (>= netcoreapp5.0)
922920
System.Xml.ReaderWriter (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.3) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.3) (< win8) (< wp8) (< wpa81)) (>= netcoreapp5.0)
923921
System.Xml.XmlDocument (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.3) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (>= netcoreapp5.0)
924-
YC.Brahma (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
925-
YC.Brahma.OpenCL (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
926-
YC.Brahma (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
927-
YC.OpenCL.NET (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
928-
YC.OpenCL.NET (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
922+
YC.Brahma (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
923+
YC.Brahma.OpenCL (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
924+
YC.Brahma (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
925+
YC.OpenCL.NET (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
926+
YC.OpenCL.NET (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
929927
ExtraConstraints.Fody (>= 1.14) - restriction: >= netstandard2.0
930928
Microsoft.Build.Framework (>= 16.6) - restriction: >= netstandard2.0
931929
System.CodeDom (>= 4.7) - restriction: >= netstandard2.0

src/GraphBLAS-sharp/Abstracts.fs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
2828
2929
метод Prune можно переименовать в Select или Filter
3030
31-
нужно выяснить, как Partitial Aplication методы интеропятся с C#
31+
нужно выяснить, как curried методы интеропятся с C#
3232
33-
возможно, стоит отказаться от перегрузок Extract и Assign, чтобы сделать их PA,
33+
возможно, стоит отказаться от перегрузок Extract и Assign, чтобы сделать их curried,
3434
тем самым, избавившись от скобок при вызове
3535
36-
можно все методы сделать как методы C# (без PA), а рядом положить модуль с PA функциями
36+
можно все методы сделать как методы C# (без curried), а рядом положить модуль с curried функциями
3737
это нужно, для более гибкого интерфейся и лучшего интеропа с C#
38+
39+
пара массивов лучше ложиться на opencl чем массив пар. Поэтому изменились аргументы Mask1D
40+
стоит это учесть и в дугих местах. Например разреженный вектор должен принимать пару массивов вместо массива пар
3841
*)
3942

4043
[<AbstractClass>]
@@ -49,7 +52,7 @@ type Matrix<'a when 'a : struct and 'a : equality>(nrow: int, ncol: int) =
4952
abstract Resize: int -> int -> OpenCLEvaluation<Matrix<'a>>
5053
abstract GetNNZ: unit -> OpenCLEvaluation<int>
5154
abstract GetTuples: unit -> OpenCLEvaluation<{| Rows: int[]; Columns: int[]; Values: 'a[] |}>
52-
abstract GetMask: bool -> OpenCLEvaluation<Mask2D option>
55+
abstract GetMask: ?isComplemented: bool -> OpenCLEvaluation<Mask2D option>
5356

5457
abstract Extract: Mask2D option -> OpenCLEvaluation<Matrix<'a>>
5558
abstract Extract: (Mask1D option * int) -> OpenCLEvaluation<Vector<'a>>
@@ -90,7 +93,7 @@ and [<AbstractClass>] Vector<'a when 'a : struct and 'a : equality>(size: int) =
9093
abstract Resize: int -> OpenCLEvaluation<Vector<'a>>
9194
abstract GetNNZ: unit -> OpenCLEvaluation<int>
9295
abstract GetTuples: unit -> OpenCLEvaluation<{| Indices: int[]; Values: 'a[] |}>
93-
abstract GetMask: bool -> OpenCLEvaluation<Mask1D option>
96+
abstract GetMask: ?isComplemented: bool -> OpenCLEvaluation<Mask1D option>
9497

9598
abstract Extract: Mask1D option -> OpenCLEvaluation<Vector<'a>>
9699
abstract Extract: int -> OpenCLEvaluation<Scalar<'a>>
@@ -110,28 +113,15 @@ and [<AbstractClass>] Vector<'a when 'a : struct and 'a : equality>(size: int) =
110113
static member inline (@.) (x: Vector<'a>, y: Matrix<'a>) = x.Vxm y
111114

112115

113-
and Mask1D(indices: int[], length: int, isComplemented: bool) =
116+
and Mask1D(indices: int[], size: int, isComplemented: bool) =
114117
member this.Indices = indices
115-
member this.Length = length
118+
member this.Size = size
116119
member this.IsComplemented = isComplemented
117120

118-
member this.Item
119-
with get (idx: int) : bool =
120-
this.Indices
121-
|> Array.contains idx
122-
|> (<>) this.IsComplemented
123-
124121

125-
and Mask2D(indices: (int * int)[], rowCount: int, columnCount: int, isComplemented: bool) =
126-
member this.Rows = indices |> Array.unzip |> fst
127-
member this.Columns = indices |> Array.unzip |> snd
122+
and Mask2D(rowIndices: int[], columnIndices: int[], rowCount: int, columnCount: int, isComplemented: bool) =
123+
member this.RowIndices = rowIndices
124+
member this.ColumnIndices = columnIndices
128125
member this.RowCount = rowCount
129126
member this.ColumnCount = columnCount
130127
member this.IsComplemented = isComplemented
131-
132-
member this.Item
133-
with get (rowIdx: int, colIdx: int) : bool =
134-
(this.Rows, this.Columns)
135-
||> Array.zip
136-
|> Array.contains (rowIdx, colIdx)
137-
|> (<>) this.IsComplemented

src/GraphBLAS-sharp/Algorithms/BFS.fs

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,66 +6,24 @@ open GraphBLAS.FSharp
66
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
77
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
88

9-
[<AutoOpen>]
10-
module Ext =
11-
type OpenCLEvaluationBuilder with
12-
member this.While(guard, body) =
13-
if not <| guard ()
14-
then this.Zero()
15-
else this.Bind(body, fun () -> this.While(guard, body))
16-
17-
member this.Delay(f) = f ()
18-
19-
member this.Zero() = this.Return()
20-
21-
member this.Combine(a, b) = this.Bind(a, fun () -> b)
22-
239
[<AutoOpen>]
2410
module BFS =
2511
let levelBFS (matrix: Matrix<bool>) (source: int) : OpenCLEvaluation<Vector<int>> =
2612
let vertexCount = matrix.RowCount
2713
let levels = Vector.Dense(Array.zeroCreate vertexCount, IntegerMonoid.add)
28-
2914
let frontier = Vector.Sparse(vertexCount, [source, true])
30-
let mutable currentLevel = 1
31-
32-
// let inline ($) (a: Mask1D option -> 'a) (b: Mask1D option) = a <| b
33-
let inline (?<-) (a: Vector<'a>) (b: Mask1D option) (c: Scalar<'a>) = a.Assign(b, c)
34-
let inline (<@@>) (a: Vector<'a>) (b: Mask1D option) (c: Scalar<'a>) = ()
35-
36-
37-
38-
// let frontier = (@.) frontier
39-
40-
// let a = levels.AssignE <| frontier.Mask
41-
// let a = levels $ frontier.Mask <| Scalar currentLevel
42-
let a = levels ? frontier.Mask <- Scalar currentLevel
43-
44-
45-
46-
47-
// opencl {
48-
// while currentLevel < vertexCount do
49-
// do! levels.Assign(frontier.Mask, Scalar currentLevel)
50-
// // let! frontier = frontier @. matrix <|| (levels.Complemented, BooleanSemiring.anyAll)
51-
// let! frontier = frontier @. matrix <| {| Mask = levels.Complemented; SR = BooleanSemiring.anyAll |}
52-
// currentLevel <- currentLevel + 1
53-
// // let! a = frontier.Reduce BooleanMonoid.any
54-
// // let s = !> a
55-
// let a = levels.Assign $ frontier.Mask
56-
57-
// return levels
58-
// }
59-
60-
// while !> (frontier.Reduce BooleanMonoid.any) && currentLevel < vertexCount do
61-
// levels.Assign(frontier.Mask, Scalar currentLevel)
62-
// frontier.Clear()
63-
// frontier.Assign(levels.Complemented, (frontier @. matrix) levels.Complemented BooleanSemiring.anyAll)
64-
// currentLevel <- currentLevel + 1
65-
66-
// upcast levels
67-
6815

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+
}
6927

7028
// let parentBFS (matrix: Matrix<bool>) (source: int) : Vector<int> =
7129
// 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.Assign(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+
}

0 commit comments

Comments
 (0)