From faf242c5b61bae28be7bc18801aefb9d69c4ac9a Mon Sep 17 00:00:00 2001 From: kirillgarbar Date: Sat, 2 Dec 2023 18:41:44 +0300 Subject: [PATCH 01/12] PageRankMatrix type --- .../Algorithms/PageRank.fs | 2 +- .../Algorithms/PageRank.fs | 4 +-- src/GraphBLAS-sharp.Backend/Objects/Matrix.fs | 33 +++++++++++++++++++ tests/GraphBLAS-sharp.Tests/Program.fs | 3 +- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs index 70273357..9e6a3f38 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs @@ -23,7 +23,7 @@ type Benchmarks( let mutable funToBenchmark = None let mutable matrix = Unchecked.defaultof> - let mutable matrixPrepared = Unchecked.defaultof> + let mutable matrixPrepared = Unchecked.defaultof> let mutable matrixHost = Unchecked.defaultof<_> let accuracy = 0.00000001f diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs b/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs index d806b4fe..d089d945 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs @@ -131,6 +131,7 @@ module internal PageRank = transposeInPlace queue DeviceOnly newMatrix |> ClMatrix.CSR + |> PageRankMatrix | _ -> failwith "Not implemented" let run (clContext: ClContext) workGroupSize = @@ -154,8 +155,7 @@ module internal PageRank = let create = GraphBLAS.FSharp.Vector.create clContext workGroupSize - fun (queue: MailboxProcessor) (matrix: ClMatrix) accuracy -> - + fun (queue: MailboxProcessor) (PageRankMatrix matrix) accuracy -> let vertexCount = matrix.RowCount //None is 0 diff --git a/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs b/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs index 81771bd0..b17dbb2b 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs @@ -173,3 +173,36 @@ type ClMatrix<'a when 'a: struct> = | ClMatrix.COO matrix -> matrix.NNZ | ClMatrix.CSC matrix -> matrix.NNZ | ClMatrix.LIL matrix -> matrix.NNZ + +/// +/// Represents an abstraction over matrix, which is converted to correct format for PageRank algorithm +/// +type PageRankMatrix<'a when 'a: struct> = + | PageRankMatrix of ClMatrix<'a> + /// + /// Gets the number of rows in matrix. + /// + member this.RowCount = + match this with + | PageRankMatrix matrix -> matrix.RowCount + + /// + /// Gets the number of columns in matrix. + /// + member this.ColumnCount = + match this with + | PageRankMatrix matrix -> matrix.ColumnCount + + /// + /// Release device resources allocated for the matrix. + /// + member this.Dispose q = + match this with + | PageRankMatrix matrix -> matrix.Dispose q + + /// + /// Gets the number of non-zero elements in matrix. + /// + member this.NNZ = + match this with + | PageRankMatrix matrix -> matrix.NNZ diff --git a/tests/GraphBLAS-sharp.Tests/Program.fs b/tests/GraphBLAS-sharp.Tests/Program.fs index 5b7b7908..b3e11bc4 100644 --- a/tests/GraphBLAS-sharp.Tests/Program.fs +++ b/tests/GraphBLAS-sharp.Tests/Program.fs @@ -92,7 +92,8 @@ let algorithmsTests = testList "Algorithms tests" [ Algorithms.BFS.tests - Algorithms.SSSP.tests ] + Algorithms.SSSP.tests + Algorithms.PageRank.tests ] |> testSequenced let deviceTests = From b278b7a4e9a97182b743cd32ba867c36cfa97a96 Mon Sep 17 00:00:00 2001 From: kirillgarbar Date: Sun, 10 Dec 2023 16:45:29 +0300 Subject: [PATCH 02/12] BFS on bool --- .../Algorithms/BFS.fs | 32 +++++++++---------- .../GraphBLAS-sharp.Benchmarks/Program.fs | 4 +-- src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs | 26 +++++++-------- .../Backend/Algorithms/BFS.fs | 16 ++++++---- 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs index a0c10cb6..db82d111 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs @@ -27,7 +27,7 @@ type Benchmarks<'elem when 'elem : struct>( let mutable matrix = Unchecked.defaultof> let mutable matrixHost = Unchecked.defaultof<_> - member val ResultLevels = Unchecked.defaultof> with get,set + member val ResultLevels = Unchecked.defaultof> with get,set [] member val OclContextInfo = Unchecked.defaultof with get, set @@ -127,24 +127,24 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>( this.BFS() this.Processor.PostAndReply Msg.MsgNotifyMe -type BFSWithoutTransferBenchmarkInt32() = +type BFSWithoutTransferBenchmarkBool() = - inherit WithoutTransferBenchmark( - (Algorithms.BFS.singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption), - int32, - (fun _ -> Utils.nextInt (System.Random())), + inherit WithoutTransferBenchmark( + (Algorithms.BFS.singleSource ArithmeticOperations.boolSumOption ArithmeticOperations.boolMulOption), + (fun _ -> true), + (fun _ -> true), 0, (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)) static member InputMatrixProvider = Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt" -type BFSPushPullWithoutTransferBenchmarkInt32() = +type BFSPushPullWithoutTransferBenchmarkBool() = - inherit WithoutTransferBenchmark( - (Algorithms.BFS.singleSourcePushPull ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption), - int32, - (fun _ -> Utils.nextInt (System.Random())), + inherit WithoutTransferBenchmark( + (Algorithms.BFS.singleSourcePushPull ArithmeticOperations.boolSumOption ArithmeticOperations.boolMulOption), + (fun _ -> true), + (fun _ -> true), 0, (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)) @@ -200,12 +200,12 @@ type WithTransferBenchmark<'elem when 'elem : struct>( this.Processor.PostAndReply Msg.MsgNotifyMe | _ -> failwith "Impossible" -type BFSWithTransferBenchmarkInt32() = +type BFSWithTransferBenchmarkBool() = - inherit WithTransferBenchmark( - (Algorithms.BFS.singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption), - int32, - (fun _ -> Utils.nextInt (System.Random())), + inherit WithTransferBenchmark( + (Algorithms.BFS.singleSource ArithmeticOperations.boolSumOption ArithmeticOperations.boolMulOption), + (fun _ -> true), + (fun _ -> true), 0, (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs index 0655cd45..5e173915 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs @@ -4,8 +4,8 @@ open BenchmarkDotNet.Running [] let main argv = let benchmarks = - BenchmarkSwitcher [| typeof - typeof + BenchmarkSwitcher [| typeof + typeof typeof |] benchmarks.Run argv |> ignore diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs b/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs index 830c0bad..0fd2f783 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs @@ -11,8 +11,8 @@ open GraphBLAS.FSharp.Objects.ClCellExtensions module internal BFS = let singleSource - (add: Expr int option -> int option>) - (mul: Expr<'a option -> int option -> int option>) + (add: Expr bool option -> bool option>) + (mul: Expr bool option -> bool option>) (clContext: ClContext) workGroupSize = @@ -41,7 +41,7 @@ module internal BFS = zeroCreate queue DeviceOnly vertexCount Dense let front = - ofList queue DeviceOnly Dense vertexCount [ source, 1 ] + ofList queue DeviceOnly Dense vertexCount [ source, true ] let mutable level = 0 let mutable stop = false @@ -67,14 +67,14 @@ module internal BFS = levels let singleSourceSparse - (add: Expr int option -> int option>) - (mul: Expr<'a option -> int option -> int option>) + (add: Expr bool option -> bool option>) + (mul: Expr bool option -> bool option>) (clContext: ClContext) workGroupSize = let spMSpV = - Operations.SpMSpV add mul clContext workGroupSize + Operations.SpMSpVBool add mul clContext workGroupSize let zeroCreate = Vector.zeroCreate clContext workGroupSize @@ -94,7 +94,7 @@ module internal BFS = zeroCreate queue DeviceOnly vertexCount Dense let mutable front = - ofList queue DeviceOnly Sparse vertexCount [ source, 1 ] + ofList queue DeviceOnly Sparse vertexCount [ source, true ] let mutable level = 0 let mutable stop = false @@ -125,8 +125,8 @@ module internal BFS = let singleSourcePushPull - (add: Expr int option -> int option>) - (mul: Expr<'a option -> int option -> int option>) + (add: Expr bool option -> bool option>) + (mul: Expr bool option -> bool option>) (clContext: ClContext) workGroupSize = @@ -135,7 +135,7 @@ module internal BFS = Operations.SpMVInPlace add mul clContext workGroupSize let spMSpV = - Operations.SpMSpV add mul clContext workGroupSize + Operations.SpMSpVBool add mul clContext workGroupSize let zeroCreate = Vector.zeroCreate clContext workGroupSize @@ -159,7 +159,7 @@ module internal BFS = ClArray.count Predicates.isSome clContext workGroupSize //Push or pull functions - let getNNZ (queue: MailboxProcessor) (v: ClVector) = + let getNNZ (queue: MailboxProcessor) (v: ClVector) = match v with | ClVector.Sparse v -> v.NNZ | ClVector.Dense v -> countNNZ queue v @@ -169,14 +169,14 @@ module internal BFS = let push nnz size = (float32 nnz) / (float32 size) <= SPARSITY - fun (queue: MailboxProcessor) (matrix: ClMatrix<'a>) (source: int) -> + fun (queue: MailboxProcessor) (matrix: ClMatrix) (source: int) -> let vertexCount = matrix.RowCount let levels = zeroCreate queue DeviceOnly vertexCount Dense let mutable frontier = - ofList queue DeviceOnly Sparse vertexCount [ source, 1 ] + ofList queue DeviceOnly Sparse vertexCount [ source, true ] let mutable level = 0 let mutable stop = false diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs index 92ba3d1b..6d83eb91 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs @@ -21,28 +21,30 @@ let testFixtures (testContext: TestContext) = let bfs = Algorithms.BFS.singleSource - ArithmeticOperations.intSumOption - ArithmeticOperations.intMulOption + ArithmeticOperations.boolSumOption + ArithmeticOperations.boolMulOption context workGroupSize let bfsSparse = Algorithms.BFS.singleSourceSparse - ArithmeticOperations.intSumOption - ArithmeticOperations.intMulOption + ArithmeticOperations.boolSumOption + ArithmeticOperations.boolMulOption context workGroupSize let bfsPushPull = Algorithms.BFS.singleSourcePushPull - ArithmeticOperations.intSumOption - ArithmeticOperations.intMulOption + ArithmeticOperations.boolSumOption + ArithmeticOperations.boolMulOption context workGroupSize testPropertyWithConfig config testName <| fun (matrix: int [,]) -> + let matrixBool = Array2D.map (fun x -> x <> 0) matrix + let graph = undirectedFromArray2D matrix 0 let largestComponent = @@ -56,7 +58,7 @@ let testFixtures (testContext: TestContext) = |> Utils.createArrayFromDictionary (Array2D.length1 matrix) 0 let matrixHost = - Utils.createMatrixFromArray2D CSR matrix ((=) 0) + Utils.createMatrixFromArray2D CSR matrixBool ((=) false) let matrix = matrixHost.ToDevice context From 6f3819b9101ee6731918c7743047386a66cf95f9 Mon Sep 17 00:00:00 2001 From: kirillgarbar Date: Sun, 10 Dec 2023 17:20:06 +0300 Subject: [PATCH 03/12] Fix merge --- .../GraphBLAS-sharp.Benchmarks.fsproj | 3 +- .../GraphBLAS-sharp.Benchmarks/Program.fs | 2 +- .../Algorithms/Algorithms.fs | 5 + src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs | 2 +- .../Algorithms/SSSP.fs | 4 +- .../GraphBLAS-sharp.Backend.fsproj | 1 + .../Quotes/Arithmetic.fs | 13 ++ src/GraphBLAS-sharp.Backend/Vector/Vector.fs | 33 ++--- .../Backend/Algorithms/MSBFS.fs | 4 +- .../Backend/Algorithms/PageRank.fs | 118 ++++++++++++++++++ .../Backend/Algorithms/SSSP.fs | 3 +- .../GraphBLAS-sharp.Tests.fsproj | 1 + tests/GraphBLAS-sharp.Tests/Program.fs | 2 +- 13 files changed, 164 insertions(+), 27 deletions(-) create mode 100644 tests/GraphBLAS-sharp.Tests/Backend/Algorithms/PageRank.fs diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/GraphBLAS-sharp.Benchmarks.fsproj b/benchmarks/GraphBLAS-sharp.Benchmarks/GraphBLAS-sharp.Benchmarks.fsproj index 2dd0c406..1ab92795 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/GraphBLAS-sharp.Benchmarks.fsproj +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/GraphBLAS-sharp.Benchmarks.fsproj @@ -25,8 +25,9 @@ + - \ No newline at end of file + diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs index 88152c72..40bbb73a 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs @@ -4,7 +4,7 @@ open BenchmarkDotNet.Running [] let main argv = let benchmarks = - BenchmarkSwitcher [| typeof + BenchmarkSwitcher [| typeof |] benchmarks.Run argv |> ignore 0 diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs b/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs index bc7de55d..180b72b6 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs @@ -19,3 +19,8 @@ module Algorithms = module SSSP = let run = SSSP.run + + module PageRank = + let run = PageRank.run + + let prepareMatrix = PageRank.prepareMatrix diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs b/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs index 9a5881eb..3215f298 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs @@ -34,7 +34,7 @@ module internal BFS = let containsNonZero = Vector.exists Predicates.isSome clContext workGroupSize - fun (queue: MailboxProcessor) (matrix: ClMatrix<'a>) (source: int) -> + fun (queue: MailboxProcessor) (matrix: ClMatrix) (source: int) -> let vertexCount = matrix.RowCount let levels = diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/SSSP.fs b/src/GraphBLAS-sharp.Backend/Algorithms/SSSP.fs index dc4499e9..05e14f33 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/SSSP.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/SSSP.fs @@ -76,6 +76,4 @@ module SSSP = front1.Dispose queue front2.Dispose queue - match distance with - | ClVector.Dense dist -> dist - | _ -> failwith "not implemented" + distance diff --git a/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj b/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj index 54f8c64d..785f5258 100644 --- a/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj +++ b/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj @@ -71,6 +71,7 @@ + diff --git a/src/GraphBLAS-sharp.Backend/Quotes/Arithmetic.fs b/src/GraphBLAS-sharp.Backend/Quotes/Arithmetic.fs index d66b15e5..8dc37dec 100644 --- a/src/GraphBLAS-sharp.Backend/Quotes/Arithmetic.fs +++ b/src/GraphBLAS-sharp.Backend/Quotes/Arithmetic.fs @@ -257,3 +257,16 @@ module ArithmeticOperations = <@ fun (x: 'a) (y: 'a) -> Some(min x y) @> let fst<'a> = <@ fun (x: 'a) (_: 'a) -> Some x @> + + //PageRank specific + let squareOfDifference = + <@ fun (x: float32 option) (y: float32 option) -> + let mutable res = 0.0f + + match x, y with + | Some f, Some s -> res <- (f - s) * (f - s) + | Some f, None -> res <- f * f + | None, Some s -> res <- s * s + | None, None -> () + + if res = 0.0f then None else Some res @> diff --git a/src/GraphBLAS-sharp.Backend/Vector/Vector.fs b/src/GraphBLAS-sharp.Backend/Vector/Vector.fs index f02798d6..bbba4404 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Vector.fs @@ -15,29 +15,30 @@ open GraphBLAS.FSharp.Backend.Vector [] module Vector = /// - /// Builds vector of given format with fixed size and fills it with the default values of desired type. + /// Builds vector of given format with fixed size and fills it with the given value. /// /// OpenCL context. /// Should be a power of 2 and greater than 1. - let zeroCreate (clContext: ClContext) workGroupSize = - let zeroCreate = - ClArray.zeroCreate clContext workGroupSize + let create (clContext: ClContext) workGroupSize = + let create = ClArray.create clContext workGroupSize - fun (processor: MailboxProcessor<_>) allocationMode size format -> + fun (processor: MailboxProcessor<_>) allocationMode size format value -> match format with - | Sparse -> - ClVector.Sparse - { Context = clContext - Indices = clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, [| 0 |]) - Values = - clContext.CreateClArrayWithSpecificAllocationMode( - allocationMode, - [| Unchecked.defaultof<'a> |] - ) // TODO empty vector - Size = size } + | Sparse -> failwith "Attempting to create full sparse vector" | Dense -> ClVector.Dense - <| zeroCreate processor allocationMode size + <| create processor allocationMode size value + + /// + /// Builds vector of given format with fixed size and fills it with the default values of desired type. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let zeroCreate (clContext: ClContext) workGroupSize = + let create = create clContext workGroupSize + + fun (processor: MailboxProcessor<_>) allocationMode size format -> + create processor allocationMode size format None /// /// Builds vector of given format with fixed size and fills it with the values from the given list. diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/MSBFS.fs b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/MSBFS.fs index 205e1218..7a4c754d 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/MSBFS.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/MSBFS.fs @@ -60,7 +60,7 @@ let makeLevelsTest context queue bfs (matrix: int [,]) = let createLevelsTest<'a> context queue testFun = testFun |> makeLevelsTest context queue - |> testPropertyWithConfig config $"test on %A{typeof<'a>}" + |> testPropertyWithConfig config $"test on %A{typeof<'a>}, %A{context}" let levelsTestFixtures (testContext: TestContext) = [ let context = testContext.ClContext @@ -112,7 +112,7 @@ let makeParentsTest context queue bfs (matrix: int [,]) = let createParentsTest<'a> context queue testFun = testFun |> makeParentsTest context queue - |> testPropertyWithConfig config $"test on %A{typeof<'a>}" + |> testPropertyWithConfig config $"test on %A{typeof<'a>}, %A{context}" let parentsTestFixtures (testContext: TestContext) = [ let context = testContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/PageRank.fs b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/PageRank.fs new file mode 100644 index 00000000..72f30025 --- /dev/null +++ b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/PageRank.fs @@ -0,0 +1,118 @@ +module GraphBLAS.FSharp.Tests.Backend.Algorithms.PageRank + +open Expecto +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Tests +open GraphBLAS.FSharp.Tests.Context +open GraphBLAS.FSharp.Objects.ClVectorExtensions +open GraphBLAS.FSharp.Objects + +let private alpha = 0.85f +let private accuracy = 0.00001f + +let prepareNaive (matrix: float32 [,]) = + let result = Array2D.copy matrix + let rowCount = Array2D.length1 matrix + let outDegrees = Array.zeroCreate rowCount + + //Count degree + Array2D.iteri (fun r c v -> outDegrees.[r] <- outDegrees.[r] + (if v <> 0f then 1f else 0f)) matrix + + //Set value + Array2D.iteri + (fun r c v -> + result.[r, c] <- + if v <> 0f then + alpha / outDegrees.[r] + else + 0f) + matrix + + //Transpose + Array2D.iteri + (fun r c _ -> + if r > c then + let temp = result.[r, c] + result.[r, c] <- result.[c, r] + result.[c, r] <- temp) + matrix + + result + +let pageRankNaive (matrix: float32 [,]) = + let rowCount = Array2D.length1 matrix + let mutable result = Array.zeroCreate rowCount + + let mutable prev = + Array.create rowCount (1f / (float32 rowCount)) + + let mutable error = accuracy + 1f + let addConst = (1f - alpha) / (float32 rowCount) + + while (error > accuracy) do + for r in 0 .. rowCount - 1 do + result.[r] <- 0f + + for c in 0 .. rowCount - 1 do + result.[r] <- result.[r] + matrix.[r, c] * prev.[c] + + result.[r] <- result.[r] + addConst + + error <- + sqrt + <| Array.fold2 (fun e x1 x2 -> e + (x1 - x2) * (x1 - x2)) 0f result prev + + let temp = result + result <- prev + prev <- temp + + prev + +let testFixtures (testContext: TestContext) = + [ let config = Utils.undirectedAlgoConfig + let context = testContext.ClContext + let queue = testContext.Queue + let workGroupSize = Utils.defaultWorkGroupSize + + let testName = + sprintf "Test on %A" testContext.ClContext + + let pageRank = + Algorithms.PageRank.run context workGroupSize + + testPropertyWithConfig config testName + <| fun (matrix: float32 [,]) -> + let matrixHost = + Utils.createMatrixFromArray2D CSR matrix ((=) 0f) + + if matrixHost.NNZ > 0 then + let preparedMatrixExpected = prepareNaive matrix + + let expected = pageRankNaive preparedMatrixExpected + + let matrix = matrixHost.ToDevice context + + let preparedMatrix = + Algorithms.PageRank.prepareMatrix context workGroupSize queue matrix + + let res = pageRank queue preparedMatrix accuracy + + let resHost = res.ToHost queue + + preparedMatrix.Dispose queue + matrix.Dispose queue + res.Dispose queue + + match resHost with + | Vector.Dense resHost -> + let actual = resHost |> Utils.unwrapOptionArray 0f + + for i in 0 .. actual.Length - 1 do + Expect.isTrue + ((abs (actual.[i] - expected.[i])) < accuracy) + (sprintf "Values should be equal. Expected %A, actual %A" expected.[i] actual.[i]) + + | _ -> failwith "Not implemented" ] + +let tests = + TestCases.gpuTests "PageRank tests" testFixtures diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/SSSP.fs b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/SSSP.fs index fa9cdff7..78feff8f 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/SSSP.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/SSSP.fs @@ -45,8 +45,7 @@ let testFixtures (testContext: TestContext) = let matrix = matrixHost.ToDevice context - let resDense = - ssspDense queue matrix source |> ClVector.Dense + let resDense = ssspDense queue matrix source let resHost = resDense.ToHost queue diff --git a/tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj b/tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj index d4913a3d..78952059 100644 --- a/tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj +++ b/tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj @@ -20,6 +20,7 @@ + diff --git a/tests/GraphBLAS-sharp.Tests/Program.fs b/tests/GraphBLAS-sharp.Tests/Program.fs index 837f2613..e2b1045b 100644 --- a/tests/GraphBLAS-sharp.Tests/Program.fs +++ b/tests/GraphBLAS-sharp.Tests/Program.fs @@ -94,7 +94,7 @@ let algorithmsTests = "Algorithms tests" [ Algorithms.BFS.tests Algorithms.SSSP.tests - Algorithms.PageRank.tests ] + Algorithms.PageRank.tests Algorithms.MSBFS.levelsTests Algorithms.MSBFS.parentsTests ] |> testSequenced From 1ed601cbc48e6a7edc6d71e3068b48bf18aeecee Mon Sep 17 00:00:00 2001 From: kirillgarbar Date: Sun, 10 Dec 2023 18:17:47 +0300 Subject: [PATCH 04/12] Fix ZeroCreate test --- .../Backend/Vector/ZeroCreate.fs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs index 79c1e4d9..ea738e61 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs @@ -38,16 +38,20 @@ let correctnessGenericTest<'a when 'a: struct and 'a: equality> let vectorSize = abs vectorSize if vectorSize > 0 then - let q = case.TestContext.Queue + try + let q = case.TestContext.Queue - let clVector = - zeroCreate q HostInterop vectorSize case.Format + let clVector = + zeroCreate q DeviceOnly vectorSize case.Format - let hostVector = clVector.ToHost q + let hostVector = clVector.ToHost q - clVector.Dispose q + clVector.Dispose q - checkResult vectorSize hostVector + checkResult vectorSize hostVector + with + | ex when ex.Message = "Attempting to create full sparse vector" -> () + | ex -> raise ex let createTest<'a> case = let getCorrectnessTestName dataType = From 858cd8290dfbcaa32161f94bf3ba682a0af1c9f7 Mon Sep 17 00:00:00 2001 From: kirillgarbar Date: Sun, 17 Dec 2023 19:23:59 +0300 Subject: [PATCH 05/12] Constants for test --- .../Backend/Algorithms/PageRank.fs | 12 +++++++----- tests/GraphBLAS-sharp.Tests/Helpers.fs | 4 ++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/PageRank.fs b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/PageRank.fs index 72f30025..83b7d9af 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/PageRank.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/PageRank.fs @@ -7,8 +7,7 @@ open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp.Objects.ClVectorExtensions open GraphBLAS.FSharp.Objects -let private alpha = 0.85f -let private accuracy = 0.00001f +let private accuracy = float32 Accuracy.low.absolute let prepareNaive (matrix: float32 [,]) = let result = Array2D.copy matrix @@ -23,7 +22,7 @@ let prepareNaive (matrix: float32 [,]) = (fun r c v -> result.[r, c] <- if v <> 0f then - alpha / outDegrees.[r] + Backend.Algorithms.PageRank.alpha / outDegrees.[r] else 0f) matrix @@ -47,7 +46,10 @@ let pageRankNaive (matrix: float32 [,]) = Array.create rowCount (1f / (float32 rowCount)) let mutable error = accuracy + 1f - let addConst = (1f - alpha) / (float32 rowCount) + + let addConst = + (1f - Backend.Algorithms.PageRank.alpha) + / (float32 rowCount) while (error > accuracy) do for r in 0 .. rowCount - 1 do @@ -109,7 +111,7 @@ let testFixtures (testContext: TestContext) = for i in 0 .. actual.Length - 1 do Expect.isTrue - ((abs (actual.[i] - expected.[i])) < accuracy) + (Utils.float32IsEqualLowAccuracy actual.[i] expected.[i]) (sprintf "Values should be equal. Expected %A, actual %A" expected.[i] actual.[i]) | _ -> failwith "Not implemented" ] diff --git a/tests/GraphBLAS-sharp.Tests/Helpers.fs b/tests/GraphBLAS-sharp.Tests/Helpers.fs index e9d2e86a..38ce1ff2 100644 --- a/tests/GraphBLAS-sharp.Tests/Helpers.fs +++ b/tests/GraphBLAS-sharp.Tests/Helpers.fs @@ -38,6 +38,10 @@ module Utils = float (abs (x - y)) < Accuracy.medium.absolute || x.Equals y + let inline float32IsEqualLowAccuracy x y = + float (abs (x - y)) < Accuracy.low.absolute + || x.Equals y + let vectorToDenseVector = function | Vector.Dense vector -> vector From 082656281c1397217916574ccfbf53899eeff778 Mon Sep 17 00:00:00 2001 From: kirillgarbar Date: Sun, 17 Dec 2023 19:24:12 +0300 Subject: [PATCH 06/12] Docs for PageRank --- .../Algorithms/Algorithms.fs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs b/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs index 180b72b6..18bb4dd1 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs @@ -21,6 +21,22 @@ module Algorithms = let run = SSSP.run module PageRank = + /// + /// Computes PageRank of the given matrix. + /// Matrix should be prepared in advance using "PageRank.prepareMatrix" method. + /// Accepts accuracy as a parameter which determines how many iterations will be performed. + /// Values of accuracy lower than 1e-06 are not recommended since the process may never stop. + /// + /// + /// + /// let preparedMatrix = PageRank.prepareMatrix clContext workGroupSize queue matrix + /// let accuracy = 1e-05 + /// let pageRank = PageRank.run clContext workGroupSize queue preparedMatrix accuracy + /// + /// let run = PageRank.run + /// + /// Converts matrix representing a graph to a format suitable for PageRank algorithm. + /// let prepareMatrix = PageRank.prepareMatrix From b82fe6887e01d3d0e22da5e87d31d16f29bd92c8 Mon Sep 17 00:00:00 2001 From: kirillgarbar Date: Sun, 17 Dec 2023 19:30:22 +0300 Subject: [PATCH 07/12] Block after setup and cleanup in benchmarks --- benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs | 4 ++++ benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs | 2 ++ benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs | 2 ++ benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs | 2 ++ benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs | 4 ++++ benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs | 3 +++ 6 files changed, 17 insertions(+) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs index 773cece7..9cb5ab3d 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs @@ -113,10 +113,12 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>( override this.GlobalSetup() = this.ReadMatrix() this.LoadMatrixToGPU() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.IterationCleanup() = this.ClearResult() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.GlobalCleanup() = @@ -180,6 +182,7 @@ type WithTransferBenchmark<'elem when 'elem : struct>( [] override this.GlobalSetup() = this.ReadMatrix() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.GlobalCleanup() = @@ -189,6 +192,7 @@ type WithTransferBenchmark<'elem when 'elem : struct>( override this.IterationCleanup() = this.ClearInputMatrix() this.ClearResult() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.Benchmark() = diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs index 9e6a3f38..d60415b8 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs @@ -117,10 +117,12 @@ type PageRankWithoutTransferBenchmarkFloat32() = this.Processor.PostAndReply(Msg.MsgNotifyMe) this.PrepareMatrix() this.ClearInputMatrix() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.IterationCleanup() = this.ClearResult() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.GlobalCleanup() = diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs index ab54db75..bcd04eb8 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs @@ -251,6 +251,7 @@ module WithTransfer = [] override this.GlobalSetup() = this.ReadMatrices() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.GlobalCleanup() = () @@ -259,6 +260,7 @@ module WithTransfer = override this.IterationCleanup() = this.ClearInputMatrices() this.ClearResult() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.Benchmark() = diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs index e8a75071..88e91cb6 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs @@ -115,6 +115,7 @@ module WithoutTransfer = override this.GlobalSetup() = this.ReadMatrices() this.LoadMatricesToGPU() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.Benchmark() = @@ -124,6 +125,7 @@ module WithoutTransfer = [] override this.IterationCleanup () = this.ClearResult() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.GlobalCleanup () = diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs index ff0495bf..fcbd13f8 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs @@ -152,6 +152,7 @@ type MxmBenchmarksMultiplicationOnly<'elem when 'elem : struct>( this.ReadMatrices () this.LoadMatricesToGPU () this.ConvertSecondMatrixToCSC() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.Benchmark () = @@ -161,6 +162,7 @@ type MxmBenchmarksMultiplicationOnly<'elem when 'elem : struct>( [] override this.IterationCleanup () = this.ClearResult() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.GlobalCleanup () = @@ -182,6 +184,7 @@ type MxmBenchmarksWithTransposing<'elem when 'elem : struct>( override this.GlobalSetup() = this.ReadMatrices() this.LoadMatricesToGPU () + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.Benchmark() = @@ -194,6 +197,7 @@ type MxmBenchmarksWithTransposing<'elem when 'elem : struct>( override this.IterationCleanup() = this.ClearResult() this.ConvertSecondMatrixToCSR() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.GlobalCleanup() = diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs index 5c4871e2..c3e566eb 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs @@ -115,6 +115,7 @@ module WithoutTransfer = override this.IterationCleanup() = this.ClearResult() this.ClearInputVectors() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.GlobalCleanup() = () @@ -159,6 +160,7 @@ module WithTransfer = [] override this.IterationSetup() = this.CreateVectors() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.Benchmark () = @@ -175,6 +177,7 @@ module WithTransfer = override this.IterationCleanup () = this.ClearInputVectors() this.ClearResult() + this.Processor.PostAndReply(Msg.MsgNotifyMe) [] override this.GlobalCleanup() = () From c8f3042193835133f67ced69052cc7907d6bc384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=93=D0=B0=D1=80?= =?UTF-8?q?=D0=B1=D0=B0=D1=80?= Date: Fri, 22 Dec 2023 01:30:57 +0300 Subject: [PATCH 08/12] Constants module and signature for PageRank module --- .../Algorithms/PageRank.fs | 6 ++-- .../Algorithms/Algorithms.fs | 4 ++- .../Algorithms/PageRank.fs | 31 ++++++++++++----- .../Algorithms/PageRank.fsi | 13 ++++++++ src/GraphBLAS-sharp.Backend/Common/Utils.fs | 1 - .../Constants/Constants.fs | 18 ++++++++++ .../GraphBLAS-sharp.Backend.fsproj | 16 ++++----- src/GraphBLAS-sharp.Backend/Objects/Matrix.fs | 33 ------------------- .../Backend/Algorithms/BFS.fs | 2 +- .../Backend/Algorithms/MSBFS.fs | 2 +- .../Backend/Algorithms/PageRank.fs | 19 ++++++----- .../Backend/Algorithms/SSSP.fs | 4 ++- .../Backend/Common/ClArray/Blit.fs | 2 +- .../Backend/Common/ClArray/Choose.fs | 4 +-- .../Backend/Common/ClArray/ChunkBySize.fs | 6 ++-- .../Backend/Common/ClArray/Concat.fs | 2 +- .../Backend/Common/ClArray/Copy.fs | 2 +- .../Backend/Common/ClArray/ExcludeElements.fs | 2 +- .../Backend/Common/ClArray/Exists.fs | 2 +- .../Backend/Common/ClArray/Fill.fs | 2 +- .../Backend/Common/ClArray/Item.fs | 2 +- .../Backend/Common/ClArray/Map.fs | 3 +- .../Backend/Common/ClArray/Map2.fs | 3 +- .../Backend/Common/ClArray/Pairwise.fs | 2 +- .../Backend/Common/ClArray/Replicate.fs | 2 +- .../Backend/Common/ClArray/Set.fs | 2 +- .../Backend/Common/ClArray/UpperBound.fs | 2 +- .../Backend/Common/Gather.fs | 4 +-- .../Backend/Common/Reduce/Reduce.fs | 2 +- .../Backend/Common/Reduce/ReduceByKey.fs | 16 ++++----- .../Backend/Common/Scan/ByKey.fs | 2 +- .../Backend/Common/Scatter.fs | 4 +-- .../Backend/Common/Sort/Bitonic.fs | 3 +- .../Backend/Common/Sort/Radix.fs | 3 +- .../Backend/Matrix/ByRows.fs | 2 +- .../Backend/Matrix/Convert.fs | 4 +-- .../Backend/Matrix/ExpandRows.fs | 2 +- .../Backend/Matrix/Intersect.fs | 2 +- .../Backend/Matrix/Kronecker.fs | 2 +- .../Backend/Matrix/Map.fs | 2 +- .../Backend/Matrix/Map2.fs | 2 +- .../Backend/Matrix/Merge.fs | 6 ++-- .../Backend/Matrix/RowsLengths.fs | 2 +- .../Backend/Matrix/SpGeMM/Expand.fs | 6 ++-- .../Backend/Matrix/SpGeMM/ExpandCOO.fs | 2 +- .../Backend/Matrix/SpGeMM/Masked.fs | 2 +- .../Backend/Matrix/SubRows.fs | 2 +- .../Backend/Matrix/Transpose.fs | 2 +- .../Backend/Vector/AssignByMask.fs | 2 +- .../Backend/Vector/Convert.fs | 2 +- .../Backend/Vector/Copy.fs | 2 +- .../Backend/Vector/Map.fs | 2 +- .../Backend/Vector/Map2.fs | 2 +- .../Backend/Vector/Merge.fs | 2 +- .../Backend/Vector/OfList.fs | 2 +- .../Backend/Vector/Reduce.fs | 2 +- .../Backend/Vector/SpMSpV.fs | 2 +- .../Backend/Vector/SpMV.fs | 2 +- .../Backend/Vector/ZeroCreate.fs | 2 +- tests/GraphBLAS-sharp.Tests/Helpers.fs | 1 - 60 files changed, 147 insertions(+), 135 deletions(-) create mode 100644 src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fsi create mode 100644 src/GraphBLAS-sharp.Backend/Constants/Constants.fs diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs index d60415b8..16cfacb5 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs @@ -23,11 +23,9 @@ type Benchmarks( let mutable funToBenchmark = None let mutable matrix = Unchecked.defaultof> - let mutable matrixPrepared = Unchecked.defaultof> + let mutable matrixPrepared = Unchecked.defaultof let mutable matrixHost = Unchecked.defaultof<_> - let accuracy = 0.00000001f - member val Result = Unchecked.defaultof> with get,set [] @@ -67,7 +65,7 @@ type Benchmarks( | Some x -> x member this.PageRank() = - this.Result <- this.FunToBenchmark this.Processor matrixPrepared accuracy + this.Result <- this.FunToBenchmark this.Processor matrixPrepared Constants.PageRank.accuracy member this.ClearInputMatrix() = matrix.Dispose this.Processor diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs b/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs index 18bb4dd1..66c49ccb 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs @@ -21,11 +21,13 @@ module Algorithms = let run = SSSP.run module PageRank = + type PageRankMatrix = PageRank.PageRankMatrix + /// /// Computes PageRank of the given matrix. /// Matrix should be prepared in advance using "PageRank.prepareMatrix" method. /// Accepts accuracy as a parameter which determines how many iterations will be performed. - /// Values of accuracy lower than 1e-06 are not recommended since the process may never stop. + /// Values of accuracy higher than 1e-06 are not recommended since the process may never stop. /// /// /// diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs b/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs index d089d945..b82e08b5 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs @@ -11,8 +11,13 @@ open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.ArraysExtensions open GraphBLAS.FSharp.Objects.ClCellExtensions -module internal PageRank = - let alpha = 0.85f +module PageRank = + type PageRankMatrix = + | PreparedMatrix of ClMatrix + + member this.Dispose(processor: MailboxProcessor) = + match this with + | PreparedMatrix matrix -> matrix.Dispose processor let private countOutDegree (clContext: ClContext) workGroupSize = @@ -40,10 +45,10 @@ module internal PageRank = outDegree - let prepareMatrix (clContext: ClContext) workGroupSize = + let internal prepareMatrix (clContext: ClContext) workGroupSize = //Passing global variable to kernel in Brahma is not possible - let alpha = alpha + let alpha = Constants.PageRank.alpha let op = <@ fun (x: float32 option) y -> @@ -131,10 +136,10 @@ module internal PageRank = transposeInPlace queue DeviceOnly newMatrix |> ClMatrix.CSR - |> PageRankMatrix + |> PreparedMatrix | _ -> failwith "Not implemented" - let run (clContext: ClContext) workGroupSize = + let internal run (clContext: ClContext) workGroupSize = let squareOfDifference = ArithmeticOperations.squareOfDifference let plus = ArithmeticOperations.float32SumOption @@ -155,7 +160,7 @@ module internal PageRank = let create = GraphBLAS.FSharp.Vector.create clContext workGroupSize - fun (queue: MailboxProcessor) (PageRankMatrix matrix) accuracy -> + fun (queue: MailboxProcessor) (PreparedMatrix matrix) accuracy -> let vertexCount = matrix.RowCount //None is 0 @@ -169,7 +174,15 @@ module internal PageRank = create queue DeviceOnly vertexCount Dense None let addition = - create queue DeviceOnly vertexCount Dense (Some((1.0f - alpha) / (float32 vertexCount))) + create + queue + DeviceOnly + vertexCount + Dense + (Some( + (1.0f - Constants.PageRank.alpha) + / (float32 vertexCount) + )) let mutable error = accuracy + 0.1f @@ -178,7 +191,7 @@ module internal PageRank = while error > accuracy do i <- i + 1 - // rank = matrix*rank + (1 - alpha)/N + // rank = matrix*rank + (1 - ALPHA)/N spMVTo queue matrix prevRank rank addToResult queue rank addition diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fsi b/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fsi new file mode 100644 index 00000000..230cd28d --- /dev/null +++ b/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fsi @@ -0,0 +1,13 @@ +namespace GraphBLAS.FSharp.Backend.Algorithms + +open Brahma.FSharp +open GraphBLAS.FSharp.Objects + +module PageRank = + [] + type PageRankMatrix = + member Dispose : MailboxProcessor -> unit + + val internal prepareMatrix : ClContext -> int -> (MailboxProcessor -> ClMatrix -> PageRankMatrix) + + val internal run : ClContext -> int -> (MailboxProcessor -> PageRankMatrix -> float32 -> ClVector) diff --git a/src/GraphBLAS-sharp.Backend/Common/Utils.fs b/src/GraphBLAS-sharp.Backend/Common/Utils.fs index 0e4ac564..3ef10555 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Utils.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Utils.fs @@ -1,7 +1,6 @@ namespace GraphBLAS.FSharp.Backend.Common module internal Utils = - let defaultWorkGroupSize = 32 let floorToPower2 = fun x -> x ||| (x >>> 1) diff --git a/src/GraphBLAS-sharp.Backend/Constants/Constants.fs b/src/GraphBLAS-sharp.Backend/Constants/Constants.fs new file mode 100644 index 00000000..5609de06 --- /dev/null +++ b/src/GraphBLAS-sharp.Backend/Constants/Constants.fs @@ -0,0 +1,18 @@ +namespace GraphBLAS.FSharp + +[] +module Constants = + module PageRank = + /// + /// PageRank algorithms will finish then + /// difference of current and previous vectors + /// is less than accuracy + /// + let accuracy = 1e-6f + /// + /// Damping factor for PageRank algorithm + /// + let alpha = 0.85f + + module Common = + let defaultWorkGroupSize = 32 diff --git a/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj b/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj index 785f5258..c2e1e085 100644 --- a/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj +++ b/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj @@ -1,4 +1,4 @@ - + @@ -11,6 +11,7 @@ + @@ -18,7 +19,6 @@ - @@ -28,7 +28,6 @@ - @@ -39,9 +38,7 @@ - - @@ -61,19 +58,18 @@ - + - + - - + + - diff --git a/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs b/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs index 86dd7976..766925aa 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs @@ -181,36 +181,3 @@ type ClMatrix<'a when 'a: struct> = | ClMatrix.COO matrix -> matrix.NNZ | ClMatrix.CSC matrix -> matrix.NNZ | ClMatrix.LIL matrix -> matrix.NNZ - -/// -/// Represents an abstraction over matrix, which is converted to correct format for PageRank algorithm -/// -type PageRankMatrix<'a when 'a: struct> = - | PageRankMatrix of ClMatrix<'a> - /// - /// Gets the number of rows in matrix. - /// - member this.RowCount = - match this with - | PageRankMatrix matrix -> matrix.RowCount - - /// - /// Gets the number of columns in matrix. - /// - member this.ColumnCount = - match this with - | PageRankMatrix matrix -> matrix.ColumnCount - - /// - /// Release device resources allocated for the matrix. - /// - member this.Dispose q = - match this with - | PageRankMatrix matrix -> matrix.Dispose q - - /// - /// Gets the number of non-zero elements in matrix. - /// - member this.NNZ = - match this with - | PageRankMatrix matrix -> matrix.NNZ diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs index 1b6561b4..2a0453a8 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs @@ -14,7 +14,7 @@ let testFixtures (testContext: TestContext) = [ let config = Utils.undirectedAlgoConfig let context = testContext.ClContext let queue = testContext.Queue - let workGroupSize = Utils.defaultWorkGroupSize + let workGroupSize = Constants.Common.defaultWorkGroupSize let testName = sprintf "Test on %A" testContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/MSBFS.fs b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/MSBFS.fs index 7a4c754d..3adad360 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/MSBFS.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/MSBFS.fs @@ -12,7 +12,7 @@ open GraphBLAS.FSharp.Objects.MatrixExtensions let config = Utils.undirectedAlgoConfig -let workGroupSize = Utils.defaultWorkGroupSize +let workGroupSize = Constants.Common.defaultWorkGroupSize let makeLevelsTest context queue bfs (matrix: int [,]) = let graph = undirectedFromArray2D matrix 0 diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/PageRank.fs b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/PageRank.fs index 83b7d9af..ebd3eab6 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/PageRank.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/PageRank.fs @@ -1,4 +1,4 @@ -module GraphBLAS.FSharp.Tests.Backend.Algorithms.PageRank +module GraphBLAS.FSharp.Tests.Backend.Algorithms.PageRank open Expecto open GraphBLAS.FSharp @@ -7,8 +7,6 @@ open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp.Objects.ClVectorExtensions open GraphBLAS.FSharp.Objects -let private accuracy = float32 Accuracy.low.absolute - let prepareNaive (matrix: float32 [,]) = let result = Array2D.copy matrix let rowCount = Array2D.length1 matrix @@ -22,7 +20,7 @@ let prepareNaive (matrix: float32 [,]) = (fun r c v -> result.[r, c] <- if v <> 0f then - Backend.Algorithms.PageRank.alpha / outDegrees.[r] + Constants.PageRank.alpha / outDegrees.[r] else 0f) matrix @@ -45,13 +43,13 @@ let pageRankNaive (matrix: float32 [,]) = let mutable prev = Array.create rowCount (1f / (float32 rowCount)) - let mutable error = accuracy + 1f + let mutable error = Constants.PageRank.accuracy + 1f let addConst = - (1f - Backend.Algorithms.PageRank.alpha) + (1f - Constants.PageRank.alpha) / (float32 rowCount) - while (error > accuracy) do + while (error > Constants.PageRank.accuracy) do for r in 0 .. rowCount - 1 do result.[r] <- 0f @@ -74,7 +72,9 @@ let testFixtures (testContext: TestContext) = [ let config = Utils.undirectedAlgoConfig let context = testContext.ClContext let queue = testContext.Queue - let workGroupSize = Utils.defaultWorkGroupSize + + let workGroupSize = + GraphBLAS.FSharp.Constants.Common.defaultWorkGroupSize let testName = sprintf "Test on %A" testContext.ClContext @@ -97,7 +97,8 @@ let testFixtures (testContext: TestContext) = let preparedMatrix = Algorithms.PageRank.prepareMatrix context workGroupSize queue matrix - let res = pageRank queue preparedMatrix accuracy + let res = + pageRank queue preparedMatrix Constants.PageRank.accuracy let resHost = res.ToHost queue diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/SSSP.fs b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/SSSP.fs index 78feff8f..3cffbd7d 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/SSSP.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/SSSP.fs @@ -15,7 +15,9 @@ let testFixtures (testContext: TestContext) = [ let config = Utils.undirectedAlgoConfig let context = testContext.ClContext let queue = testContext.Queue - let workGroupSize = Utils.defaultWorkGroupSize + + let workGroupSize = + GraphBLAS.FSharp.Constants.Common.defaultWorkGroupSize let testName = sprintf "Test on %A" testContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Blit.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Blit.fs index 8387bdcc..55df7a4a 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Blit.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Blit.fs @@ -34,7 +34,7 @@ let makeTest<'a> isEqual testFun (source: 'a [], sourceIndex, target: 'a [], tar |> Utils.compareArrays isEqual actual target let createTest<'a when 'a: equality> isEqual = - ClArray.blit context Utils.defaultWorkGroupSize + ClArray.blit context Constants.Common.defaultWorkGroupSize |> makeTest<'a> isEqual |> testPropertyWithConfig config $"test on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs index 3fd89e84..4797b6fb 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs @@ -9,7 +9,7 @@ open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Objects.ArraysExtensions open GraphBLAS.FSharp.Objects.ClContextExtensions -let workGroupSize = Utils.defaultWorkGroupSize +let workGroupSize = Constants.Common.defaultWorkGroupSize let config = Utils.defaultConfig @@ -80,7 +80,7 @@ let makeTest2 testContext isEqual opMap testFun (firstArray: 'a [], secondArray: |> Utils.compareArrays isEqual actual expected let createTest2 testsContext (isEqual: 'a -> 'a -> bool) (opMapQ, opMap) testFun = - testFun opMapQ testsContext.ClContext Utils.defaultWorkGroupSize + testFun opMapQ testsContext.ClContext Constants.Common.defaultWorkGroupSize |> makeTest2 testsContext isEqual opMap |> testPropertyWithConfig config $"test on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ChunkBySize.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ChunkBySize.fs index 2cc3133e..513984c4 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ChunkBySize.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ChunkBySize.fs @@ -32,7 +32,7 @@ let makeTestGetChunk<'a when 'a: equality> testFun (array: 'a [], startPosition, |> Expect.sequenceEqual actual (Array.sub array startPosition count) let creatTestSub<'a when 'a: equality> = - ClArray.sub context Utils.defaultWorkGroupSize + ClArray.sub context Constants.Common.defaultWorkGroupSize |> makeTestGetChunk<'a> |> testPropertyWithConfig config $"test on %A{typeof<'a>}" @@ -72,7 +72,7 @@ let chunkBySizeConfig = arbitrary = [ typeof ] } let creatTestChunkBySize<'a when 'a: equality> isEqual = - ClArray.chunkBySize context Utils.defaultWorkGroupSize + ClArray.chunkBySize context Constants.Common.defaultWorkGroupSize |> makeTestChunkBySize<'a> isEqual |> testPropertyWithConfig chunkBySizeConfig $"test on %A{typeof<'a>}" @@ -89,7 +89,7 @@ let chunkBySizeTests = let creatTestChunkBySizeLazy<'a when 'a: equality> isEqual = (fun processor allocationMode chunkSize array -> - ClArray.lazyChunkBySize context Utils.defaultWorkGroupSize processor allocationMode chunkSize array + ClArray.lazyChunkBySize context Constants.Common.defaultWorkGroupSize processor allocationMode chunkSize array |> Seq.map (fun lazyValue -> lazyValue.Value) |> Seq.toArray) |> makeTestChunkBySize<'a> isEqual diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs index 48dcb77c..1d704e0c 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs @@ -35,7 +35,7 @@ let makeTest<'a> isEqual testFun (arrays: 'a [] []) = |> Utils.compareArrays isEqual actual expected let createTest<'a> isEqual = - ClArray.concat context Utils.defaultWorkGroupSize + ClArray.concat context Constants.Common.defaultWorkGroupSize |> makeTest<'a> isEqual |> testPropertyWithConfig config $"test on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Copy.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Copy.fs index c36475a0..cd8f4a59 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Copy.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Copy.fs @@ -13,7 +13,7 @@ let logger = Log.create "ClArray.Copy.Tests" let context = Context.defaultContext.ClContext -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let q = Context.defaultContext.Queue diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ExcludeElements.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ExcludeElements.fs index 335cd665..33a94b92 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ExcludeElements.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ExcludeElements.fs @@ -48,7 +48,7 @@ let makeTest<'a> isEqual (zero: 'a) testFun ((array, bitmap): 'a array * int arr |> Expect.isEmpty expected let createTest<'a> (zero: 'a) isEqual = - ClArray.excludeElements context Utils.defaultWorkGroupSize + ClArray.excludeElements context Constants.Common.defaultWorkGroupSize |> makeTest<'a> isEqual zero |> testPropertyWithConfig config $"test on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Exists.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Exists.fs index ac991951..80c735da 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Exists.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Exists.fs @@ -19,7 +19,7 @@ let q = defaultContext.Queue let config = Utils.defaultConfig -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let correctnessGenericTest<'a when 'a: struct and 'a: equality> isZero exists (array: 'a []) = diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Fill.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Fill.fs index 8a285a2f..7ec14be2 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Fill.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Fill.fs @@ -33,7 +33,7 @@ let makeTest<'a> isEqual testFun (value: 'a, targetPosition, count, target: 'a [ |> Utils.compareArrays isEqual actual target let createTest<'a> isEqual = - ClArray.fill context Utils.defaultWorkGroupSize + ClArray.fill context Constants.Common.defaultWorkGroupSize |> makeTest<'a> isEqual |> testPropertyWithConfig config $"test on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Item.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Item.fs index a3786832..00e21cde 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Item.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Item.fs @@ -33,7 +33,7 @@ let makeTest<'a when 'a: equality> testFun (array: 'a [], position) = |> Expect.equal actual expected let createTest<'a when 'a: equality> = - ClArray.item context Utils.defaultWorkGroupSize + ClArray.item context Constants.Common.defaultWorkGroupSize |> makeTest<'a> |> testPropertyWithConfig config $"test on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map.fs index b87816ba..2689de09 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map.fs @@ -10,7 +10,8 @@ open GraphBLAS.FSharp.Objects.ClContextExtensions let context = defaultContext.Queue -let wgSize = Utils.defaultWorkGroupSize +let wgSize = + GraphBLAS.FSharp.Constants.Common.defaultWorkGroupSize let config = Utils.defaultConfig diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map2.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map2.fs index 69b28dad..a291858e 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map2.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map2.fs @@ -10,7 +10,8 @@ open GraphBLAS.FSharp.Objects.ClContextExtensions let context = defaultContext.Queue -let wgSize = Utils.defaultWorkGroupSize +let wgSize = + GraphBLAS.FSharp.Constants.Common.defaultWorkGroupSize let config = Utils.defaultConfig diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Pairwise.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Pairwise.fs index 12db7aa8..00a8daa2 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Pairwise.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Pairwise.fs @@ -34,7 +34,7 @@ let makeTest<'a> isEqual testFun (array: 'a []) = |> Expect.isTrue (array.Size <= 1) let createTest<'a> isEqual = - ClArray.pairwise context Utils.defaultWorkGroupSize + ClArray.pairwise context Constants.Common.defaultWorkGroupSize |> makeTest<'a> isEqual |> testPropertyWithConfig config $"test on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Replicate.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Replicate.fs index 2d6ecc6b..dd698189 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Replicate.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Replicate.fs @@ -15,7 +15,7 @@ let context = Context.defaultContext.ClContext let q = Context.defaultContext.Queue -let workGroupSize = Utils.defaultWorkGroupSize +let workGroupSize = Constants.Common.defaultWorkGroupSize let config = Utils.defaultConfig diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Set.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Set.fs index cf1d09e5..c5a76404 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Set.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Set.fs @@ -30,7 +30,7 @@ let makeTest<'a when 'a: equality> testFun (array: 'a [], position, value: 'a) = |> Utils.compareArrays (=) actual array let createTest<'a when 'a: equality> = - ClArray.set context Utils.defaultWorkGroupSize + ClArray.set context Constants.Common.defaultWorkGroupSize |> makeTest<'a> |> testPropertyWithConfig config $"test on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/UpperBound.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/UpperBound.fs index 7f1f2c81..492e98b6 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/UpperBound.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/UpperBound.fs @@ -45,7 +45,7 @@ let makeTest testFun (array: 'a [], value: 'a) = |> Expect.equal actual expected let createTest<'a when 'a: equality and 'a: comparison> = - ClArray.upperBound<'a> context Utils.defaultWorkGroupSize + ClArray.upperBound<'a> context Constants.Common.defaultWorkGroupSize |> makeTest |> testPropertyWithConfig config $"test on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs index b82b65d6..094d8f44 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs @@ -49,7 +49,7 @@ let makeTest isEqual testFun (array: (uint * 'a * 'a) []) = let createTest<'a> (isEqual: 'a -> 'a -> bool) testFun = let testFun = - testFun context Utils.defaultWorkGroupSize + testFun context Constants.Common.defaultWorkGroupSize makeTest isEqual testFun |> testPropertyWithConfig Utils.defaultConfig $"test on %A{typeof<'a>}" @@ -90,7 +90,7 @@ let makeTestInit isEqual testFun indexMap (array: ('a * 'a) []) = let createTestInit<'a> (isEqual: 'a -> 'a -> bool) testFun indexMapQ indexMap = let testFun = - testFun indexMapQ context Utils.defaultWorkGroupSize + testFun indexMapQ context Constants.Common.defaultWorkGroupSize makeTestInit isEqual testFun indexMap |> testPropertyWithConfig Utils.defaultConfig $"test on {typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs index 54dfee30..439d24f6 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs @@ -15,7 +15,7 @@ let context = Context.defaultContext.ClContext let config = Utils.defaultConfig -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let q = Context.defaultContext.Queue diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs index 1ff419ef..16a5f46b 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs @@ -63,7 +63,7 @@ let makeTest isEqual reduce reduceOp (arrayAndKeys: (int * 'a) []) = let createTestSequential<'a> (isEqual: 'a -> 'a -> bool) reduceOp reduceOpQ = let reduce = - Common.Reduce.ByKey.sequential reduceOpQ context Utils.defaultWorkGroupSize + Common.Reduce.ByKey.sequential reduceOpQ context Constants.Common.defaultWorkGroupSize makeTest isEqual reduce reduceOp |> testPropertyWithConfig config $"test on {typeof<'a>}" @@ -97,12 +97,12 @@ let sequentialTest = let createTestOneWorkGroup<'a> (isEqual: 'a -> 'a -> bool) reduceOp reduceOpQ = let reduce = - Common.Reduce.ByKey.oneWorkGroupSegments reduceOpQ context Utils.defaultWorkGroupSize + Common.Reduce.ByKey.oneWorkGroupSegments reduceOpQ context Constants.Common.defaultWorkGroupSize makeTest isEqual reduce reduceOp |> testPropertyWithConfig { config with - endSize = Utils.defaultWorkGroupSize } + endSize = Constants.Common.defaultWorkGroupSize } $"test on {typeof<'a>}" let oneWorkGroupTest = @@ -166,7 +166,7 @@ let makeTestSequentialSegments isEqual reduce reduceOp (valuesAndKeys: (int * 'a let createTestSequentialSegments<'a> (isEqual: 'a -> 'a -> bool) reduceOp reduceOpQ = let reduce = - Common.Reduce.ByKey.segmentSequential reduceOpQ context Utils.defaultWorkGroupSize + Common.Reduce.ByKey.segmentSequential reduceOpQ context Constants.Common.defaultWorkGroupSize makeTestSequentialSegments isEqual reduce reduceOp |> testPropertyWithConfig { config with startSize = 1000 } $"test on {typeof<'a>}" @@ -252,7 +252,7 @@ let makeTest2D isEqual reduce reduceOp (array: (int * int * 'a) []) = let createTestSequential2D<'a> (isEqual: 'a -> 'a -> bool) reduceOp reduceOpQ = let reduce = - Common.Reduce.ByKey2D.sequential reduceOpQ context Utils.defaultWorkGroupSize + Common.Reduce.ByKey2D.sequential reduceOpQ context Constants.Common.defaultWorkGroupSize makeTest2D isEqual reduce reduceOp |> testPropertyWithConfig @@ -331,7 +331,7 @@ let makeTestSequentialSegments2D isEqual reduce reduceOp (array: (int * int * 'a let createTestSequentialSegments2D<'a> (isEqual: 'a -> 'a -> bool) reduceOp reduceOpQ = let reduce = - Common.Reduce.ByKey2D.segmentSequential reduceOpQ context Utils.defaultWorkGroupSize + Common.Reduce.ByKey2D.segmentSequential reduceOpQ context Constants.Common.defaultWorkGroupSize makeTestSequentialSegments2D isEqual reduce reduceOp |> testPropertyWithConfig @@ -430,7 +430,7 @@ let testOption<'a> isEqual reduceOp testFun (array: (int * 'a) []) = |> checkResultOption isEqual keys values reduceOp let createTestOption (isEqual: 'a -> 'a -> bool) (reduceOpQ, reduceOp) = - Common.Reduce.ByKey.Option.segmentSequentialByOffsets reduceOpQ context Utils.defaultWorkGroupSize + Common.Reduce.ByKey.Option.segmentSequentialByOffsets reduceOpQ context Constants.Common.defaultWorkGroupSize |> testOption<'a> isEqual reduceOp |> testPropertyWithConfig { config with @@ -518,7 +518,7 @@ let test2DOption<'a> isEqual reduceOp reduce (array: (int * int * 'a) []) = |> checkResult2DOption isEqual firstKeys secondKeys values reduceOp let createTest2DOption (isEqual: 'a -> 'a -> bool) (reduceOpQ, reduceOp) = - Common.Reduce.ByKey2D.Option.segmentSequential reduceOpQ context Utils.defaultWorkGroupSize + Common.Reduce.ByKey2D.Option.segmentSequential reduceOpQ context Constants.Common.defaultWorkGroupSize |> test2DOption<'a> isEqual reduceOp |> testPropertyWithConfig { config with diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs index 1cea79dd..d48efa75 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs @@ -53,7 +53,7 @@ let createTest (zero: 'a) opAddQ opAdd isEqual deviceScan hostScan = let hostScan = hostScan zero opAdd let deviceScan = - deviceScan opAddQ zero context Utils.defaultWorkGroupSize + deviceScan opAddQ zero context Constants.Common.defaultWorkGroupSize makeTestSequentialSegments isEqual hostScan deviceScan |> testPropertyWithConfig Utils.defaultConfig $"test on {typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scatter.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scatter.fs index c1d71dca..4923ed6f 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scatter.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scatter.fs @@ -15,7 +15,7 @@ let context = defaultContext.ClContext let config = Utils.defaultConfig -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let q = defaultContext.Queue @@ -89,7 +89,7 @@ let makeTestInit<'a when 'a: equality> hostScatter valueMap scatter (positions: let createInitTest clScatter hostScatter name valuesMap valuesMapQ = let scatter = - clScatter valuesMapQ context Utils.defaultWorkGroupSize + clScatter valuesMapQ context Constants.Common.defaultWorkGroupSize makeTestInit<'a> hostScatter valuesMap scatter |> testPropertyWithConfig config name diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs index 6297fe13..d76053a8 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs @@ -17,7 +17,8 @@ module Bitonic = { Utils.defaultConfig with endSize = 1000000 } - let wgSize = Utils.defaultWorkGroupSize + let wgSize = + GraphBLAS.FSharp.Constants.Common.defaultWorkGroupSize let q = defaultContext.Queue diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs index 44206379..13f4e9fb 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs @@ -10,7 +10,8 @@ let config = { Utils.defaultConfig with startSize = 1000000 } -let workGroupSize = Utils.defaultWorkGroupSize +let workGroupSize = + GraphBLAS.FSharp.Constants.Common.defaultWorkGroupSize let processor = Context.defaultContext.Queue diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs index caa86e58..8635f07e 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs @@ -45,7 +45,7 @@ let makeTest<'a when 'a: struct> isEqual zero testFun (array: 'a [,]) = |> Expect.isFalse (Array.exists ((<<) not <| isEqual zero) array.[index, *])) let createTest isEqual (zero: 'a) = - CSR.Matrix.byRows context Utils.defaultWorkGroupSize + CSR.Matrix.byRows context Constants.Common.defaultWorkGroupSize |> makeTest<'a> isEqual zero |> testPropertyWithConfig config $"test on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Convert.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Convert.fs index 8e88e216..537a66d8 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Convert.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Convert.fs @@ -15,7 +15,7 @@ let logger = Log.create "Convert.Tests" let config = Utils.defaultConfig -let workGroupSize = Utils.defaultWorkGroupSize +let workGroupSize = Constants.Common.defaultWorkGroupSize let context = defaultContext.ClContext @@ -55,7 +55,7 @@ let makeTest context q formatFrom formatTo convertFun isZero (array: 'a [,]) = let createTest<'a when 'a: struct and 'a: equality> convertFun formatTo (isZero: 'a -> bool) = let convertFun = - convertFun context Utils.defaultWorkGroupSize + convertFun context Constants.Common.defaultWorkGroupSize Utils.listOfUnionCases |> List.map diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ExpandRows.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ExpandRows.fs index 63cd8bee..a85d0e46 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ExpandRows.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ExpandRows.fs @@ -34,7 +34,7 @@ let makeTest isZero testFun (array: 'a [,]) = |> Expect.sequenceEqual actual expected let createTest (isZero: 'a -> bool) = - CSR.Matrix.expandRowPointers context Utils.defaultWorkGroupSize + CSR.Matrix.expandRowPointers context GraphBLAS.FSharp.Constants.Common.defaultWorkGroupSize |> makeTest isZero |> testPropertyWithConfig config $"test on {typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Intersect.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Intersect.fs index 15760ada..d1137e1b 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Intersect.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Intersect.fs @@ -14,7 +14,7 @@ let config = { Utils.defaultConfig with arbitrary = [ typeof ] } -let workGroupSize = Utils.defaultWorkGroupSize +let workGroupSize = Constants.Common.defaultWorkGroupSize let context = defaultContext.ClContext let processor = defaultContext.Queue diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs index 6d0f8d01..94470fc3 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs @@ -17,7 +17,7 @@ let config = let logger = Log.create "kronecker.Tests" -let workGroupSize = Utils.defaultWorkGroupSize +let workGroupSize = Constants.Common.defaultWorkGroupSize let makeTest testContext zero isEqual op kroneckerFun (leftMatrix: 'a [,], rightMatrix: 'a [,]) = let context = testContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs index e61d65bf..d84811a1 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs @@ -17,7 +17,7 @@ open GraphBLAS.FSharp.Objects.MatrixExtensions let logger = Log.create "Map.Tests" let config = Utils.defaultConfig -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let getCorrectnessTestName case datatype = $"Correctness on %s{datatype}, %A{case}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs index 9d746f11..112e230c 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs @@ -17,7 +17,7 @@ open GraphBLAS.FSharp.Objects.ClContextExtensions let logger = Log.create "Map2.Tests" let config = Utils.defaultConfig -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let getCorrectTestName case datatype = $"Correctness on %s{datatype}, %A{case}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Merge.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Merge.fs index af7a2700..c491034e 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Merge.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Merge.fs @@ -96,7 +96,7 @@ let makeTestCOO isEqual zero testFun (leftArray: 'a [,], rightArray: 'a [,]) = checkResult isEqual zero actual leftArray rightArray let createTestCOO isEqual (zero: 'a) = - Matrix.COO.Merge.run context Utils.defaultWorkGroupSize + Matrix.COO.Merge.run context GraphBLAS.FSharp.Constants.Common.defaultWorkGroupSize |> makeTestCOO isEqual zero |> testPropertyWithConfig config $"test on {typeof<'a>}" @@ -150,7 +150,7 @@ let createTestCOODisjoint isEqual (zero: 'a) = { Utils.defaultConfig with arbitrary = [ typeof ] } - Matrix.COO.Merge.runDisjoint context Utils.defaultWorkGroupSize + Matrix.COO.Merge.runDisjoint context GraphBLAS.FSharp.Constants.Common.defaultWorkGroupSize |> makeTestCOODisjoint isEqual zero |> testPropertyWithConfig configDisjoint $"test on {typeof<'a>}" @@ -214,7 +214,7 @@ let makeTestCSR isEqual zero testFun (leftArray: 'a [,], rightArray: 'a [,]) = checkResult isEqual zero actual leftArray rightArray let createTestCSR isEqual (zero: 'a) = - Matrix.CSR.Merge.run context Utils.defaultWorkGroupSize + Matrix.CSR.Merge.run context GraphBLAS.FSharp.Constants.Common.defaultWorkGroupSize |> makeTestCSR isEqual zero |> testPropertyWithConfig config $"test on {typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/RowsLengths.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/RowsLengths.fs index f690ca3e..5b75cdd0 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/RowsLengths.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/RowsLengths.fs @@ -50,7 +50,7 @@ let makeTest isZero testFun (array: 'a [,]) = |> Utils.compareArrays (=) actual expected let createTest<'a when 'a: struct> (isZero: 'a -> bool) = - CSR.Matrix.NNZInRows context Utils.defaultWorkGroupSize + CSR.Matrix.NNZInRows context GraphBLAS.FSharp.Constants.Common.defaultWorkGroupSize |> makeTest isZero |> testPropertyWithConfig config $"test on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs index 46b1d204..2daf91fd 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs @@ -62,7 +62,7 @@ let makeTest isZero testFun (leftArray: 'a [,], rightArray: 'a [,]) = |> Expect.sequenceEqual actualPointers expectedPointers let createTest<'a when 'a: struct> (isZero: 'a -> bool) = - Expand.getSegmentPointers context Utils.defaultWorkGroupSize + Expand.getSegmentPointers context Constants.Common.defaultWorkGroupSize |> makeTest isZero |> testPropertyWithConfig config $"test on {typeof<'a>}" @@ -161,7 +161,7 @@ let makeExpandTest isEqual zero testFun (leftArray: 'a [,], rightArray: 'a [,]) |> Utils.compareArrays (=) actualRows expectedRows let createExpandTest isEqual (zero: 'a) testFun = - testFun context Utils.defaultWorkGroupSize + testFun context Constants.Common.defaultWorkGroupSize |> makeExpandTest isEqual zero |> testPropertyWithConfig config $"test on %A{typeof<'a>}" @@ -208,7 +208,7 @@ let makeGeneralTest zero isEqual opAdd opMul testFun (leftArray: 'a [,], rightAr |> Expect.isTrue (expected.NNZ = 0) let createGeneralTest (zero: 'a) isEqual (opAddQ, opAdd) (opMulQ, opMul) testFun = - testFun opAddQ opMulQ context Utils.defaultWorkGroupSize + testFun opAddQ opMulQ context Constants.Common.defaultWorkGroupSize |> makeGeneralTest zero isEqual opAdd opMul |> testPropertyWithConfig config $"test on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/ExpandCOO.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/ExpandCOO.fs index 43787eac..916c97a9 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/ExpandCOO.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/ExpandCOO.fs @@ -49,7 +49,7 @@ let makeGeneralTest zero isEqual opAdd opMul testFun (leftArray: 'a [,], rightAr |> Expect.isTrue (expected.NNZ = 0) let createGeneralTest (zero: 'a) isEqual (opAddQ, opAdd) (opMulQ, opMul) testFun = - testFun opAddQ opMulQ context Utils.defaultWorkGroupSize + testFun opAddQ opMulQ context Constants.Common.defaultWorkGroupSize |> makeGeneralTest zero isEqual opAdd opMul |> testPropertyWithConfig config $"test on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Masked.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Masked.fs index 18cc44c4..e5a1e826 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Masked.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Masked.fs @@ -12,7 +12,7 @@ open GraphBLAS.FSharp.Tests.Context let logger = Log.create "SpGeMM.Masked.Tests" let context = defaultContext.ClContext -let workGroupSize = Utils.defaultWorkGroupSize +let workGroupSize = Constants.Common.defaultWorkGroupSize let makeTest context q zero isEqual plus mul mxmFun (leftMatrix: 'a [,], rightMatrix: 'a [,], mask: bool [,]) = diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs index 9a9ae54c..38898186 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs @@ -51,7 +51,7 @@ let makeTest isEqual zero testFun (array: 'a [,], sourceRow, count) = Utils.compareCOOMatrix isEqual actual expected let createTest isEqual (zero: 'a) = - CSR.Matrix.subRows context Utils.defaultWorkGroupSize + CSR.Matrix.subRows context GraphBLAS.FSharp.Constants.Common.defaultWorkGroupSize |> makeTest isEqual zero |> testPropertyWithConfig config $"test on {typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Transpose.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Transpose.fs index e7308335..d6b9cfe9 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Transpose.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Transpose.fs @@ -14,7 +14,7 @@ let logger = Log.create "Transpose.Tests" let config = Utils.defaultConfig -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let getCorrectnessTestName case datatype = $"Correctness on %s{datatype}, %A{case.Format}, %A{case.TestContext}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/AssignByMask.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/AssignByMask.fs index 3c0fb675..5d40ca00 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/AssignByMask.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/AssignByMask.fs @@ -16,7 +16,7 @@ let logger = Log.create "Vector.assignByMask.Tests" let config = Utils.defaultConfig -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let getCorrectnessTestName case datatype = $"Correctness on %s{datatype}, vector: %A{case.Format}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Convert.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Convert.fs index d184bc47..ac9073f9 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Convert.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Convert.fs @@ -16,7 +16,7 @@ let logger = let config = Utils.defaultConfig -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let makeTest formatFrom diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs index a83a1f3f..3910ddcd 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs @@ -14,7 +14,7 @@ let logger = Log.create "Vector.copy.Tests" let config = Utils.defaultConfig -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let checkResult (isEqual: 'a -> 'a -> bool) (actual: Vector<'a>) (expected: Vector<'a>) = Expect.equal actual.Size expected.Size "The size should be the same" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map.fs index c3cfeab7..25fed6a3 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map.fs @@ -18,7 +18,7 @@ open Mono.CompilerServices.SymbolWriter let logger = Log.create "Vector.Map.Tests" let config = Utils.defaultConfig -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let getCorrectnessTestName case datatype = $"Correctness on %s{datatype}, %A{case}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs index 771798c7..0ef5a5dc 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs @@ -15,7 +15,7 @@ let logger = Log.create "Vector.ElementWise.Tests" let config = Utils.defaultConfig -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let getCorrectnessTestName<'a> (case: OperationCase<'a>) dataType = $"Correctness on '{dataType} option -> '{dataType} option -> '{dataType} option, {case.Format}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Merge.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Merge.fs index ae363e78..a1afec05 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Merge.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Merge.fs @@ -76,7 +76,7 @@ let makeTest isEqual zero testFun (firstArray: 'a []) (secondArray: 'a []) = |> Utils.compareArrays (=) actualIndices expectedIndices let createTest<'a when 'a: struct> isEqual (zero: 'a) = - Vector.Sparse.Merge.run context Utils.defaultWorkGroupSize + Vector.Sparse.Merge.run context Constants.Common.defaultWorkGroupSize |> makeTest isEqual zero |> testPropertyWithConfig config $"test on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/OfList.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/OfList.fs index 9623073f..436aba91 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/OfList.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/OfList.fs @@ -15,7 +15,7 @@ let logger = Log.create "Vector.ofList.Tests" let config = Utils.defaultConfig -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let checkResult (isEqual: 'a -> 'a -> bool) diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Reduce.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Reduce.fs index 7775d541..00e157bf 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Reduce.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Reduce.fs @@ -11,7 +11,7 @@ open GraphBLAS.FSharp.Objects.ClCellExtensions let logger = Log.create "Vector.reduce.Tests" -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let config = Utils.defaultConfig diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMSpV.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMSpV.fs index c554b25e..f4195db7 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMSpV.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMSpV.fs @@ -13,7 +13,7 @@ open GraphBLAS.FSharp.Objects let config = Utils.defaultConfig -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let checkResult sumOp diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs index 45ab8054..b4688fa4 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs @@ -15,7 +15,7 @@ open GraphBLAS.FSharp.Backend.Quotes let config = Utils.defaultConfig -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let checkResult isEqual sumOp mulOp zero (baseMtx: 'a [,]) (baseVtr: 'a []) (actual: 'a option []) = let rows = Array2D.length1 baseMtx diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs index ea738e61..cccfa3d7 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs @@ -15,7 +15,7 @@ let logger = Log.create "Vector.zeroCreate.Tests" let config = Utils.defaultConfig -let wgSize = Utils.defaultWorkGroupSize +let wgSize = Constants.Common.defaultWorkGroupSize let checkResult size (actual: Vector<'a>) = Expect.equal actual.Size size "The size should be the same" diff --git a/tests/GraphBLAS-sharp.Tests/Helpers.fs b/tests/GraphBLAS-sharp.Tests/Helpers.fs index 38ce1ff2..947287bc 100644 --- a/tests/GraphBLAS-sharp.Tests/Helpers.fs +++ b/tests/GraphBLAS-sharp.Tests/Helpers.fs @@ -11,7 +11,6 @@ open OpenCL.Net [] module Utils = - let defaultWorkGroupSize = 32 let defaultConfig = { FsCheckConfig.defaultConfig with From 0ab7361197e4acb2cfc2ed0b71484cb4d4d0619b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=93=D0=B0=D1=80?= =?UTF-8?q?=D0=B1=D0=B0=D1=80?= Date: Fri, 22 Dec 2023 23:12:48 +0300 Subject: [PATCH 09/12] MailboxProcessor extensions --- .../GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs | 9 +++++---- .../Algorithms/PageRank.fs | 9 +++++---- .../GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs | 9 +++++---- .../Matrix/SpGeMM/Expand.fs | 7 ++++--- .../Matrix/SpGeMM/Masked.fs | 13 +++++++------ .../GraphBLAS-sharp.Benchmarks/Vector/Map2.fs | 7 ++++--- .../GraphBLAS-sharp.Backend.fsproj | 3 ++- .../Objects/ArraysExtentions.fs | 3 ++- .../Objects/MailboxProcessorExtensions.fs | 6 ++++++ src/GraphBLAS-sharp.Backend/Objects/Matrix.fs | 7 ++++--- 10 files changed, 44 insertions(+), 29 deletions(-) create mode 100644 src/GraphBLAS-sharp.Backend/Objects/MailboxProcessorExtensions.fs diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs index 9cb5ab3d..c8b6c21c 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs @@ -9,6 +9,7 @@ open GraphBLAS.FSharp.IO open GraphBLAS.FSharp.Benchmarks open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions open GraphBLAS.FSharp.Backend.Quotes [] @@ -113,12 +114,12 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>( override this.GlobalSetup() = this.ReadMatrix() this.LoadMatrixToGPU() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.IterationCleanup() = this.ClearResult() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.GlobalCleanup() = @@ -182,7 +183,7 @@ type WithTransferBenchmark<'elem when 'elem : struct>( [] override this.GlobalSetup() = this.ReadMatrix() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.GlobalCleanup() = @@ -192,7 +193,7 @@ type WithTransferBenchmark<'elem when 'elem : struct>( override this.IterationCleanup() = this.ClearInputMatrix() this.ClearResult() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.Benchmark() = diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs index 16cfacb5..c00c5f70 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs @@ -7,6 +7,7 @@ open GraphBLAS.FSharp.IO open Brahma.FSharp open Microsoft.FSharp.Core open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions open GraphBLAS.FSharp.Benchmarks open GraphBLAS.FSharp.Objects @@ -112,15 +113,15 @@ type PageRankWithoutTransferBenchmarkFloat32() = override this.GlobalSetup() = this.ReadMatrix() this.LoadMatrixToGPU() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor this.PrepareMatrix() this.ClearInputMatrix() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.IterationCleanup() = this.ClearResult() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.GlobalCleanup() = @@ -129,4 +130,4 @@ type PageRankWithoutTransferBenchmarkFloat32() = [] override this.Benchmark() = this.PageRank() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs index bcd04eb8..190369f5 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs @@ -8,6 +8,7 @@ open GraphBLAS.FSharp.IO open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.MatrixExtensions open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Benchmarks @@ -118,12 +119,12 @@ module WithoutTransfer = override this.GlobalSetup() = this.ReadMatrices () this.LoadMatricesToGPU () - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.Benchmark () = this.EWiseAddition() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.IterationCleanup () = @@ -251,7 +252,7 @@ module WithTransfer = [] override this.GlobalSetup() = this.ReadMatrices() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.GlobalCleanup() = () @@ -260,7 +261,7 @@ module WithTransfer = override this.IterationCleanup() = this.ClearInputMatrices() this.ClearResult() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.Benchmark() = diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs index 88e91cb6..d379739c 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs @@ -8,6 +8,7 @@ open GraphBLAS.FSharp.IO open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions open GraphBLAS.FSharp.Benchmarks [] @@ -115,17 +116,17 @@ module WithoutTransfer = override this.GlobalSetup() = this.ReadMatrices() this.LoadMatricesToGPU() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.Benchmark() = this.Mxm() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.IterationCleanup () = this.ClearResult() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.GlobalCleanup () = diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs index fcbd13f8..18ff0b22 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs @@ -8,6 +8,7 @@ open Brahma.FSharp open GraphBLAS.FSharp open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions open GraphBLAS.FSharp.Benchmarks [] @@ -152,17 +153,17 @@ type MxmBenchmarksMultiplicationOnly<'elem when 'elem : struct>( this.ReadMatrices () this.LoadMatricesToGPU () this.ConvertSecondMatrixToCSC() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.Benchmark () = this.Mxm() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.IterationCleanup () = this.ClearResult() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.GlobalCleanup () = @@ -184,20 +185,20 @@ type MxmBenchmarksWithTransposing<'elem when 'elem : struct>( override this.GlobalSetup() = this.ReadMatrices() this.LoadMatricesToGPU () - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.Benchmark() = this.ConvertSecondMatrixToCSC() this.Mxm() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.IterationCleanup() = this.ClearResult() this.ConvertSecondMatrixToCSR() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.GlobalCleanup() = diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs index c3e566eb..9d78980b 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs @@ -10,6 +10,7 @@ open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions [] [] @@ -115,7 +116,7 @@ module WithoutTransfer = override this.IterationCleanup() = this.ClearResult() this.ClearInputVectors() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.GlobalCleanup() = () @@ -160,7 +161,7 @@ module WithTransfer = [] override this.IterationSetup() = this.CreateVectors() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.Benchmark () = @@ -177,7 +178,7 @@ module WithTransfer = override this.IterationCleanup () = this.ClearInputVectors() this.ClearResult() - this.Processor.PostAndReply(Msg.MsgNotifyMe) + finish this.Processor [] override this.GlobalCleanup() = () diff --git a/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj b/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj index c2e1e085..cac6456d 100644 --- a/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj +++ b/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj @@ -1,4 +1,4 @@ - + @@ -13,6 +13,7 @@ + diff --git a/src/GraphBLAS-sharp.Backend/Objects/ArraysExtentions.fs b/src/GraphBLAS-sharp.Backend/Objects/ArraysExtentions.fs index 5f5da3ae..c4176b66 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/ArraysExtentions.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/ArraysExtentions.fs @@ -1,12 +1,13 @@ namespace GraphBLAS.FSharp.Objects open Brahma.FSharp +open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions module ArraysExtensions = type ClArray<'a> with member this.FreeAndWait(q: MailboxProcessor) = q.Post(Msg.CreateFreeMsg this) - q.PostAndReply(Msg.MsgNotifyMe) + finish q member this.ToHost(q: MailboxProcessor) = let dst = Array.zeroCreate this.Length diff --git a/src/GraphBLAS-sharp.Backend/Objects/MailboxProcessorExtensions.fs b/src/GraphBLAS-sharp.Backend/Objects/MailboxProcessorExtensions.fs new file mode 100644 index 00000000..fb56045c --- /dev/null +++ b/src/GraphBLAS-sharp.Backend/Objects/MailboxProcessorExtensions.fs @@ -0,0 +1,6 @@ +namespace GraphBLAS.FSharp.Objects + +open Brahma.FSharp + +module MailboxProcessorExtensions = + let finish (q: MailboxProcessor) = q.PostAndReply(Msg.MsgNotifyMe) diff --git a/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs b/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs index 766925aa..901cb6c3 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs @@ -2,6 +2,7 @@ namespace GraphBLAS.FSharp.Objects open Brahma.FSharp open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions type MatrixFormat = | CSR @@ -49,7 +50,7 @@ module ClMatrix = q.Post(Msg.CreateFreeMsg<_>(this.Values)) q.Post(Msg.CreateFreeMsg<_>(this.Rows)) q.Post(Msg.CreateFreeMsg<_>(this.ColumnPointers)) - q.PostAndReply(Msg.MsgNotifyMe) + finish q member this.Dispose q = (this :> IDeviceMemObject).Dispose q @@ -76,7 +77,7 @@ module ClMatrix = q.Post(Msg.CreateFreeMsg<_>(this.Values)) q.Post(Msg.CreateFreeMsg<_>(this.Columns)) q.Post(Msg.CreateFreeMsg<_>(this.Rows)) - q.PostAndReply(Msg.MsgNotifyMe) + finish q member this.Dispose q = (this :> IDeviceMemObject).Dispose q @@ -114,7 +115,7 @@ module ClMatrix = q.Post(Msg.CreateFreeMsg<_>(this.RowIndices)) q.Post(Msg.CreateFreeMsg<_>(this.ColumnIndices)) q.Post(Msg.CreateFreeMsg<_>(this.Values)) - q.PostAndReply(Msg.MsgNotifyMe) + finish q member this.Dispose q = (this :> IDeviceMemObject).Dispose q From 97b6db49639c5acc23566a5818c74f91e17281c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=93=D0=B0=D1=80?= =?UTF-8?q?=D0=B1=D0=B0=D1=80?= Date: Fri, 22 Dec 2023 23:18:28 +0300 Subject: [PATCH 10/12] Module qualifiers --- src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs | 1 + src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fsi | 1 + src/GraphBLAS-sharp.Backend/Algorithms/SSSP.fs | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs b/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs index b82e08b5..fadd389e 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs @@ -11,6 +11,7 @@ open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.ArraysExtensions open GraphBLAS.FSharp.Objects.ClCellExtensions +[] module PageRank = type PageRankMatrix = | PreparedMatrix of ClMatrix diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fsi b/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fsi index 230cd28d..290f6a1f 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fsi +++ b/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fsi @@ -3,6 +3,7 @@ namespace GraphBLAS.FSharp.Backend.Algorithms open Brahma.FSharp open GraphBLAS.FSharp.Objects +[] module PageRank = [] type PageRankMatrix = diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/SSSP.fs b/src/GraphBLAS-sharp.Backend/Algorithms/SSSP.fs index 05e14f33..489a796c 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/SSSP.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/SSSP.fs @@ -7,7 +7,7 @@ open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.ClCellExtensions -module SSSP = +module internal SSSP = let run (clContext: ClContext) workGroupSize = let less = ArithmeticOperations.less From f671a2e89ff4efedcf5aa620e3e56dbc86c6e6fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=93=D0=B0=D1=80?= =?UTF-8?q?=D0=B1=D0=B0=D1=80?= Date: Sat, 23 Dec 2023 21:20:02 +0300 Subject: [PATCH 11/12] Add pagerank link --- src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs b/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs index fadd389e..eecff073 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs @@ -140,6 +140,7 @@ module PageRank = |> PreparedMatrix | _ -> failwith "Not implemented" + // PageRank algorithm explanation: pi.math.cornell.edu/~mec/Winter2009/RalucaRemus/Lecture3/lecture3 let internal run (clContext: ClContext) workGroupSize = let squareOfDifference = ArithmeticOperations.squareOfDifference From 6de410fcb81971567724d4b58cf22d79b542256f Mon Sep 17 00:00:00 2001 From: Kirill <71129570+kirillgarbar@users.noreply.github.com> Date: Sat, 24 Feb 2024 11:07:11 +0300 Subject: [PATCH 12/12] Restart CI attempt --- benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs index c8b6c21c..c34492dc 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs @@ -13,8 +13,8 @@ open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions open GraphBLAS.FSharp.Backend.Quotes [] -[] -[] +[] +[] [)>] type Benchmarks<'elem when 'elem : struct>( buildFunToBenchmark,