From 0c5db3fac486029dabced77c52735a919534526e Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Tue, 18 Jul 2023 12:17:55 +0700 Subject: [PATCH 01/22] refactor: comments; common api --- .../Matrix/Map2/Map2.fs | 2 +- .../Matrix/SpGeMM/Expand.fs | 2 +- .../Matrix/SpGeMM/Masked.fs | 2 +- .../GraphBLAS-sharp.Benchmarks/Vector/Map2.fs | 2 +- src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs | 4 +- src/GraphBLAS-sharp.Backend/Common/ClArray.fs | 139 +++++++- src/GraphBLAS-sharp.Backend/Common/Common.fs | 326 ++++++++++++++++++ src/GraphBLAS-sharp.Backend/Common/Gather.fs | 11 - src/GraphBLAS-sharp.Backend/Common/Merge.fs | 2 +- .../Common/PrefixSum.fs | 62 +--- src/GraphBLAS-sharp.Backend/Common/Scatter.fs | 74 ---- .../Common/Sort/Radix.fs | 6 +- src/GraphBLAS-sharp.Backend/Common/Sum.fs | 83 +---- .../GraphBLAS-sharp.Backend.fsproj | 12 +- src/GraphBLAS-sharp.Backend/Matrix/COO/Map.fs | 6 +- .../Matrix/COO/Map2.fs | 2 +- .../Matrix/COO/Matrix.fs | 7 +- .../Matrix/COO/Merge.fs | 2 +- .../Matrix/CSR/Kronecker.fs | 4 +- src/GraphBLAS-sharp.Backend/Matrix/CSR/Map.fs | 8 +- .../Matrix/CSR/Map2.fs | 2 +- .../Matrix/CSR/Matrix.fs | 2 +- .../Matrix/CSR/Merge.fs | 2 +- src/GraphBLAS-sharp.Backend/Matrix/Common.fs | 4 +- .../Matrix/LIL/Matrix.fs | 2 +- src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs | 97 +++++- .../Matrix/SpGeMM/Expand.fs | 4 +- .../Matrix/SpGeMM/Masked.fs | 4 +- .../{ClCell.fs => ClCellExtensions.fs} | 2 +- .../Objects/ClContextExtensions.fs | 2 +- .../Quotes/PreparePositions.fs | 2 +- .../Vector/Dense/Vector.fs | 19 +- src/GraphBLAS-sharp.Backend/Vector/SpMV.fs | 2 +- .../Vector/Sparse/Common.fs | 4 +- .../Vector/Sparse/Map.fs | 95 ++++- .../Vector/Sparse/Map2.fs | 2 +- .../Vector/Sparse/Merge.fs | 2 +- .../Vector/Sparse/Vector.fs | 2 + src/GraphBLAS-sharp.Backend/Vector/Vector.fs | 102 +++++- .../Backend/Common/ClArray/Choose.fs | 2 +- .../Backend/Common/ClArray/ChunkBySize.fs | 2 +- .../Backend/Common/ClArray/Concat.fs | 2 +- .../Backend/Common/ClArray/Copy.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 | 2 +- .../Backend/Common/ClArray/Map2.fs | 2 +- .../Backend/Common/ClArray/Pairwise.fs | 2 +- .../Backend/Common/ClArray/Replicate.fs | 2 +- .../Backend/Common/ClArray/UpperBound.fs | 2 +- .../Backend/Common/Gather.fs | 2 +- .../Backend/Common/Reduce/Reduce.fs | 2 +- .../Backend/Common/Reduce/ReduceByKey.fs | 2 +- .../Backend/Common/Reduce/Sum.fs | 2 +- .../Backend/Common/Scan/ByKey.fs | 2 +- .../Backend/Common/Scan/PrefixSum.fs | 2 +- .../Backend/Common/Sort/Radix.fs | 2 +- .../Backend/Matrix/ByRows.fs | 2 +- .../Backend/Matrix/Convert.fs | 2 +- .../Backend/Matrix/ExpandRows.fs | 2 +- .../Backend/Matrix/Kronecker.fs | 2 +- .../Backend/Matrix/Map.fs | 2 +- .../Backend/Matrix/Map2.fs | 38 +- .../Backend/Matrix/RowsLengths.fs | 2 +- .../Backend/Matrix/SpGeMM/Expand.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/Map2.fs | 2 +- .../Backend/Vector/OfList.fs | 2 +- .../Backend/Vector/Reduce.fs | 2 +- .../Backend/Vector/SpMV.fs | 2 +- .../Backend/Vector/ZeroCreate.fs | 2 +- 76 files changed, 847 insertions(+), 370 deletions(-) create mode 100644 src/GraphBLAS-sharp.Backend/Common/Common.fs rename src/GraphBLAS-sharp.Backend/Objects/{ClCell.fs => ClCellExtensions.fs} (95%) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs index 2e2582f1..02dddc3e 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs @@ -8,7 +8,7 @@ open Brahma.FSharp open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Objects.MatrixExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Benchmarks diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs index 0a7193e7..184bee28 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs @@ -8,7 +8,7 @@ open Brahma.FSharp open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Benchmarks open GraphBLAS.FSharp.Backend diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs index 2a164021..d1c16cb9 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs @@ -8,7 +8,7 @@ open Brahma.FSharp open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Benchmarks open GraphBLAS.FSharp.Backend diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs index 523f5185..7db34de2 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs @@ -11,7 +11,7 @@ open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions open GraphBLAS.FSharp.Backend.Vector -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions [] [] diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs b/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs index 9896a557..6f9cb430 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs @@ -8,9 +8,9 @@ open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Backend.Vector open GraphBLAS.FSharp.Backend.Vector.Dense -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions module BFS = let singleSource diff --git a/src/GraphBLAS-sharp.Backend/Common/ClArray.fs b/src/GraphBLAS-sharp.Backend/Common/ClArray.fs index d048c650..3cd69406 100644 --- a/src/GraphBLAS-sharp.Backend/Common/ClArray.fs +++ b/src/GraphBLAS-sharp.Backend/Common/ClArray.fs @@ -1,15 +1,20 @@ namespace GraphBLAS.FSharp.Backend.Common -open System.Collections.Generic open Brahma.FSharp open Microsoft.FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects.ClContext -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Quotes module ClArray = + /// + /// Creates an array given the dimension and a generator function to compute the elements. + /// + /// The function to generate the initial values for each index. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let init (initializer: Expr 'a>) (clContext: ClContext) workGroupSize = let init = @@ -36,6 +41,11 @@ module ClArray = outputArray + /// + /// Creates an array whose elements are all initially the given value. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let create (clContext: ClContext) workGroupSize = let create = @@ -65,6 +75,11 @@ module ClArray = outputArray + /// + /// Creates an array where the entries are initially the default value of desired type. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let zeroCreate<'a> (clContext: ClContext) workGroupSize = let create = create clContext workGroupSize @@ -72,6 +87,11 @@ module ClArray = fun (processor: MailboxProcessor<_>) allocationMode length -> create processor allocationMode length Unchecked.defaultof<'a> + /// + /// Builds a new array that contains the elements of the given array. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let copy (clContext: ClContext) workGroupSize = let copy = <@ fun (ndRange: Range1D) (inputArrayBuffer: ClArray<'a>) (outputArrayBuffer: ClArray<'a>) inputArrayLength -> @@ -100,6 +120,11 @@ module ClArray = outputArray + /// + /// Creates an array of the given size by replicating the values of the given initial array. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let replicate (clContext: ClContext) workGroupSize = let replicate = @@ -132,6 +157,13 @@ module ClArray = outputArray + /// + /// Builds a new array whose elements are the results of applying the given function + /// to each of the elements of the array. + /// + /// The function to transform elements of the array. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let map<'a, 'b> (op: Expr<'a -> 'b>) (clContext: ClContext) workGroupSize = let map = @@ -160,6 +192,14 @@ module ClArray = result + /// + /// Builds a new array whose elements are the results of applying the given function + /// to the corresponding pairs of values, where the first element of pair is from the given array + /// and the second element is the given value. + /// + /// The function to transform elements of the array. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let mapWithValue<'a, 'b, 'c> (clContext: ClContext) workGroupSize (op: Expr<'a -> 'b -> 'c>) = let map = @@ -192,6 +232,16 @@ module ClArray = result + /// + /// Fills the third given array with the results of applying the given function + /// to the corresponding elements of the first two given arrays pairwise. + /// + /// + /// The first two input arrays must have the same lengths. + /// + /// The function to transform the pairs of the input elements. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let map2InPlace<'a, 'b, 'c> (map: Expr<'a -> 'b -> 'c>) (clContext: ClContext) workGroupSize = let kernel = @@ -219,6 +269,16 @@ module ClArray = processor.Post(Msg.CreateRunMsg<_, _>(kernel)) + /// + /// Builds a new array whose elements are the results of applying the given function + /// to the corresponding elements of the two given arrays pairwise. + /// + /// + /// The two input arrays must have the same lengths. + /// + /// The function to transform the pairs of the input elements. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let map2<'a, 'b, 'c> map (clContext: ClContext) workGroupSize = let map2 = map2InPlace<'a, 'b, 'c> map clContext workGroupSize @@ -306,10 +366,12 @@ module ClArray = let lastOccurrence2 clContext = getUniqueBitmap2General lastOccurrence clContext - ///Remove duplicates form the given array. - ///Computational context - ///Should be a power of 2 and greater than 1. - ///Should be sorted. + /// + /// Removes duplicates form the given array. + /// + /// Computational context + /// Should be a power of 2 and greater than 1. + /// Should be sorted. let removeDuplications (clContext: ClContext) workGroupSize = let scatter = @@ -339,6 +401,12 @@ module ClArray = outputArray + /// + /// Tests if any element of the array satisfies the given predicate. + /// + /// The function to test the input elements. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let exists (predicate: Expr<'a -> bool>) (clContext: ClContext) workGroupSize = let exists = @@ -368,7 +436,7 @@ module ClArray = result - let assignOption (op: Expr<'a -> 'b option>) (clContext: ClContext) workGroupSize = + let private assignOption (op: Expr<'a -> 'b option>) (clContext: ClContext) workGroupSize = let assign = <@ fun (ndRange: Range1D) length (values: ClArray<'a>) (positions: ClArray) (result: ClArray<'b>) resultLength -> @@ -404,6 +472,13 @@ module ClArray = processor.Post(Msg.CreateRunMsg<_, _>(kernel)) + /// + /// Applies the given function to each element of the array. + /// Returns the array comprised of the results x for each element where the function returns Some(x). + /// + /// The function to generate options from the elements. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let choose<'a, 'b> (predicate: Expr<'a -> 'b option>) (clContext: ClContext) workGroupSize = let getBitmap = map<'a, int> (Map.chooseBitmap predicate) clContext workGroupSize @@ -510,6 +585,11 @@ module ClArray = result + /// + /// Builds a new array that contains the given subrange specified by starting index and length. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let sub (clContext: ClContext) workGroupSize = let kernel = @@ -549,10 +629,10 @@ module ClArray = result /// - /// Lazy divides the input array into chunks of size at most chunkSize. + /// Divides lazily the input array into chunks of size at most chunkSize. /// - /// Cl context. - /// Work group size. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. /// /// Since calculations are performed lazily, the array should not change. /// @@ -581,8 +661,8 @@ module ClArray = /// /// Divides the input array into chunks of size at most chunkSize. /// - /// Cl context. - /// Work group size. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let chunkBySize (clContext: ClContext) workGroupSize = let chunkBySizeLazy = lazyChunkBySize clContext workGroupSize @@ -592,6 +672,11 @@ module ClArray = |> Seq.map (fun lazyValue -> lazyValue.Value) |> Seq.toArray + /// + /// Reads a range of elements from the first array and write them into the second. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let blit<'a> (clContext: ClContext) workGroupSize = let assign = @@ -635,6 +720,11 @@ module ClArray = processor.Post(Msg.CreateRunMsg<_, _>(kernel)) + /// + /// Builds a new array that contains the elements of each of the given sequence of arrays. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let concat (clContext: ClContext) workGroupSize = let blit = blit clContext workGroupSize @@ -659,6 +749,11 @@ module ClArray = result + /// + /// Fills a range of elements of the array with the given value. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let fill (clContext: ClContext) workGroupSize = let fill = @@ -693,6 +788,12 @@ module ClArray = processor.Post(Msg.CreateRunMsg<_, _>(kernel)) + /// + /// Returns an array of each element in the input array and its predecessor, + /// with the exception of the first element which is only returned as the predecessor of the second element. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let pairwise (clContext: ClContext) workGroupSize = let idGather = @@ -765,6 +866,11 @@ module ClArray = let upperBound<'a when 'a: comparison> clContext = bound<'a, int> Search.Bin.lowerBound clContext + /// + /// Gets the value at the specified position from the input array. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let item<'a> (clContext: ClContext) workGroupSize = let kernel = @@ -794,6 +900,11 @@ module ClArray = result + /// + /// Sets an element of an array. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let set<'a> (clContext: ClContext) workGroupSize = let kernel = diff --git a/src/GraphBLAS-sharp.Backend/Common/Common.fs b/src/GraphBLAS-sharp.Backend/Common/Common.fs new file mode 100644 index 00000000..2cc84c31 --- /dev/null +++ b/src/GraphBLAS-sharp.Backend/Common/Common.fs @@ -0,0 +1,326 @@ +namespace GraphBLAS.FSharp.Backend.Common + +open Brahma.FSharp +open GraphBLAS.FSharp.Backend.Common +open Microsoft.FSharp.Quotations + +module Common = + module Gather = + /// + /// Fills the given output array using the given value array and a function. The function maps old position + /// of each element of the value array to its position in the output array. + /// + /// + /// If index is out of bounds, the value will be ignored. + /// + /// + /// + /// let positions = [| 1; 0; 2; 6; 4; 3; 5 |] + /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; |] + /// run clContext 32 processor positions values result + /// ... + /// > val result = [| 2.8; 1.9; 3.7; 7.3; 5.5; 4.6; 6.4 |] + /// + /// + let runInit positionMap (clContext: ClContext) workGroupSize = Gather.runInit positionMap clContext workGroupSize + + /// + /// Fills the given output array using the given value and position arrays. Array of positions indicates + /// which element from the value array should be in each position of the output array. + /// + /// + /// If index is out of bounds, the value will be ignored. + /// + /// + /// + /// let positions = [| 1; 0; 2; 6; 4; 3; 5 |] + /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; |] + /// run clContext 32 processor positions values result + /// ... + /// > val result = [| 2.8; 1.9; 3.7; 7.3; 5.5; 4.6; 6.4 |] + /// + /// + let run (clContext: ClContext) workGroupSize = Gather.run clContext workGroupSize + + module Scatter = + /// + /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array + /// should be a value from the given one. + /// + /// + /// Every element of the positions array must not be less than the previous one. + /// If there are several elements with the same indices, the FIRST one of them will be at the common index. + /// If index is out of bounds, the value will be ignored. + /// + /// + /// + /// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |] + /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; 8.2; 9.1 |] + /// run clContext 32 processor positions values result + /// ... + /// > val result = [| 1,9; 3.7; 6.4; 7.3; 9.1 |] + /// + /// + let firstOccurence clContext = Scatter.firstOccurrence clContext + + /// + /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array + /// should be a value from the given one. + /// + /// + /// Every element of the positions array must not be less than the previous one. + /// If there are several elements with the same indices, the LAST one of them will be at the common index. + /// If index is out of bounds, the value will be ignored. + /// + /// + /// + /// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |] + /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; 8.2; 9.1 |] + /// run clContext 32 processor positions values result + /// ... + /// > val result = [| 2.8; 5.5; 6.4; 8.2; 9.1 |] + /// + /// + let lastOccurence clContext = Scatter.lastOccurrence clContext + + /// + /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array + /// should be a values obtained by applying the mapping to the global id. + /// + /// + /// Every element of the positions array must not be less than the previous one. + /// If there are several elements with the same indices, the FIRST one of them will be at the common index. + /// If index is out of bounds, the value will be ignored. + /// + /// + /// + /// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |] + /// let valueMap = id + /// run clContext 32 processor positions values result + /// ... + /// > val result = [| 0; 2; 5; 6; 8 |] + /// + /// + /// Maps global id to a value + let initFirstOccurence valueMap = Scatter.initFirsOccurrence valueMap + + /// + /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array + /// should be a values obtained by applying the mapping to the global id. + /// + /// + /// Every element of the positions array must not be less than the previous one. + /// If there are several elements with the same indices, the LAST one of them will be at the common index. + /// If index is out of bounds, the value will be ignored. + /// + /// + /// + /// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |] + /// let valueMap = id + /// run clContext 32 processor positions values result + /// ... + /// > val result = [| 1; 4; 5; 7; 8 |] + /// + /// + /// Maps global id to a value + let initLastOccurrence valueMap = Scatter.initLastOccurrence valueMap + + module PrefixSum = + let runExcludeInPlace plus = PrefixSum.runExcludeInPlace plus + + let runIncludeInPlace plus = PrefixSum.runIncludeInPlace plus + + let runBackwardsExcludeInPlace plus = PrefixSum.runBackwardsExcludeInPlace plus + + let runBackwardsIncludeInPlace plus = PrefixSum.runBackwardsIncludeInPlace plus + + /// + /// Exclude inplace prefix sum. + /// + /// + /// + /// let arr = [| 1; 1; 1; 1 |] + /// let sum = [| 0 |] + /// runExcludeInplace clContext workGroupSize processor arr sum (+) 0 + /// |> ignore + /// ... + /// > val arr = [| 0; 1; 2; 3 |] + /// > val sum = [| 4 |] + /// + /// + ///ClContext. + ///Should be a power of 2 and greater than 1. + ///Associative binary operation. + ///Zero element for binary operation. + let standardExcludeInPlace (clContext: ClContext) workGroupSize = + + let scan = + runExcludeInPlace <@ (+) @> clContext workGroupSize + + fun (processor: MailboxProcessor<_>) (inputArray: ClArray) -> + + scan processor inputArray 0 + + /// + /// Include inplace prefix sum. + /// + /// + /// + /// let arr = [| 1; 1; 1; 1 |] + /// let sum = [| 0 |] + /// runExcludeInplace clContext workGroupSize processor arr sum (+) 0 + /// |> ignore + /// ... + /// > val arr = [| 1; 2; 3; 4 |] + /// > val sum = [| 4 |] + /// + /// + ///ClContext. + ///Should be a power of 2 and greater than 1. + ///Associative binary operation. + ///Zero element for binary operation. + let standardIncludeInPlace (clContext: ClContext) workGroupSize = + + let scan = + runIncludeInPlace <@ (+) @> clContext workGroupSize + + fun (processor: MailboxProcessor<_>) (inputArray: ClArray) -> + + scan processor inputArray 0 + + module ByKey = + /// + /// Exclude scan by key. + /// + /// + /// + /// let arr = [| 1; 1; 1; 1; 1; 1|] + /// let keys = [| 1; 2; 2; 2; 3; 3 |] + /// ... + /// > val result = [| 0; 0; 1; 2; 0; 1 |] + /// + /// + let sequentialExclude op = PrefixSum.ByKey.sequentialExclude op + + /// + /// Include scan by key. + /// + /// + /// + /// let arr = [| 1; 1; 1; 1; 1; 1|] + /// let keys = [| 1; 2; 2; 2; 3; 3 |] + /// ... + /// > val result = [| 1; 1; 2; 3; 1; 2 |] + /// + /// + let sequentialInclude op = PrefixSum.ByKey.sequentialInclude op + + module Reduce = + /// + /// Summarizes array elements. + /// + /// ClContext. + /// Work group size. + /// Summation operation. + /// Neutral element for summation. + let sum op zero (clContext: ClContext) workGroupSize = Reduce.sum op zero clContext workGroupSize + + /// + /// Reduces an array of values. + /// + /// ClContext. + /// Work group size. + /// Reduction operation. + let reduce op (clContext: ClContext) workGroupSize = Reduce.reduce op clContext workGroupSize + + /// + /// Reduction of an array of values by an array of keys. + /// + module ByKey = + /// + /// Reduces an array of values by key using a single work item. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// The length of the result must be calculated in advance. + /// + let sequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = + Reduce.ByKey.sequential reduceOp clContext workGroupSize + + /// + /// Reduces values by key. Each segment is reduced by one work item. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// The length of the result must be calculated in advance. + /// + let segmentSequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = + Reduce.ByKey.segmentSequential reduceOp clContext workGroupSize + + /// + /// Reduces values by key. One work group participates in the reduction. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// Reduces an array of values that does not exceed the size of the workgroup. + /// The length of the result must be calculated in advance. + /// + let oneWorkGroupSegments (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = + Reduce.ByKey.oneWorkGroupSegments reduceOp clContext workGroupSize + + module Option = + /// + /// Reduces values by key. Each segment is reduced by one work item. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// The length of the result must be calculated in advance. + /// + let segmentSequential<'a> (reduceOp: Expr<'a -> 'a -> 'a option>) (clContext: ClContext) workGroupSize = + Reduce.ByKey.Option.segmentSequential reduceOp clContext workGroupSize + + module ByKey2D = + /// + /// Reduces an array of values by 2D keys using a single work item. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// The length of the result must be calculated in advance. + /// + let sequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = + Reduce.ByKey2D.sequential reduceOp clContext workGroupSize + + /// + /// Reduces values by key. Each segment is reduced by one work item. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// The length of the result must be calculated in advance. + /// + let segmentSequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = + Reduce.ByKey2D.segmentSequential reduceOp clContext workGroupSize + + module Option = + /// + /// Reduces values by key. Each segment is reduced by one work item. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// The length of the result must be calculated in advance. + /// + let segmentSequential (reduceOp: Expr<'a -> 'a -> 'a option>) (clContext: ClContext) workGroupSize = + Reduce.ByKey2D.Option.segmentSequential reduceOp clContext workGroupSize diff --git a/src/GraphBLAS-sharp.Backend/Common/Gather.fs b/src/GraphBLAS-sharp.Backend/Common/Gather.fs index 791c88de..b10127cf 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Gather.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Gather.fs @@ -29,17 +29,6 @@ module internal Gather = processor.Post(Msg.CreateRunMsg<_, _>(kernel)) - /// - /// Creates a new array obtained from positions replaced with values from the given array at these positions (indices). - /// - /// - /// - /// let positions = [| 2; 0; 2; 1 |] - /// let array = [| 1.4; 2.5; 3.6 |] - /// ... - /// > val result = [| 3.6; 1.4; 3.6; 2.5 |] - /// - /// let run (clContext: ClContext) workGroupSize = let gather = diff --git a/src/GraphBLAS-sharp.Backend/Common/Merge.fs b/src/GraphBLAS-sharp.Backend/Common/Merge.fs index 07199ef2..f647367e 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Merge.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Merge.fs @@ -1,7 +1,7 @@ namespace GraphBLAS.FSharp.Backend.Common open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions module Merge = let run<'a, 'b when 'a: struct and 'b: struct and 'a: comparison> (clContext: ClContext) workGroupSize = diff --git a/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs b/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs index 09cdfb5d..de86653b 100644 --- a/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs +++ b/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs @@ -4,9 +4,9 @@ open Brahma.FSharp open FSharp.Quotations open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions -module PrefixSum = +module internal PrefixSum = let private update (opAdd: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = let update = @@ -208,24 +208,6 @@ module PrefixSum = let runBackwardsIncludeInPlace plus = runInPlace plus true scanInclusive - /// - /// Exclude inplace prefix sum. - /// - /// - /// - /// let arr = [| 1; 1; 1; 1 |] - /// let sum = [| 0 |] - /// runExcludeInplace clContext workGroupSize processor arr sum (+) 0 - /// |> ignore - /// ... - /// > val arr = [| 0; 1; 2; 3 |] - /// > val sum = [| 4 |] - /// - /// - ///ClContext. - ///Should be a power of 2 and greater than 1. - ///Associative binary operation. - ///Zero element for binary operation. let standardExcludeInPlace (clContext: ClContext) workGroupSize = let scan = @@ -235,24 +217,6 @@ module PrefixSum = scan processor inputArray 0 - /// - /// Include inplace prefix sum. - /// - /// - /// - /// let arr = [| 1; 1; 1; 1 |] - /// let sum = [| 0 |] - /// runExcludeInplace clContext workGroupSize processor arr sum (+) 0 - /// |> ignore - /// ... - /// > val arr = [| 1; 2; 3; 4 |] - /// > val sum = [| 4 |] - /// - /// - ///ClContext. - ///Should be a power of 2 and greater than 1. - ///Associative binary operation. - ///Zero element for binary operation. let standardIncludeInPlace (clContext: ClContext) workGroupSize = let scan = @@ -304,28 +268,6 @@ module PrefixSum = processor.Post(Msg.CreateRunMsg<_, _> kernel) - /// - /// Exclude scan by key. - /// - /// - /// - /// let arr = [| 1; 1; 1; 1; 1; 1|] - /// let keys = [| 1; 2; 2; 2; 3; 3 |] - /// ... - /// > val result = [| 0; 0; 1; 2; 0; 1 |] - /// - /// let sequentialExclude op = sequentialSegments (Map.fst ()) op - /// - /// Include scan by key. - /// - /// - /// - /// let arr = [| 1; 1; 1; 1; 1; 1|] - /// let keys = [| 1; 2; 2; 2; 3; 3 |] - /// ... - /// > val result = [| 1; 1; 2; 3; 1; 2 |] - /// - /// let sequentialInclude op = sequentialSegments (Map.snd ()) op diff --git a/src/GraphBLAS-sharp.Backend/Common/Scatter.fs b/src/GraphBLAS-sharp.Backend/Common/Scatter.fs index 4f51cb93..cc74677d 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Scatter.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Scatter.fs @@ -45,47 +45,11 @@ module internal Scatter = processor.Post(Msg.CreateRunMsg<_, _>(kernel)) - /// - /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array - /// should be a value from the given one. - /// - /// - /// Every element of the positions array must not be less than the previous one. - /// If there are several elements with the same indices, the FIRST one of them will be at the common index. - /// If index is out of bounds, the value will be ignored. - /// - /// - /// - /// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |] - /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; 8.2; 9.1 |] - /// run clContext 32 processor positions values result - /// ... - /// > val result = [| 1,9; 3.7; 6.4; 7.3; 9.1 |] - /// - /// let firstOccurrence clContext = general <| Predicates.firstOccurrence () <| clContext - /// - /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array - /// should be a value from the given one. - /// - /// - /// Every element of the positions array must not be less than the previous one. - /// If there are several elements with the same indices, the LAST one of them will be at the common index. - /// If index is out of bounds, the value will be ignored. - /// - /// - /// - /// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |] - /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; 8.2; 9.1 |] - /// run clContext 32 processor positions values result - /// ... - /// > val result = [| 2.8; 5.5; 6.4; 8.2; 9.1 |] - /// - /// let lastOccurrence clContext = general <| Predicates.lastOccurrence () @@ -128,49 +92,11 @@ module internal Scatter = processor.Post(Msg.CreateRunMsg<_, _>(kernel)) - /// - /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array - /// should be a values obtained by applying the mapping to the global id. - /// - /// - /// Every element of the positions array must not be less than the previous one. - /// If there are several elements with the same indices, the FIRST one of them will be at the common index. - /// If index is out of bounds, the value will be ignored. - /// - /// - /// - /// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |] - /// let valueMap = id - /// run clContext 32 processor positions values result - /// ... - /// > val result = [| 0; 2; 5; 6; 8 |] - /// - /// - /// Maps global id to a value let initFirsOccurrence<'a> valueMap = generalInit<'a> <| Predicates.firstOccurrence () <| valueMap - /// - /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array - /// should be a values obtained by applying the mapping to the global id. - /// - /// - /// Every element of the positions array must not be less than the previous one. - /// If there are several elements with the same indices, the LAST one of them will be at the common index. - /// If index is out of bounds, the value will be ignored. - /// - /// - /// - /// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |] - /// let valueMap = id - /// run clContext 32 processor positions values result - /// ... - /// > val result = [| 1; 4; 5; 7; 8 |] - /// - /// - /// Maps global id to a value let initLastOccurrence<'a> valueMap = generalInit<'a> <| Predicates.lastOccurrence () diff --git a/src/GraphBLAS-sharp.Backend/Common/Sort/Radix.fs b/src/GraphBLAS-sharp.Backend/Common/Sort/Radix.fs index 29f9e26a..1ff45868 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Sort/Radix.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Sort/Radix.fs @@ -3,11 +3,11 @@ namespace GraphBLAS.FSharp.Backend.Common.Sort open Brahma.FSharp open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Objects.ClContext -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -module Radix = +module internal Radix = // the number of bits considered per iteration let defaultBitCount = 4 diff --git a/src/GraphBLAS-sharp.Backend/Common/Sum.fs b/src/GraphBLAS-sharp.Backend/Common/Sum.fs index fe7feeb2..72c52bfc 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Sum.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Sum.fs @@ -4,11 +4,11 @@ open Brahma.FSharp open GraphBLAS.FSharp.Backend.Quotes open Microsoft.FSharp.Control open Microsoft.FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions -module Reduce = +module internal Reduce = /// /// Generalized reduction pattern. /// @@ -132,13 +132,6 @@ module Reduce = resultCell - /// - /// Summarize array elements. - /// - /// ClContext. - /// Work group size. - /// Summation operation. - /// Neutral element for summation. let sum op zero (clContext: ClContext) workGroupSize = let scan = scanSum op clContext workGroupSize zero @@ -236,12 +229,6 @@ module Reduce = resultCell - /// - /// Reduce an array of values. - /// - /// ClContext. - /// Work group size. - /// Reduction operation. let reduce op (clContext: ClContext) workGroupSize = let scan = scanReduce op clContext workGroupSize @@ -258,15 +245,6 @@ module Reduce = /// Reduction of an array of values by an array of keys. /// module ByKey = - /// - /// Reduce an array of values by key using a single work item. - /// - /// ClContext. - /// Work group size. - /// Operation for reducing values. - /// - /// The length of the result must be calculated in advance. - /// let sequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = let kernel = @@ -317,15 +295,6 @@ module Reduce = reducedValues, reducedKeys - /// - /// Reduces values by key. Each segment is reduced by one work item. - /// - /// ClContext. - /// Work group size. - /// Operation for reducing values. - /// - /// The length of the result must be calculated in advance. - /// let segmentSequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = let kernel = @@ -383,16 +352,6 @@ module Reduce = reducedValues, reducedKeys - /// - /// Reduces values by key. One work group participates in the reduction. - /// - /// ClContext. - /// Work group size. - /// Operation for reducing values. - /// - /// Reduces an array of values that does not exceed the size of the workgroup. - /// The length of the result must be calculated in advance. - /// let oneWorkGroupSegments (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = let kernel = @@ -473,15 +432,6 @@ module Reduce = reducedValues, reducedKeys module Option = - /// - /// Reduces values by key. Each segment is reduced by one work item. - /// - /// ClContext. - /// Work group size. - /// Operation for reducing values. - /// - /// The length of the result must be calculated in advance. - /// let segmentSequential<'a> (reduceOp: Expr<'a -> 'a -> 'a option>) (clContext: ClContext) workGroupSize = let kernel = @@ -590,15 +540,6 @@ module Reduce = Some(resultValues, resultKeys) module ByKey2D = - /// - /// Reduce an array of values by 2D keys using a single work item. - /// - /// ClContext. - /// Work group size. - /// Operation for reducing values. - /// - /// The length of the result must be calculated in advance. - /// let sequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = let kernel = @@ -669,15 +610,6 @@ module Reduce = reducedValues, firstReducedKeys, secondReducedKeys - /// - /// Reduces values by key. Each segment is reduced by one work item. - /// - /// ClContext. - /// Work group size. - /// Operation for reducing values. - /// - /// The length of the result must be calculated in advance. - /// let segmentSequential<'a> (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = let kernel = @@ -745,15 +677,6 @@ module Reduce = reducedValues, firstReducedKeys, secondReducedKeys module Option = - /// - /// Reduces values by key. Each segment is reduced by one work item. - /// - /// ClContext. - /// Work group size. - /// Operation for reducing values. - /// - /// The length of the result must be calculated in advance. - /// let segmentSequential<'a> (reduceOp: Expr<'a -> 'a -> 'a option>) (clContext: ClContext) workGroupSize = let kernel = diff --git a/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj b/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj index 4709660f..173f3123 100644 --- a/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj +++ b/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj @@ -17,7 +17,7 @@ - + @@ -27,18 +27,19 @@ - + + + - - - + + @@ -63,6 +64,7 @@ + diff --git a/src/GraphBLAS-sharp.Backend/Matrix/COO/Map.fs b/src/GraphBLAS-sharp.Backend/Matrix/COO/Map.fs index 7700b476..52989dee 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/COO/Map.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/COO/Map.fs @@ -8,7 +8,7 @@ open Microsoft.FSharp.Quotations open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions module internal Map = let preparePositions<'a, 'b> opAdd (clContext: ClContext) workGroupSize = @@ -84,13 +84,13 @@ module internal Map = resultBitmap, resultValues, resultRows, resultColumns let run<'a, 'b when 'a: struct and 'b: struct and 'b: equality> - (opAdd: Expr<'a option -> 'b option>) + (op: Expr<'a option -> 'b option>) (clContext: ClContext) workGroupSize = let map = - preparePositions opAdd clContext workGroupSize + preparePositions op clContext workGroupSize let setPositions = Common.setPositions<'b> clContext workGroupSize diff --git a/src/GraphBLAS-sharp.Backend/Matrix/COO/Map2.fs b/src/GraphBLAS-sharp.Backend/Matrix/COO/Map2.fs index 3d79eb9a..f757bac9 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/COO/Map2.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/COO/Map2.fs @@ -7,7 +7,7 @@ open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions module internal Map2 = diff --git a/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs b/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs index fd0fc338..e4469abe 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs @@ -6,18 +6,15 @@ open GraphBLAS.FSharp.Backend.Quotes open Microsoft.FSharp.Quotations open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions module Matrix = let map = Map.run let map2 = Map2.run - ///. - ///. - ///Should be a power of 2 and greater than 1. let rec map2AtLeastOne<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality> (clContext: ClContext) (opAdd: Expr -> 'c option>) diff --git a/src/GraphBLAS-sharp.Backend/Matrix/COO/Merge.fs b/src/GraphBLAS-sharp.Backend/Matrix/COO/Merge.fs index e9cbf08d..2d75b161 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/COO/Merge.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/COO/Merge.fs @@ -1,7 +1,7 @@ namespace GraphBLAS.FSharp.Backend.Matrix.COO open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Objects module Merge = diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Kronecker.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Kronecker.fs index 10151f41..ca0b8f81 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Kronecker.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Kronecker.fs @@ -8,9 +8,9 @@ open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Backend.Matrix.COO open GraphBLAS.FSharp.Backend.Matrix.CSR -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions module internal Kronecker = diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map.fs index a6c2b077..c61bcdde 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map.fs @@ -6,9 +6,9 @@ open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions module internal Map = @@ -83,13 +83,13 @@ module internal Map = resultBitmap, resultValues, resultRows, resultColumns let run<'a, 'b when 'a: struct and 'b: struct and 'b: equality> - (opAdd: Expr<'a option -> 'b option>) + (op: Expr<'a option -> 'b option>) (clContext: ClContext) workGroupSize = let map = - preparePositions opAdd clContext workGroupSize + preparePositions op clContext workGroupSize let setPositions = Common.setPositions<'b> clContext workGroupSize diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs index bfd5f161..ba06e8d5 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs @@ -7,7 +7,7 @@ open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Matrix.COO module internal Map2 = diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs index 22171912..1e4b6b3d 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs @@ -7,7 +7,7 @@ open GraphBLAS.FSharp.Backend.Quotes open Microsoft.FSharp.Quotations open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Objects.ClVector open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Merge.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Merge.fs index cf98d531..d8cb366e 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Merge.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Merge.fs @@ -4,7 +4,7 @@ open Brahma.FSharp open System open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions module Merge = let run<'a, 'b when 'a: struct and 'b: struct> (clContext: ClContext) workGroupSize = diff --git a/src/GraphBLAS-sharp.Backend/Matrix/Common.fs b/src/GraphBLAS-sharp.Backend/Matrix/Common.fs index 5588b203..b6641b3a 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/Common.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/Common.fs @@ -2,8 +2,8 @@ namespace GraphBLAS.FSharp.Backend.Matrix open Brahma.FSharp open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Objects.ClContext -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions module internal Common = ///. diff --git a/src/GraphBLAS-sharp.Backend/Matrix/LIL/Matrix.fs b/src/GraphBLAS-sharp.Backend/Matrix/LIL/Matrix.fs index 34eff782..aa7dfe42 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/LIL/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/LIL/Matrix.fs @@ -2,7 +2,7 @@ namespace GraphBLAS.FSharp.Backend.Matrix.LIL open Brahma.FSharp open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Objects.ClMatrix module Matrix = diff --git a/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs b/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs index cd754379..82b062b3 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs @@ -7,9 +7,15 @@ open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Objects.ClMatrix open GraphBLAS.FSharp.Backend.Vector -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions module Matrix = + /// + /// Creates new matrix with the values from the given one. + /// New matrix represented in the format of the given one. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let copy (clContext: ClContext) workGroupSize = let copy = ClArray.copy clContext workGroupSize @@ -166,8 +172,8 @@ module Matrix = /// /// Creates a new matrix, represented in CSC format, that is equal to the given one. /// - ///OpenCL context. - ///Should be a power of 2 and greater than 1. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let toCSC (clContext: ClContext) workGroupSize = let COOtoCSR = COO.Matrix.toCSR clContext workGroupSize @@ -228,6 +234,11 @@ module Matrix = |> ClMatrix.CSC | _ -> failwith "Not yet implemented" + /// + /// Creates a new matrix, represented in LIL format, that is equal to the given one. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let toLIL (clContext: ClContext) workGroupSize = let copy = copy clContext workGroupSize @@ -255,12 +266,22 @@ module Matrix = |> ClMatrix.LIL | ClMatrix.LIL _ -> copy processor allocationMode matrix - let map (opAdd: Expr<'a option -> 'b option>) (clContext: ClContext) workGroupSize = + /// + /// Builds a new matrix whose elements are the results of applying the given function + /// to each of the elements of the matrix. + /// + /// + /// A function to transform values of the input matrix. + /// Operand and result types should be optional to distinguish explicit and implicit zeroes + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let map (op: Expr<'a option -> 'b option>) (clContext: ClContext) workGroupSize = let mapCOO = - COO.Matrix.map opAdd clContext workGroupSize + COO.Matrix.map op clContext workGroupSize let mapCSR = - CSR.Matrix.map opAdd clContext workGroupSize + CSR.Matrix.map op clContext workGroupSize let transposeCOO = COO.Matrix.transposeInPlace clContext workGroupSize @@ -275,12 +296,25 @@ module Matrix = |> ClMatrix.COO | _ -> failwith "Not yet implemented" - let map2 (opAdd: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) workGroupSize = + /// + /// Builds a new matrix whose values are the results of applying the given function + /// to the corresponding pairs of values from the two matrices. + /// + /// + /// A function to transform pairs of values from the input matrices. + /// Operands and result types should be optional to distinguish explicit and implicit zeroes + /// + /// + /// Formats of the given matrices should match, otherwise an exception will be thrown. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let map2 (op: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) workGroupSize = let map2COO = - COO.Matrix.map2 opAdd clContext workGroupSize + COO.Matrix.map2 op clContext workGroupSize let map2CSR = - CSR.Matrix.map2 opAdd clContext workGroupSize + CSR.Matrix.map2 op clContext workGroupSize let transposeCOO = COO.Matrix.transposeInPlace clContext workGroupSize @@ -299,12 +333,25 @@ module Matrix = |> ClMatrix.COO | _ -> failwith "Matrix formats are not matching" - let map2AtLeastOne (opAdd: Expr -> 'c option>) (clContext: ClContext) workGroupSize = + /// + /// Builds a new matrix whose values are the results of applying the given function + /// to the corresponding pairs of values from the two matrices. + /// + /// + /// A function to transform pairs of values from the input matrices. + /// Operation assumption: one of the operands should always be non-zero. + /// + /// + /// Formats of the given matrices should match, otherwise an exception will be thrown. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let map2AtLeastOne (op: Expr -> 'c option>) (clContext: ClContext) workGroupSize = let COOMap2 = - COO.Matrix.map2AtLeastOne clContext opAdd workGroupSize + COO.Matrix.map2AtLeastOne clContext op workGroupSize let CSRMap2 = - CSR.Matrix.map2AtLeastOne clContext opAdd workGroupSize + CSR.Matrix.map2AtLeastOne clContext op workGroupSize let COOTranspose = COO.Matrix.transposeInPlace clContext workGroupSize @@ -390,6 +437,15 @@ module Matrix = |> ClMatrix.CSR | ClMatrix.LIL _ -> failwith "Not yet implemented" + /// + /// Kronecker product for matrices. + /// + /// + /// Element-wise operation. + /// Operands and result types should be optional to distinguish explicit and implicit zeroes + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let kronecker (op: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) workGroupSize = let run = CSR.Matrix.kronecker clContext workGroupSize op @@ -401,7 +457,17 @@ module Matrix = Option.map ClMatrix.COO result | _ -> failwith "Both matrices should be in CSR format." + /// + /// Sparse general matrix-matrix multiplication. + /// module SpGeMM = + /// + /// Masked matrix-matrix multiplication. + /// + /// Type of binary function to reduce entries. + /// Type of binary function to combine entries. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let masked (opAdd: Expr<'c -> 'c -> 'c option>) (opMul: Expr<'a -> 'b -> 'c option>) @@ -417,6 +483,13 @@ module Matrix = | ClMatrix.CSR m1, ClMatrix.CSC m2, ClMatrix.COO mask -> runCSRnCSC queue m1 m2 mask |> ClMatrix.COO | _ -> failwith "Matrix formats are not matching" + /// + /// Generalized matrix-matrix multiplication. + /// + /// Type of binary function to reduce entries. + /// Type of binary function to combine entries. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let expand (opAdd: Expr<'c -> 'c -> 'c option>) (opMul: Expr<'a -> 'b -> 'c option>) diff --git a/src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Expand.fs b/src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Expand.fs index 92eba752..4ec663b2 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Expand.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Expand.fs @@ -5,10 +5,10 @@ open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Backend.Common.Sort open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions open FSharp.Quotations open GraphBLAS.FSharp.Backend.Objects.ClMatrix diff --git a/src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Masked.fs b/src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Masked.fs index 700018c3..1a75fc45 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Masked.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Masked.fs @@ -5,8 +5,8 @@ open Brahma.FSharp open Microsoft.FSharp.Quotations open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContext -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions module internal Masked = let private calculate diff --git a/src/GraphBLAS-sharp.Backend/Objects/ClCell.fs b/src/GraphBLAS-sharp.Backend/Objects/ClCellExtensions.fs similarity index 95% rename from src/GraphBLAS-sharp.Backend/Objects/ClCell.fs rename to src/GraphBLAS-sharp.Backend/Objects/ClCellExtensions.fs index 6b6b188f..3800ebc6 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/ClCell.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/ClCellExtensions.fs @@ -2,7 +2,7 @@ namespace GraphBLAS.FSharp.Backend.Objects open Brahma.FSharp -module ClCell = +module ClCellExtensions = type ClCell<'a> with member this.ToHost(processor: MailboxProcessor<_>) = processor.PostAndReply(fun ch -> Msg.CreateToHostMsg<_>(this, (Array.zeroCreate<'a> 1), ch)).[0] diff --git a/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs b/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs index bd5c8a3a..f72c71c4 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs @@ -2,7 +2,7 @@ namespace GraphBLAS.FSharp.Backend.Objects open Brahma.FSharp -module ClContext = +module ClContextExtensions = type AllocationFlag = | DeviceOnly | HostInterop diff --git a/src/GraphBLAS-sharp.Backend/Quotes/PreparePositions.fs b/src/GraphBLAS-sharp.Backend/Quotes/PreparePositions.fs index d219e7ec..4252cd18 100644 --- a/src/GraphBLAS-sharp.Backend/Quotes/PreparePositions.fs +++ b/src/GraphBLAS-sharp.Backend/Quotes/PreparePositions.fs @@ -2,7 +2,7 @@ namespace GraphBLAS.FSharp.Backend.Quotes open Brahma.FSharp -module PreparePositions = +module internal PreparePositions = let both<'c> = <@ fun index (result: 'c option) (rawPositionsBuffer: ClArray) (allValuesBuffer: ClArray<'c>) -> rawPositionsBuffer.[index] <- 0 diff --git a/src/GraphBLAS-sharp.Backend/Vector/Dense/Vector.fs b/src/GraphBLAS-sharp.Backend/Vector/Dense/Vector.fs index 53f8de3e..ff522be3 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Dense/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Dense/Vector.fs @@ -5,10 +5,23 @@ open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Backend.Quotes open Microsoft.FSharp.Quotations open GraphBLAS.FSharp.Backend.Objects.ClVector -open GraphBLAS.FSharp.Backend.Objects.ClContext -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions module Vector = + let map<'a, 'b when 'a: struct and 'b: struct> + (op: Expr<'a option -> 'b option>) + (clContext: ClContext) + workGroupSize + = + + let map = + ClArray.map op clContext workGroupSize + + fun (processor: MailboxProcessor<_>) allocationMode (leftVector: ClArray<'a option>) -> + + map processor allocationMode leftVector + let map2InPlace<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct> (opAdd: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) @@ -22,7 +35,6 @@ module Vector = map2InPlace processor leftVector rightVector resultVector - let map2<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct> (opAdd: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) @@ -36,7 +48,6 @@ module Vector = map2 processor allocationMode leftVector rightVector - let map2AtLeastOne op clContext workGroupSize = map2 (Convert.atLeastOneToOption op) clContext workGroupSize diff --git a/src/GraphBLAS-sharp.Backend/Vector/SpMV.fs b/src/GraphBLAS-sharp.Backend/Vector/SpMV.fs index 46895b0c..72a7b89f 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/SpMV.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/SpMV.fs @@ -4,7 +4,7 @@ open Brahma.FSharp open GraphBLAS.FSharp.Backend.Common open Microsoft.FSharp.Quotations open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions module SpMV = let runTo diff --git a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Common.fs b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Common.fs index cb6a8971..002b4f9e 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Common.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Common.fs @@ -4,8 +4,8 @@ open Brahma.FSharp open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Backend.Objects.ClVector open Microsoft.FSharp.Control -open GraphBLAS.FSharp.Backend.Objects.ClContext -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions module internal Common = let setPositions<'a when 'a: struct> (clContext: ClContext) workGroupSize = diff --git a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map.fs b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map.fs index 3d804101..6259c3c7 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map.fs @@ -1,6 +1,7 @@ namespace GraphBLAS.FSharp.Backend.Vector.Sparse open FSharp.Quotations.Evaluator.QuotationEvaluationExtensions +open GraphBLAS.FSharp.Backend.Objects open Microsoft.FSharp.Quotations open Brahma.FSharp open GraphBLAS.FSharp.Backend @@ -8,13 +9,99 @@ open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Backend.Vector.Sparse open GraphBLAS.FSharp.Backend.Objects.ClVector open GraphBLAS.FSharp.Backend.Common.ClArray -open GraphBLAS.FSharp.Backend.Objects.ClCell -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -module Map = +module internal Map = + let preparePositions<'a, 'b> opAdd (clContext: ClContext) workGroupSize = + + let preparePositions (op: Expr<'a option -> 'b option>) = + <@ fun (ndRange: Range1D) size valuesLength (values: ClArray<'a>) (indices: ClArray) (resultBitmap: ClArray) (resultValues: ClArray<'b>) (resultIndices: ClArray) -> + + let gid = ndRange.GlobalID0 + + if gid < size then + + let value = + (%Search.Bin.byKey) valuesLength gid indices values + + match (%op) value with + | Some resultValue -> + resultValues.[gid] <- resultValue + resultIndices.[gid] <- gid + + resultBitmap.[gid] <- 1 + | None -> resultBitmap.[gid] <- 0 @> + + let kernel = + clContext.Compile <| preparePositions opAdd + + fun (processor: MailboxProcessor<_>) (size: int) (values: ClArray<'a>) (indices: ClArray) -> + + let resultBitmap = + clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, size) + + let resultIndices = + clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, size) + + let resultValues = + clContext.CreateClArrayWithSpecificAllocationMode<'b>(DeviceOnly, size) + + let ndRange = + Range1D.CreateValid(size, workGroupSize) + + let kernel = kernel.GetKernel() + + processor.Post( + Msg.MsgSetArguments + (fun () -> + kernel.KernelFunc + ndRange + size + values.Length + values + indices + resultBitmap + resultValues + resultIndices) + ) + + processor.Post(Msg.CreateRunMsg<_, _> kernel) + + resultBitmap, resultValues, resultIndices + + let run<'a, 'b when 'a: struct and 'b: struct and 'b: equality> + (op: Expr<'a option -> 'b option>) + (clContext: ClContext) + workGroupSize + = + + let map = + preparePositions op clContext workGroupSize + + let setPositions = + Common.setPositions<'b> clContext workGroupSize + + fun (queue: MailboxProcessor<_>) allocationMode (vector: ClVector.Sparse<'a>) -> + + let bitmap, values, indices = + map queue vector.Size vector.Values vector.Indices + + let resultValues, resultIndices = + setPositions queue allocationMode values indices bitmap + + queue.Post(Msg.CreateFreeMsg<_>(bitmap)) + queue.Post(Msg.CreateFreeMsg<_>(values)) + queue.Post(Msg.CreateFreeMsg<_>(indices)) + + { Context = clContext + Indices = indices + Values = resultValues + Size = vector.Size } + module WithValueOption = - let preparePositions<'a, 'b, 'c> opAdd (clContext: ClContext) workGroupSize = + let private preparePositions<'a, 'b, 'c> opAdd (clContext: ClContext) workGroupSize = let preparePositions (op: Expr<'a option -> 'b option -> 'c option>) = <@ fun (ndRange: Range1D) (operand: ClCell<'a option>) size valuesLength (indices: ClArray) (values: ClArray<'b>) (resultIndices: ClArray) (resultValues: ClArray<'c>) (resultBitmap: ClArray) -> diff --git a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map2.fs b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map2.fs index 1b8ef660..5cd60600 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map2.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map2.fs @@ -5,7 +5,7 @@ open FSharp.Quotations open Microsoft.FSharp.Control open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Objects.ClVector -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Quotes module internal Map2 = diff --git a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Merge.fs b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Merge.fs index 459ab6d5..87351087 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Merge.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Merge.fs @@ -2,7 +2,7 @@ namespace GraphBLAS.FSharp.Backend.Vector.Sparse open Brahma.FSharp open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions module internal Merge = let run<'a, 'b when 'a: struct and 'b: struct> (clContext: ClContext) workGroupSize = diff --git a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs index 5b3594ae..06121194 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs @@ -21,6 +21,8 @@ module Vector = Values = copyData processor allocationMode vector.Values Size = vector.Size } + let map = Map.run + let mapWithValue = Map.WithValueOption.run let map2 = Map2.run diff --git a/src/GraphBLAS-sharp.Backend/Vector/Vector.fs b/src/GraphBLAS-sharp.Backend/Vector/Vector.fs index 9c94992b..73ae99f3 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Vector.fs @@ -6,11 +6,16 @@ open Microsoft.FSharp.Control open Microsoft.FSharp.Quotations open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Objects.ClVector module Vector = + /// + /// 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 zeroCreate = ClArray.zeroCreate clContext workGroupSize @@ -31,6 +36,11 @@ module Vector = ClVector.Dense <| zeroCreate processor allocationMode size + /// + /// Builds vector of given format with fixed size and fills it with the values from the given list. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let ofList (clContext: ClContext) workGroupSize = let scatter = Scatter.lastOccurrence clContext workGroupSize @@ -76,6 +86,12 @@ module Vector = ClVector.Dense result + /// + /// Creates new vector with the values from the given one. + /// New vector represented in the format of the given one. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let copy (clContext: ClContext) workGroupSize = let sparseCopy = Sparse.Vector.copy clContext workGroupSize @@ -91,6 +107,12 @@ module Vector = ClVector.Dense <| copyOptionData processor allocationMode vector + /// + /// Sparsifies the given vector if it is in a dense format. + /// If the given vector is already sparse, copies it. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let toSparse (clContext: ClContext) workGroupSize = let toSparse = Dense.Vector.toSparse clContext workGroupSize @@ -104,6 +126,12 @@ module Vector = <| toSparse processor allocationMode vector | ClVector.Sparse _ -> copy processor allocationMode vector + /// + /// Densifies the given vector if it is in a sparse format. + /// If the given vector is already dense, copies it. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let toDense (clContext: ClContext) workGroupSize = let toDense = Sparse.Vector.toDense clContext workGroupSize @@ -119,12 +147,47 @@ module Vector = ClVector.Dense <| toDense processor allocationMode vector - let map2 (opAdd: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) workGroupSize = + /// + /// Builds a new vector whose elements are the results of applying the given function + /// to each of the elements of the vector. + /// + /// + /// A function to transform values of the input vector. + /// Operand and result types should be optional to distinguish explicit and implicit zeroes. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let map (op: Expr<'a option -> 'b option>) (clContext: ClContext) workGroupSize = + let mapSparse = + Sparse.Vector.map op clContext workGroupSize + + let mapDense = + Dense.Vector.map op clContext workGroupSize + + fun (processor: MailboxProcessor<_>) allocationMode matrix -> + match matrix with + | ClVector.Sparse v -> mapSparse processor allocationMode v |> ClVector.Sparse + | ClVector.Dense v -> mapDense processor allocationMode v |> ClVector.Dense + + /// + /// Builds a new vector whose values are the results of applying the given function + /// to the corresponding pairs of values from the two vectors. + /// + /// + /// A function to transform pairs of values from the input vectors. + /// Operands and result types should be optional to distinguish explicit and implicit zeroes. + /// + /// + /// Formats of the given vectors should match, otherwise an exception will be thrown. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let map2 (op: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) workGroupSize = let map2Dense = - Dense.Vector.map2 opAdd clContext workGroupSize + Dense.Vector.map2 op clContext workGroupSize let map2Sparse = - Sparse.Vector.map2 opAdd clContext workGroupSize + Sparse.Vector.map2 op clContext workGroupSize fun (processor: MailboxProcessor<_>) allocationMode (leftVector: ClVector<'a>) (rightVector: ClVector<'b>) -> match leftVector, rightVector with @@ -136,12 +199,25 @@ module Vector = <| map2Sparse processor allocationMode left right | _ -> failwith "Vector formats are not matching." - let map2AtLeastOne (opAdd: Expr -> 'c option>) (clContext: ClContext) workGroupSize = + /// + /// Builds a new vector whose values are the results of applying the given function + /// to the corresponding pairs of values from the two vectors. + /// + /// + /// A function to transform pairs of values from the input vectors. + /// Operation assumption: one of the operands should always be non-zero. + /// + /// + /// Formats of the given vectors should match, otherwise an exception will be thrown. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let map2AtLeastOne (op: Expr -> 'c option>) (clContext: ClContext) workGroupSize = let map2Sparse = - Sparse.Vector.map2AtLeastOne opAdd clContext workGroupSize + Sparse.Vector.map2AtLeastOne op clContext workGroupSize let map2Dense = - Dense.Vector.map2AtLeastOne opAdd clContext workGroupSize + Dense.Vector.map2AtLeastOne op clContext workGroupSize fun (processor: MailboxProcessor<_>) allocationMode (leftVector: ClVector<'a>) (rightVector: ClVector<'b>) -> match leftVector, rightVector with @@ -177,6 +253,18 @@ module Vector = let assignByMaskComplemented<'a, 'b when 'a: struct and 'b: struct> op clContext workGroupSize = assignByMaskGeneral<'a, 'b> (Convert.assignComplementedToOption op) clContext workGroupSize + /// + /// Applies a function to each value of the vector, threading an accumulator argument through the computation. + /// Begin by applying the function to the first two values. + /// Then feed this result into the function along with the third value and so on. + /// Return the final result. + /// + /// + /// Implicit zeroes are ignored during the computation. + /// + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let reduce (opAdd: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = let sparseReduce = Sparse.Vector.reduce opAdd clContext workGroupSize diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs index c79d035f..4ffcd21e 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs @@ -4,7 +4,7 @@ open GraphBLAS.FSharp.Backend.Common open Expecto open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open Brahma.FSharp open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ChunkBySize.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ChunkBySize.fs index ae282f9a..032fdc0d 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ChunkBySize.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ChunkBySize.fs @@ -5,7 +5,7 @@ open Brahma.FSharp open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs index d27cdebf..381c03b1 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs @@ -5,7 +5,7 @@ open Brahma.FSharp open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Copy.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Copy.fs index 2c8d2ba2..c058f135 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Copy.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Copy.fs @@ -6,7 +6,7 @@ open Expecto.Logging.Message open Brahma.FSharp open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions let logger = Log.create "ClArray.Copy.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Exists.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Exists.fs index ff061074..5d011c98 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Exists.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Exists.fs @@ -8,7 +8,7 @@ open Context open Brahma.FSharp open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions let logger = Log.create "ClArray.containsNonZero.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Fill.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Fill.fs index 0921ff26..a0d65654 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Fill.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Fill.fs @@ -6,7 +6,7 @@ open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Item.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Item.fs index 352f2517..4de050f5 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Item.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Item.fs @@ -6,7 +6,7 @@ open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map.fs index a49ea492..ca1b2024 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map.fs @@ -6,7 +6,7 @@ open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Backend.Quotes open Expecto -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let context = defaultContext.Queue diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map2.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map2.fs index ae4342b8..23e5b70a 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map2.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map2.fs @@ -5,7 +5,7 @@ open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp.Backend.Common open Expecto -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let context = defaultContext.Queue diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Pairwise.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Pairwise.fs index 5bd6957d..8fa3bb07 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Pairwise.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Pairwise.fs @@ -6,7 +6,7 @@ open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Replicate.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Replicate.fs index 0299eb05..1a1d5ff8 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Replicate.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Replicate.fs @@ -6,7 +6,7 @@ open Expecto.Logging.Message open Brahma.FSharp open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions let logger = Log.create "Replicate.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/UpperBound.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/UpperBound.fs index 78905478..8b19da9b 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/UpperBound.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/UpperBound.fs @@ -5,7 +5,7 @@ open Brahma.FSharp open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs index 3019d9d3..8129fce2 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs @@ -5,7 +5,7 @@ open GraphBLAS.FSharp.Tests open Expecto open Microsoft.FSharp.Collections open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Quotes let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs index 3500e639..931f7bae 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs @@ -6,7 +6,7 @@ open Expecto.Logging.Message open Brahma.FSharp open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions let logger = Log.create "Reduce.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs index 772eafb5..e17e59cb 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs @@ -5,7 +5,7 @@ open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open Brahma.FSharp open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Sum.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Sum.fs index 977b085e..8011d1fc 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Sum.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Sum.fs @@ -9,7 +9,7 @@ open GraphBLAS.FSharp.Tests open FSharp.Quotations open Context open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions let logger = Log.create "Sum.Test" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs index a89b5f36..ff3f8aba 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs @@ -1,7 +1,7 @@ module GraphBLAS.FSharp.Tests.Backend.Common.Scan.ByKey open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open Expecto open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/PrefixSum.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/PrefixSum.fs index fbf12398..ebff059d 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/PrefixSum.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/PrefixSum.fs @@ -7,7 +7,7 @@ open Brahma.FSharp open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions let logger = Log.create "ClArray.PrefixSum.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs index 2f565f3e..7aa7fde8 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs @@ -5,7 +5,7 @@ open GraphBLAS.FSharp.Backend.Common.Sort open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let config = { Utils.defaultConfig with diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs index 98270784..d16c5523 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs @@ -6,7 +6,7 @@ open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.ClVectorExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Convert.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Convert.fs index c27bf511..cab5a09a 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Convert.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Convert.fs @@ -10,7 +10,7 @@ open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Objects.MatrixExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let logger = Log.create "Convert.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ExpandRows.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ExpandRows.fs index 413df587..fee57240 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ExpandRows.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ExpandRows.fs @@ -5,7 +5,7 @@ open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open Brahma.FSharp open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs index add171ee..12bbafa5 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs @@ -48,7 +48,7 @@ let makeTest testContext zero isEqual op kroneckerFun (leftMatrix: 'a [,], right let m2 = m2.ToDevice context let result = - kroneckerFun processor ClContext.HostInterop m1 m2 + kroneckerFun processor ClContextExtensions.HostInterop m1 m2 let actual = Option.map (fun (m: ClMatrix<'a>) -> m.ToHost processor) result diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs index 6276019b..801a1ea4 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs @@ -8,7 +8,7 @@ open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Backend open GraphBLAS.FSharp.Tests.TestCases diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs index 1a8e2dab..aca527da 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs @@ -13,14 +13,14 @@ open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Tests.Backend open GraphBLAS.FSharp.Objects.MatrixExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let logger = Log.create "Map2.Tests" let config = Utils.defaultConfig let wgSize = Utils.defaultWorkGroupSize -let getCorrectnessTestName case datatype = +let getCorrectTestName case datatype = $"Correctness on %s{datatype}, %A{case}" let checkResult isEqual op zero (baseMtx1: 'a [,]) (baseMtx2: 'a [,]) (actual: Matrix<'a>) = @@ -95,8 +95,8 @@ let correctnessGenericTest | ex when ex.Message = "InvalidBufferSize" -> () | ex -> raise ex -let creatTestMap2Add case (zero: 'a) add isEqual addQ map2 = - let getCorrectnessTestName = getCorrectnessTestName case +let createTestMap2Add case (zero: 'a) add isEqual addQ map2 = + let getCorrectnessTestName = getCorrectTestName case let context = case.TestContext.ClContext let q = case.TestContext.Queue @@ -114,14 +114,14 @@ let testFixturesMap2Add case = let q = case.TestContext.Queue q.Error.Add(fun e -> failwithf "%A" e) - creatTestMap2Add case false (||) (=) ArithmeticOperations.boolSumOption Matrix.map2 - creatTestMap2Add case 0 (+) (=) ArithmeticOperations.intSumOption Matrix.map2 + createTestMap2Add case false (||) (=) ArithmeticOperations.boolSumOption Matrix.map2 + createTestMap2Add case 0 (+) (=) ArithmeticOperations.intSumOption Matrix.map2 if Utils.isFloat64Available context.ClDevice then - creatTestMap2Add case 0.0 (+) Utils.floatIsEqual ArithmeticOperations.floatSumOption Matrix.map2 + createTestMap2Add case 0.0 (+) Utils.floatIsEqual ArithmeticOperations.floatSumOption Matrix.map2 - creatTestMap2Add case 0.0f (+) Utils.float32IsEqual ArithmeticOperations.float32SumOption Matrix.map2 - creatTestMap2Add case 0uy (+) (=) ArithmeticOperations.byteSumOption Matrix.map2 ] + createTestMap2Add case 0.0f (+) Utils.float32IsEqual ArithmeticOperations.float32SumOption Matrix.map2 + createTestMap2Add case 0uy (+) (=) ArithmeticOperations.byteSumOption Matrix.map2 ] let addTests = operationGPUTests "Backend.Matrix.map2 add tests" testFixturesMap2Add @@ -131,13 +131,13 @@ let testFixturesMap2AddAtLeastOne case = let q = case.TestContext.Queue q.Error.Add(fun e -> failwithf "%A" e) - creatTestMap2Add case false (||) (=) ArithmeticOperations.boolSumAtLeastOne Matrix.map2AtLeastOne - creatTestMap2Add case 0 (+) (=) ArithmeticOperations.intSumAtLeastOne Matrix.map2AtLeastOne + createTestMap2Add case false (||) (=) ArithmeticOperations.boolSumAtLeastOne Matrix.map2AtLeastOne + createTestMap2Add case 0 (+) (=) ArithmeticOperations.intSumAtLeastOne Matrix.map2AtLeastOne if Utils.isFloat64Available context.ClDevice then - creatTestMap2Add case 0.0 (+) Utils.floatIsEqual ArithmeticOperations.floatSumAtLeastOne Matrix.map2AtLeastOne + createTestMap2Add case 0.0 (+) Utils.floatIsEqual ArithmeticOperations.floatSumAtLeastOne Matrix.map2AtLeastOne - creatTestMap2Add + createTestMap2Add case 0.0f (+) @@ -145,7 +145,7 @@ let testFixturesMap2AddAtLeastOne case = ArithmeticOperations.float32SumAtLeastOne Matrix.map2AtLeastOne - creatTestMap2Add case 0uy (+) (=) ArithmeticOperations.byteSumAtLeastOne Matrix.map2AtLeastOne ] + createTestMap2Add case 0uy (+) (=) ArithmeticOperations.byteSumAtLeastOne Matrix.map2AtLeastOne ] let addAtLeastOneTests = @@ -156,13 +156,13 @@ let testFixturesMap2MulAtLeastOne case = let q = case.TestContext.Queue q.Error.Add(fun e -> failwithf "%A" e) - creatTestMap2Add case false (&&) (=) ArithmeticOperations.boolMulAtLeastOne Matrix.map2AtLeastOne - creatTestMap2Add case 0 (*) (=) ArithmeticOperations.intMulAtLeastOne Matrix.map2AtLeastOne + createTestMap2Add case false (&&) (=) ArithmeticOperations.boolMulAtLeastOne Matrix.map2AtLeastOne + createTestMap2Add case 0 (*) (=) ArithmeticOperations.intMulAtLeastOne Matrix.map2AtLeastOne if Utils.isFloat64Available context.ClDevice then - creatTestMap2Add case 0.0 (*) Utils.floatIsEqual ArithmeticOperations.floatMulAtLeastOne Matrix.map2AtLeastOne + createTestMap2Add case 0.0 (*) Utils.floatIsEqual ArithmeticOperations.floatMulAtLeastOne Matrix.map2AtLeastOne - creatTestMap2Add + createTestMap2Add case 0.0f (*) @@ -170,7 +170,7 @@ let testFixturesMap2MulAtLeastOne case = ArithmeticOperations.float32MulAtLeastOne Matrix.map2AtLeastOne - creatTestMap2Add case 0uy (*) (=) ArithmeticOperations.byteMulAtLeastOne Matrix.map2AtLeastOne ] + createTestMap2Add case 0uy (*) (=) ArithmeticOperations.byteMulAtLeastOne Matrix.map2AtLeastOne ] let mulAtLeastOneTests = operationGPUTests "Backend.Matrix.map2AtLeastOne multiplication tests" testFixturesMap2MulAtLeastOne diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/RowsLengths.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/RowsLengths.fs index 6aab0988..35245698 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/RowsLengths.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/RowsLengths.fs @@ -9,7 +9,7 @@ open GraphBLAS.FSharp.Tests.Backend open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let processor = Context.defaultContext.Queue diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs index 67eac9d3..30949a6d 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs @@ -13,7 +13,7 @@ open GraphBLAS.FSharp.Tests.Backend open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.MatrixExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs index e48a20e0..66c4a8eb 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs @@ -6,7 +6,7 @@ open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Objects.MatrixExtensions open GraphBLAS.FSharp.Objects.Matrix diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Transpose.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Transpose.fs index 01e78bf7..1a3a1e83 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Transpose.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Transpose.fs @@ -10,7 +10,7 @@ open GraphBLAS.FSharp.Tests.TestCases open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Objects.MatrixExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let logger = Log.create "Transpose.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/AssignByMask.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/AssignByMask.fs index 50dab7c2..54f69e9a 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/AssignByMask.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/AssignByMask.fs @@ -11,7 +11,7 @@ open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Vector open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let logger = Log.create "Vector.assignByMask.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Convert.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Convert.fs index 2f586b03..8220564e 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Convert.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Convert.fs @@ -10,7 +10,7 @@ open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Vector open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let logger = Log.create "Backend.Vector.Convert.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs index f5d28ca3..d912ad11 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs @@ -9,7 +9,7 @@ open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Vector open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let logger = Log.create "Vector.copy.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs index e5eadaa4..122e28a4 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs @@ -10,7 +10,7 @@ open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Vector open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let logger = Log.create "Vector.ElementWise.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/OfList.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/OfList.fs index 6bc5a392..3f282e6e 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/OfList.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/OfList.fs @@ -10,7 +10,7 @@ open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Vector open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let logger = Log.create "Vector.ofList.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Reduce.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Reduce.fs index 42f29688..c512b7c3 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Reduce.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Reduce.fs @@ -7,7 +7,7 @@ open GraphBLAS.FSharp.Tests open Brahma.FSharp open FSharp.Quotations open TestCases -open GraphBLAS.FSharp.Backend.Objects.ClCell +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions open GraphBLAS.FSharp.Backend.Vector let logger = Log.create "Vector.reduce.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs index e19ade53..a6995069 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs @@ -12,7 +12,7 @@ open Microsoft.FSharp.Core open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Vector open GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let config = Utils.defaultConfig diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs index 313e0066..f310a506 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs @@ -10,7 +10,7 @@ open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Vector open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContext +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions let logger = Log.create "Vector.zeroCreate.Tests" From 7ec498df159b43cc810eeb9a718eb7aead7acd77 Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Tue, 18 Jul 2023 17:00:57 +0700 Subject: [PATCH 02/22] wip: refactor --- .../Matrix/Map2/Map2.fs | 38 +- .../Matrix/SpGeMM/Expand.fs | 2 +- .../Matrix/SpGeMM/Masked.fs | 18 +- .../GraphBLAS-sharp.Benchmarks/Vector/Map2.fs | 16 +- src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs | 2 +- .../GraphBLAS-sharp.Backend.fsproj | 15 +- .../Matrix/{Matrix.fs => Primitives.fs} | 155 +----- .../Operations/Kronecker.fs | 457 ++++++++++++++++ .../Operations/Operations.fs | 246 +++++++++ .../Operations/SpGeMM/Expand.fs | 494 ++++++++++++++++++ .../Operations/SpGeMM/Masked.fs | 187 +++++++ .../{Vector => Operations}/SpMV.fs | 2 +- .../Vector/{Vector.fs => Primitives.fs} | 63 +-- 13 files changed, 1437 insertions(+), 258 deletions(-) rename src/GraphBLAS-sharp.Backend/Matrix/{Matrix.fs => Primitives.fs} (68%) create mode 100644 src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs create mode 100644 src/GraphBLAS-sharp.Backend/Operations/Operations.fs create mode 100644 src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs create mode 100644 src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Masked.fs rename src/GraphBLAS-sharp.Backend/{Vector => Operations}/SpMV.fs (99%) rename src/GraphBLAS-sharp.Backend/Vector/{Vector.fs => Primitives.fs} (76%) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs index 02dddc3e..f1d7f3d6 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs @@ -20,7 +20,7 @@ type Benchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem : st buildFunToBenchmark, converter: string -> 'elem, converterBool, - buildMatrix: Matrix.COO<_> -> Matrix<_>) = + buildMatrix: Primitives.COO<_> -> Matrix<_>) = let mutable funToBenchmark = None let mutable firstMatrix = Unchecked.defaultof> @@ -138,10 +138,10 @@ module WithoutTransfer = type Float32() = inherit Benchmark,float32>( - (Matrix.map2 ArithmeticOperations.float32SumOption), + (Primitives.map2 ArithmeticOperations.float32SumOption), float32, (fun _ -> Utils.nextSingle (System.Random())), - Matrix.COO + Primitives.COO ) static member InputMatricesProvider = @@ -150,10 +150,10 @@ module WithoutTransfer = type Bool() = inherit Benchmark,bool>( - (Matrix.map2 ArithmeticOperations.boolSumOption), + (Primitives.map2 ArithmeticOperations.boolSumOption), (fun _ -> true), (fun _ -> true), - Matrix.COO + Primitives.COO ) static member InputMatricesProvider = @@ -163,10 +163,10 @@ module WithoutTransfer = type Float32() = inherit Benchmark,float32>( - (Matrix.map2 ArithmeticOperations.float32SumOption), + (Primitives.map2 ArithmeticOperations.float32SumOption), float32, (fun _ -> Utils.nextSingle (System.Random())), - (fun matrix -> Matrix.CSR matrix.ToCSR) + (fun matrix -> Primitives.CSR matrix.ToCSR) ) static member InputMatricesProvider = @@ -175,10 +175,10 @@ module WithoutTransfer = type Bool() = inherit Benchmark,bool>( - (Matrix.map2 ArithmeticOperations.boolSumOption), + (Primitives.map2 ArithmeticOperations.boolSumOption), (fun _ -> true), (fun _ -> true), - (fun matrix -> Matrix.CSR matrix.ToCSR) + (fun matrix -> Primitives.CSR matrix.ToCSR) ) static member InputMatricesProvider = @@ -189,10 +189,10 @@ module WithoutTransfer = type Bool() = inherit Benchmark,bool>( - (Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne), + (Primitives.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne), (fun _ -> true), (fun _ -> true), - Matrix.COO + Primitives.COO ) static member InputMatricesProvider = @@ -201,10 +201,10 @@ module WithoutTransfer = type Float32() = inherit Benchmark,float32>( - (Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne), + (Primitives.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne), float32, (fun _ -> Utils.nextSingle (System.Random())), - Matrix.COO + Primitives.COO ) static member InputMatricesProvider = @@ -214,10 +214,10 @@ module WithoutTransfer = type Bool() = inherit Benchmark,bool>( - (Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne), + (Primitives.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne), (fun _ -> true), (fun _ -> true), - (fun matrix -> Matrix.CSR matrix.ToCSR) + (fun matrix -> Primitives.CSR matrix.ToCSR) ) static member InputMatricesProvider = @@ -226,10 +226,10 @@ module WithoutTransfer = type Float32() = inherit Benchmark,float32>( - (Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne), + (Primitives.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne), float32, (fun _ -> Utils.nextSingle (System.Random())), - (fun matrix -> Matrix.CSR matrix.ToCSR) + (fun matrix -> Primitives.CSR matrix.ToCSR) ) static member InputMatricesProvider = @@ -273,10 +273,10 @@ module WithTransfer = type Float32() = inherit Benchmark,float32>( - (Matrix.map2 ArithmeticOperations.float32SumOption), + (Primitives.map2 ArithmeticOperations.float32SumOption), float32, (fun _ -> Utils.nextSingle (System.Random())), - Matrix.COO, + Primitives.COO, (fun matrix -> matrix.ToHost) ) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs index 184bee28..4241707b 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs @@ -139,7 +139,7 @@ module WithoutTransfer = type Float32() = inherit Benchmark( - Matrix.SpGeMM.expand (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), + Primitives.SpGeMM.expand (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs index d1c16cb9..2efc736d 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs @@ -77,7 +77,7 @@ type Masked<'elem when 'elem : struct>( member this.FunCSR2CSC = match funCSR2CSC with | None -> - let x = Matrix.toCSCInPlace this.OclContext this.WorkGroupSize + let x = Primitives.toCSCInPlace this.OclContext this.WorkGroupSize funCSR2CSC <- Some x x | Some x -> x @@ -85,7 +85,7 @@ type Masked<'elem when 'elem : struct>( member this.FunCSC2CSR = match funCSC2CSR with | None -> - let x = Matrix.toCSRInPlace this.OclContext this.WorkGroupSize + let x = Primitives.toCSRInPlace this.OclContext this.WorkGroupSize funCSC2CSR <- Some x x | Some x -> x @@ -110,7 +110,7 @@ type Masked<'elem when 'elem : struct>( this.ResultMatrix.Dispose this.Processor member this.ReadMask(maskReader) = - maskHost <- Matrix.COO <| this.ReadMatrix maskReader + maskHost <- Primitives.COO <| this.ReadMatrix maskReader member this.ReadMatrices() = let matrixReader, maskReader = this.InputMatrixReader @@ -204,7 +204,7 @@ type MxmBenchmarksWithTransposing<'elem when 'elem : struct>( type Mxm4Float32MultiplicationOnlyBenchmark() = inherit MxmBenchmarksMultiplicationOnly( - Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), + Primitives.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) @@ -216,7 +216,7 @@ type Mxm4Float32MultiplicationOnlyBenchmark() = type Mxm4Float32WithTransposingBenchmark() = inherit MxmBenchmarksWithTransposing( - Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), + Primitives.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) @@ -228,7 +228,7 @@ type Mxm4Float32WithTransposingBenchmark() = type Mxm4BoolMultiplicationOnlyBenchmark() = inherit MxmBenchmarksMultiplicationOnly( - (Matrix.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)), + (Primitives.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)), (fun _ -> true), (fun _ -> true), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) @@ -240,7 +240,7 @@ type Mxm4BoolMultiplicationOnlyBenchmark() = type Mxm4BoolWithTransposingBenchmark() = inherit MxmBenchmarksWithTransposing( - (Matrix.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)), + (Primitives.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)), (fun _ -> true), (fun _ -> true), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) @@ -252,7 +252,7 @@ type Mxm4BoolWithTransposingBenchmark() = type Mxm4Float32MultiplicationOnlyWithZerosFilterBenchmark() = inherit MxmBenchmarksMultiplicationOnly( - (Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul)), + (Primitives.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul)), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) @@ -264,7 +264,7 @@ type Mxm4Float32MultiplicationOnlyWithZerosFilterBenchmark() = type Mxm4Float32WithTransposingWithZerosFilterBenchmark() = inherit MxmBenchmarksWithTransposing( - Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), + Primitives.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs index 7db34de2..9e0bc4de 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs @@ -122,26 +122,26 @@ module WithoutTransfer = type Float() = inherit Benchmark( - (Vector.map2 ArithmeticOperations.floatSumOption), + (Primitives.map2 ArithmeticOperations.floatSumOption), VectorGenerator.floatPair Sparse) type Int32() = inherit Benchmark( - (Vector.map2 ArithmeticOperations.intSumOption), + (Primitives.map2 ArithmeticOperations.intSumOption), VectorGenerator.intPair Sparse) module AtLeastOne = type Float() = inherit Benchmark( - (Vector.map2AtLeastOne ArithmeticOperations.floatSumAtLeastOne), + (Primitives.map2AtLeastOne ArithmeticOperations.floatSumAtLeastOne), VectorGenerator.floatPair Sparse) type Int32() = inherit Benchmark( - (Vector.map2AtLeastOne ArithmeticOperations.intSumAtLeastOne), + (Primitives.map2AtLeastOne ArithmeticOperations.intSumAtLeastOne), VectorGenerator.intPair Sparse) module WithTransfer = @@ -178,24 +178,24 @@ module WithTransfer = type Float() = inherit Benchmark( - (Vector.map2 ArithmeticOperations.floatSumOption), + (Primitives.map2 ArithmeticOperations.floatSumOption), VectorGenerator.floatPair Sparse) type Int32() = inherit Benchmark( - (Vector.map2 ArithmeticOperations.intSumOption), + (Primitives.map2 ArithmeticOperations.intSumOption), VectorGenerator.intPair Sparse) module AtLeastOne = type Float() = inherit Benchmark( - (Vector.map2AtLeastOne ArithmeticOperations.floatSumAtLeastOne), + (Primitives.map2AtLeastOne ArithmeticOperations.floatSumAtLeastOne), VectorGenerator.floatPair Sparse) type Int32() = inherit Benchmark( - (Vector.map2AtLeastOne ArithmeticOperations.intSumAtLeastOne), + (Primitives.map2AtLeastOne ArithmeticOperations.intSumAtLeastOne), VectorGenerator.intPair Sparse) diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs b/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs index 6f9cb430..bf9ee64e 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs @@ -26,7 +26,7 @@ module BFS = let zeroCreate = ClArray.zeroCreate clContext workGroupSize - let ofList = Vector.ofList clContext workGroupSize + let ofList = Primitives.ofList clContext workGroupSize let maskComplementedTo = Vector.map2InPlace Mask.complementedOp clContext workGroupSize diff --git a/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj b/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj index 173f3123..4c6b2646 100644 --- a/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj +++ b/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj @@ -46,8 +46,7 @@ - - + @@ -61,10 +60,20 @@ - + + + + + + + + + + + diff --git a/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs b/src/GraphBLAS-sharp.Backend/Matrix/Primitives.fs similarity index 68% rename from src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs rename to src/GraphBLAS-sharp.Backend/Matrix/Primitives.fs index 82b062b3..2c0858a0 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/Primitives.fs @@ -7,9 +7,8 @@ open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Objects.ClMatrix open GraphBLAS.FSharp.Backend.Vector -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -module Matrix = +module Primitives = /// /// Creates new matrix with the values from the given one. /// New matrix represented in the format of the given one. @@ -296,80 +295,6 @@ module Matrix = |> ClMatrix.COO | _ -> failwith "Not yet implemented" - /// - /// Builds a new matrix whose values are the results of applying the given function - /// to the corresponding pairs of values from the two matrices. - /// - /// - /// A function to transform pairs of values from the input matrices. - /// Operands and result types should be optional to distinguish explicit and implicit zeroes - /// - /// - /// Formats of the given matrices should match, otherwise an exception will be thrown. - /// - /// OpenCL context. - /// Should be a power of 2 and greater than 1. - let map2 (op: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) workGroupSize = - let map2COO = - COO.Matrix.map2 op clContext workGroupSize - - let map2CSR = - CSR.Matrix.map2 op clContext workGroupSize - - let transposeCOO = - COO.Matrix.transposeInPlace clContext workGroupSize - - fun (processor: MailboxProcessor<_>) allocationMode matrix1 matrix2 -> - match matrix1, matrix2 with - | ClMatrix.COO m1, ClMatrix.COO m2 -> - map2COO processor allocationMode m1 m2 - |> ClMatrix.COO - | ClMatrix.CSR m1, ClMatrix.CSR m2 -> - map2CSR processor allocationMode m1 m2 - |> ClMatrix.COO - | ClMatrix.CSC m1, ClMatrix.CSC m2 -> - (map2CSR processor allocationMode m1.ToCSR m2.ToCSR) - |> transposeCOO processor - |> ClMatrix.COO - | _ -> failwith "Matrix formats are not matching" - - /// - /// Builds a new matrix whose values are the results of applying the given function - /// to the corresponding pairs of values from the two matrices. - /// - /// - /// A function to transform pairs of values from the input matrices. - /// Operation assumption: one of the operands should always be non-zero. - /// - /// - /// Formats of the given matrices should match, otherwise an exception will be thrown. - /// - /// OpenCL context. - /// Should be a power of 2 and greater than 1. - let map2AtLeastOne (op: Expr -> 'c option>) (clContext: ClContext) workGroupSize = - let COOMap2 = - COO.Matrix.map2AtLeastOne clContext op workGroupSize - - let CSRMap2 = - CSR.Matrix.map2AtLeastOne clContext op workGroupSize - - let COOTranspose = - COO.Matrix.transposeInPlace clContext workGroupSize - - fun (processor: MailboxProcessor<_>) allocationMode matrix1 matrix2 -> - match matrix1, matrix2 with - | ClMatrix.COO m1, ClMatrix.COO m2 -> - COOMap2 processor allocationMode m1 m2 - |> ClMatrix.COO - | ClMatrix.CSR m1, ClMatrix.CSR m2 -> - CSRMap2 processor allocationMode m1 m2 - |> ClMatrix.COO - | ClMatrix.CSC m1, ClMatrix.CSC m2 -> - (CSRMap2 processor allocationMode m1.ToCSR m2.ToCSR) - |> COOTranspose processor - |> ClMatrix.COO - | _ -> failwith "Matrix formats are not matching" - /// /// Transposes the given matrix and returns result. /// The given matrix should neither be used afterwards nor be disposed. @@ -436,81 +361,3 @@ module Matrix = Values = copyData processor allocationMode m.Values } |> ClMatrix.CSR | ClMatrix.LIL _ -> failwith "Not yet implemented" - - /// - /// Kronecker product for matrices. - /// - /// - /// Element-wise operation. - /// Operands and result types should be optional to distinguish explicit and implicit zeroes - /// - /// OpenCL context. - /// Should be a power of 2 and greater than 1. - let kronecker (op: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) workGroupSize = - let run = - CSR.Matrix.kronecker clContext workGroupSize op - - fun (queue: MailboxProcessor<_>) allocationFlag (matrix1: ClMatrix<'a>) (matrix2: ClMatrix<'b>) -> - match matrix1, matrix2 with - | ClMatrix.CSR m1, ClMatrix.CSR m2 -> - let result = run queue allocationFlag m1 m2 - Option.map ClMatrix.COO result - | _ -> failwith "Both matrices should be in CSR format." - - /// - /// Sparse general matrix-matrix multiplication. - /// - module SpGeMM = - /// - /// Masked matrix-matrix multiplication. - /// - /// Type of binary function to reduce entries. - /// Type of binary function to combine entries. - /// OpenCL context. - /// Should be a power of 2 and greater than 1. - let masked - (opAdd: Expr<'c -> 'c -> 'c option>) - (opMul: Expr<'a -> 'b -> 'c option>) - (clContext: ClContext) - workGroupSize - = - - let runCSRnCSC = - SpGeMM.Masked.run opAdd opMul clContext workGroupSize - - fun (queue: MailboxProcessor<_>) (matrix1: ClMatrix<'a>) (matrix2: ClMatrix<'b>) (mask: ClMatrix<_>) -> - match matrix1, matrix2, mask with - | ClMatrix.CSR m1, ClMatrix.CSC m2, ClMatrix.COO mask -> runCSRnCSC queue m1 m2 mask |> ClMatrix.COO - | _ -> failwith "Matrix formats are not matching" - - /// - /// Generalized matrix-matrix multiplication. - /// - /// Type of binary function to reduce entries. - /// Type of binary function to combine entries. - /// OpenCL context. - /// Should be a power of 2 and greater than 1. - let expand - (opAdd: Expr<'c -> 'c -> 'c option>) - (opMul: Expr<'a -> 'b -> 'c option>) - (clContext: ClContext) - workGroupSize - = - - let run = - SpGeMM.Expand.run opAdd opMul clContext workGroupSize - - fun (processor: MailboxProcessor<_>) allocationMode (leftMatrix: ClMatrix<'a>) (rightMatrix: ClMatrix<'b>) -> - match leftMatrix, rightMatrix with - | ClMatrix.CSR leftMatrix, ClMatrix.CSR rightMatrix -> - let allocCapacity = - List.max [ sizeof<'a> - sizeof<'c> - sizeof<'b> ] - * 1 - - let resultCapacity = - (clContext.MaxMemAllocSize / allocCapacity) / 3 - - run processor allocationMode resultCapacity leftMatrix rightMatrix - | _ -> failwith "Matrix formats are not matching" diff --git a/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs b/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs new file mode 100644 index 00000000..ca0b8f81 --- /dev/null +++ b/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs @@ -0,0 +1,457 @@ +namespace GraphBLAS.FSharp.Backend.Matrix.CSR + +open FSharpx.Collections +open Microsoft.FSharp.Quotations +open FSharp.Quotations.Evaluator.QuotationEvaluationExtensions +open Brahma.FSharp +open GraphBLAS.FSharp.Backend.Quotes +open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp.Backend.Matrix.COO +open GraphBLAS.FSharp.Backend.Matrix.CSR +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions +open GraphBLAS.FSharp.Backend.Objects.ClMatrix +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions + +module internal Kronecker = + let private updateBitmap (clContext: ClContext) workGroupSize op = + + let updateBitmap (op: Expr<'a option -> 'b option -> 'c option>) = + <@ fun (ndRange: Range1D) (operand: ClCell<'a>) valuesLength zeroCount (values: ClArray<'b>) (resultBitmap: ClArray) -> + + let gid = ndRange.GlobalID0 + + if gid = 0 then + + let item = resultBitmap.[0] + let newItem = item + zeroCount + + match (%op) (Some operand.Value) None with + | Some _ -> resultBitmap.[0] <- newItem + | _ -> () + + elif (gid - 1) < valuesLength then + + let item = resultBitmap.[gid] + let newItem = item + 1 + + match (%op) (Some operand.Value) (Some values.[gid - 1]) with + | Some _ -> resultBitmap.[gid] <- newItem + | _ -> () @> + + let updateBitmap = clContext.Compile <| updateBitmap op + + fun (processor: MailboxProcessor<_>) (operand: ClCell<'a>) (matrixRight: CSR<'b>) (bitmap: ClArray) -> + + let resultLength = matrixRight.NNZ + 1 + + let ndRange = + Range1D.CreateValid(resultLength, workGroupSize) + + let updateBitmap = updateBitmap.GetKernel() + + let numberOfZeros = + matrixRight.ColumnCount * matrixRight.RowCount + - matrixRight.NNZ + + processor.Post( + Msg.MsgSetArguments + (fun () -> + updateBitmap.KernelFunc ndRange operand matrixRight.NNZ numberOfZeros matrixRight.Values bitmap) + ) + + processor.Post(Msg.CreateRunMsg<_, _> updateBitmap) + + let private getAllocationSize (clContext: ClContext) workGroupSize op = + + let updateBitmap = updateBitmap clContext workGroupSize op + + let sum = + Reduce.sum <@ fun x y -> x + y @> 0 clContext workGroupSize + + let item = ClArray.item clContext workGroupSize + + let createClArray = + ClArray.zeroCreate clContext workGroupSize + + let opOnHost = op.Evaluate() + + fun (queue: MailboxProcessor<_>) (matrixZero: COO<'c> option) (matrixLeft: CSR<'a>) (matrixRight: CSR<'b>) -> + + let nnz = + match opOnHost None None with + | Some _ -> + let leftZeroCount = + matrixLeft.RowCount * matrixLeft.ColumnCount + - matrixLeft.NNZ + + let rightZeroCount = + matrixRight.RowCount * matrixRight.ColumnCount + - matrixRight.NNZ + + leftZeroCount * rightZeroCount + | _ -> 0 + + let bitmap = + createClArray queue DeviceOnly (matrixRight.NNZ + 1) + + for index in 0 .. matrixLeft.NNZ - 1 do + let value = item queue index matrixLeft.Values + + updateBitmap queue value matrixRight bitmap + + value.Free queue + + let bitmapSum = sum queue bitmap + + bitmap.Free queue + + let leftZeroCount = + matrixLeft.ColumnCount * matrixLeft.RowCount + - matrixLeft.NNZ + + match matrixZero with + | Some m -> m.NNZ * leftZeroCount + | _ -> 0 + + nnz + + bitmapSum.ToHostAndFree queue + + let private preparePositions<'a, 'b, 'c when 'b: struct> (clContext: ClContext) workGroupSize op = + + let preparePositions (op: Expr<'a option -> 'b option -> 'c option>) = + <@ fun (ndRange: Range1D) (operand: ClCell<'a>) rowCount columnCount (values: ClArray<'b>) (rowPointers: ClArray) (columns: ClArray) (resultBitmap: ClArray) (resultValues: ClArray<'c>) -> + + let gid = ndRange.GlobalID0 + + if gid < rowCount * columnCount then + + let columnIndex = gid % columnCount + let rowIndex = gid / columnCount + + let firstIndex = rowPointers.[rowIndex] + let lastIndex = rowPointers.[rowIndex + 1] - 1 + + let value = + (%Search.Bin.inRange) firstIndex lastIndex columnIndex columns values + + match (%op) (Some operand.Value) value with + | Some resultValue -> + resultValues.[gid] <- resultValue + resultBitmap.[gid] <- 1 + | None -> resultBitmap.[gid] <- 0 @> + + let kernel = clContext.Compile <| preparePositions op + + fun (processor: MailboxProcessor<_>) (operand: ClCell<'a>) (matrix: CSR<'b>) (resultDenseMatrix: ClArray<'c>) (resultBitmap: ClArray) -> + + let resultLength = matrix.RowCount * matrix.ColumnCount + + let ndRange = + Range1D.CreateValid(resultLength, workGroupSize) + + let kernel = kernel.GetKernel() + + processor.Post( + Msg.MsgSetArguments + (fun () -> + kernel.KernelFunc + ndRange + operand + matrix.RowCount + matrix.ColumnCount + matrix.Values + matrix.RowPointers + matrix.Columns + resultBitmap + resultDenseMatrix) + ) + + processor.Post(Msg.CreateRunMsg<_, _> kernel) + + let private setPositions<'c when 'c: struct> (clContext: ClContext) workGroupSize = + + let setPositions = + <@ fun (ndRange: Range1D) rowCount columnCount startIndex (rowOffset: ClCell) (columnOffset: ClCell) (bitmap: ClArray) (values: ClArray<'c>) (resultRows: ClArray) (resultColumns: ClArray) (resultValues: ClArray<'c>) -> + + let gid = ndRange.GlobalID0 + + if gid < rowCount * columnCount + && (gid = 0 && bitmap.[gid] = 1 + || gid > 0 && bitmap.[gid - 1] < bitmap.[gid]) then + + let columnIndex = gid % columnCount + let rowIndex = gid / columnCount + + let index = startIndex + bitmap.[gid] - 1 + + resultRows.[index] <- rowIndex + rowOffset.Value + resultColumns.[index] <- columnIndex + columnOffset.Value + resultValues.[index] <- values.[gid] @> + + let kernel = clContext.Compile <| setPositions + + let scan = + PrefixSum.standardIncludeInPlace clContext workGroupSize + + fun (processor: MailboxProcessor<_>) rowCount columnCount (rowOffset: int) (columnOffset: int) (startIndex: int) (resultMatrix: COO<'c>) (values: ClArray<'c>) (bitmap: ClArray) -> + + let sum = scan processor bitmap + + let ndRange = + Range1D.CreateValid(rowCount * columnCount, workGroupSize) + + let kernel = kernel.GetKernel() + + let rowOffset = rowOffset |> clContext.CreateClCell + let columnOffset = columnOffset |> clContext.CreateClCell + + processor.Post( + Msg.MsgSetArguments + (fun () -> + kernel.KernelFunc + ndRange + rowCount + columnCount + startIndex + rowOffset + columnOffset + bitmap + values + resultMatrix.Rows + resultMatrix.Columns + resultMatrix.Values) + ) + + processor.Post(Msg.CreateRunMsg<_, _> kernel) + + (sum.ToHostAndFree processor) + startIndex + + let private copyToResult (clContext: ClContext) workGroupSize = + + let copyToResult = + <@ fun (ndRange: Range1D) startIndex sourceLength (rowOffset: ClCell) (columnOffset: ClCell) (sourceRows: ClArray) (sourceColumns: ClArray) (sourceValues: ClArray<'c>) (resultRows: ClArray) (resultColumns: ClArray) (resultValues: ClArray<'c>) -> + + let gid = ndRange.GlobalID0 + + if gid < sourceLength then + let index = startIndex + gid + + resultRows.[index] <- rowOffset.Value + sourceRows.[gid] + resultColumns.[index] <- columnOffset.Value + sourceColumns.[gid] + resultValues.[index] <- sourceValues.[gid] @> + + let kernel = clContext.Compile <| copyToResult + + fun (processor: MailboxProcessor<_>) startIndex (rowOffset: int) (columnOffset: int) (resultMatrix: COO<'c>) (sourceMatrix: COO<'c>) -> + + let ndRange = + Range1D.CreateValid(sourceMatrix.NNZ, workGroupSize) + + let kernel = kernel.GetKernel() + + let rowOffset = rowOffset |> clContext.CreateClCell + let columnOffset = columnOffset |> clContext.CreateClCell + + processor.Post( + Msg.MsgSetArguments + (fun () -> + kernel.KernelFunc + ndRange + startIndex + sourceMatrix.NNZ + rowOffset + columnOffset + sourceMatrix.Rows + sourceMatrix.Columns + sourceMatrix.Values + resultMatrix.Rows + resultMatrix.Columns + resultMatrix.Values) + ) + + processor.Post(Msg.CreateRunMsg<_, _> kernel) + + let private insertZero (clContext: ClContext) workGroupSize = + + let copy = copyToResult clContext workGroupSize + + fun queue startIndex (zeroCounts: int list array) (matrixZero: COO<'c>) resultMatrix -> + + let rowCount = zeroCounts.Length + + let mutable startIndex = startIndex + + let insertMany row firstColumn count = + for i in 0 .. count - 1 do + let rowOffset = row * matrixZero.RowCount + + let columnOffset = + (firstColumn + i) * matrixZero.ColumnCount + + copy queue startIndex rowOffset columnOffset resultMatrix matrixZero + + startIndex <- startIndex + matrixZero.NNZ + + let rec insertInRowRec zeroCounts row column = + match zeroCounts with + | [] -> () + | h :: tl -> + insertMany row column h + + insertInRowRec tl row (h + column + 1) + + for row in 0 .. rowCount - 1 do + insertInRowRec zeroCounts.[row] row 0 + + let private insertNonZero (clContext: ClContext) workGroupSize op = + + let item = ClArray.item clContext workGroupSize + + let preparePositions = + preparePositions clContext workGroupSize op + + let setPositions = setPositions clContext workGroupSize + + fun queue (rowsEdges: (int * int) array) (matrixRight: CSR<'b>) (leftValues: ClArray<'a>) (leftColsHost: int array) (resultMatrix: COO<'c>) -> + + let setPositions = + setPositions queue matrixRight.RowCount matrixRight.ColumnCount + + let rowCount = rowsEdges.Length + + let length = + matrixRight.RowCount * matrixRight.ColumnCount + + let bitmap = + clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, length) + + let mappedMatrix = + clContext.CreateClArrayWithSpecificAllocationMode<'c>(DeviceOnly, length) + + let mutable startIndex = 0 + + for row in 0 .. rowCount - 1 do + let leftEdge, rightEdge = rowsEdges.[row] + + for i in leftEdge .. rightEdge do + let value = item queue i leftValues + let column = leftColsHost.[i] + + let rowOffset = row * matrixRight.RowCount + let columnOffset = column * matrixRight.ColumnCount + + preparePositions queue value matrixRight mappedMatrix bitmap + + value.Free queue + + startIndex <- setPositions rowOffset columnOffset startIndex resultMatrix mappedMatrix bitmap + + bitmap.Free queue + mappedMatrix.Free queue + + startIndex + + let private mapAll<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality> + (clContext: ClContext) + workGroupSize + (op: Expr<'a option -> 'b option -> 'c option>) + = + + let insertNonZero = insertNonZero clContext workGroupSize op + + let insertZero = insertZero clContext workGroupSize + + fun (queue: MailboxProcessor<_>) allocationMode (resultNNZ: int) (matrixZero: COO<'c> option) (matrixLeft: CSR<'a>) (matrixRight: CSR<'b>) -> + + let resultRows = + clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, resultNNZ) + + let resultColumns = + clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, resultNNZ) + + let resultValues = + clContext.CreateClArrayWithSpecificAllocationMode<'c>(allocationMode, resultNNZ) + + let resultMatrix = + { Context = clContext + Rows = resultRows + Columns = resultColumns + Values = resultValues + RowCount = matrixLeft.RowCount * matrixRight.RowCount + ColumnCount = matrixLeft.ColumnCount * matrixRight.ColumnCount } + + let leftRowPointers = matrixLeft.RowPointers.ToHost queue + let leftColumns = matrixLeft.Columns.ToHost queue + + let nnzInRows = + leftRowPointers + |> Array.pairwise + |> Array.map (fun (fst, snd) -> snd - fst) + + let rowsEdges = + leftRowPointers + |> Array.pairwise + |> Array.map (fun (fst, snd) -> (fst, snd - 1)) + + let (zeroCounts: int list array) = Array.zeroCreate matrixLeft.RowCount + + { 0 .. matrixLeft.RowCount - 1 } + |> Seq.iter2 + (fun edges i -> + zeroCounts.[i] <- + leftColumns.[fst edges..snd edges] + |> Array.toList + |> List.insertAt 0 -1 + |> List.insertAt (nnzInRows.[i] + 1) matrixLeft.ColumnCount + |> List.pairwise + |> List.map (fun (fstCol, sndCol) -> sndCol - fstCol - 1)) + rowsEdges + + let startIndex = + insertNonZero queue rowsEdges matrixRight matrixLeft.Values leftColumns resultMatrix + + matrixZero + |> Option.iter (fun m -> insertZero queue startIndex zeroCounts m resultMatrix) + + resultMatrix + + let run<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality> + (clContext: ClContext) + workGroupSize + (op: Expr<'a option -> 'b option -> 'c option>) + = + + let getSize = + getAllocationSize clContext workGroupSize op + + let mapWithValue = + Map.WithValue.run clContext op workGroupSize + + let mapAll = mapAll clContext workGroupSize op + + let bitonic = + Sort.Bitonic.sortKeyValuesInplace clContext workGroupSize + + fun (queue: MailboxProcessor<_>) allocationMode (matrixLeft: CSR<'a>) (matrixRight: CSR<'b>) -> + + let matrixZero = + mapWithValue queue allocationMode None matrixRight + + let size = + getSize queue matrixZero matrixLeft matrixRight + + if size = 0 then + matrixZero + |> Option.iter (fun m -> m.Dispose queue) + + None + else + let result = + mapAll queue allocationMode size matrixZero matrixLeft matrixRight + + matrixZero + |> Option.iter (fun m -> m.Dispose queue) + + bitonic queue result.Rows result.Columns result.Values + + result |> Some diff --git a/src/GraphBLAS-sharp.Backend/Operations/Operations.fs b/src/GraphBLAS-sharp.Backend/Operations/Operations.fs new file mode 100644 index 00000000..f2722fa5 --- /dev/null +++ b/src/GraphBLAS-sharp.Backend/Operations/Operations.fs @@ -0,0 +1,246 @@ +namespace GraphBLAS.FSharp.Backend + +open Brahma.FSharp +open Microsoft.FSharp.Quotations +open GraphBLAS.FSharp.Backend.Objects +open GraphBLAS.FSharp.Backend.Matrix +open GraphBLAS.FSharp.Backend.Vector +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions + +module Operations = + module Vector = + /// + /// Builds a new vector whose values are the results of applying the given function + /// to the corresponding pairs of values from the two vectors. + /// + /// + /// A function to transform pairs of values from the input vectors. + /// Operands and result types should be optional to distinguish explicit and implicit zeroes. + /// + /// + /// Formats of the given vectors should match, otherwise an exception will be thrown. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let map2 (op: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) workGroupSize = + let map2Dense = + Dense.Vector.map2 op clContext workGroupSize + + let map2Sparse = + Sparse.Vector.map2 op clContext workGroupSize + + fun (processor: MailboxProcessor<_>) allocationMode (leftVector: ClVector<'a>) (rightVector: ClVector<'b>) -> + match leftVector, rightVector with + | ClVector.Dense left, ClVector.Dense right -> + ClVector.Dense + <| map2Dense processor allocationMode left right + | ClVector.Sparse left, ClVector.Sparse right -> + ClVector.Sparse + <| map2Sparse processor allocationMode left right + | _ -> failwith "Vector formats are not matching." + + /// + /// Builds a new vector whose values are the results of applying the given function + /// to the corresponding pairs of values from the two vectors. + /// + /// + /// A function to transform pairs of values from the input vectors. + /// Operation assumption: one of the operands should always be non-zero. + /// + /// + /// Formats of the given vectors should match, otherwise an exception will be thrown. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let map2AtLeastOne (op: Expr -> 'c option>) (clContext: ClContext) workGroupSize = + let map2Sparse = + Sparse.Vector.map2AtLeastOne op clContext workGroupSize + + let map2Dense = + Dense.Vector.map2AtLeastOne op clContext workGroupSize + + fun (processor: MailboxProcessor<_>) allocationMode (leftVector: ClVector<'a>) (rightVector: ClVector<'b>) -> + match leftVector, rightVector with + | ClVector.Sparse left, ClVector.Sparse right -> + ClVector.Sparse + <| map2Sparse processor allocationMode left right + | ClVector.Dense left, ClVector.Dense right -> + ClVector.Dense + <| map2Dense processor allocationMode left right + | _ -> failwith "Vector formats are not matching." + + module Matrix = + /// + /// Builds a new matrix whose values are the results of applying the given function + /// to the corresponding pairs of values from the two matrices. + /// + /// + /// A function to transform pairs of values from the input matrices. + /// Operands and result types should be optional to distinguish explicit and implicit zeroes + /// + /// + /// Formats of the given matrices should match, otherwise an exception will be thrown. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let map2 (op: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) workGroupSize = + let map2COO = + COO.Matrix.map2 op clContext workGroupSize + + let map2CSR = + CSR.Matrix.map2 op clContext workGroupSize + + let transposeCOO = + COO.Matrix.transposeInPlace clContext workGroupSize + + fun (processor: MailboxProcessor<_>) allocationMode matrix1 matrix2 -> + match matrix1, matrix2 with + | ClMatrix.COO m1, ClMatrix.COO m2 -> + map2COO processor allocationMode m1 m2 + |> ClMatrix.COO + | ClMatrix.CSR m1, ClMatrix.CSR m2 -> + map2CSR processor allocationMode m1 m2 + |> ClMatrix.COO + | ClMatrix.CSC m1, ClMatrix.CSC m2 -> + (map2CSR processor allocationMode m1.ToCSR m2.ToCSR) + |> transposeCOO processor + |> ClMatrix.COO + | _ -> failwith "Matrix formats are not matching" + + /// + /// Builds a new matrix whose values are the results of applying the given function + /// to the corresponding pairs of values from the two matrices. + /// + /// + /// A function to transform pairs of values from the input matrices. + /// Operation assumption: one of the operands should always be non-zero. + /// + /// + /// Formats of the given matrices should match, otherwise an exception will be thrown. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let map2AtLeastOne (op: Expr -> 'c option>) (clContext: ClContext) workGroupSize = + let COOMap2 = + COO.Matrix.map2AtLeastOne clContext op workGroupSize + + let CSRMap2 = + CSR.Matrix.map2AtLeastOne clContext op workGroupSize + + let COOTranspose = + COO.Matrix.transposeInPlace clContext workGroupSize + + fun (processor: MailboxProcessor<_>) allocationMode matrix1 matrix2 -> + match matrix1, matrix2 with + | ClMatrix.COO m1, ClMatrix.COO m2 -> + COOMap2 processor allocationMode m1 m2 + |> ClMatrix.COO + | ClMatrix.CSR m1, ClMatrix.CSR m2 -> + CSRMap2 processor allocationMode m1 m2 + |> ClMatrix.COO + | ClMatrix.CSC m1, ClMatrix.CSC m2 -> + (CSRMap2 processor allocationMode m1.ToCSR m2.ToCSR) + |> COOTranspose processor + |> ClMatrix.COO + | _ -> failwith "Matrix formats are not matching" + + /// + /// Matrix-vector multiplication. + /// + /// Type of binary function to reduce entries. + /// Type of binary function to combine entries. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let SpMV + (add: Expr<'c option -> 'c option -> 'c option>) + (mul: Expr<'a option -> 'b option -> 'c option>) + (clContext: ClContext) + workGroupSize + = + + let run = SpMV.run add mul clContext workGroupSize + + fun (queue: MailboxProcessor<_>) allocationMode (matrix: ClMatrix<'a>) (vector: ClVector<'b>) -> + match matrix, vector with + | ClMatrix.CSR m, ClVector.Dense v -> run queue allocationMode m v |> ClVector.Dense + | _ -> failwith "Not implemented yet" + + + /// + /// Kronecker product for matrices. + /// + /// + /// Element-wise operation. + /// Operands and result types should be optional to distinguish explicit and implicit zeroes + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let kronecker (op: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) workGroupSize = + let run = + CSR.Matrix.kronecker clContext workGroupSize op + + fun (queue: MailboxProcessor<_>) allocationFlag (matrix1: ClMatrix<'a>) (matrix2: ClMatrix<'b>) -> + match matrix1, matrix2 with + | ClMatrix.CSR m1, ClMatrix.CSR m2 -> + let result = run queue allocationFlag m1 m2 + Option.map ClMatrix.COO result + | _ -> failwith "Both matrices should be in CSR format." + + /// + /// Sparse general matrix-matrix multiplication. + /// + module SpGeMM = + /// + /// Masked matrix-matrix multiplication. + /// + /// Type of binary function to reduce entries. + /// Type of binary function to combine entries. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let masked + (opAdd: Expr<'c -> 'c -> 'c option>) + (opMul: Expr<'a -> 'b -> 'c option>) + (clContext: ClContext) + workGroupSize + = + + let runCSRnCSC = + SpGeMM.Masked.run opAdd opMul clContext workGroupSize + + fun (queue: MailboxProcessor<_>) (matrix1: ClMatrix<'a>) (matrix2: ClMatrix<'b>) (mask: ClMatrix<_>) -> + match matrix1, matrix2, mask with + | ClMatrix.CSR m1, ClMatrix.CSC m2, ClMatrix.COO mask -> runCSRnCSC queue m1 m2 mask |> ClMatrix.COO + | _ -> failwith "Matrix formats are not matching" + + /// + /// Generalized matrix-matrix multiplication. + /// + /// Type of binary function to reduce entries. + /// Type of binary function to combine entries. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let expand + (opAdd: Expr<'c -> 'c -> 'c option>) + (opMul: Expr<'a -> 'b -> 'c option>) + (clContext: ClContext) + workGroupSize + = + + let run = + SpGeMM.Expand.run opAdd opMul clContext workGroupSize + + fun (processor: MailboxProcessor<_>) allocationMode (leftMatrix: ClMatrix<'a>) (rightMatrix: ClMatrix<'b>) -> + match leftMatrix, rightMatrix with + | ClMatrix.CSR leftMatrix, ClMatrix.CSR rightMatrix -> + let allocCapacity = + List.max [ sizeof<'a> + sizeof<'c> + sizeof<'b> ] + * 1 + + let resultCapacity = + (clContext.MaxMemAllocSize / allocCapacity) / 3 + + run processor allocationMode resultCapacity leftMatrix rightMatrix + | _ -> failwith "Matrix formats are not matching" + diff --git a/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs new file mode 100644 index 00000000..ea15ca75 --- /dev/null +++ b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs @@ -0,0 +1,494 @@ +namespace GraphBLAS.FSharp.Backend.Matrix.SpGeMM + +open Brahma.FSharp +open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp.Backend.Common.Sort +open GraphBLAS.FSharp.Backend.Matrix +open GraphBLAS.FSharp.Backend.Quotes +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Backend.Objects +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions +open FSharp.Quotations +open GraphBLAS.FSharp.Backend.Objects.ClMatrix + +module internal Expand = + let getSegmentPointers (clContext: ClContext) workGroupSize = + + let gather = Gather.run clContext workGroupSize + + let prefixSum = + PrefixSum.standardExcludeInPlace clContext workGroupSize + + fun (processor: MailboxProcessor<_>) (leftMatrixColumns: ClArray) (rightMatrixRowsLengths: ClArray) -> + + let segmentsLengths = + clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, leftMatrixColumns.Length) + + // extract needed lengths by left matrix nnz + gather processor leftMatrixColumns rightMatrixRowsLengths segmentsLengths + + // compute pointers + let length = + (prefixSum processor segmentsLengths) + .ToHostAndFree processor + + length, segmentsLengths + + let multiply (predicate: Expr<'a -> 'b -> 'c option>) (clContext: ClContext) workGroupSize = + let getBitmap = + ClArray.map2<'a, 'b, int> (Map.choose2Bitmap predicate) clContext workGroupSize + + let prefixSum = + PrefixSum.standardExcludeInPlace clContext workGroupSize + + let assignValues = + ClArray.assignOption2 predicate clContext workGroupSize + + let scatter = + Scatter.lastOccurrence clContext workGroupSize + + fun (processor: MailboxProcessor<_>) (firstValues: ClArray<'a>) (secondValues: ClArray<'b>) (columns: ClArray) (rows: ClArray) -> + + let positions = + getBitmap processor DeviceOnly firstValues secondValues + + let resultLength = + (prefixSum processor positions) + .ToHostAndFree(processor) + + if resultLength = 0 then + positions.Free processor + + None + else + let resultColumns = + clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, resultLength) + + scatter processor positions columns resultColumns + + let resultRows = + clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, resultLength) + + scatter processor positions rows resultRows + + let resultValues = + clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, resultLength) + + assignValues processor firstValues secondValues positions resultValues + + positions.Free processor + + Some(resultValues, resultColumns, resultRows) + + let expand (clContext: ClContext) workGroupSize = + + let idScatter = + Scatter.initLastOccurrence Map.id clContext workGroupSize + + let scatter = + Scatter.lastOccurrence clContext workGroupSize + + let zeroCreate = + ClArray.zeroCreate clContext workGroupSize + + let maxPrefixSum = + PrefixSum.runIncludeInPlace <@ max @> clContext workGroupSize + + let create = ClArray.create clContext workGroupSize + + let gather = Gather.run clContext workGroupSize + + let segmentPrefixSum = + PrefixSum.ByKey.sequentialInclude <@ (+) @> 0 clContext workGroupSize + + let removeDuplicates = + ClArray.removeDuplications clContext workGroupSize + + let leftMatrixGather = Gather.run clContext workGroupSize + + let rightMatrixGather = Gather.run clContext workGroupSize + + fun (processor: MailboxProcessor<_>) (lengths: int) (segmentsPointers: ClArray) (leftMatrix: ClMatrix.COO<'a>) (rightMatrix: ClMatrix.CSR<'b>) -> + // Compute left matrix positions + let leftMatrixPositions = zeroCreate processor DeviceOnly lengths + + idScatter processor segmentsPointers leftMatrixPositions + + (maxPrefixSum processor leftMatrixPositions 0) + .Free processor + + // Compute right matrix positions + let rightMatrixPositions = create processor DeviceOnly lengths 1 + + let requiredRightMatrixPointers = + zeroCreate processor DeviceOnly leftMatrix.Columns.Length + + gather processor leftMatrix.Columns rightMatrix.RowPointers requiredRightMatrixPointers + + scatter processor segmentsPointers requiredRightMatrixPointers rightMatrixPositions + + requiredRightMatrixPointers.Free processor + + // another way to get offsets ??? + let offsets = + removeDuplicates processor segmentsPointers + + segmentPrefixSum processor offsets.Length rightMatrixPositions leftMatrixPositions offsets + + offsets.Free processor + + // compute columns + let columns = + clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, lengths) + + gather processor rightMatrixPositions rightMatrix.Columns columns + + let rows = + clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, lengths) + + gather processor leftMatrixPositions leftMatrix.Rows rows + + // compute left matrix values + let leftMatrixValues = + clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, lengths) + + leftMatrixGather processor leftMatrixPositions leftMatrix.Values leftMatrixValues + + leftMatrixPositions.Free processor + + // compute right matrix values + let rightMatrixValues = + clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, lengths) + + rightMatrixGather processor rightMatrixPositions rightMatrix.Values rightMatrixValues + + rightMatrixPositions.Free processor + + // left, right matrix values, columns and rows indices + leftMatrixValues, rightMatrixValues, columns, rows + + let sortByColumnsAndRows (clContext: ClContext) workGroupSize = + + let sortByKeyIndices = + Radix.runByKeysStandard clContext workGroupSize + + let sortByKeyValues = + Radix.runByKeysStandard clContext workGroupSize + + let sortKeys = + Radix.standardRunKeysOnly clContext workGroupSize + + fun (processor: MailboxProcessor<_>) (values: ClArray<'a>) (columns: ClArray) (rows: ClArray) -> + // sort by columns + let valuesSortedByColumns = + sortByKeyValues processor DeviceOnly columns values + + let rowsSortedByColumns = + sortByKeyIndices processor DeviceOnly columns rows + + let sortedColumns = sortKeys processor columns + + // sort by rows + let valuesSortedByRows = + sortByKeyValues processor DeviceOnly rowsSortedByColumns valuesSortedByColumns + + let columnsSortedByRows = + sortByKeyIndices processor DeviceOnly rowsSortedByColumns sortedColumns + + let sortedRows = sortKeys processor rowsSortedByColumns + + valuesSortedByColumns.Free processor + rowsSortedByColumns.Free processor + sortedColumns.Free processor + + valuesSortedByRows, columnsSortedByRows, sortedRows + + let reduce opAdd (clContext: ClContext) workGroupSize = + + let reduce = + Reduce.ByKey2D.Option.segmentSequential opAdd clContext workGroupSize + + let getUniqueBitmap = + ClArray.Bitmap.lastOccurrence2 clContext workGroupSize + + let prefixSum = + PrefixSum.standardExcludeInPlace clContext workGroupSize + + let idScatter = + Scatter.initFirsOccurrence Map.id clContext workGroupSize + + fun (processor: MailboxProcessor<_>) allocationMode (values: ClArray<'a>) (columns: ClArray) (rows: ClArray) -> + + let bitmap = + getUniqueBitmap processor DeviceOnly columns rows + + let uniqueKeysCount = + (prefixSum processor bitmap) + .ToHostAndFree processor + + let offsets = + clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, uniqueKeysCount) + + idScatter processor bitmap offsets + + bitmap.Free processor + + let reduceResult = + reduce processor allocationMode uniqueKeysCount offsets columns rows values + + offsets.Free processor + + // reducedValues, reducedColumns, reducedRows option + reduceResult + + let runCOO opAdd opMul (clContext: ClContext) workGroupSize = + + let getSegmentPointers = + getSegmentPointers clContext workGroupSize + + let expand = expand clContext workGroupSize + + let multiply = multiply opMul clContext workGroupSize + + let sort = + sortByColumnsAndRows clContext workGroupSize + + let reduce = reduce opAdd clContext workGroupSize + + fun (processor: MailboxProcessor<_>) allocationMode (rightMatrixRowsNNZ: ClArray) (rightMatrix: ClMatrix.CSR<'b>) (leftMatrix: ClMatrix.COO<'a>) -> + + let length, segmentPointers = + getSegmentPointers processor leftMatrix.Columns rightMatrixRowsNNZ + + if length = 0 then + segmentPointers.Free processor + + length, None + else + // expand + let leftMatrixValues, rightMatrixValues, columns, rows = + expand processor length segmentPointers leftMatrix rightMatrix + + segmentPointers.Free processor + + // multiply + let mulResult = + multiply processor leftMatrixValues rightMatrixValues columns rows + + leftMatrixValues.Free processor + rightMatrixValues.Free processor + columns.Free processor + rows.Free processor + + let result = + mulResult + |> Option.bind + (fun (resultValues, resultColumns, resultRows) -> + // sort + let sortedValues, sortedColumns, sortedRows = + sort processor resultValues resultColumns resultRows + + resultValues.Free processor + resultColumns.Free processor + resultRows.Free processor + + // addition + let reduceResult = + reduce processor allocationMode sortedValues sortedColumns sortedRows + + sortedValues.Free processor + sortedColumns.Free processor + sortedRows.Free processor + + reduceResult) + + length, result + + let runOneStep opAdd opMul (clContext: ClContext) workGroupSize = + + let runCOO = + runCOO opAdd opMul clContext workGroupSize + + let expandRowPointers = + CSR.Matrix.expandRowPointers clContext workGroupSize + + fun (processor: MailboxProcessor<_>) allocationMode (leftMatrix: ClMatrix.CSR<'a>) rightMatrixRowsNNZ (rightMatrix: ClMatrix.CSR<'b>) -> + + let rows = + expandRowPointers processor DeviceOnly leftMatrix + + let leftMatrixCOO = + { Context = clContext + RowCount = leftMatrix.RowCount + ColumnCount = leftMatrix.ColumnCount + Rows = rows + Columns = leftMatrix.Columns + Values = leftMatrix.Values } + + let _, result = + runCOO processor allocationMode rightMatrixRowsNNZ rightMatrix leftMatrixCOO + + rows.Free processor + + result + |> Option.map + (fun (values, columns, rows) -> + { Context = clContext + RowCount = leftMatrix.RowCount + ColumnCount = rightMatrix.ColumnCount + Rows = rows + Columns = columns + Values = values }) + + let runManySteps opAdd opMul (clContext: ClContext) workGroupSize = + + let gather = Gather.run clContext workGroupSize + + let upperBound = + ClArray.upperBound clContext workGroupSize + + let set = ClArray.set clContext workGroupSize + + let subMatrix = + CSR.Matrix.subRows clContext workGroupSize + + let runCOO = + runCOO opAdd opMul clContext workGroupSize + + fun (processor: MailboxProcessor<_>) allocationMode maxAllocSize generalLength (leftMatrix: ClMatrix.CSR<'a>) segmentLengths rightMatrixRowsNNZ (rightMatrix: ClMatrix.CSR<'b>) -> + // extract segment lengths by left matrix rows pointers + let segmentPointersByLeftMatrixRows = + clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, leftMatrix.RowPointers.Length) + + gather processor leftMatrix.RowPointers segmentLengths segmentPointersByLeftMatrixRows + + // set last element to one step length + set processor segmentPointersByLeftMatrixRows (leftMatrix.RowPointers.Length - 1) generalLength + + // curring + let upperBound = + upperBound processor segmentPointersByLeftMatrixRows + + let subMatrix = subMatrix processor DeviceOnly + + let runCOO = + runCOO processor allocationMode rightMatrixRowsNNZ rightMatrix + + let rec helper beginRow workOffset previousResult = + if beginRow < leftMatrix.RowCount then + let currentBound = + clContext.CreateClCell(workOffset + maxAllocSize: int) + + // find largest row that fit into maxAllocSize + let upperBound = + (upperBound currentBound).ToHostAndFree processor + + let endRow = upperBound - 2 + + currentBound.Free processor + + // TODO(handle largest rows) + // (we can split row, multiply and merge them but merge path needed) + if endRow = beginRow then + failwith "It is impossible to multiply such a long row" + + // extract matrix TODO(Transfer overhead) + let subMatrix = + subMatrix beginRow (endRow - beginRow) leftMatrix + + // compute sub result + let length, result = runCOO subMatrix + // increase workOffset according to previous expand + let workOffset = workOffset + length + + match result with + | Some result -> + helper endRow workOffset + <| result :: previousResult + | None -> helper endRow workOffset previousResult + else + previousResult + + let result = helper 0 0 [] |> List.rev + + segmentPointersByLeftMatrixRows.Free processor + + result + + let run opAdd opMul (clContext: ClContext) workGroupSize = + + let getNNZInRows = + CSR.Matrix.NNZInRows clContext workGroupSize + + let getSegmentPointers = + getSegmentPointers clContext workGroupSize + + let runOneStep = + runOneStep opAdd opMul clContext workGroupSize + + let concat = ClArray.concat clContext workGroupSize + + let concatData = ClArray.concat clContext workGroupSize + + let runManySteps = + runManySteps opAdd opMul clContext workGroupSize + + fun (processor: MailboxProcessor<_>) allocationMode maxAllocSize (leftMatrix: ClMatrix.CSR<'a>) (rightMatrix: ClMatrix.CSR<'b>) -> + + let rightMatrixRowsNNZ = + getNNZInRows processor DeviceOnly rightMatrix + + let generalLength, segmentLengths = + getSegmentPointers processor leftMatrix.Columns rightMatrixRowsNNZ + + if generalLength < maxAllocSize then + segmentLengths.Free processor + + runOneStep processor allocationMode leftMatrix rightMatrixRowsNNZ rightMatrix + else + let result = + runManySteps + processor + allocationMode + maxAllocSize + generalLength + leftMatrix + segmentLengths + rightMatrixRowsNNZ + rightMatrix + + rightMatrixRowsNNZ.Free processor + segmentLengths.Free processor + + match result with + | _ :: _ -> + let valuesList, columnsList, rowsList = result |> List.unzip3 + + let values = + concatData processor allocationMode valuesList + + let columns = + concat processor allocationMode columnsList + + let rows = concat processor allocationMode rowsList + + // TODO(overhead: compute result length 3 time) + // release resources + valuesList + |> List.iter (fun array -> array.Free processor) + + columnsList + |> List.iter (fun array -> array.Free processor) + + rowsList + |> List.iter (fun array -> array.Free processor) + + { Context = clContext + RowCount = leftMatrix.RowCount + ColumnCount = rightMatrix.ColumnCount + Rows = rows + Columns = columns + Values = values } + |> Some + | _ -> None diff --git a/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Masked.fs b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Masked.fs new file mode 100644 index 00000000..1a75fc45 --- /dev/null +++ b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Masked.fs @@ -0,0 +1,187 @@ +namespace GraphBLAS.FSharp.Backend.Matrix.SpGeMM + +open GraphBLAS.FSharp.Backend.Common +open Brahma.FSharp +open Microsoft.FSharp.Quotations +open GraphBLAS.FSharp.Backend.Objects +open GraphBLAS.FSharp.Backend.Objects.ClMatrix +open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions + +module internal Masked = + let private calculate + (opAdd: Expr<'c -> 'c -> 'c option>) + (opMul: Expr<'a -> 'b -> 'c option>) + (context: ClContext) + workGroupSize + = + + let run = + <@ fun (ndRange: Range1D) (leftRowPointers: ClArray) (leftColumns: ClArray) (leftValues: ClArray<'a>) (rightRows: ClArray) (rightColumnPointers: ClArray) (rightValues: ClArray<'b>) (maskRows: ClArray) (maskColumns: ClArray) (resultValues: ClArray<'c>) (resultValuesBitmap: ClArray) -> + + let gid = ndRange.GlobalID0 + let groupId = gid / workGroupSize + let row = maskRows.[groupId] + let col = maskColumns.[groupId] + + let rowBeginIdx = leftRowPointers.[row] + let nnzPerRow = leftRowPointers.[row + 1] - rowBeginIdx + + let colBeginIdx = rightColumnPointers.[col] + + let nnzPerCol = + rightColumnPointers.[col + 1] - colBeginIdx + + let lid = ndRange.LocalID0 + + let products = localArray<'c option> workGroupSize + products.[lid] <- None + + let threadProcessedSize = + (nnzPerRow + workGroupSize - 1) / workGroupSize + + let mutable start = threadProcessedSize * lid + let mutable i = threadProcessedSize * lid + + while i - start < threadProcessedSize && i < nnzPerRow do + let indexToFind = leftColumns.[rowBeginIdx + i] + + // Binary search + let mutable leftEdge = colBeginIdx + let mutable rightEdge = leftEdge + nnzPerCol + + while leftEdge < rightEdge do + let middle = (leftEdge + rightEdge) / 2 + let foundIdx = rightRows.[middle] + + if foundIdx < indexToFind then + leftEdge <- middle + 1 + elif foundIdx > indexToFind then + rightEdge <- middle + else + // Found needed index + let a = leftValues.[rowBeginIdx + i] + let b = rightValues.[middle] + let increase = (%opMul) a b + + let product = products.[lid] + + match product, increase with + | Some x, Some y -> + let buff = (%opAdd) x y + products.[lid] <- buff + | None, Some _ -> products.[lid] <- increase + | _ -> () + + // Break alternative + leftEdge <- rightEdge + + i <- i + 1 + + // Sum up all products + let mutable step = 2 + + while step <= workGroupSize do + barrierLocal () + + if lid < workGroupSize / step then + let i = step * (lid + 1) - 1 + + let increase = products.[i - (step >>> 1)] + + match increase, products.[i] with + | Some x, Some y -> + let buff = (%opAdd) x y + products.[i] <- buff + | Some _, None -> products.[i] <- increase + | _ -> () + + step <- step <<< 1 + + if lid = 0 then + match products.[workGroupSize - 1] with + | Some p -> + resultValues.[groupId] <- p + resultValuesBitmap.[groupId] <- 1 + | None -> resultValuesBitmap.[groupId] <- 0 @> + + let program = context.Compile(run) + + fun (queue: MailboxProcessor<_>) (matrixLeft: ClMatrix.CSR<'a>) (matrixRight: ClMatrix.CSC<'b>) (mask: ClMatrix.COO<_>) -> + + let values = + context.CreateClArrayWithSpecificAllocationMode<'c>(DeviceOnly, mask.NNZ) + + let bitmap = + context.CreateClArrayWithSpecificAllocationMode(DeviceOnly, mask.NNZ) + + let kernel = program.GetKernel() + + let ndRange = + Range1D.CreateValid(workGroupSize * mask.NNZ, workGroupSize) + + queue.Post( + Msg.MsgSetArguments + (fun () -> + kernel.KernelFunc + ndRange + matrixLeft.RowPointers + matrixLeft.Columns + matrixLeft.Values + matrixRight.Rows + matrixRight.ColumnPointers + matrixRight.Values + mask.Rows + mask.Columns + values + bitmap) + ) + + queue.Post(Msg.CreateRunMsg<_, _>(kernel)) + + values, bitmap + + let run + (opAdd: Expr<'c -> 'c -> 'c option>) + (opMul: Expr<'a -> 'b -> 'c option>) + (context: ClContext) + workGroupSize + = + + let calculate = + calculate opAdd opMul context workGroupSize + + let scatter = + Scatter.lastOccurrence context workGroupSize + + let scatterData = + Scatter.lastOccurrence context workGroupSize + + let scanInPlace = + PrefixSum.standardExcludeInPlace context workGroupSize + + fun (queue: MailboxProcessor<_>) (matrixLeft: ClMatrix.CSR<'a>) (matrixRight: ClMatrix.CSC<'b>) (mask: ClMatrix.COO<_>) -> + + let values, positions = + calculate queue matrixLeft matrixRight mask + + let resultNNZ = + (scanInPlace queue positions).ToHostAndFree(queue) + + let resultRows = context.CreateClArray resultNNZ + let resultColumns = context.CreateClArray resultNNZ + let resultValues = context.CreateClArray<'c> resultNNZ + + scatter queue positions mask.Rows resultRows + scatter queue positions mask.Columns resultColumns + scatterData queue positions values resultValues + + queue.Post(Msg.CreateFreeMsg<_>(values)) + queue.Post(Msg.CreateFreeMsg<_>(positions)) + + { Context = context + RowCount = matrixLeft.RowCount + ColumnCount = matrixRight.ColumnCount + Rows = resultRows + Columns = resultColumns + Values = resultValues } diff --git a/src/GraphBLAS-sharp.Backend/Vector/SpMV.fs b/src/GraphBLAS-sharp.Backend/Operations/SpMV.fs similarity index 99% rename from src/GraphBLAS-sharp.Backend/Vector/SpMV.fs rename to src/GraphBLAS-sharp.Backend/Operations/SpMV.fs index 72a7b89f..fbe08bd9 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/SpMV.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/SpMV.fs @@ -6,7 +6,7 @@ open Microsoft.FSharp.Quotations open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -module SpMV = +module internal SpMV = let runTo (add: Expr<'c option -> 'c option -> 'c option>) (mul: Expr<'a option -> 'b option -> 'c option>) diff --git a/src/GraphBLAS-sharp.Backend/Vector/Vector.fs b/src/GraphBLAS-sharp.Backend/Vector/Primitives.fs similarity index 76% rename from src/GraphBLAS-sharp.Backend/Vector/Vector.fs rename to src/GraphBLAS-sharp.Backend/Vector/Primitives.fs index 73ae99f3..5fef5f57 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Primitives.fs @@ -9,8 +9,7 @@ open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Objects.ClVector - -module Vector = +module Primitives = /// /// Builds vector of given format with fixed size and fills it with the default values of desired type. /// @@ -169,66 +168,6 @@ module Vector = | ClVector.Sparse v -> mapSparse processor allocationMode v |> ClVector.Sparse | ClVector.Dense v -> mapDense processor allocationMode v |> ClVector.Dense - /// - /// Builds a new vector whose values are the results of applying the given function - /// to the corresponding pairs of values from the two vectors. - /// - /// - /// A function to transform pairs of values from the input vectors. - /// Operands and result types should be optional to distinguish explicit and implicit zeroes. - /// - /// - /// Formats of the given vectors should match, otherwise an exception will be thrown. - /// - /// OpenCL context. - /// Should be a power of 2 and greater than 1. - let map2 (op: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) workGroupSize = - let map2Dense = - Dense.Vector.map2 op clContext workGroupSize - - let map2Sparse = - Sparse.Vector.map2 op clContext workGroupSize - - fun (processor: MailboxProcessor<_>) allocationMode (leftVector: ClVector<'a>) (rightVector: ClVector<'b>) -> - match leftVector, rightVector with - | ClVector.Dense left, ClVector.Dense right -> - ClVector.Dense - <| map2Dense processor allocationMode left right - | ClVector.Sparse left, ClVector.Sparse right -> - ClVector.Sparse - <| map2Sparse processor allocationMode left right - | _ -> failwith "Vector formats are not matching." - - /// - /// Builds a new vector whose values are the results of applying the given function - /// to the corresponding pairs of values from the two vectors. - /// - /// - /// A function to transform pairs of values from the input vectors. - /// Operation assumption: one of the operands should always be non-zero. - /// - /// - /// Formats of the given vectors should match, otherwise an exception will be thrown. - /// - /// OpenCL context. - /// Should be a power of 2 and greater than 1. - let map2AtLeastOne (op: Expr -> 'c option>) (clContext: ClContext) workGroupSize = - let map2Sparse = - Sparse.Vector.map2AtLeastOne op clContext workGroupSize - - let map2Dense = - Dense.Vector.map2AtLeastOne op clContext workGroupSize - - fun (processor: MailboxProcessor<_>) allocationMode (leftVector: ClVector<'a>) (rightVector: ClVector<'b>) -> - match leftVector, rightVector with - | ClVector.Sparse left, ClVector.Sparse right -> - ClVector.Sparse - <| map2Sparse processor allocationMode left right - | ClVector.Dense left, ClVector.Dense right -> - ClVector.Dense - <| map2Dense processor allocationMode left right - | _ -> failwith "Vector formats are not matching." - let private assignByMaskGeneral<'a, 'b when 'a: struct and 'b: struct> op (clContext: ClContext) workGroupSize = let sparseFillVector = From 5d900f5b968710f9530122679fc95d98c9710604 Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Fri, 21 Jul 2023 17:49:40 +0700 Subject: [PATCH 03/22] refactor: namespace/module names --- .../Algorithms/BFS.fs | 44 +- .../GraphBLAS-sharp.Benchmarks/Helpers.fs | 2 - .../Matrix/Map2/Map2.fs | 47 +- .../Matrix/SpGeMM/Expand.fs | 12 +- .../Matrix/SpGeMM/Masked.fs | 25 +- .../GraphBLAS-sharp.Benchmarks/Vector/Map2.fs | 22 +- paket.lock | 236 ++++----- .../Algorithms/Algorithms.fs | 6 + src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs | 23 +- src/GraphBLAS-sharp.Backend/Common/ClArray.fs | 8 +- src/GraphBLAS-sharp.Backend/Common/Common.fs | 87 +-- src/GraphBLAS-sharp.Backend/Common/Merge.fs | 144 ----- .../Common/PrefixSum.fs | 4 +- .../Common/Sort/Radix.fs | 23 +- src/GraphBLAS-sharp.Backend/Common/Sum.fs | 8 +- .../GraphBLAS-sharp.Backend.fsproj | 27 +- src/GraphBLAS-sharp.Backend/Matrix/COO/Map.fs | 6 +- .../Matrix/COO/Map2.fs | 8 +- .../Matrix/COO/Matrix.fs | 14 +- .../Matrix/COO/Merge.fs | 4 +- .../Matrix/CSR/Kronecker.fs | 457 ---------------- src/GraphBLAS-sharp.Backend/Matrix/CSR/Map.fs | 10 +- .../Matrix/CSR/Map2.fs | 7 +- .../Matrix/CSR/Matrix.fs | 14 +- .../Matrix/CSR/Merge.fs | 5 +- src/GraphBLAS-sharp.Backend/Matrix/Common.fs | 6 +- .../Matrix/LIL/Matrix.fs | 6 +- .../Matrix/{Primitives.fs => Matrix.fs} | 10 +- .../Matrix/SpGeMM/Expand.fs | 494 ------------------ .../Matrix/SpGeMM/Masked.fs | 187 ------- .../Objects/ArraysExtentions.fs | 2 +- .../Objects/AtLeastOne.fs | 2 +- .../Objects/ClCellExtensions.fs | 2 +- .../Objects/ClContextExtensions.fs | 2 +- src/GraphBLAS-sharp.Backend/Objects/Common.fs | 2 +- src/GraphBLAS-sharp.Backend/Objects/Matrix.fs | 3 +- src/GraphBLAS-sharp.Backend/Objects/Vector.fs | 4 +- .../Operations/Kronecker.fs | 15 +- .../Operations/Operations.fs | 27 +- .../Operations/SpGeMM/Expand.fs | 20 +- .../Operations/SpGeMM/Masked.fs | 12 +- .../Operations/SpMV.fs | 6 +- .../Quotes/Arithmetic.fs | 2 +- src/GraphBLAS-sharp.Backend/Quotes/Convert.fs | 2 +- .../Vector/Dense/Vector.fs | 14 +- .../Vector/Sparse/Common.fs | 9 +- .../Vector/Sparse/Map.fs | 20 +- .../Vector/Sparse/Map2.fs | 6 +- .../Vector/Sparse/Merge.fs | 4 +- .../Vector/Sparse/Vector.fs | 7 +- .../Vector/{Primitives.fs => Vector.fs} | 24 +- src/GraphBLAS-sharp/Objects/Matrix.fs | 4 +- .../Objects/MatrixExtensions.fs | 4 +- src/GraphBLAS-sharp/Objects/Vector.fs | 6 +- .../Objects/VectorExtensions.fs | 4 +- .../Backend/Algorithms/BFS.fs | 9 +- .../Backend/Common/ClArray/Blit.fs | 5 +- .../Backend/Common/ClArray/Choose.fs | 8 +- .../Backend/Common/ClArray/ChunkBySize.fs | 6 +- .../Backend/Common/ClArray/Concat.fs | 7 +- .../Backend/Common/ClArray/Copy.fs | 6 +- .../Backend/Common/ClArray/Exists.fs | 8 +- .../Backend/Common/ClArray/Fill.fs | 5 +- .../Backend/Common/ClArray/Item.fs | 6 +- .../Backend/Common/ClArray/Map.fs | 6 +- .../Backend/Common/ClArray/Map2.fs | 7 +- .../Backend/Common/ClArray/Pairwise.fs | 6 +- .../Common/ClArray/RemoveDuplicates.fs | 2 +- .../Backend/Common/ClArray/Replicate.fs | 6 +- .../Backend/Common/ClArray/Set.fs | 4 +- .../Backend/Common/ClArray/UpperBound.fs | 4 +- .../Backend/Common/Gather.fs | 8 +- .../Backend/Common/Merge.fs | 54 -- .../Backend/Common/Reduce/Reduce.fs | 6 +- .../Backend/Common/Reduce/ReduceByKey.fs | 8 +- .../Backend/Common/Reduce/Sum.fs | 8 +- .../Backend/Common/Scan/ByKey.fs | 6 +- .../Backend/Common/Scan/PrefixSum.fs | 8 +- .../Backend/Common/Scatter.fs | 9 +- .../Backend/Common/Sort/Bitonic.fs | 6 +- .../Backend/Common/Sort/Radix.fs | 8 +- .../Backend/Matrix/ByRows.fs | 6 +- .../Backend/Matrix/Convert.fs | 5 +- .../Backend/Matrix/ExpandRows.fs | 6 +- .../Backend/Matrix/Kronecker.fs | 8 +- .../Backend/Matrix/Map.fs | 5 +- .../Backend/Matrix/Map2.fs | 26 +- .../Backend/Matrix/Merge.fs | 3 +- .../Backend/Matrix/RowsLengths.fs | 6 +- .../Backend/Matrix/SpGeMM/Expand.fs | 27 +- .../Backend/Matrix/SpGeMM/Masked.fs | 12 +- .../Backend/Matrix/SubRows.fs | 5 +- .../Backend/Matrix/Transpose.fs | 6 +- .../Backend/Vector/AssignByMask.fs | 7 +- .../Backend/Vector/Convert.fs | 7 +- .../Backend/Vector/Copy.fs | 7 +- .../Backend/Vector/Map2.fs | 6 +- .../Backend/Vector/Merge.fs | 9 +- .../Backend/Vector/OfList.fs | 7 +- .../Backend/Vector/Reduce.fs | 7 +- .../Backend/Vector/SpMV.fs | 15 +- .../Backend/Vector/ZeroCreate.fs | 5 +- tests/GraphBLAS-sharp.Tests/Generators.fs | 2 - .../GraphBLAS-sharp.Tests.fsproj | 1 - tests/GraphBLAS-sharp.Tests/Helpers.fs | 12 +- tests/GraphBLAS-sharp.Tests/Program.fs | 1 - 106 files changed, 621 insertions(+), 1945 deletions(-) create mode 100644 src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs delete mode 100644 src/GraphBLAS-sharp.Backend/Common/Merge.fs delete mode 100644 src/GraphBLAS-sharp.Backend/Matrix/CSR/Kronecker.fs rename src/GraphBLAS-sharp.Backend/Matrix/{Primitives.fs => Matrix.fs} (98%) delete mode 100644 src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Expand.fs delete mode 100644 src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Masked.fs rename src/GraphBLAS-sharp.Backend/Vector/{Primitives.fs => Vector.fs} (94%) delete mode 100644 tests/GraphBLAS-sharp.Tests/Backend/Common/Merge.fs diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs index 7115a90c..ca2f9a07 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs @@ -2,15 +2,14 @@ open System.IO open BenchmarkDotNet.Attributes -open GraphBLAS.FSharp -open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.IO -open Brahma.FSharp -open Backend.Algorithms.BFS open Microsoft.FSharp.Core -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open Brahma.FSharp +open GraphBLAS.FSharp.IO +open GraphBLAS.FSharp.Algorithms open GraphBLAS.FSharp.Benchmarks -open GraphBLAS.FSharp.Backend.Objects +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Backend.Quotes [] [] @@ -20,11 +19,12 @@ type Benchmarks<'elem when 'elem : struct>( buildFunToBenchmark, converter: string -> 'elem, binaryConverter, - vertex: int) + vertex: int, + buildMatrix) = let mutable funToBenchmark = None - let mutable matrix = Unchecked.defaultof> + let mutable matrix = Unchecked.defaultof> let mutable matrixHost = Unchecked.defaultof<_> member val ResultLevels = Unchecked.defaultof> with get,set @@ -69,7 +69,7 @@ type Benchmarks<'elem when 'elem : struct>( this.ResultLevels <- this.FunToBenchmark this.Processor matrix vertex member this.ClearInputMatrix() = - (matrix :> IDeviceMemObject).Dispose this.Processor + matrix.Dispose this.Processor member this.ClearResult() = this.ResultLevels.FreeAndWait this.Processor @@ -82,7 +82,7 @@ type Benchmarks<'elem when 'elem : struct>( matrixHost <- this.InputMatrixReader.ReadMatrix converter member this.LoadMatrixToGPU() = - matrix <- matrixHost.ToCSR.ToDevice this.OclContext + matrix <- buildMatrix this.OclContext matrixHost abstract member GlobalSetup : unit -> unit @@ -96,13 +96,15 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>( buildFunToBenchmark, converter: string -> 'elem, boolConverter, - vertex) = + vertex, + buildMatrix) = inherit Benchmarks<'elem>( buildFunToBenchmark, converter, boolConverter, - vertex) + vertex, + buildMatrix) [] override this.GlobalSetup() = @@ -125,10 +127,11 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>( type BFSWithoutTransferBenchmarkInt32() = inherit WithoutTransferBenchmark( - (singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption), + (singleSourceBFS ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption), int32, (fun _ -> Utils.nextInt (System.Random())), - 0) + 0, + (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)) static member InputMatrixProvider = Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt" @@ -137,13 +140,15 @@ type WithTransferBenchmark<'elem when 'elem : struct>( buildFunToBenchmark, converter: string -> 'elem, boolConverter, - vertex) = + vertex, + buildMatrix) = inherit Benchmarks<'elem>( buildFunToBenchmark, converter, boolConverter, - vertex) + vertex, + buildMatrix) [] override this.GlobalSetup() = @@ -168,10 +173,11 @@ type WithTransferBenchmark<'elem when 'elem : struct>( type BFSWithTransferBenchmarkInt32() = inherit WithTransferBenchmark( - (singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption), + (singleSourceBFS ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption), int32, (fun _ -> Utils.nextInt (System.Random())), - 0) + 0, + (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)) static member InputMatrixProvider = Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt" diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Helpers.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Helpers.fs index 6ce43002..0867e214 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Helpers.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Helpers.fs @@ -5,14 +5,12 @@ namespace GraphBLAS.FSharp.Benchmarks open Brahma.FSharp open Brahma.FSharp.OpenCL.Translator open Brahma.FSharp.OpenCL.Translator.QuotationTransformers -open GraphBLAS.FSharp.Backend.Objects open OpenCL.Net open System.IO open System.Text.RegularExpressions open GraphBLAS.FSharp.Tests open FsCheck open Expecto -open GraphBLAS.FSharp.Test module Utils = type BenchmarkContext = diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs index f1d7f3d6..144d7552 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs @@ -1,15 +1,14 @@ namespace GraphBLAS.FSharp.Benchmarks.Matrix.Map2 open System.IO -open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.IO open BenchmarkDotNet.Attributes open Brahma.FSharp +open GraphBLAS.FSharp.IO +open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Objects.MatrixExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Matrix +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Benchmarks [] @@ -20,7 +19,7 @@ type Benchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem : st buildFunToBenchmark, converter: string -> 'elem, converterBool, - buildMatrix: Primitives.COO<_> -> Matrix<_>) = + buildMatrix: Matrix.COO<_> -> Matrix<_>) = let mutable funToBenchmark = None let mutable firstMatrix = Unchecked.defaultof> @@ -138,10 +137,10 @@ module WithoutTransfer = type Float32() = inherit Benchmark,float32>( - (Primitives.map2 ArithmeticOperations.float32SumOption), + (Matrix.map2 ArithmeticOperations.float32SumOption), float32, (fun _ -> Utils.nextSingle (System.Random())), - Primitives.COO + Matrix.COO ) static member InputMatricesProvider = @@ -150,10 +149,10 @@ module WithoutTransfer = type Bool() = inherit Benchmark,bool>( - (Primitives.map2 ArithmeticOperations.boolSumOption), + (Matrix.map2 ArithmeticOperations.boolSumOption), (fun _ -> true), (fun _ -> true), - Primitives.COO + Matrix.COO ) static member InputMatricesProvider = @@ -163,10 +162,10 @@ module WithoutTransfer = type Float32() = inherit Benchmark,float32>( - (Primitives.map2 ArithmeticOperations.float32SumOption), + (Matrix.map2 ArithmeticOperations.float32SumOption), float32, (fun _ -> Utils.nextSingle (System.Random())), - (fun matrix -> Primitives.CSR matrix.ToCSR) + (fun matrix -> Matrix.CSR matrix.ToCSR) ) static member InputMatricesProvider = @@ -175,10 +174,10 @@ module WithoutTransfer = type Bool() = inherit Benchmark,bool>( - (Primitives.map2 ArithmeticOperations.boolSumOption), + (Matrix.map2 ArithmeticOperations.boolSumOption), (fun _ -> true), (fun _ -> true), - (fun matrix -> Primitives.CSR matrix.ToCSR) + (fun matrix -> Matrix.CSR matrix.ToCSR) ) static member InputMatricesProvider = @@ -189,10 +188,10 @@ module WithoutTransfer = type Bool() = inherit Benchmark,bool>( - (Primitives.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne), + (Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne), (fun _ -> true), (fun _ -> true), - Primitives.COO + Matrix.COO ) static member InputMatricesProvider = @@ -201,10 +200,10 @@ module WithoutTransfer = type Float32() = inherit Benchmark,float32>( - (Primitives.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne), + (Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne), float32, (fun _ -> Utils.nextSingle (System.Random())), - Primitives.COO + Matrix.COO ) static member InputMatricesProvider = @@ -214,10 +213,10 @@ module WithoutTransfer = type Bool() = inherit Benchmark,bool>( - (Primitives.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne), + (Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne), (fun _ -> true), (fun _ -> true), - (fun matrix -> Primitives.CSR matrix.ToCSR) + (fun matrix -> Matrix.CSR matrix.ToCSR) ) static member InputMatricesProvider = @@ -226,10 +225,10 @@ module WithoutTransfer = type Float32() = inherit Benchmark,float32>( - (Primitives.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne), + (Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne), float32, (fun _ -> Utils.nextSingle (System.Random())), - (fun matrix -> Primitives.CSR matrix.ToCSR) + (fun matrix -> Matrix.CSR matrix.ToCSR) ) static member InputMatricesProvider = @@ -273,10 +272,10 @@ module WithTransfer = type Float32() = inherit Benchmark,float32>( - (Primitives.map2 ArithmeticOperations.float32SumOption), + (Matrix.map2 ArithmeticOperations.float32SumOption), float32, (fun _ -> Utils.nextSingle (System.Random())), - Primitives.COO, + Matrix.COO, (fun matrix -> matrix.ToHost) ) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs index 4241707b..5c1110da 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs @@ -1,16 +1,14 @@ module GraphBLAS.FSharp.Benchmarks.Matrix.SpGeMM.Expand open System.IO -open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.IO open BenchmarkDotNet.Attributes open Brahma.FSharp +open GraphBLAS.FSharp.IO +open GraphBLAS.FSharp.Operations +open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Benchmarks -open GraphBLAS.FSharp.Backend [] [] @@ -139,7 +137,7 @@ module WithoutTransfer = type Float32() = inherit Benchmark( - Primitives.SpGeMM.expand (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), + SpGeMM.expand (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs index 2efc736d..936ab398 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs @@ -5,12 +5,11 @@ open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.IO open BenchmarkDotNet.Attributes open Brahma.FSharp +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Benchmarks -open GraphBLAS.FSharp.Backend [] [] @@ -77,7 +76,7 @@ type Masked<'elem when 'elem : struct>( member this.FunCSR2CSC = match funCSR2CSC with | None -> - let x = Primitives.toCSCInPlace this.OclContext this.WorkGroupSize + let x = Matrix.toCSCInPlace this.OclContext this.WorkGroupSize funCSR2CSC <- Some x x | Some x -> x @@ -85,7 +84,7 @@ type Masked<'elem when 'elem : struct>( member this.FunCSC2CSR = match funCSC2CSR with | None -> - let x = Primitives.toCSRInPlace this.OclContext this.WorkGroupSize + let x = Matrix.toCSRInPlace this.OclContext this.WorkGroupSize funCSC2CSR <- Some x x | Some x -> x @@ -110,7 +109,7 @@ type Masked<'elem when 'elem : struct>( this.ResultMatrix.Dispose this.Processor member this.ReadMask(maskReader) = - maskHost <- Primitives.COO <| this.ReadMatrix maskReader + maskHost <- Matrix.COO <| this.ReadMatrix maskReader member this.ReadMatrices() = let matrixReader, maskReader = this.InputMatrixReader @@ -204,7 +203,7 @@ type MxmBenchmarksWithTransposing<'elem when 'elem : struct>( type Mxm4Float32MultiplicationOnlyBenchmark() = inherit MxmBenchmarksMultiplicationOnly( - Primitives.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), + SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) @@ -216,7 +215,7 @@ type Mxm4Float32MultiplicationOnlyBenchmark() = type Mxm4Float32WithTransposingBenchmark() = inherit MxmBenchmarksWithTransposing( - Primitives.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), + SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) @@ -228,7 +227,7 @@ type Mxm4Float32WithTransposingBenchmark() = type Mxm4BoolMultiplicationOnlyBenchmark() = inherit MxmBenchmarksMultiplicationOnly( - (Primitives.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)), + (SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)), (fun _ -> true), (fun _ -> true), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) @@ -240,7 +239,7 @@ type Mxm4BoolMultiplicationOnlyBenchmark() = type Mxm4BoolWithTransposingBenchmark() = inherit MxmBenchmarksWithTransposing( - (Primitives.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)), + (SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)), (fun _ -> true), (fun _ -> true), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) @@ -252,7 +251,7 @@ type Mxm4BoolWithTransposingBenchmark() = type Mxm4Float32MultiplicationOnlyWithZerosFilterBenchmark() = inherit MxmBenchmarksMultiplicationOnly( - (Primitives.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul)), + (SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul)), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) @@ -264,7 +263,7 @@ type Mxm4Float32MultiplicationOnlyWithZerosFilterBenchmark() = type Mxm4Float32WithTransposingWithZerosFilterBenchmark() = inherit MxmBenchmarksWithTransposing( - Primitives.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), + SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs index 9e0bc4de..6ee7ce7f 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs @@ -2,16 +2,14 @@ module GraphBLAS.FSharp.Benchmarks.Vector.Map2 open FsCheck open BenchmarkDotNet.Attributes - open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Backend.Quotes +open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Benchmarks open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions -open GraphBLAS.FSharp.Backend.Vector -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions [] [] @@ -122,26 +120,26 @@ module WithoutTransfer = type Float() = inherit Benchmark( - (Primitives.map2 ArithmeticOperations.floatSumOption), + (Vector.map2 ArithmeticOperations.floatSumOption), VectorGenerator.floatPair Sparse) type Int32() = inherit Benchmark( - (Primitives.map2 ArithmeticOperations.intSumOption), + (Vector.map2 ArithmeticOperations.intSumOption), VectorGenerator.intPair Sparse) module AtLeastOne = type Float() = inherit Benchmark( - (Primitives.map2AtLeastOne ArithmeticOperations.floatSumAtLeastOne), + (Vector.map2AtLeastOne ArithmeticOperations.floatSumAtLeastOne), VectorGenerator.floatPair Sparse) type Int32() = inherit Benchmark( - (Primitives.map2AtLeastOne ArithmeticOperations.intSumAtLeastOne), + (Vector.map2AtLeastOne ArithmeticOperations.intSumAtLeastOne), VectorGenerator.intPair Sparse) module WithTransfer = @@ -178,24 +176,24 @@ module WithTransfer = type Float() = inherit Benchmark( - (Primitives.map2 ArithmeticOperations.floatSumOption), + (Vector.map2 ArithmeticOperations.floatSumOption), VectorGenerator.floatPair Sparse) type Int32() = inherit Benchmark( - (Primitives.map2 ArithmeticOperations.intSumOption), + (Vector.map2 ArithmeticOperations.intSumOption), VectorGenerator.intPair Sparse) module AtLeastOne = type Float() = inherit Benchmark( - (Primitives.map2AtLeastOne ArithmeticOperations.floatSumAtLeastOne), + (Vector.map2AtLeastOne ArithmeticOperations.floatSumAtLeastOne), VectorGenerator.floatPair Sparse) type Int32() = inherit Benchmark( - (Primitives.map2AtLeastOne ArithmeticOperations.intSumAtLeastOne), + (Vector.map2AtLeastOne ArithmeticOperations.intSumAtLeastOne), VectorGenerator.intPair Sparse) diff --git a/paket.lock b/paket.lock index 59d73a6a..961e13b6 100644 --- a/paket.lock +++ b/paket.lock @@ -2,23 +2,23 @@ STORAGE: NONE NUGET remote: https://www.nuget.org/api/v2 altcover (7.6.812) - BenchmarkDotNet (0.13.5) - BenchmarkDotNet.Annotations (>= 0.13.5) - restriction: >= netstandard2.0 - CommandLineParser (>= 2.4.3) - restriction: >= netstandard2.0 + BenchmarkDotNet (0.13.6) + BenchmarkDotNet.Annotations (>= 0.13.6) - restriction: >= netstandard2.0 + CommandLineParser (>= 2.9.1) - restriction: >= netstandard2.0 Gee.External.Capstone (>= 2.3) - restriction: >= netstandard2.0 Iced (>= 1.17) - restriction: >= netstandard2.0 - Microsoft.CodeAnalysis.CSharp (>= 3.0) - restriction: >= netstandard2.0 + Microsoft.CodeAnalysis.CSharp (>= 4.1) - restriction: >= netstandard2.0 Microsoft.Diagnostics.Runtime (>= 2.2.332302) - restriction: >= netstandard2.0 Microsoft.Diagnostics.Tracing.TraceEvent (>= 3.0.2) - restriction: >= netstandard2.0 Microsoft.DotNet.PlatformAbstractions (>= 3.1.6) - restriction: >= netstandard2.0 Microsoft.Win32.Registry (>= 5.0) - restriction: && (< net6.0) (>= netstandard2.0) - Perfolizer (>= 0.2.1) - restriction: >= netstandard2.0 - System.Management (>= 6.0) - restriction: >= netstandard2.0 + Perfolizer (0.2.1) - restriction: >= netstandard2.0 + System.Management (>= 5.0) - restriction: >= netstandard2.0 System.Numerics.Vectors (>= 4.5) - restriction: && (< net6.0) (>= netstandard2.0) System.Reflection.Emit (>= 4.7) - restriction: && (< net6.0) (>= netstandard2.0) System.Reflection.Emit.Lightweight (>= 4.7) - restriction: && (< net6.0) (>= netstandard2.0) System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: && (< net6.0) (>= netstandard2.0) - BenchmarkDotNet.Annotations (0.13.5) - restriction: >= netstandard2.0 + BenchmarkDotNet.Annotations (0.13.6) - restriction: >= netstandard2.0 Brahma.FSharp (2.0.5) Brahma.FSharp.OpenCL.Printer (>= 2.0.5) - restriction: >= net7.0 Brahma.FSharp.OpenCL.Shared (>= 2.0.5) - restriction: >= net7.0 @@ -52,8 +52,8 @@ NUGET ExtraConstraints.Fody (1.14) Fody (>= 6.0) - restriction: || (>= net452) (>= netstandard1.4) NETStandard.Library (>= 1.6.1) - restriction: && (< net452) (>= netstandard1.4) - Fody (6.7) - restriction: || (>= net452) (>= netstandard1.4) - FsCheck (2.16.5) - restriction: || (>= net461) (>= netstandard2.0) + Fody (6.8) - restriction: || (>= net452) (>= netstandard1.4) + FsCheck (2.16.6) - restriction: || (>= net461) (>= netstandard2.0) FSharp.Core (>= 4.2.3) - restriction: || (>= net452) (>= netstandard1.6) FSharp.Core (7.0) FSharp.Quotations.Evaluator (2.1) @@ -63,7 +63,7 @@ NUGET FSharpx.Text.StructuredFormat (3.1) FSharp.Core (>= 4.6.2) - restriction: || (>= net452) (>= netstandard2.0) Gee.External.Capstone (2.3) - restriction: >= netstandard2.0 - Iced (1.18) - restriction: >= netstandard2.0 + Iced (1.20) - restriction: >= netstandard2.0 MathNet.Numerics (5.0) - restriction: || (>= net45) (>= netstandard1.6) System.ValueTuple (>= 4.4) - restriction: && (>= net461) (< net48) MathNet.Numerics.FSharp (4.0) @@ -83,26 +83,27 @@ NUGET System.Security.Permissions (>= 4.7) - restriction: && (< net472) (>= netstandard2.0) Microsoft.Build.Tasks.Git (1.1.1) - copy_local: true Microsoft.CodeAnalysis.Analyzers (3.3.4) - restriction: >= netstandard2.0 - Microsoft.CodeAnalysis.Common (4.5) - restriction: >= netstandard2.0 - Microsoft.CodeAnalysis.Analyzers (>= 3.3.3) - restriction: >= netstandard2.0 - System.Collections.Immutable (>= 6.0) - restriction: >= netstandard2.0 - System.Memory (>= 4.5.5) - restriction: && (< netcoreapp3.1) (>= netstandard2.0) - System.Reflection.Metadata (>= 6.0.1) - restriction: >= netstandard2.0 + Microsoft.CodeAnalysis.Common (4.6) - restriction: >= netstandard2.0 + Microsoft.CodeAnalysis.Analyzers (>= 3.3.4) - restriction: >= netstandard2.0 + System.Collections.Immutable (>= 7.0) - restriction: >= netstandard2.0 + System.Memory (>= 4.5.5) - restriction: && (< net6.0) (>= netstandard2.0) + System.Reflection.Metadata (>= 7.0) - restriction: >= netstandard2.0 System.Runtime.CompilerServices.Unsafe (>= 6.0) - restriction: >= netstandard2.0 - System.Text.Encoding.CodePages (>= 6.0) - restriction: >= netstandard2.0 - System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: && (< netcoreapp3.1) (>= netstandard2.0) - Microsoft.CodeAnalysis.CSharp (4.5) - restriction: >= netstandard2.0 - Microsoft.CodeAnalysis.Common (4.5) - restriction: >= netstandard2.0 - Microsoft.CodeCoverage (17.6) - restriction: || (>= net45) (>= netcoreapp2.1) + System.Text.Encoding.CodePages (>= 7.0) - restriction: >= netstandard2.0 + System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: && (< net6.0) (>= netstandard2.0) + Microsoft.CodeAnalysis.CSharp (4.6) - restriction: >= netstandard2.0 + Microsoft.CodeAnalysis.Common (4.6) - restriction: >= netstandard2.0 + Microsoft.CodeCoverage (17.6.3) - restriction: || (>= net45) (>= netcoreapp2.1) Microsoft.CSharp (4.7) - restriction: || (&& (< netstandard1.3) (>= uap10.0)) (&& (< netstandard2.0) (>= uap10.0)) - Microsoft.Diagnostics.NETCore.Client (0.2.421201) - restriction: >= netstandard2.0 - Microsoft.Bcl.AsyncInterfaces (>= 1.1) - restriction: && (< net6.0) (>= netstandard2.0) - Microsoft.Extensions.Logging (>= 2.1.1) - restriction: >= netstandard2.0 + Microsoft.Diagnostics.NETCore.Client (0.2.430602) - restriction: >= netstandard2.0 + Microsoft.Bcl.AsyncInterfaces (>= 6.0) - restriction: && (< net6.0) (>= netstandard2.0) + Microsoft.Extensions.Logging (>= 6.0) - restriction: >= netstandard2.0 + System.Buffers (>= 4.5.1) - restriction: && (< net6.0) (>= netstandard2.0) Microsoft.Diagnostics.Runtime (2.4.416101) - restriction: >= netstandard2.0 Microsoft.Diagnostics.NETCore.Client (>= 0.2.251802) - restriction: >= netstandard2.0 System.Collections.Immutable (>= 5.0) - restriction: >= netstandard2.0 System.Runtime.CompilerServices.Unsafe (>= 5.0) - restriction: >= netstandard2.0 - Microsoft.Diagnostics.Tracing.TraceEvent (3.1.2) - restriction: >= netstandard2.0 + Microsoft.Diagnostics.Tracing.TraceEvent (3.1.3) - restriction: >= netstandard2.0 System.Runtime.CompilerServices.Unsafe (>= 5.0) - restriction: >= netstandard2.0 Microsoft.DotNet.PlatformAbstractions (3.1.6) - restriction: >= netstandard2.0 System.Runtime.InteropServices.RuntimeInformation (>= 4.0) - restriction: || (>= net45) (&& (>= netstandard1.3) (< netstandard2.0)) @@ -121,7 +122,7 @@ NUGET Microsoft.Extensions.Options (>= 7.0) - restriction: || (>= net462) (>= netstandard2.0) System.Diagnostics.DiagnosticSource (>= 7.0) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.1)) (&& (>= netstandard2.0) (< netstandard2.1)) System.ValueTuple (>= 4.5) - restriction: >= net462 - Microsoft.Extensions.Logging.Abstractions (7.0) - restriction: >= netstandard2.0 + Microsoft.Extensions.Logging.Abstractions (7.0.1) - restriction: >= netstandard2.0 System.Buffers (>= 4.5.1) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) System.Memory (>= 4.5.5) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) Microsoft.Extensions.Options (7.0.1) - restriction: >= netstandard2.0 @@ -138,17 +139,17 @@ NUGET System.ComponentModel.Primitives (>= 4.1) - restriction: >= uap10.0 System.ComponentModel.TypeConverter (>= 4.1) - restriction: >= uap10.0 System.Runtime.InteropServices.RuntimeInformation (>= 4.0) - restriction: >= uap10.0 - Microsoft.NETCore.Platforms (7.0.2) - restriction: || (&& (>= monoandroid) (>= netcoreapp2.0) (< netstandard1.3)) (&& (>= monoandroid) (>= netcoreapp2.1) (< netstandard1.3)) (&& (< monoandroid) (>= netcoreapp2.0) (< netcoreapp2.1)) (&& (< monoandroid) (< netstandard1.1) (>= netstandard1.6) (< win8)) (&& (>= monotouch) (>= netcoreapp2.0)) (&& (>= monotouch) (>= netcoreapp2.1)) (&& (< net45) (>= net46) (< netstandard1.4) (>= netstandard1.6)) (&& (< net45) (>= net461) (>= netstandard1.6) (< netstandard2.0)) (&& (< net45) (< netstandard1.2) (>= netstandard1.6) (< win8)) (&& (< net45) (< netstandard1.3) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (< netstandard1.4) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (< netstandard1.5) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (>= netstandard1.6) (< netstandard2.0) (< win8) (< wpa81)) (&& (>= net461) (>= netcoreapp2.0)) (&& (>= net461) (>= netcoreapp2.1)) (&& (>= netcoreapp2.0) (< netcoreapp2.1) (>= xamarinios)) (&& (>= netcoreapp2.0) (< netcoreapp2.1) (>= xamarinmac)) (&& (>= netcoreapp2.0) (< netcoreapp2.1) (>= xamarintvos)) (&& (>= netcoreapp2.0) (< netcoreapp2.1) (>= xamarinwatchos)) (&& (>= netcoreapp2.0) (< netstandard2.0)) (&& (>= netcoreapp2.0) (>= uap10.1)) (&& (< netcoreapp2.0) (>= netcoreapp2.1)) (&& (>= netcoreapp2.1) (< netcoreapp3.0)) (&& (>= netcoreapp2.1) (>= uap10.1)) (&& (< netstandard1.0) (>= netstandard1.6) (< portable-net45+win8)) (&& (< netstandard1.0) (>= netstandard1.6) (>= win8)) (&& (< netstandard1.0) (>= netstandard1.6) (< win8)) (&& (< netstandard1.1) (>= netstandard1.6) (>= uap10.0) (< win8)) (&& (< netstandard1.3) (>= netstandard1.6) (>= uap10.0) (< win8) (< wpa81)) (&& (< netstandard1.3) (>= netstandard1.6) (< win8) (>= wpa81)) (&& (< netstandard1.5) (>= netstandard1.6) (>= uap10.0)) (&& (>= netstandard1.6) (< portable-net45+win8+wpa81)) (&& (>= netstandard1.6) (>= uap10.1)) (&& (>= netstandard1.6) (>= wp8)) + Microsoft.NETCore.Platforms (7.0.4) - restriction: || (&& (>= monoandroid) (>= netcoreapp2.0) (< netstandard1.3)) (&& (>= monoandroid) (>= netcoreapp2.1) (< netstandard1.3)) (&& (< monoandroid) (>= netcoreapp2.0) (< netcoreapp2.1)) (&& (< monoandroid) (< netstandard1.1) (>= netstandard1.6) (< win8)) (&& (>= monotouch) (>= netcoreapp2.0)) (&& (>= monotouch) (>= netcoreapp2.1)) (&& (< net45) (>= net46) (< netstandard1.4) (>= netstandard1.6)) (&& (< net45) (>= net461) (>= netstandard1.6) (< netstandard2.0)) (&& (< net45) (< netstandard1.2) (>= netstandard1.6) (< win8)) (&& (< net45) (< netstandard1.3) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (< netstandard1.4) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (< netstandard1.5) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (>= netstandard1.6) (< netstandard2.0) (< win8) (< wpa81)) (&& (>= net461) (>= netcoreapp2.0)) (&& (>= net461) (>= netcoreapp2.1)) (&& (>= netcoreapp2.0) (< netcoreapp2.1) (>= xamarinios)) (&& (>= netcoreapp2.0) (< netcoreapp2.1) (>= xamarinmac)) (&& (>= netcoreapp2.0) (< netcoreapp2.1) (>= xamarintvos)) (&& (>= netcoreapp2.0) (< netcoreapp2.1) (>= xamarinwatchos)) (&& (>= netcoreapp2.0) (< netstandard2.0)) (&& (>= netcoreapp2.0) (>= uap10.1)) (&& (< netcoreapp2.0) (>= netcoreapp2.1)) (&& (>= netcoreapp2.1) (< netcoreapp3.0)) (&& (>= netcoreapp2.1) (>= uap10.1)) (&& (< netstandard1.0) (>= netstandard1.6) (< portable-net45+win8)) (&& (< netstandard1.0) (>= netstandard1.6) (>= win8)) (&& (< netstandard1.0) (>= netstandard1.6) (< win8)) (&& (< netstandard1.1) (>= netstandard1.6) (>= uap10.0) (< win8)) (&& (< netstandard1.3) (>= netstandard1.6) (>= uap10.0) (< win8) (< wpa81)) (&& (< netstandard1.3) (>= netstandard1.6) (< win8) (>= wpa81)) (&& (< netstandard1.5) (>= netstandard1.6) (>= uap10.0)) (&& (>= netstandard1.6) (< portable-net45+win8+wpa81)) (&& (>= netstandard1.6) (>= uap10.1)) (&& (>= netstandard1.6) (>= wp8)) Microsoft.NETCore.Targets (5.0) - restriction: || (&& (< monoandroid) (< net45) (< netstandard1.2) (>= netstandard1.6) (< win8)) (&& (< monoandroid) (< net45) (< netstandard1.3) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.4) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.5) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< monoandroid) (< netstandard1.1) (>= netstandard1.6) (< win8)) (&& (< monotouch) (< net45) (>= netstandard1.6) (< netstandard2.0) (< win8) (< wpa81) (< xamarintvos) (< xamarinwatchos)) (&& (< netstandard1.1) (>= netstandard1.6) (>= uap10.0) (< win8)) (&& (< netstandard1.3) (>= netstandard1.6) (>= uap10.0) (< win8) (< wpa81)) (&& (< netstandard1.5) (>= netstandard1.6) (>= uap10.0) (< win8) (< wpa81)) (&& (>= netstandard1.6) (< portable-net45+win8+wpa81)) Microsoft.SourceLink.Common (1.1.1) - copy_local: true Microsoft.SourceLink.GitHub (1.0) - copy_local: true Microsoft.Build.Tasks.Git (>= 1.0) Microsoft.SourceLink.Common (>= 1.0) - Microsoft.TestPlatform.ObjectModel (17.6) - restriction: >= netcoreapp3.1 - NuGet.Frameworks (>= 5.11) - restriction: || (>= net462) (>= netstandard2.0) + Microsoft.TestPlatform.ObjectModel (17.6.3) - restriction: >= netcoreapp3.1 + NuGet.Frameworks (>= 6.5) - restriction: || (>= net462) (>= netstandard2.0) System.Reflection.Metadata (>= 1.6) - restriction: || (>= net462) (>= netstandard2.0) - Microsoft.TestPlatform.TestHost (17.6) - restriction: >= netcoreapp2.1 - Microsoft.TestPlatform.ObjectModel (>= 17.6) - restriction: >= netcoreapp3.1 + Microsoft.TestPlatform.TestHost (17.6.3) - restriction: >= netcoreapp2.1 + Microsoft.TestPlatform.ObjectModel (>= 17.6.3) - restriction: >= netcoreapp3.1 Newtonsoft.Json (>= 13.0.1) - restriction: >= netcoreapp3.1 Microsoft.Win32.Primitives (4.3) - restriction: || (&& (< net45) (>= net46) (< netstandard1.4) (>= netstandard1.6)) (&& (< net45) (< netstandard1.4) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (< netstandard1.5) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (>= netstandard1.6) (< netstandard2.0) (< win8) (< wpa81)) (&& (< netstandard1.5) (>= netstandard1.6) (>= uap10.0)) Microsoft.NETCore.Platforms (>= 1.1) - restriction: && (< monoandroid) (< monotouch) (< net46) (>= netstandard1.3) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) @@ -213,9 +214,9 @@ NUGET System.Runtime.Serialization.Formatters (>= 4.3) - restriction: && (< net20) (>= netstandard1.3) (< netstandard2.0) System.Runtime.Serialization.Primitives (>= 4.3) - restriction: || (&& (< net20) (>= netstandard1.0) (< netstandard1.3)) (&& (< net20) (>= netstandard1.3) (< netstandard2.0)) System.Xml.XmlDocument (>= 4.3) - restriction: && (< net20) (>= netstandard1.3) (< netstandard2.0) - NuGet.Frameworks (6.5) - restriction: >= netcoreapp3.1 - Perfolizer (0.3.4) - restriction: >= netstandard2.0 - System.Memory (>= 4.5.4) - restriction: && (>= netstandard2.0) (< netstandard2.1) + NuGet.Frameworks (6.6.1) - restriction: >= netcoreapp3.1 + Perfolizer (0.2.1) - restriction: >= netstandard2.0 + System.Memory (>= 4.5.3) - restriction: >= netstandard2.0 QuikGraph (2.5) NETStandard.Library (>= 1.6.1) - restriction: && (< net35) (>= netstandard1.3) (< netstandard2.0) runtime.debian.8-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3.3) - restriction: && (< monotouch) (< net45) (>= netstandard1.6) (< netstandard2.0) (< xamarintvos) (< xamarinwatchos) @@ -391,9 +392,9 @@ NUGET System.Runtime (>= 4.3) - restriction: || (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.3) (< win8) (< wp8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (&& (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) System.Runtime.Extensions (>= 4.3) - restriction: && (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) System.Threading (>= 4.3) - restriction: && (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) - System.Management (7.0.1) - restriction: >= netstandard2.0 + System.Management (7.0.2) - restriction: >= netstandard2.0 System.CodeDom (>= 7.0) - restriction: >= netstandard2.0 - System.Memory (4.5.5) - restriction: || (&& (< monoandroid) (>= netcoreapp2.0) (< netcoreapp2.1) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< net46) (< netcoreapp2.0) (>= netstandard2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (>= net462) (&& (< net6.0) (>= netstandard2.0)) (&& (< netcoreapp3.1) (>= netstandard2.0)) (&& (>= netstandard2.0) (< netstandard2.1)) (&& (>= netstandard2.0) (>= uap10.1)) + System.Memory (4.5.5) - restriction: || (&& (< monoandroid) (>= netcoreapp2.0) (< netcoreapp2.1) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (>= net462) (>= netstandard2.0) System.Buffers (>= 4.5.1) - restriction: || (&& (>= monoandroid) (< netstandard1.1)) (&& (< monoandroid) (< net45) (>= netstandard1.1) (< netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< netstandard1.1) (>= portable-net45+win8+wpa81) (< win8)) (>= monotouch) (&& (>= net45) (< netstandard2.0)) (&& (< net45) (< netcoreapp2.0) (>= netstandard2.0)) (>= net461) (&& (< netstandard1.1) (>= win8)) (&& (< netstandard2.0) (< uap10.1) (>= wpa81)) (>= xamarinios) (>= xamarinmac) (>= xamarintvos) (>= xamarinwatchos) System.Numerics.Vectors (>= 4.4) - restriction: && (< net45) (< netcoreapp2.0) (>= netstandard2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) System.Numerics.Vectors (>= 4.5) - restriction: >= net461 @@ -486,7 +487,7 @@ NUGET Microsoft.NETCore.Targets (>= 1.1) - restriction: && (< monoandroid) (< monotouch) (< net45) (>= netstandard1.0) (< win8) (< wp8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) System.Reflection (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (>= netstandard1.0) (< win8) (< wp8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) System.Runtime (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (>= netstandard1.0) (< win8) (< wp8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) - System.Reflection.Metadata (7.0.1) - restriction: >= netstandard2.0 + System.Reflection.Metadata (7.0.2) - restriction: >= netstandard2.0 System.Collections.Immutable (>= 7.0) - restriction: || (>= net462) (>= netstandard2.0) System.Memory (>= 4.5.5) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) System.Reflection.Primitives (4.3) - restriction: || (&& (< net45) (< netstandard1.2) (>= netstandard1.6) (< win8)) (&& (< net45) (< netstandard1.3) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (< netstandard1.4) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (< netstandard1.5) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (>= netstandard1.6) (< netstandard2.0) (< win8) (< wpa81)) (&& (< netstandard1.5) (>= netstandard1.6) (>= uap10.0)) (&& (>= netstandard1.6) (< portable-net45+win8+wpa81)) @@ -677,7 +678,7 @@ NUGET Microsoft.NETCore.Platforms (>= 1.1) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.3) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.3) (< win8) (< wp8) (< wpa81)) Microsoft.NETCore.Targets (>= 1.1) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.3) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.3) (< win8) (< wp8) (< wpa81)) System.Runtime (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.3) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.3) (< win8) (< wp8) (< wpa81)) - System.Threading.Tasks.Extensions (4.5.4) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< netstandard2.0) (< win8) (< wpa81) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (< netstandard1.2) (>= netstandard1.6) (< win8)) (&& (< monoandroid) (< net45) (< netstandard1.3) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.4) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.5) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (>= net46) (< netstandard1.4) (>= netstandard1.6)) (&& (>= net462) (>= netstandard2.0)) (&& (< net6.0) (>= netstandard2.0)) (&& (< netcoreapp3.1) (>= netstandard2.0)) (&& (< netstandard1.5) (>= netstandard1.6) (>= uap10.0) (< win8) (< wpa81)) (&& (>= netstandard1.6) (< portable-net45+win8+wpa81)) (&& (>= netstandard2.0) (< netstandard2.1)) + System.Threading.Tasks.Extensions (4.5.4) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< netstandard2.0) (< win8) (< wpa81) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (< netstandard1.2) (>= netstandard1.6) (< win8)) (&& (< monoandroid) (< net45) (< netstandard1.3) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.4) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.5) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (>= net46) (< netstandard1.4) (>= netstandard1.6)) (&& (>= net462) (>= netstandard2.0)) (&& (< net6.0) (>= netstandard2.0)) (&& (< netstandard1.5) (>= netstandard1.6) (>= uap10.0) (< win8) (< wpa81)) (&& (>= netstandard1.6) (< portable-net45+win8+wpa81)) (&& (>= netstandard2.0) (< netstandard2.1)) System.Runtime.CompilerServices.Unsafe (>= 4.5.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.0) (< netstandard2.0) (< win8) (< wpa81) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< netstandard1.0) (>= portable-net45+win8+wp8+wpa81) (< win8)) (&& (>= net45) (< netstandard2.0)) (&& (< net45) (< netcoreapp2.1) (>= netstandard2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (>= net461) (&& (< netstandard1.0) (>= win8)) (&& (< netstandard2.0) (>= wpa81)) (>= wp8) System.Threading.Timer (4.3) - restriction: || (&& (< net45) (< netstandard1.3) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (< netstandard1.4) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (< netstandard1.5) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (>= netstandard1.6) (< netstandard2.0) (< win8) (< wpa81)) (&& (< netstandard1.5) (>= netstandard1.6) (>= uap10.0)) Microsoft.NETCore.Platforms (>= 1.1) - restriction: && (< monoandroid) (< monotouch) (< net451) (>= netstandard1.2) (< win81) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) @@ -761,11 +762,11 @@ NUGET BinaryDefense.FSharp.Analyzers.Hashing (0.2.2) FSharp.Analyzers.SDK (>= 0.8) - restriction: >= net5.0 FSharp.Core (>= 5.0.1) - restriction: >= net5.0 - FSharp.Analyzers.SDK (0.11) - restriction: >= net5.0 - FSharp.Compiler.Service (>= 41.0.1) - restriction: >= net5.0 - FSharp.Core (>= 6.0.1) - restriction: >= net5.0 - McMaster.NETCore.Plugins (>= 1.4) - restriction: >= net5.0 - FSharp.Compiler.Service (43.7.300) - restriction: >= net5.0 + FSharp.Analyzers.SDK (0.12) - restriction: >= net5.0 + FSharp.Compiler.Service (>= 43.7.200) - restriction: >= net6.0 + FSharp.Core (>= 7.0.200) - restriction: >= net6.0 + McMaster.NETCore.Plugins (>= 1.4) - restriction: >= net6.0 + FSharp.Compiler.Service (43.7.300) - restriction: >= net6.0 FSharp.Core (7.0.300) - restriction: >= netstandard2.0 System.Buffers (>= 4.5.1) - restriction: >= netstandard2.0 System.Collections.Immutable (>= 6.0) - restriction: >= netstandard2.0 @@ -775,45 +776,30 @@ NUGET System.Reflection.Metadata (>= 6.0.1) - restriction: >= netstandard2.0 System.Runtime.CompilerServices.Unsafe (>= 6.0) - restriction: >= netstandard2.0 FSharp.Core (7.0.300) - restriction: >= net5.0 - McMaster.NETCore.Plugins (1.4) - restriction: >= net5.0 + McMaster.NETCore.Plugins (1.4) - restriction: >= net6.0 Microsoft.DotNet.PlatformAbstractions (>= 3.1.6) - restriction: >= netcoreapp2.1 Microsoft.Extensions.DependencyModel (>= 5.0) - restriction: >= netcoreapp2.1 - Microsoft.Bcl.AsyncInterfaces (7.0) - restriction: || (&& (>= net462) (>= net5.0)) (&& (>= net5.0) (< net6.0)) - Microsoft.DotNet.PlatformAbstractions (3.1.6) - restriction: >= net5.0 - Microsoft.Extensions.DependencyModel (7.0) - restriction: >= net5.0 - System.Buffers (>= 4.5.1) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) - System.Memory (>= 4.5.5) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) + Microsoft.DotNet.PlatformAbstractions (3.1.6) - restriction: >= net6.0 + Microsoft.Extensions.DependencyModel (7.0) - restriction: >= net6.0 System.Text.Encodings.Web (>= 7.0) - restriction: || (>= net462) (>= netstandard2.0) System.Text.Json (>= 7.0) - restriction: || (>= net462) (>= netstandard2.0) - System.Buffers (4.5.1) - restriction: >= net5.0 - System.Collections.Immutable (7.0) - restriction: >= net5.0 - System.Memory (>= 4.5.5) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) + System.Buffers (4.5.1) - restriction: >= net6.0 + System.Collections.Immutable (7.0) - restriction: >= net6.0 System.Runtime.CompilerServices.Unsafe (>= 6.0) - restriction: || (>= net462) (&& (>= net6.0) (< net7.0)) (&& (< net6.0) (>= netstandard2.0)) - System.Diagnostics.DiagnosticSource (7.0.2) - restriction: >= net5.0 - System.Memory (>= 4.5.5) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) + System.Diagnostics.DiagnosticSource (7.0.2) - restriction: >= net6.0 System.Runtime.CompilerServices.Unsafe (>= 6.0) - restriction: || (>= net462) (&& (>= net6.0) (< net7.0)) (&& (< net6.0) (>= netstandard2.0)) - System.Memory (4.5.5) - restriction: >= net5.0 + System.Memory (4.5.5) - restriction: >= net6.0 System.Buffers (>= 4.5.1) - restriction: || (&& (>= monoandroid) (< netstandard1.1)) (&& (< monoandroid) (< net45) (>= netstandard1.1) (< netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< netstandard1.1) (>= portable-net45+win8+wpa81) (< win8)) (>= monotouch) (&& (>= net45) (< netstandard2.0)) (&& (< net45) (< netcoreapp2.0) (>= netstandard2.0)) (>= net461) (&& (< netstandard1.1) (>= win8)) (&& (< netstandard2.0) (< uap10.1) (>= wpa81)) (>= xamarinios) (>= xamarinmac) (>= xamarintvos) (>= xamarinwatchos) System.Runtime.CompilerServices.Unsafe (>= 4.5.3) - restriction: || (&& (>= monoandroid) (< netstandard1.1)) (&& (< monoandroid) (< net45) (>= netstandard1.1) (< netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (>= netcoreapp2.0) (< netcoreapp2.1)) (&& (< monoandroid) (< netstandard1.1) (>= portable-net45+win8+wpa81) (< win8)) (>= monotouch) (&& (>= net45) (< netstandard2.0)) (&& (< net45) (< netcoreapp2.0) (>= netstandard2.0)) (>= net461) (&& (< netstandard1.1) (>= win8)) (&& (< netstandard2.0) (>= wpa81)) (>= uap10.1) (>= xamarinios) (>= xamarinmac) (>= xamarintvos) (>= xamarinwatchos) - System.Numerics.Vectors (4.5) - restriction: || (&& (>= net462) (>= net5.0)) (&& (>= net5.0) (< net6.0)) - System.Reflection.Emit (4.7) - restriction: >= net5.0 - System.Reflection.Metadata (7.0.1) - restriction: >= net5.0 + System.Reflection.Emit (4.7) - restriction: >= net6.0 + System.Reflection.Metadata (7.0.2) - restriction: >= net6.0 System.Collections.Immutable (>= 7.0) - restriction: || (>= net462) (>= netstandard2.0) - System.Memory (>= 4.5.5) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) - System.Runtime.CompilerServices.Unsafe (6.0) - restriction: || (>= net5.0) (&& (>= net6.0) (< net7.0)) - System.Text.Encodings.Web (7.0) - restriction: >= net5.0 - System.Buffers (>= 4.5.1) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) - System.Memory (>= 4.5.5) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) + System.Runtime.CompilerServices.Unsafe (6.0) - restriction: >= net6.0 + System.Text.Encodings.Web (7.0) - restriction: >= net6.0 System.Runtime.CompilerServices.Unsafe (>= 6.0) - restriction: || (>= net462) (&& (>= net6.0) (< net7.0)) (&& (< net6.0) (>= netstandard2.0)) - System.Text.Json (7.0.2) - restriction: >= net5.0 - Microsoft.Bcl.AsyncInterfaces (>= 7.0) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) - System.Buffers (>= 4.5.1) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) - System.Memory (>= 4.5.5) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) - System.Numerics.Vectors (>= 4.5) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) + System.Text.Json (7.0.3) - restriction: >= net6.0 System.Runtime.CompilerServices.Unsafe (>= 6.0) - restriction: || (>= net462) (&& (>= net6.0) (< net7.0)) (&& (< net6.0) (>= netstandard2.0)) System.Text.Encodings.Web (>= 7.0) - restriction: || (>= net462) (>= netstandard2.0) - System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) - System.Threading.Tasks.Extensions (4.5.4) - restriction: || (&& (>= net462) (>= net5.0)) (&& (>= net5.0) (< net6.0)) GROUP Build STORAGE: NONE @@ -947,27 +933,34 @@ NUGET FSharp.Core (>= 4.7.2) - restriction: >= netstandard2.0 System.Reactive (>= 5.0 < 6.0) - restriction: >= netstandard2.0 FSharp.Core (7.0.300) - restriction: >= netstandard2.0 - Microsoft.Build.Framework (17.5) - restriction: >= netstandard2.0 + Microsoft.Build.Framework (17.6.3) - restriction: >= netstandard2.0 + Microsoft.VisualStudio.Setup.Configuration.Interop (>= 3.2.2146) - restriction: >= net472 Microsoft.Win32.Registry (>= 5.0) - restriction: && (< net472) (< net7.0) (>= netstandard2.0) System.Runtime.CompilerServices.Unsafe (>= 6.0) - restriction: >= net472 - System.Security.Permissions (>= 6.0) - restriction: || (&& (< net472) (>= netstandard2.0)) (>= net7.0) - Microsoft.Build.Utilities.Core (17.5) - restriction: >= netstandard2.0 - Microsoft.Build.Framework (>= 17.5) - restriction: >= netstandard2.0 + System.Security.Permissions (>= 7.0) - restriction: || (&& (< net472) (>= netstandard2.0)) (>= net7.0) + System.Security.Principal.Windows (>= 5.0) - restriction: && (< net472) (< net7.0) (>= netstandard2.0) + Microsoft.Build.Utilities.Core (17.6.3) - restriction: >= netstandard2.0 + Microsoft.Build.Framework (>= 17.6.3) - restriction: >= netstandard2.0 Microsoft.IO.Redist (>= 6.0) - restriction: >= net472 - Microsoft.NET.StringTools (>= 17.5) - restriction: >= netstandard2.0 + Microsoft.NET.StringTools (>= 17.6.3) - restriction: >= netstandard2.0 + Microsoft.VisualStudio.Setup.Configuration.Interop (>= 3.2.2146) - restriction: || (>= net472) (>= net7.0) Microsoft.Win32.Registry (>= 5.0) - restriction: && (< net472) (< net7.0) (>= netstandard2.0) - System.Collections.Immutable (>= 6.0) - restriction: >= netstandard2.0 - System.Configuration.ConfigurationManager (>= 6.0) - restriction: >= netstandard2.0 - System.Security.Permissions (>= 6.0) - restriction: && (< net472) (< net7.0) (>= netstandard2.0) - System.Text.Encoding.CodePages (>= 6.0) - restriction: && (< net472) (< net7.0) (>= netstandard2.0) + System.Collections.Immutable (>= 7.0) - restriction: >= netstandard2.0 + System.Configuration.ConfigurationManager (>= 7.0) - restriction: >= netstandard2.0 + System.Memory (>= 4.5.5) - restriction: || (>= net472) (&& (< net7.0) (>= netstandard2.0)) + System.Runtime.CompilerServices.Unsafe (>= 6.0) - restriction: || (>= net472) (&& (< net7.0) (>= netstandard2.0)) + System.Security.Permissions (>= 7.0) - restriction: >= netstandard2.0 + System.Security.Principal.Windows (>= 5.0) - restriction: || (>= net472) (&& (< net7.0) (>= netstandard2.0)) + System.Text.Encoding.CodePages (>= 7.0) - restriction: && (< net472) (< net7.0) (>= netstandard2.0) Microsoft.IO.Redist (6.0) - restriction: >= net472 System.Buffers (>= 4.5.1) - restriction: >= net472 System.Memory (>= 4.5.4) - restriction: >= net472 - Microsoft.NET.StringTools (17.5) - restriction: >= netstandard2.0 + Microsoft.NET.StringTools (17.6.3) - restriction: >= netstandard2.0 System.Memory (>= 4.5.5) - restriction: || (>= net472) (&& (< net7.0) (>= netstandard2.0)) System.Runtime.CompilerServices.Unsafe (>= 6.0) - restriction: || (>= net472) (&& (< net7.0) (>= netstandard2.0)) - Microsoft.NETCore.Platforms (7.0.2) - restriction: || (&& (>= monoandroid) (>= netcoreapp2.0) (< netstandard1.3)) (&& (>= monoandroid) (>= netcoreapp2.1) (< netstandard1.3)) (&& (< monoandroid) (< net45) (< netcoreapp3.1) (>= netstandard2.0) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (< netstandard1.2) (>= netstandard2.0) (< win8)) (&& (< monoandroid) (< net45) (< netstandard1.3) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.5) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (>= net5.0) (< netcoreapp2.1) (< netstandard2.1) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (>= netcoreapp2.0) (< netcoreapp2.1)) (&& (>= monotouch) (>= netcoreapp2.0)) (&& (>= monotouch) (>= netcoreapp2.1)) (&& (>= net461) (>= netcoreapp2.0)) (&& (>= net461) (>= netcoreapp2.1)) (&& (>= netcoreapp2.0) (< netcoreapp2.1) (>= xamarinios)) (&& (>= netcoreapp2.0) (< netcoreapp2.1) (>= xamarinmac)) (&& (>= netcoreapp2.0) (< netcoreapp2.1) (>= xamarintvos)) (&& (>= netcoreapp2.0) (< netcoreapp2.1) (>= xamarinwatchos)) (&& (>= netcoreapp2.0) (>= uap10.1)) (&& (< netcoreapp2.0) (>= netcoreapp2.1)) (&& (>= netcoreapp2.1) (< netcoreapp3.0)) (&& (>= netcoreapp2.1) (>= uap10.1)) + Microsoft.NETCore.Platforms (7.0.4) - restriction: || (&& (< monoandroid) (< net45) (< netcoreapp3.1) (>= netstandard2.0) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (< netstandard1.2) (>= netstandard2.0) (< win8)) (&& (< monoandroid) (< net45) (< netstandard1.3) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.5) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (>= net5.0) (< netcoreapp2.1) (< netstandard2.1) (< xamarintvos) (< xamarinwatchos)) (&& (>= netcoreapp2.0) (< netcoreapp2.1)) (&& (>= netcoreapp2.1) (< netcoreapp3.0)) Microsoft.NETCore.Targets (5.0) - restriction: || (&& (< monoandroid) (< net45) (< netcoreapp3.1) (>= netstandard2.0) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (< netstandard1.2) (>= netstandard2.0) (< win8)) (&& (< monoandroid) (< net45) (< netstandard1.3) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.5) (>= netstandard2.0) (< win8) (< wpa81)) + Microsoft.VisualStudio.Setup.Configuration.Interop (3.6.2115) - restriction: || (>= net472) (>= net7.0) Microsoft.Win32.Registry (5.0) - restriction: || (&& (< net45) (>= netstandard2.0)) (&& (< net472) (< net7.0) (>= netstandard2.0)) System.Buffers (>= 4.5.1) - restriction: || (&& (>= monoandroid) (< netstandard1.3)) (>= monotouch) (&& (< net46) (< netcoreapp2.0) (>= netstandard2.0)) (>= xamarinios) (>= xamarinmac) (>= xamarintvos) (>= xamarinwatchos) System.Memory (>= 4.5.4) - restriction: || (&& (< monoandroid) (>= netcoreapp2.0) (< netcoreapp2.1) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< net46) (< netcoreapp2.0) (>= netstandard2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (>= uap10.1) @@ -979,21 +972,21 @@ NUGET Microsoft.Build.Framework (>= 17.5) - restriction: >= netstandard2.0 Microsoft.Build.Utilities.Core (>= 17.5) - restriction: >= netstandard2.0 Newtonsoft.Json (13.0.3) - restriction: >= netstandard2.0 - NuGet.Common (6.5) - restriction: >= netstandard2.0 - NuGet.Frameworks (>= 6.5) - restriction: >= netstandard2.0 - NuGet.Configuration (6.5) - restriction: >= netstandard2.0 - NuGet.Common (>= 6.5) - restriction: >= netstandard2.0 + NuGet.Common (6.6.1) - restriction: >= netstandard2.0 + NuGet.Frameworks (>= 6.6.1) - restriction: >= netstandard2.0 + NuGet.Configuration (6.6.1) - restriction: >= netstandard2.0 + NuGet.Common (>= 6.6.1) - restriction: >= netstandard2.0 System.Security.Cryptography.ProtectedData (>= 4.4) - restriction: && (< net472) (>= netstandard2.0) - NuGet.Frameworks (6.5) - restriction: >= netstandard2.0 - NuGet.Packaging (6.5) - restriction: >= netstandard2.0 + NuGet.Frameworks (6.6.1) - restriction: >= netstandard2.0 + NuGet.Packaging (6.6.1) - restriction: >= netstandard2.0 Newtonsoft.Json (>= 13.0.1) - restriction: >= netstandard2.0 - NuGet.Configuration (>= 6.5) - restriction: >= netstandard2.0 - NuGet.Versioning (>= 6.5) - restriction: >= netstandard2.0 + NuGet.Configuration (>= 6.6.1) - restriction: >= netstandard2.0 + NuGet.Versioning (>= 6.6.1) - restriction: >= netstandard2.0 System.Security.Cryptography.Cng (>= 5.0) - restriction: || (&& (< net472) (>= netstandard2.0)) (>= net5.0) System.Security.Cryptography.Pkcs (>= 5.0) - restriction: || (&& (< net472) (>= netstandard2.0)) (>= net5.0) - NuGet.Protocol (6.5) - restriction: >= netstandard2.0 - NuGet.Packaging (>= 6.5) - restriction: >= netstandard2.0 - NuGet.Versioning (6.5) - restriction: >= netstandard2.0 + NuGet.Protocol (6.6.1) - restriction: >= netstandard2.0 + NuGet.Packaging (>= 6.6.1) - restriction: >= netstandard2.0 + NuGet.Versioning (6.6.1) - restriction: >= netstandard2.0 Octokit (0.48) System.Buffers (4.5.1) - restriction: || (&& (>= monoandroid) (< netstandard1.1) (>= netstandard2.0)) (&& (>= monoandroid) (< netstandard1.3) (>= netstandard2.0)) (&& (< monoandroid) (< netstandard1.1) (>= netstandard2.0) (< win8)) (&& (>= monotouch) (>= netstandard2.0)) (&& (< net45) (< netcoreapp2.0) (>= netstandard2.0)) (&& (>= net461) (>= netstandard2.0)) (&& (>= net462) (>= netstandard2.0)) (&& (>= net462) (>= netstandard2.1)) (&& (< net462) (< net6.0) (>= netstandard2.0)) (&& (< net462) (>= netstandard2.0) (< netstandard2.1)) (>= net472) (&& (>= net5.0) (< netstandard2.1)) (&& (< net6.0) (>= netstandard2.1)) (&& (< netstandard1.1) (>= netstandard2.0) (>= win8)) (&& (>= netstandard2.0) (>= xamarintvos)) (&& (>= netstandard2.0) (>= xamarinwatchos)) (>= xamarinios) (>= xamarinmac) System.Collections.Immutable (7.0) - restriction: >= netstandard2.0 @@ -1037,7 +1030,7 @@ NUGET System.Formats.Asn1 (>= 5.0) - restriction: && (>= netcoreapp3.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) System.Security.Cryptography.Algorithms (>= 4.3.1) - restriction: || (&& (< monoandroid) (< monotouch) (< net46) (>= netstandard1.6) (< netstandard2.0) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net46) (>= netstandard1.3) (< netstandard1.4)) (&& (< monoandroid) (< net46) (>= netstandard1.4) (< netstandard1.6) (< uap10.1)) (&& (>= net46) (< netstandard1.4)) (&& (>= net461) (< net462) (< netstandard1.6)) (&& (>= net462) (< netstandard1.6)) (>= net47) System.Security.Cryptography.Encoding (4.3) - restriction: || (&& (< monoandroid) (< net46) (< netstandard1.4) (>= netstandard2.0)) (&& (< monoandroid) (< net46) (< netstandard1.6) (>= netstandard2.0)) (&& (< monoandroid) (>= net5.0) (< netstandard1.4)) (&& (< monoandroid) (>= net5.0) (< netstandard1.6)) (&& (< monoandroid) (>= net5.0) (< netstandard2.0) (< xamarintvos) (< xamarinwatchos)) (&& (>= net46) (>= net5.0) (< netstandard1.4)) (&& (< net46) (>= net461) (< netstandard1.6) (>= netstandard2.0)) (&& (< net46) (>= net462) (< netstandard1.6) (>= netstandard2.0)) (&& (< net46) (>= net47) (>= netstandard2.0)) (&& (>= net461) (>= net5.0) (< netstandard1.6)) (&& (>= net462) (>= net5.0) (< netstandard1.6)) (&& (>= net463) (>= net5.0) (< netstandard1.4)) (&& (>= net463) (>= net5.0) (< netstandard1.6)) (&& (>= net463) (>= net5.0) (< netstandard2.0)) (&& (>= net463) (< netstandard1.4) (>= netstandard2.0)) (&& (>= net463) (< netstandard1.6) (>= netstandard2.0)) (&& (>= net47) (< net472) (>= netstandard2.0)) (&& (>= net47) (>= net5.0)) - System.Security.Cryptography.Pkcs (7.0.1) - restriction: || (&& (< net472) (>= netstandard2.0)) (>= net5.0) + System.Security.Cryptography.Pkcs (7.0.3) - restriction: || (&& (< net472) (>= netstandard2.0)) (>= net5.0) System.Buffers (>= 4.5.1) - restriction: && (< net462) (>= netstandard2.0) (< netstandard2.1) System.Formats.Asn1 (>= 7.0) - restriction: || (&& (< net462) (>= netstandard2.0)) (>= netstandard2.1) System.Memory (>= 4.5.5) - restriction: && (< net462) (>= netstandard2.0) (< netstandard2.1) @@ -1048,7 +1041,7 @@ NUGET System.Security.Permissions (7.0) - restriction: >= netstandard2.0 System.Security.AccessControl (>= 6.0) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) System.Windows.Extensions (>= 7.0) - restriction: >= net6.0 - System.Security.Principal.Windows (5.0) - restriction: || (&& (>= monoandroid) (< netstandard1.3) (>= netstandard2.0)) (&& (< monoandroid) (>= netcoreapp2.0)) (&& (>= monotouch) (>= netstandard2.0)) (&& (< net45) (< netcoreapp2.0) (>= netstandard2.0)) (&& (>= net461) (>= netstandard2.0)) (&& (>= net462) (>= netstandard2.0)) (&& (< net6.0) (>= netstandard2.0)) (>= netcoreapp2.1) (&& (>= netstandard2.0) (>= uap10.1)) (&& (>= netstandard2.0) (>= xamarintvos)) (&& (>= netstandard2.0) (>= xamarinwatchos)) (>= xamarinios) (>= xamarinmac) + System.Security.Principal.Windows (5.0) - restriction: || (&& (>= monoandroid) (< netstandard1.3) (>= netstandard2.0)) (&& (< monoandroid) (>= netcoreapp2.0)) (&& (>= monotouch) (>= netstandard2.0)) (&& (< net45) (< netcoreapp2.0) (>= netstandard2.0)) (&& (>= net461) (>= netstandard2.0)) (&& (>= net462) (>= netstandard2.0)) (>= net472) (&& (< net6.0) (>= netstandard2.0)) (&& (< net7.0) (>= netstandard2.0)) (>= netcoreapp2.1) (&& (>= netstandard2.0) (>= uap10.1)) (&& (>= netstandard2.0) (>= xamarintvos)) (&& (>= netstandard2.0) (>= xamarinwatchos)) (>= xamarinios) (>= xamarinmac) Microsoft.NETCore.Platforms (>= 5.0) - restriction: || (&& (>= netcoreapp2.0) (< netcoreapp2.1)) (&& (>= netcoreapp2.1) (< netcoreapp3.0)) System.Text.Encoding.CodePages (7.0) - restriction: && (< net472) (< net7.0) (>= netstandard2.0) System.Memory (>= 4.5.5) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) @@ -1189,27 +1182,34 @@ NUGET FSharp.Literate (4.0.0-rc1) FSharp.Compiler.Service (>= 34.1) - restriction: >= netstandard2.0 FSharp.Core (>= 4.7) - restriction: >= netstandard2.0 - Microsoft.Build.Framework (17.5) - restriction: >= netstandard2.0 + Microsoft.Build.Framework (17.6.3) - restriction: >= netstandard2.0 + Microsoft.VisualStudio.Setup.Configuration.Interop (>= 3.2.2146) - restriction: >= net472 Microsoft.Win32.Registry (>= 5.0) - restriction: && (< net472) (< net7.0) (>= netstandard2.0) System.Runtime.CompilerServices.Unsafe (>= 6.0) - restriction: >= net472 - System.Security.Permissions (>= 6.0) - restriction: || (&& (< net472) (>= netstandard2.0)) (>= net7.0) - Microsoft.Build.Utilities.Core (17.5) - restriction: >= netstandard2.0 - Microsoft.Build.Framework (>= 17.5) - restriction: >= netstandard2.0 + System.Security.Permissions (>= 7.0) - restriction: || (&& (< net472) (>= netstandard2.0)) (>= net7.0) + System.Security.Principal.Windows (>= 5.0) - restriction: && (< net472) (< net7.0) (>= netstandard2.0) + Microsoft.Build.Utilities.Core (17.6.3) - restriction: >= netstandard2.0 + Microsoft.Build.Framework (>= 17.6.3) - restriction: >= netstandard2.0 Microsoft.IO.Redist (>= 6.0) - restriction: >= net472 - Microsoft.NET.StringTools (>= 17.5) - restriction: >= netstandard2.0 + Microsoft.NET.StringTools (>= 17.6.3) - restriction: >= netstandard2.0 + Microsoft.VisualStudio.Setup.Configuration.Interop (>= 3.2.2146) - restriction: || (>= net472) (>= net7.0) Microsoft.Win32.Registry (>= 5.0) - restriction: && (< net472) (< net7.0) (>= netstandard2.0) - System.Collections.Immutable (>= 6.0) - restriction: >= netstandard2.0 - System.Configuration.ConfigurationManager (>= 6.0) - restriction: >= netstandard2.0 - System.Security.Permissions (>= 6.0) - restriction: && (< net472) (< net7.0) (>= netstandard2.0) - System.Text.Encoding.CodePages (>= 6.0) - restriction: && (< net472) (< net7.0) (>= netstandard2.0) + System.Collections.Immutable (>= 7.0) - restriction: >= netstandard2.0 + System.Configuration.ConfigurationManager (>= 7.0) - restriction: >= netstandard2.0 + System.Memory (>= 4.5.5) - restriction: || (>= net472) (&& (< net7.0) (>= netstandard2.0)) + System.Runtime.CompilerServices.Unsafe (>= 6.0) - restriction: || (>= net472) (&& (< net7.0) (>= netstandard2.0)) + System.Security.Permissions (>= 7.0) - restriction: >= netstandard2.0 + System.Security.Principal.Windows (>= 5.0) - restriction: || (>= net472) (&& (< net7.0) (>= netstandard2.0)) + System.Text.Encoding.CodePages (>= 7.0) - restriction: && (< net472) (< net7.0) (>= netstandard2.0) Microsoft.IO.Redist (6.0) - restriction: >= net472 System.Buffers (>= 4.5.1) - restriction: >= net472 System.Memory (>= 4.5.4) - restriction: >= net472 - Microsoft.NET.StringTools (17.5) - restriction: >= netstandard2.0 + Microsoft.NET.StringTools (17.6.3) - restriction: >= netstandard2.0 System.Memory (>= 4.5.5) - restriction: || (>= net472) (&& (< net7.0) (>= netstandard2.0)) System.Runtime.CompilerServices.Unsafe (>= 6.0) - restriction: || (>= net472) (&& (< net7.0) (>= netstandard2.0)) - Microsoft.NETCore.Platforms (7.0.2) - restriction: || (&& (>= monoandroid) (>= netcoreapp2.0) (< netstandard1.3)) (&& (>= monoandroid) (>= netcoreapp2.1) (< netstandard1.3)) (&& (< monoandroid) (< net45) (< netstandard1.2) (>= netstandard2.0) (< win8)) (&& (< monoandroid) (< net45) (< netstandard1.3) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.5) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (>= net5.0) (< netcoreapp2.1) (< netstandard2.1) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (>= netcoreapp2.0) (< netcoreapp2.1) (< netstandard2.1) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (>= netcoreapp2.0) (< netcoreapp2.1) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (>= monotouch) (>= netcoreapp2.0)) (&& (>= monotouch) (>= netcoreapp2.1)) (&& (< net45) (>= netstandard2.0) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< net46) (>= netstandard2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (>= net461) (>= netcoreapp2.0)) (&& (>= net461) (>= netcoreapp2.1)) (&& (>= netcoreapp2.0) (>= uap10.1)) (&& (< netcoreapp2.0) (>= netcoreapp2.1) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (>= netcoreapp2.1) (< netcoreapp3.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (>= netcoreapp2.1) (>= uap10.1)) + Microsoft.NETCore.Platforms (7.0.4) - restriction: || (&& (>= monoandroid) (>= netcoreapp2.0) (< netstandard1.3)) (&& (>= monoandroid) (>= netcoreapp2.1) (< netstandard1.3)) (&& (< monoandroid) (< net45) (< netstandard1.2) (>= netstandard2.0) (< win8)) (&& (< monoandroid) (< net45) (< netstandard1.3) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.5) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (>= net5.0) (< netcoreapp2.1) (< netstandard2.1) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (>= netcoreapp2.0) (< netcoreapp2.1) (< netstandard2.1) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (>= netcoreapp2.0) (< netcoreapp2.1) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (>= monotouch) (>= netcoreapp2.0)) (&& (>= monotouch) (>= netcoreapp2.1)) (&& (< net45) (>= netstandard2.0) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< net46) (>= netstandard2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (>= net461) (>= netcoreapp2.0)) (&& (>= net461) (>= netcoreapp2.1)) (&& (>= netcoreapp2.0) (>= uap10.1)) (&& (< netcoreapp2.0) (>= netcoreapp2.1) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (>= netcoreapp2.1) (< netcoreapp3.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (>= netcoreapp2.1) (>= uap10.1)) Microsoft.NETCore.Targets (5.0) - restriction: || (&& (< monoandroid) (< net45) (< netstandard1.2) (>= netstandard2.0) (< win8)) (&& (< monoandroid) (< net45) (< netstandard1.3) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.5) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< net45) (>= netstandard2.0) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< net46) (>= netstandard2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) + Microsoft.VisualStudio.Setup.Configuration.Interop (3.6.2115) - restriction: || (>= net472) (>= net7.0) Microsoft.Win32.Primitives (4.3) - restriction: && (< net46) (>= netstandard2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) Microsoft.NETCore.Platforms (>= 1.1) - restriction: && (< monoandroid) (< monotouch) (< net46) (>= netstandard1.3) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) Microsoft.NETCore.Targets (>= 1.1) - restriction: && (< monoandroid) (< monotouch) (< net46) (>= netstandard1.3) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) @@ -1225,21 +1225,21 @@ NUGET Microsoft.Build.Framework (>= 17.5) - restriction: >= netstandard2.0 Microsoft.Build.Utilities.Core (>= 17.5) - restriction: >= netstandard2.0 Newtonsoft.Json (13.0.3) - restriction: >= netstandard2.0 - NuGet.Common (6.5) - restriction: >= netstandard2.0 - NuGet.Frameworks (>= 6.5) - restriction: >= netstandard2.0 - NuGet.Configuration (6.5) - restriction: >= netstandard2.0 - NuGet.Common (>= 6.5) - restriction: >= netstandard2.0 + NuGet.Common (6.6.1) - restriction: >= netstandard2.0 + NuGet.Frameworks (>= 6.6.1) - restriction: >= netstandard2.0 + NuGet.Configuration (6.6.1) - restriction: >= netstandard2.0 + NuGet.Common (>= 6.6.1) - restriction: >= netstandard2.0 System.Security.Cryptography.ProtectedData (>= 4.4) - restriction: && (< net472) (>= netstandard2.0) - NuGet.Frameworks (6.5) - restriction: >= netstandard2.0 - NuGet.Packaging (6.5) - restriction: >= netstandard2.0 + NuGet.Frameworks (6.6.1) - restriction: >= netstandard2.0 + NuGet.Packaging (6.6.1) - restriction: >= netstandard2.0 Newtonsoft.Json (>= 13.0.1) - restriction: >= netstandard2.0 - NuGet.Configuration (>= 6.5) - restriction: >= netstandard2.0 - NuGet.Versioning (>= 6.5) - restriction: >= netstandard2.0 + NuGet.Configuration (>= 6.6.1) - restriction: >= netstandard2.0 + NuGet.Versioning (>= 6.6.1) - restriction: >= netstandard2.0 System.Security.Cryptography.Cng (>= 5.0) - restriction: || (&& (< net472) (>= netstandard2.0)) (>= net5.0) System.Security.Cryptography.Pkcs (>= 5.0) - restriction: || (&& (< net472) (>= netstandard2.0)) (>= net5.0) - NuGet.Protocol (6.5) - restriction: >= netstandard2.0 - NuGet.Packaging (>= 6.5) - restriction: >= netstandard2.0 - NuGet.Versioning (6.5) - restriction: >= netstandard2.0 + NuGet.Protocol (6.6.1) - restriction: >= netstandard2.0 + NuGet.Packaging (>= 6.6.1) - restriction: >= netstandard2.0 + NuGet.Versioning (6.6.1) - restriction: >= netstandard2.0 runtime.debian.8-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3.3) - restriction: && (< net46) (>= netstandard2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) runtime.debian.9-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3.3) - restriction: && (< net46) (>= netstandard2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) runtime.fedora.23-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3.3) - restriction: && (< net46) (>= netstandard2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) @@ -1388,7 +1388,7 @@ NUGET System.Reflection.Emit (4.7) - restriction: && (< net461) (>= netstandard2.0) System.Reflection.Emit.ILGeneration (>= 4.7) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.1) (< netstandard2.0) (< win8) (< wpa81) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (< netcoreapp2.0) (>= netstandard2.0) (< netstandard2.1) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< netstandard1.1) (>= portable-net45+win8+wpa81) (< win8)) (&& (< netstandard1.1) (>= win8)) (&& (< netstandard2.0) (>= wpa81)) (>= uap10.1) System.Reflection.Emit.ILGeneration (4.7) - restriction: || (&& (< monoandroid) (< net45) (< netcoreapp2.0) (>= netstandard2.0) (< netstandard2.1) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< netstandard1.1) (>= netstandard2.0) (< win8)) (&& (< netstandard1.1) (>= netstandard2.0) (>= win8)) (&& (>= netstandard2.0) (>= uap10.1)) - System.Reflection.Metadata (7.0.1) - restriction: || (>= net461) (>= netstandard2.0) + System.Reflection.Metadata (7.0.2) - restriction: || (>= net461) (>= netstandard2.0) System.Collections.Immutable (>= 7.0) - restriction: || (>= net462) (>= netstandard2.0) System.Memory (>= 4.5.5) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) System.Reflection.Primitives (4.3) - restriction: || (&& (< monoandroid) (< net45) (< netstandard1.3) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.5) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< net45) (>= netstandard2.0) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) @@ -1464,7 +1464,7 @@ NUGET System.Runtime.InteropServices (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net46) (>= netstandard1.3) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) System.Security.Cryptography.Primitives (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net46) (>= netstandard1.3) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) System.Text.Encoding (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net46) (>= netstandard1.3) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) - System.Security.Cryptography.Pkcs (7.0.1) - restriction: || (&& (< net472) (>= netstandard2.0)) (>= net5.0) + System.Security.Cryptography.Pkcs (7.0.3) - restriction: || (&& (< net472) (>= netstandard2.0)) (>= net5.0) System.Buffers (>= 4.5.1) - restriction: && (< net462) (>= netstandard2.0) (< netstandard2.1) System.Formats.Asn1 (>= 7.0) - restriction: || (&& (< net462) (>= netstandard2.0)) (>= netstandard2.1) System.Memory (>= 4.5.5) - restriction: && (< net462) (>= netstandard2.0) (< netstandard2.1) @@ -1482,7 +1482,7 @@ NUGET System.Security.Permissions (7.0) - restriction: >= netstandard2.0 System.Security.AccessControl (>= 6.0) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) System.Windows.Extensions (>= 7.0) - restriction: >= net6.0 - System.Security.Principal.Windows (5.0) - restriction: || (&& (>= monoandroid) (< netstandard1.3) (>= netstandard2.0)) (&& (< monoandroid) (>= netcoreapp2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (>= monotouch) (>= netstandard2.0)) (&& (< net46) (< netcoreapp2.0) (>= netstandard2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (>= net461) (>= netstandard2.0)) (&& (>= net462) (>= netstandard2.0)) (&& (< net6.0) (>= netstandard2.0)) (&& (>= netcoreapp2.1) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (>= netstandard2.0) (>= uap10.1)) + System.Security.Principal.Windows (5.0) - restriction: || (&& (>= monoandroid) (< netstandard1.3) (>= netstandard2.0)) (&& (< monoandroid) (>= netcoreapp2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (>= monotouch) (>= netstandard2.0)) (&& (< net46) (< netcoreapp2.0) (>= netstandard2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (>= net461) (>= netstandard2.0)) (&& (>= net462) (>= netstandard2.0)) (>= net472) (&& (< net6.0) (>= netstandard2.0)) (&& (< net7.0) (>= netstandard2.0)) (&& (>= netcoreapp2.1) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (>= netstandard2.0) (>= uap10.1)) Microsoft.NETCore.Platforms (>= 5.0) - restriction: || (&& (>= netcoreapp2.0) (< netcoreapp2.1)) (&& (>= netcoreapp2.1) (< netcoreapp3.0)) System.Text.Encoding (4.3) - restriction: || (&& (< monoandroid) (< net45) (< netstandard1.3) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.4) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.5) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.6) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< net45) (>= net463) (>= netstandard2.0)) (&& (< net45) (>= netstandard2.0) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< net46) (>= netstandard2.0) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) Microsoft.NETCore.Platforms (>= 1.1) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.3) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.3) (< win8) (< wp8) (< wpa81)) diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs b/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs new file mode 100644 index 00000000..e45bbc3a --- /dev/null +++ b/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs @@ -0,0 +1,6 @@ +namespace GraphBLAS.FSharp + +open GraphBLAS.FSharp.Backend.Algorithms + +module Algorithms = + let singleSourceBFS = BFS.singleSource diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs b/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs index bf9ee64e..30ecf994 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs @@ -1,18 +1,17 @@ namespace GraphBLAS.FSharp.Backend.Algorithms -open GraphBLAS.FSharp.Backend open Brahma.FSharp open FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Vector +open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Backend.Vector.Dense -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClCellExtensions -module BFS = +module internal BFS = let singleSource (add: Expr int option -> int option>) (mul: Expr<'a option -> int option -> int option>) @@ -21,12 +20,12 @@ module BFS = = let spMVTo = - SpMV.runTo add mul clContext workGroupSize + SpMVInplace add mul clContext workGroupSize let zeroCreate = ClArray.zeroCreate clContext workGroupSize - let ofList = Primitives.ofList clContext workGroupSize + let ofList = Vector.ofList clContext workGroupSize let maskComplementedTo = Vector.map2InPlace Mask.complementedOp clContext workGroupSize @@ -37,7 +36,7 @@ module BFS = let containsNonZero = ClArray.exists Predicates.isSome clContext workGroupSize - fun (queue: MailboxProcessor) (matrix: ClMatrix.CSR<'a>) (source: int) -> + fun (queue: MailboxProcessor) (matrix: ClMatrix<'a>) (source: int) -> let vertexCount = matrix.RowCount let levels = zeroCreate queue HostInterop vertexCount @@ -58,7 +57,7 @@ module BFS = fillSubVectorTo queue levels front (clContext.CreateClCell level) levels //Getting new frontier - spMVTo queue matrix front front + spMVTo queue matrix frontier frontier maskComplementedTo queue front levels front diff --git a/src/GraphBLAS-sharp.Backend/Common/ClArray.fs b/src/GraphBLAS-sharp.Backend/Common/ClArray.fs index 3cd69406..2470989c 100644 --- a/src/GraphBLAS-sharp.Backend/Common/ClArray.fs +++ b/src/GraphBLAS-sharp.Backend/Common/ClArray.fs @@ -1,12 +1,12 @@ -namespace GraphBLAS.FSharp.Backend.Common +namespace GraphBLAS.FSharp open Brahma.FSharp open Microsoft.FSharp.Quotations open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClCellExtensions module ClArray = /// diff --git a/src/GraphBLAS-sharp.Backend/Common/Common.fs b/src/GraphBLAS-sharp.Backend/Common/Common.fs index 2cc84c31..8576fe78 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Common.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Common.fs @@ -1,10 +1,18 @@ -namespace GraphBLAS.FSharp.Backend.Common +namespace GraphBLAS.FSharp open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common open Microsoft.FSharp.Quotations +open GraphBLAS.FSharp.Backend.Common module Common = + module Bitonic = + let sortKeyValuesInplace = Sort.Bitonic.sortKeyValuesInplace + + module Radix = + let runByKeysStandard = Sort.Radix.runByKeysStandard + + let standardRunKeysOnly = Sort.Radix.standardRunKeysOnly + module Gather = /// /// Fills the given output array using the given value array and a function. The function maps old position @@ -22,7 +30,8 @@ module Common = /// > val result = [| 2.8; 1.9; 3.7; 7.3; 5.5; 4.6; 6.4 |] /// /// - let runInit positionMap (clContext: ClContext) workGroupSize = Gather.runInit positionMap clContext workGroupSize + let runInit positionMap (clContext: ClContext) workGroupSize = + Gather.runInit positionMap clContext workGroupSize /// /// Fills the given output array using the given value and position arrays. Array of positions indicates @@ -61,7 +70,7 @@ module Common = /// > val result = [| 1,9; 3.7; 6.4; 7.3; 9.1 |] /// /// - let firstOccurence clContext = Scatter.firstOccurrence clContext + let firstOccurrence clContext = Scatter.firstOccurrence clContext /// /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array @@ -81,7 +90,7 @@ module Common = /// > val result = [| 2.8; 5.5; 6.4; 8.2; 9.1 |] /// /// - let lastOccurence clContext = Scatter.lastOccurrence clContext + let lastOccurrence clContext = Scatter.lastOccurrence clContext /// /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array @@ -102,7 +111,7 @@ module Common = /// /// /// Maps global id to a value - let initFirstOccurence valueMap = Scatter.initFirsOccurrence valueMap + let initFirstOccurrence valueMap = Scatter.initFirsOccurrence valueMap /// /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array @@ -130,9 +139,11 @@ module Common = let runIncludeInPlace plus = PrefixSum.runIncludeInPlace plus - let runBackwardsExcludeInPlace plus = PrefixSum.runBackwardsExcludeInPlace plus + let runBackwardsExcludeInPlace plus = + PrefixSum.runBackwardsExcludeInPlace plus - let runBackwardsIncludeInPlace plus = PrefixSum.runBackwardsIncludeInPlace plus + let runBackwardsIncludeInPlace plus = + PrefixSum.runBackwardsIncludeInPlace plus /// /// Exclude inplace prefix sum. @@ -223,7 +234,8 @@ module Common = /// Work group size. /// Summation operation. /// Neutral element for summation. - let sum op zero (clContext: ClContext) workGroupSize = Reduce.sum op zero clContext workGroupSize + let sum op zero (clContext: ClContext) workGroupSize = + Reduce.sum op zero clContext workGroupSize /// /// Reduces an array of values. @@ -231,7 +243,8 @@ module Common = /// ClContext. /// Work group size. /// Reduction operation. - let reduce op (clContext: ClContext) workGroupSize = Reduce.reduce op clContext workGroupSize + let reduce op (clContext: ClContext) workGroupSize = + Reduce.reduce op clContext workGroupSize /// /// Reduction of an array of values by an array of keys. @@ -287,32 +300,19 @@ module Common = let segmentSequential<'a> (reduceOp: Expr<'a -> 'a -> 'a option>) (clContext: ClContext) workGroupSize = Reduce.ByKey.Option.segmentSequential reduceOp clContext workGroupSize - module ByKey2D = - /// - /// Reduces an array of values by 2D keys using a single work item. - /// - /// ClContext. - /// Work group size. - /// Operation for reducing values. - /// - /// The length of the result must be calculated in advance. - /// - let sequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = - Reduce.ByKey2D.sequential reduceOp clContext workGroupSize - - /// - /// Reduces values by key. Each segment is reduced by one work item. - /// - /// ClContext. - /// Work group size. - /// Operation for reducing values. - /// - /// The length of the result must be calculated in advance. - /// - let segmentSequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = - Reduce.ByKey2D.segmentSequential reduceOp clContext workGroupSize + module ByKey2D = + /// + /// Reduces an array of values by 2D keys using a single work item. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// The length of the result must be calculated in advance. + /// + let sequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = + Reduce.ByKey2D.sequential reduceOp clContext workGroupSize - module Option = /// /// Reduces values by key. Each segment is reduced by one work item. /// @@ -322,5 +322,18 @@ module Common = /// /// The length of the result must be calculated in advance. /// - let segmentSequential (reduceOp: Expr<'a -> 'a -> 'a option>) (clContext: ClContext) workGroupSize = - Reduce.ByKey2D.Option.segmentSequential reduceOp clContext workGroupSize + let segmentSequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = + Reduce.ByKey2D.segmentSequential reduceOp clContext workGroupSize + + module Option = + /// + /// Reduces values by key. Each segment is reduced by one work item. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// The length of the result must be calculated in advance. + /// + let segmentSequential (reduceOp: Expr<'a -> 'a -> 'a option>) (clContext: ClContext) workGroupSize = + Reduce.ByKey2D.Option.segmentSequential reduceOp clContext workGroupSize diff --git a/src/GraphBLAS-sharp.Backend/Common/Merge.fs b/src/GraphBLAS-sharp.Backend/Common/Merge.fs deleted file mode 100644 index f647367e..00000000 --- a/src/GraphBLAS-sharp.Backend/Common/Merge.fs +++ /dev/null @@ -1,144 +0,0 @@ -namespace GraphBLAS.FSharp.Backend.Common - -open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions - -module Merge = - let run<'a, 'b when 'a: struct and 'b: struct and 'a: comparison> (clContext: ClContext) workGroupSize = - - let defaultValue = Unchecked.defaultof<'a> - - let merge = - <@ fun (ndRange: Range1D) (firstSide: int) (secondSide: int) (sumOfSides: int) (firstValues: ClArray<'a>) (secondValues: ClArray<'a>) (resultValues: ClArray<'a>) -> - - let gid = ndRange.GlobalID0 - let lid = ndRange.LocalID0 - - let mutable beginIdxLocal = local () - let mutable endIdxLocal = local () - - if lid < 2 then - // (n - 1) * wgSize - 1 for lid = 0 - // n * wgSize - 1 for lid = 1 - // where n in 1 .. wgGroupCount - let x = lid * (workGroupSize - 1) + gid - 1 - - let diagonalNumber = min (sumOfSides - 1) x - - let mutable leftEdge = max 0 (diagonalNumber + 1 - secondSide) - - let mutable rightEdge = min (firstSide - 1) diagonalNumber - - while leftEdge <= rightEdge do - let middleIdx = (leftEdge + rightEdge) / 2 - - let firstIndex = firstValues.[middleIdx] - - let secondIndex = - secondValues.[diagonalNumber - middleIdx] - - if firstIndex <= secondIndex then - leftEdge <- middleIdx + 1 - else - rightEdge <- middleIdx - 1 - - // Here localID equals either 0 or 1 - if lid = 0 then - beginIdxLocal <- leftEdge - else - endIdxLocal <- leftEdge - - barrierLocal () - - let beginIdx = beginIdxLocal - let endIdx = endIdxLocal - let firstLocalLength = endIdx - beginIdx - - let mutable x = workGroupSize - firstLocalLength - - if endIdx = firstSide then - x <- secondSide - gid + lid + beginIdx - - let secondLocalLength = x - - //First indices are from 0 to firstLocalLength - 1 inclusive - //Second indices are from firstLocalLength to firstLocalLength + secondLocalLength - 1 inclusive - let localIndices = localArray<'a> workGroupSize - - if lid < firstLocalLength then - localIndices.[lid] <- firstValues.[beginIdx + lid] - - if lid < secondLocalLength then - localIndices.[firstLocalLength + lid] <- secondValues.[gid - beginIdx] - - barrierLocal () - - if gid < sumOfSides then - let mutable leftEdge = lid + 1 - secondLocalLength - if leftEdge < 0 then leftEdge <- 0 - - let mutable rightEdge = firstLocalLength - 1 - - rightEdge <- min rightEdge lid - - while leftEdge <= rightEdge do - let middleIdx = (leftEdge + rightEdge) / 2 - let firstIndex = localIndices.[middleIdx] - - let secondIndex = - localIndices.[firstLocalLength + lid - middleIdx] - - if firstIndex <= secondIndex then - leftEdge <- middleIdx + 1 - else - rightEdge <- middleIdx - 1 - - let boundaryX = rightEdge - let boundaryY = lid - leftEdge - - // boundaryX and boundaryY can't be off the right edge of array (only off the left edge) - let isValidX = boundaryX >= 0 - let isValidY = boundaryY >= 0 - - let mutable fstIdx = defaultValue - - if isValidX then - fstIdx <- localIndices.[boundaryX] - - let mutable sndIdx = defaultValue - - if isValidY then - sndIdx <- localIndices.[firstLocalLength + boundaryY] - - if not isValidX || isValidY && fstIdx <= sndIdx then - resultValues.[gid] <- sndIdx - else - resultValues.[gid] <- fstIdx @> - - let kernel = clContext.Compile merge - - fun (processor: MailboxProcessor<_>) (firstValues: ClArray<'a>) (secondValues: ClArray<'a>) -> - - let firstSide = firstValues.Length - - let secondSide = secondValues.Length - - let sumOfSides = firstSide + secondSide - - let resultValues = - clContext.CreateClArrayWithSpecificAllocationMode<'a>(DeviceOnly, sumOfSides) - - let ndRange = - Range1D.CreateValid(sumOfSides, workGroupSize) - - let kernel = kernel.GetKernel() - - processor.Post( - Msg.MsgSetArguments - (fun () -> - kernel.KernelFunc ndRange firstSide secondSide sumOfSides firstValues secondValues resultValues) - ) - - processor.Post(Msg.CreateRunMsg<_, _>(kernel)) - - resultValues diff --git a/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs b/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs index de86653b..9d241e6b 100644 --- a/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs +++ b/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs @@ -3,8 +3,8 @@ namespace GraphBLAS.FSharp.Backend.Common open Brahma.FSharp open FSharp.Quotations open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClCellExtensions module internal PrefixSum = let private update (opAdd: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = diff --git a/src/GraphBLAS-sharp.Backend/Common/Sort/Radix.fs b/src/GraphBLAS-sharp.Backend/Common/Sort/Radix.fs index 1ff45868..03ad4ed0 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Sort/Radix.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Sort/Radix.fs @@ -2,18 +2,19 @@ namespace GraphBLAS.FSharp.Backend.Common.Sort open Brahma.FSharp +open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClCellExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions module internal Radix = // the number of bits considered per iteration - let defaultBitCount = 4 + let private defaultBitCount = 4 - let keyBitCount = 32 + let private keyBitCount = 32 - let localPrefixSum = + let private localPrefixSum = <@ fun (lid: int) (workGroupSize: int) (array: int []) -> let mutable offset = 1 @@ -29,7 +30,7 @@ module internal Radix = barrierLocal () array.[lid] <- value @> - let count (clContext: ClContext) workGroupSize mask = + let private count (clContext: ClContext) workGroupSize mask = let bitCount = mask + 1 @@ -108,7 +109,7 @@ module internal Radix = globalOffsets, localOffsets - let scatter (clContext: ClContext) workGroupSize mask = + let private scatter (clContext: ClContext) workGroupSize mask = let kernel = <@ fun (ndRange: Range1D) length (keys: ClArray) (shift: ClCell) (workGroupCount: ClCell) (globalOffsets: ClArray) (localOffsets: ClArray) (result: ClArray) -> @@ -147,7 +148,7 @@ module internal Radix = processor.Post(Msg.CreateRunMsg<_, _>(kernel)) - let runKeysOnly (clContext: ClContext) workGroupSize bitCount = + let private runKeysOnly (clContext: ClContext) workGroupSize bitCount = let copy = ClArray.copy clContext workGroupSize let mask = (pown 2 bitCount) - 1 @@ -198,7 +199,7 @@ module internal Radix = let standardRunKeysOnly clContext workGroupSize = runKeysOnly clContext workGroupSize defaultBitCount - let scatterByKey (clContext: ClContext) workGroupSize mask = + let private scatterByKey (clContext: ClContext) workGroupSize mask = let kernel = <@ fun (ndRange: Range1D) length (keys: ClArray) (values: ClArray<'a>) (shift: ClCell) (workGroupCount: ClCell) (globalOffsets: ClArray) (localOffsets: ClArray) (resultKeys: ClArray) (resultValues: ClArray<'a>) -> @@ -248,7 +249,7 @@ module internal Radix = processor.Post(Msg.CreateRunMsg<_, _>(kernel)) - let runByKeys (clContext: ClContext) workGroupSize bitCount = + let private runByKeys (clContext: ClContext) workGroupSize bitCount = let copy = ClArray.copy clContext workGroupSize let dataCopy = ClArray.copy clContext workGroupSize diff --git a/src/GraphBLAS-sharp.Backend/Common/Sum.fs b/src/GraphBLAS-sharp.Backend/Common/Sum.fs index 72c52bfc..7df6beee 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Sum.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Sum.fs @@ -1,12 +1,12 @@ namespace GraphBLAS.FSharp.Backend.Common open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Quotes open Microsoft.FSharp.Control open Microsoft.FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions +open GraphBLAS.FSharp.Backend.Quotes +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClCellExtensions module internal Reduce = /// diff --git a/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj b/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj index 4c6b2646..3ffc0137 100644 --- a/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj +++ b/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj @@ -34,7 +34,6 @@ - @@ -46,7 +45,7 @@ - + @@ -55,24 +54,18 @@ - - - - - + + + + + + + + - - - - - - - - - - + diff --git a/src/GraphBLAS-sharp.Backend/Matrix/COO/Map.fs b/src/GraphBLAS-sharp.Backend/Matrix/COO/Map.fs index 52989dee..0d1ed5aa 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/COO/Map.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/COO/Map.fs @@ -5,10 +5,10 @@ open Brahma.FSharp open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Backend.Quotes open Microsoft.FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects +open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend -open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClMatrix +open GraphBLAS.FSharp.Objects.ClContextExtensions module internal Map = let preparePositions<'a, 'b> opAdd (clContext: ClContext) workGroupSize = diff --git a/src/GraphBLAS-sharp.Backend/Matrix/COO/Map2.fs b/src/GraphBLAS-sharp.Backend/Matrix/COO/Map2.fs index f757bac9..8e5134bf 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/COO/Map2.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/COO/Map2.fs @@ -1,13 +1,13 @@ namespace GraphBLAS.FSharp.Backend.Matrix.COO open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Matrix open Microsoft.FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClMatrix +open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Backend.Matrix module internal Map2 = diff --git a/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs b/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs index e4469abe..38c70060 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs @@ -1,14 +1,14 @@ namespace GraphBLAS.FSharp.Backend.Matrix.COO open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Backend.Quotes open Microsoft.FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClMatrix +open GraphBLAS.FSharp.Objects.ClCellExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions module Matrix = let map = Map.run @@ -125,7 +125,7 @@ module Matrix = let transposeInPlace (clContext: ClContext) workGroupSize = let sort = - Sort.Bitonic.sortKeyValuesInplace clContext workGroupSize + Bitonic.sortKeyValuesInplace clContext workGroupSize fun (queue: MailboxProcessor<_>) (matrix: ClMatrix.COO<'a>) -> sort queue matrix.Columns matrix.Rows matrix.Values diff --git a/src/GraphBLAS-sharp.Backend/Matrix/COO/Merge.fs b/src/GraphBLAS-sharp.Backend/Matrix/COO/Merge.fs index 2d75b161..5e847976 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/COO/Merge.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/COO/Merge.fs @@ -1,8 +1,8 @@ namespace GraphBLAS.FSharp.Backend.Matrix.COO open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects module Merge = let run<'a, 'b when 'a: struct and 'b: struct> (clContext: ClContext) workGroupSize = diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Kronecker.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Kronecker.fs deleted file mode 100644 index ca0b8f81..00000000 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Kronecker.fs +++ /dev/null @@ -1,457 +0,0 @@ -namespace GraphBLAS.FSharp.Backend.Matrix.CSR - -open FSharpx.Collections -open Microsoft.FSharp.Quotations -open FSharp.Quotations.Evaluator.QuotationEvaluationExtensions -open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Matrix.COO -open GraphBLAS.FSharp.Backend.Matrix.CSR -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions -open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions - -module internal Kronecker = - let private updateBitmap (clContext: ClContext) workGroupSize op = - - let updateBitmap (op: Expr<'a option -> 'b option -> 'c option>) = - <@ fun (ndRange: Range1D) (operand: ClCell<'a>) valuesLength zeroCount (values: ClArray<'b>) (resultBitmap: ClArray) -> - - let gid = ndRange.GlobalID0 - - if gid = 0 then - - let item = resultBitmap.[0] - let newItem = item + zeroCount - - match (%op) (Some operand.Value) None with - | Some _ -> resultBitmap.[0] <- newItem - | _ -> () - - elif (gid - 1) < valuesLength then - - let item = resultBitmap.[gid] - let newItem = item + 1 - - match (%op) (Some operand.Value) (Some values.[gid - 1]) with - | Some _ -> resultBitmap.[gid] <- newItem - | _ -> () @> - - let updateBitmap = clContext.Compile <| updateBitmap op - - fun (processor: MailboxProcessor<_>) (operand: ClCell<'a>) (matrixRight: CSR<'b>) (bitmap: ClArray) -> - - let resultLength = matrixRight.NNZ + 1 - - let ndRange = - Range1D.CreateValid(resultLength, workGroupSize) - - let updateBitmap = updateBitmap.GetKernel() - - let numberOfZeros = - matrixRight.ColumnCount * matrixRight.RowCount - - matrixRight.NNZ - - processor.Post( - Msg.MsgSetArguments - (fun () -> - updateBitmap.KernelFunc ndRange operand matrixRight.NNZ numberOfZeros matrixRight.Values bitmap) - ) - - processor.Post(Msg.CreateRunMsg<_, _> updateBitmap) - - let private getAllocationSize (clContext: ClContext) workGroupSize op = - - let updateBitmap = updateBitmap clContext workGroupSize op - - let sum = - Reduce.sum <@ fun x y -> x + y @> 0 clContext workGroupSize - - let item = ClArray.item clContext workGroupSize - - let createClArray = - ClArray.zeroCreate clContext workGroupSize - - let opOnHost = op.Evaluate() - - fun (queue: MailboxProcessor<_>) (matrixZero: COO<'c> option) (matrixLeft: CSR<'a>) (matrixRight: CSR<'b>) -> - - let nnz = - match opOnHost None None with - | Some _ -> - let leftZeroCount = - matrixLeft.RowCount * matrixLeft.ColumnCount - - matrixLeft.NNZ - - let rightZeroCount = - matrixRight.RowCount * matrixRight.ColumnCount - - matrixRight.NNZ - - leftZeroCount * rightZeroCount - | _ -> 0 - - let bitmap = - createClArray queue DeviceOnly (matrixRight.NNZ + 1) - - for index in 0 .. matrixLeft.NNZ - 1 do - let value = item queue index matrixLeft.Values - - updateBitmap queue value matrixRight bitmap - - value.Free queue - - let bitmapSum = sum queue bitmap - - bitmap.Free queue - - let leftZeroCount = - matrixLeft.ColumnCount * matrixLeft.RowCount - - matrixLeft.NNZ - - match matrixZero with - | Some m -> m.NNZ * leftZeroCount - | _ -> 0 - + nnz - + bitmapSum.ToHostAndFree queue - - let private preparePositions<'a, 'b, 'c when 'b: struct> (clContext: ClContext) workGroupSize op = - - let preparePositions (op: Expr<'a option -> 'b option -> 'c option>) = - <@ fun (ndRange: Range1D) (operand: ClCell<'a>) rowCount columnCount (values: ClArray<'b>) (rowPointers: ClArray) (columns: ClArray) (resultBitmap: ClArray) (resultValues: ClArray<'c>) -> - - let gid = ndRange.GlobalID0 - - if gid < rowCount * columnCount then - - let columnIndex = gid % columnCount - let rowIndex = gid / columnCount - - let firstIndex = rowPointers.[rowIndex] - let lastIndex = rowPointers.[rowIndex + 1] - 1 - - let value = - (%Search.Bin.inRange) firstIndex lastIndex columnIndex columns values - - match (%op) (Some operand.Value) value with - | Some resultValue -> - resultValues.[gid] <- resultValue - resultBitmap.[gid] <- 1 - | None -> resultBitmap.[gid] <- 0 @> - - let kernel = clContext.Compile <| preparePositions op - - fun (processor: MailboxProcessor<_>) (operand: ClCell<'a>) (matrix: CSR<'b>) (resultDenseMatrix: ClArray<'c>) (resultBitmap: ClArray) -> - - let resultLength = matrix.RowCount * matrix.ColumnCount - - let ndRange = - Range1D.CreateValid(resultLength, workGroupSize) - - let kernel = kernel.GetKernel() - - processor.Post( - Msg.MsgSetArguments - (fun () -> - kernel.KernelFunc - ndRange - operand - matrix.RowCount - matrix.ColumnCount - matrix.Values - matrix.RowPointers - matrix.Columns - resultBitmap - resultDenseMatrix) - ) - - processor.Post(Msg.CreateRunMsg<_, _> kernel) - - let private setPositions<'c when 'c: struct> (clContext: ClContext) workGroupSize = - - let setPositions = - <@ fun (ndRange: Range1D) rowCount columnCount startIndex (rowOffset: ClCell) (columnOffset: ClCell) (bitmap: ClArray) (values: ClArray<'c>) (resultRows: ClArray) (resultColumns: ClArray) (resultValues: ClArray<'c>) -> - - let gid = ndRange.GlobalID0 - - if gid < rowCount * columnCount - && (gid = 0 && bitmap.[gid] = 1 - || gid > 0 && bitmap.[gid - 1] < bitmap.[gid]) then - - let columnIndex = gid % columnCount - let rowIndex = gid / columnCount - - let index = startIndex + bitmap.[gid] - 1 - - resultRows.[index] <- rowIndex + rowOffset.Value - resultColumns.[index] <- columnIndex + columnOffset.Value - resultValues.[index] <- values.[gid] @> - - let kernel = clContext.Compile <| setPositions - - let scan = - PrefixSum.standardIncludeInPlace clContext workGroupSize - - fun (processor: MailboxProcessor<_>) rowCount columnCount (rowOffset: int) (columnOffset: int) (startIndex: int) (resultMatrix: COO<'c>) (values: ClArray<'c>) (bitmap: ClArray) -> - - let sum = scan processor bitmap - - let ndRange = - Range1D.CreateValid(rowCount * columnCount, workGroupSize) - - let kernel = kernel.GetKernel() - - let rowOffset = rowOffset |> clContext.CreateClCell - let columnOffset = columnOffset |> clContext.CreateClCell - - processor.Post( - Msg.MsgSetArguments - (fun () -> - kernel.KernelFunc - ndRange - rowCount - columnCount - startIndex - rowOffset - columnOffset - bitmap - values - resultMatrix.Rows - resultMatrix.Columns - resultMatrix.Values) - ) - - processor.Post(Msg.CreateRunMsg<_, _> kernel) - - (sum.ToHostAndFree processor) + startIndex - - let private copyToResult (clContext: ClContext) workGroupSize = - - let copyToResult = - <@ fun (ndRange: Range1D) startIndex sourceLength (rowOffset: ClCell) (columnOffset: ClCell) (sourceRows: ClArray) (sourceColumns: ClArray) (sourceValues: ClArray<'c>) (resultRows: ClArray) (resultColumns: ClArray) (resultValues: ClArray<'c>) -> - - let gid = ndRange.GlobalID0 - - if gid < sourceLength then - let index = startIndex + gid - - resultRows.[index] <- rowOffset.Value + sourceRows.[gid] - resultColumns.[index] <- columnOffset.Value + sourceColumns.[gid] - resultValues.[index] <- sourceValues.[gid] @> - - let kernel = clContext.Compile <| copyToResult - - fun (processor: MailboxProcessor<_>) startIndex (rowOffset: int) (columnOffset: int) (resultMatrix: COO<'c>) (sourceMatrix: COO<'c>) -> - - let ndRange = - Range1D.CreateValid(sourceMatrix.NNZ, workGroupSize) - - let kernel = kernel.GetKernel() - - let rowOffset = rowOffset |> clContext.CreateClCell - let columnOffset = columnOffset |> clContext.CreateClCell - - processor.Post( - Msg.MsgSetArguments - (fun () -> - kernel.KernelFunc - ndRange - startIndex - sourceMatrix.NNZ - rowOffset - columnOffset - sourceMatrix.Rows - sourceMatrix.Columns - sourceMatrix.Values - resultMatrix.Rows - resultMatrix.Columns - resultMatrix.Values) - ) - - processor.Post(Msg.CreateRunMsg<_, _> kernel) - - let private insertZero (clContext: ClContext) workGroupSize = - - let copy = copyToResult clContext workGroupSize - - fun queue startIndex (zeroCounts: int list array) (matrixZero: COO<'c>) resultMatrix -> - - let rowCount = zeroCounts.Length - - let mutable startIndex = startIndex - - let insertMany row firstColumn count = - for i in 0 .. count - 1 do - let rowOffset = row * matrixZero.RowCount - - let columnOffset = - (firstColumn + i) * matrixZero.ColumnCount - - copy queue startIndex rowOffset columnOffset resultMatrix matrixZero - - startIndex <- startIndex + matrixZero.NNZ - - let rec insertInRowRec zeroCounts row column = - match zeroCounts with - | [] -> () - | h :: tl -> - insertMany row column h - - insertInRowRec tl row (h + column + 1) - - for row in 0 .. rowCount - 1 do - insertInRowRec zeroCounts.[row] row 0 - - let private insertNonZero (clContext: ClContext) workGroupSize op = - - let item = ClArray.item clContext workGroupSize - - let preparePositions = - preparePositions clContext workGroupSize op - - let setPositions = setPositions clContext workGroupSize - - fun queue (rowsEdges: (int * int) array) (matrixRight: CSR<'b>) (leftValues: ClArray<'a>) (leftColsHost: int array) (resultMatrix: COO<'c>) -> - - let setPositions = - setPositions queue matrixRight.RowCount matrixRight.ColumnCount - - let rowCount = rowsEdges.Length - - let length = - matrixRight.RowCount * matrixRight.ColumnCount - - let bitmap = - clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, length) - - let mappedMatrix = - clContext.CreateClArrayWithSpecificAllocationMode<'c>(DeviceOnly, length) - - let mutable startIndex = 0 - - for row in 0 .. rowCount - 1 do - let leftEdge, rightEdge = rowsEdges.[row] - - for i in leftEdge .. rightEdge do - let value = item queue i leftValues - let column = leftColsHost.[i] - - let rowOffset = row * matrixRight.RowCount - let columnOffset = column * matrixRight.ColumnCount - - preparePositions queue value matrixRight mappedMatrix bitmap - - value.Free queue - - startIndex <- setPositions rowOffset columnOffset startIndex resultMatrix mappedMatrix bitmap - - bitmap.Free queue - mappedMatrix.Free queue - - startIndex - - let private mapAll<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality> - (clContext: ClContext) - workGroupSize - (op: Expr<'a option -> 'b option -> 'c option>) - = - - let insertNonZero = insertNonZero clContext workGroupSize op - - let insertZero = insertZero clContext workGroupSize - - fun (queue: MailboxProcessor<_>) allocationMode (resultNNZ: int) (matrixZero: COO<'c> option) (matrixLeft: CSR<'a>) (matrixRight: CSR<'b>) -> - - let resultRows = - clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, resultNNZ) - - let resultColumns = - clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, resultNNZ) - - let resultValues = - clContext.CreateClArrayWithSpecificAllocationMode<'c>(allocationMode, resultNNZ) - - let resultMatrix = - { Context = clContext - Rows = resultRows - Columns = resultColumns - Values = resultValues - RowCount = matrixLeft.RowCount * matrixRight.RowCount - ColumnCount = matrixLeft.ColumnCount * matrixRight.ColumnCount } - - let leftRowPointers = matrixLeft.RowPointers.ToHost queue - let leftColumns = matrixLeft.Columns.ToHost queue - - let nnzInRows = - leftRowPointers - |> Array.pairwise - |> Array.map (fun (fst, snd) -> snd - fst) - - let rowsEdges = - leftRowPointers - |> Array.pairwise - |> Array.map (fun (fst, snd) -> (fst, snd - 1)) - - let (zeroCounts: int list array) = Array.zeroCreate matrixLeft.RowCount - - { 0 .. matrixLeft.RowCount - 1 } - |> Seq.iter2 - (fun edges i -> - zeroCounts.[i] <- - leftColumns.[fst edges..snd edges] - |> Array.toList - |> List.insertAt 0 -1 - |> List.insertAt (nnzInRows.[i] + 1) matrixLeft.ColumnCount - |> List.pairwise - |> List.map (fun (fstCol, sndCol) -> sndCol - fstCol - 1)) - rowsEdges - - let startIndex = - insertNonZero queue rowsEdges matrixRight matrixLeft.Values leftColumns resultMatrix - - matrixZero - |> Option.iter (fun m -> insertZero queue startIndex zeroCounts m resultMatrix) - - resultMatrix - - let run<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality> - (clContext: ClContext) - workGroupSize - (op: Expr<'a option -> 'b option -> 'c option>) - = - - let getSize = - getAllocationSize clContext workGroupSize op - - let mapWithValue = - Map.WithValue.run clContext op workGroupSize - - let mapAll = mapAll clContext workGroupSize op - - let bitonic = - Sort.Bitonic.sortKeyValuesInplace clContext workGroupSize - - fun (queue: MailboxProcessor<_>) allocationMode (matrixLeft: CSR<'a>) (matrixRight: CSR<'b>) -> - - let matrixZero = - mapWithValue queue allocationMode None matrixRight - - let size = - getSize queue matrixZero matrixLeft matrixRight - - if size = 0 then - matrixZero - |> Option.iter (fun m -> m.Dispose queue) - - None - else - let result = - mapAll queue allocationMode size matrixZero matrixLeft matrixRight - - matrixZero - |> Option.iter (fun m -> m.Dispose queue) - - bitonic queue result.Rows result.Columns result.Values - - result |> Some diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map.fs index c61bcdde..a89989db 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map.fs @@ -5,11 +5,11 @@ open FSharp.Quotations open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions -open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClCellExtensions +open GraphBLAS.FSharp.Objects.ClMatrix +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions module internal Map = let preparePositions<'a, 'b> op (clContext: ClContext) workGroupSize = diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs index ba06e8d5..5737477f 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs @@ -5,10 +5,9 @@ open Microsoft.FSharp.Quotations open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Matrix.COO +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClMatrix +open GraphBLAS.FSharp.Objects.ClContextExtensions module internal Map2 = let preparePositions<'a, 'b, 'c> opAdd (clContext: ClContext) workGroupSize = diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs index 1e4b6b3d..30fc2ddc 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs @@ -1,15 +1,15 @@ namespace GraphBLAS.FSharp.Backend.Matrix.CSR open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Backend.Quotes open Microsoft.FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ClVector -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClMatrix +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClVector +open GraphBLAS.FSharp.Objects.ArraysExtensions module Matrix = @@ -334,5 +334,3 @@ module Matrix = pointerPairs.Free processor rowsLength - - let kronecker = Kronecker.run diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Merge.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Merge.fs index d8cb366e..8376053e 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Merge.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Merge.fs @@ -2,9 +2,8 @@ namespace GraphBLAS.FSharp.Backend.Matrix.CSR open Brahma.FSharp open System -open GraphBLAS.FSharp.Backend.Objects - -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClContextExtensions module Merge = let run<'a, 'b when 'a: struct and 'b: struct> (clContext: ClContext) workGroupSize = diff --git a/src/GraphBLAS-sharp.Backend/Matrix/Common.fs b/src/GraphBLAS-sharp.Backend/Matrix/Common.fs index b6641b3a..604e1d72 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/Common.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/Common.fs @@ -1,9 +1,9 @@ namespace GraphBLAS.FSharp.Backend.Matrix open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions +open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClCellExtensions module internal Common = ///. diff --git a/src/GraphBLAS-sharp.Backend/Matrix/LIL/Matrix.fs b/src/GraphBLAS-sharp.Backend/Matrix/LIL/Matrix.fs index aa7dfe42..838fdead 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/LIL/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/LIL/Matrix.fs @@ -1,9 +1,9 @@ namespace GraphBLAS.FSharp.Backend.Matrix.LIL open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ClMatrix +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Objects.ClMatrix +open GraphBLAS.FSharp.Objects.ClContextExtensions module Matrix = let toCSR (clContext: ClContext) workGroupSize = diff --git a/src/GraphBLAS-sharp.Backend/Matrix/Primitives.fs b/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs similarity index 98% rename from src/GraphBLAS-sharp.Backend/Matrix/Primitives.fs rename to src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs index 2c0858a0..2d479f87 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/Primitives.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs @@ -1,14 +1,14 @@ -namespace GraphBLAS.FSharp.Backend.Matrix +namespace GraphBLAS.FSharp open Brahma.FSharp open Microsoft.FSharp.Quotations -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClMatrix open GraphBLAS.FSharp.Backend.Vector +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClMatrix -module Primitives = +module Matrix = /// /// Creates new matrix with the values from the given one. /// New matrix represented in the format of the given one. diff --git a/src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Expand.fs b/src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Expand.fs deleted file mode 100644 index 4ec663b2..00000000 --- a/src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Expand.fs +++ /dev/null @@ -1,494 +0,0 @@ -namespace GraphBLAS.FSharp.Backend.Matrix.SpGeMM - -open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Common.Sort -open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions -open FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects.ClMatrix - -module Expand = - let getSegmentPointers (clContext: ClContext) workGroupSize = - - let gather = Gather.run clContext workGroupSize - - let prefixSum = - PrefixSum.standardExcludeInPlace clContext workGroupSize - - fun (processor: MailboxProcessor<_>) (leftMatrixColumns: ClArray) (rightMatrixRowsLengths: ClArray) -> - - let segmentsLengths = - clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, leftMatrixColumns.Length) - - // extract needed lengths by left matrix nnz - gather processor leftMatrixColumns rightMatrixRowsLengths segmentsLengths - - // compute pointers - let length = - (prefixSum processor segmentsLengths) - .ToHostAndFree processor - - length, segmentsLengths - - let multiply (predicate: Expr<'a -> 'b -> 'c option>) (clContext: ClContext) workGroupSize = - let getBitmap = - ClArray.map2<'a, 'b, int> (Map.choose2Bitmap predicate) clContext workGroupSize - - let prefixSum = - PrefixSum.standardExcludeInPlace clContext workGroupSize - - let assignValues = - ClArray.assignOption2 predicate clContext workGroupSize - - let scatter = - Scatter.lastOccurrence clContext workGroupSize - - fun (processor: MailboxProcessor<_>) (firstValues: ClArray<'a>) (secondValues: ClArray<'b>) (columns: ClArray) (rows: ClArray) -> - - let positions = - getBitmap processor DeviceOnly firstValues secondValues - - let resultLength = - (prefixSum processor positions) - .ToHostAndFree(processor) - - if resultLength = 0 then - positions.Free processor - - None - else - let resultColumns = - clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, resultLength) - - scatter processor positions columns resultColumns - - let resultRows = - clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, resultLength) - - scatter processor positions rows resultRows - - let resultValues = - clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, resultLength) - - assignValues processor firstValues secondValues positions resultValues - - positions.Free processor - - Some(resultValues, resultColumns, resultRows) - - let expand (clContext: ClContext) workGroupSize = - - let idScatter = - Scatter.initLastOccurrence Map.id clContext workGroupSize - - let scatter = - Scatter.lastOccurrence clContext workGroupSize - - let zeroCreate = - ClArray.zeroCreate clContext workGroupSize - - let maxPrefixSum = - PrefixSum.runIncludeInPlace <@ max @> clContext workGroupSize - - let create = ClArray.create clContext workGroupSize - - let gather = Gather.run clContext workGroupSize - - let segmentPrefixSum = - PrefixSum.ByKey.sequentialInclude <@ (+) @> 0 clContext workGroupSize - - let removeDuplicates = - ClArray.removeDuplications clContext workGroupSize - - let leftMatrixGather = Gather.run clContext workGroupSize - - let rightMatrixGather = Gather.run clContext workGroupSize - - fun (processor: MailboxProcessor<_>) (lengths: int) (segmentsPointers: ClArray) (leftMatrix: ClMatrix.COO<'a>) (rightMatrix: ClMatrix.CSR<'b>) -> - // Compute left matrix positions - let leftMatrixPositions = zeroCreate processor DeviceOnly lengths - - idScatter processor segmentsPointers leftMatrixPositions - - (maxPrefixSum processor leftMatrixPositions 0) - .Free processor - - // Compute right matrix positions - let rightMatrixPositions = create processor DeviceOnly lengths 1 - - let requiredRightMatrixPointers = - zeroCreate processor DeviceOnly leftMatrix.Columns.Length - - gather processor leftMatrix.Columns rightMatrix.RowPointers requiredRightMatrixPointers - - scatter processor segmentsPointers requiredRightMatrixPointers rightMatrixPositions - - requiredRightMatrixPointers.Free processor - - // another way to get offsets ??? - let offsets = - removeDuplicates processor segmentsPointers - - segmentPrefixSum processor offsets.Length rightMatrixPositions leftMatrixPositions offsets - - offsets.Free processor - - // compute columns - let columns = - clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, lengths) - - gather processor rightMatrixPositions rightMatrix.Columns columns - - let rows = - clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, lengths) - - gather processor leftMatrixPositions leftMatrix.Rows rows - - // compute left matrix values - let leftMatrixValues = - clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, lengths) - - leftMatrixGather processor leftMatrixPositions leftMatrix.Values leftMatrixValues - - leftMatrixPositions.Free processor - - // compute right matrix values - let rightMatrixValues = - clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, lengths) - - rightMatrixGather processor rightMatrixPositions rightMatrix.Values rightMatrixValues - - rightMatrixPositions.Free processor - - // left, right matrix values, columns and rows indices - leftMatrixValues, rightMatrixValues, columns, rows - - let sortByColumnsAndRows (clContext: ClContext) workGroupSize = - - let sortByKeyIndices = - Radix.runByKeysStandard clContext workGroupSize - - let sortByKeyValues = - Radix.runByKeysStandard clContext workGroupSize - - let sortKeys = - Radix.standardRunKeysOnly clContext workGroupSize - - fun (processor: MailboxProcessor<_>) (values: ClArray<'a>) (columns: ClArray) (rows: ClArray) -> - // sort by columns - let valuesSortedByColumns = - sortByKeyValues processor DeviceOnly columns values - - let rowsSortedByColumns = - sortByKeyIndices processor DeviceOnly columns rows - - let sortedColumns = sortKeys processor columns - - // sort by rows - let valuesSortedByRows = - sortByKeyValues processor DeviceOnly rowsSortedByColumns valuesSortedByColumns - - let columnsSortedByRows = - sortByKeyIndices processor DeviceOnly rowsSortedByColumns sortedColumns - - let sortedRows = sortKeys processor rowsSortedByColumns - - valuesSortedByColumns.Free processor - rowsSortedByColumns.Free processor - sortedColumns.Free processor - - valuesSortedByRows, columnsSortedByRows, sortedRows - - let reduce opAdd (clContext: ClContext) workGroupSize = - - let reduce = - Reduce.ByKey2D.Option.segmentSequential opAdd clContext workGroupSize - - let getUniqueBitmap = - ClArray.Bitmap.lastOccurrence2 clContext workGroupSize - - let prefixSum = - PrefixSum.standardExcludeInPlace clContext workGroupSize - - let idScatter = - Scatter.initFirsOccurrence Map.id clContext workGroupSize - - fun (processor: MailboxProcessor<_>) allocationMode (values: ClArray<'a>) (columns: ClArray) (rows: ClArray) -> - - let bitmap = - getUniqueBitmap processor DeviceOnly columns rows - - let uniqueKeysCount = - (prefixSum processor bitmap) - .ToHostAndFree processor - - let offsets = - clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, uniqueKeysCount) - - idScatter processor bitmap offsets - - bitmap.Free processor - - let reduceResult = - reduce processor allocationMode uniqueKeysCount offsets columns rows values - - offsets.Free processor - - // reducedValues, reducedColumns, reducedRows option - reduceResult - - let runCOO opAdd opMul (clContext: ClContext) workGroupSize = - - let getSegmentPointers = - getSegmentPointers clContext workGroupSize - - let expand = expand clContext workGroupSize - - let multiply = multiply opMul clContext workGroupSize - - let sort = - sortByColumnsAndRows clContext workGroupSize - - let reduce = reduce opAdd clContext workGroupSize - - fun (processor: MailboxProcessor<_>) allocationMode (rightMatrixRowsNNZ: ClArray) (rightMatrix: ClMatrix.CSR<'b>) (leftMatrix: ClMatrix.COO<'a>) -> - - let length, segmentPointers = - getSegmentPointers processor leftMatrix.Columns rightMatrixRowsNNZ - - if length = 0 then - segmentPointers.Free processor - - length, None - else - // expand - let leftMatrixValues, rightMatrixValues, columns, rows = - expand processor length segmentPointers leftMatrix rightMatrix - - segmentPointers.Free processor - - // multiply - let mulResult = - multiply processor leftMatrixValues rightMatrixValues columns rows - - leftMatrixValues.Free processor - rightMatrixValues.Free processor - columns.Free processor - rows.Free processor - - let result = - mulResult - |> Option.bind - (fun (resultValues, resultColumns, resultRows) -> - // sort - let sortedValues, sortedColumns, sortedRows = - sort processor resultValues resultColumns resultRows - - resultValues.Free processor - resultColumns.Free processor - resultRows.Free processor - - // addition - let reduceResult = - reduce processor allocationMode sortedValues sortedColumns sortedRows - - sortedValues.Free processor - sortedColumns.Free processor - sortedRows.Free processor - - reduceResult) - - length, result - - let runOneStep opAdd opMul (clContext: ClContext) workGroupSize = - - let runCOO = - runCOO opAdd opMul clContext workGroupSize - - let expandRowPointers = - CSR.Matrix.expandRowPointers clContext workGroupSize - - fun (processor: MailboxProcessor<_>) allocationMode (leftMatrix: ClMatrix.CSR<'a>) rightMatrixRowsNNZ (rightMatrix: ClMatrix.CSR<'b>) -> - - let rows = - expandRowPointers processor DeviceOnly leftMatrix - - let leftMatrixCOO = - { Context = clContext - RowCount = leftMatrix.RowCount - ColumnCount = leftMatrix.ColumnCount - Rows = rows - Columns = leftMatrix.Columns - Values = leftMatrix.Values } - - let _, result = - runCOO processor allocationMode rightMatrixRowsNNZ rightMatrix leftMatrixCOO - - rows.Free processor - - result - |> Option.map - (fun (values, columns, rows) -> - { Context = clContext - RowCount = leftMatrix.RowCount - ColumnCount = rightMatrix.ColumnCount - Rows = rows - Columns = columns - Values = values }) - - let runManySteps opAdd opMul (clContext: ClContext) workGroupSize = - - let gather = Gather.run clContext workGroupSize - - let upperBound = - ClArray.upperBound clContext workGroupSize - - let set = ClArray.set clContext workGroupSize - - let subMatrix = - CSR.Matrix.subRows clContext workGroupSize - - let runCOO = - runCOO opAdd opMul clContext workGroupSize - - fun (processor: MailboxProcessor<_>) allocationMode maxAllocSize generalLength (leftMatrix: ClMatrix.CSR<'a>) segmentLengths rightMatrixRowsNNZ (rightMatrix: ClMatrix.CSR<'b>) -> - // extract segment lengths by left matrix rows pointers - let segmentPointersByLeftMatrixRows = - clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, leftMatrix.RowPointers.Length) - - gather processor leftMatrix.RowPointers segmentLengths segmentPointersByLeftMatrixRows - - // set last element to one step length - set processor segmentPointersByLeftMatrixRows (leftMatrix.RowPointers.Length - 1) generalLength - - // curring - let upperBound = - upperBound processor segmentPointersByLeftMatrixRows - - let subMatrix = subMatrix processor DeviceOnly - - let runCOO = - runCOO processor allocationMode rightMatrixRowsNNZ rightMatrix - - let rec helper beginRow workOffset previousResult = - if beginRow < leftMatrix.RowCount then - let currentBound = - clContext.CreateClCell(workOffset + maxAllocSize: int) - - // find largest row that fit into maxAllocSize - let upperBound = - (upperBound currentBound).ToHostAndFree processor - - let endRow = upperBound - 2 - - currentBound.Free processor - - // TODO(handle largest rows) - // (we can split row, multiply and merge them but merge path needed) - if endRow = beginRow then - failwith "It is impossible to multiply such a long row" - - // extract matrix TODO(Transfer overhead) - let subMatrix = - subMatrix beginRow (endRow - beginRow) leftMatrix - - // compute sub result - let length, result = runCOO subMatrix - // increase workOffset according to previous expand - let workOffset = workOffset + length - - match result with - | Some result -> - helper endRow workOffset - <| result :: previousResult - | None -> helper endRow workOffset previousResult - else - previousResult - - let result = helper 0 0 [] |> List.rev - - segmentPointersByLeftMatrixRows.Free processor - - result - - let run opAdd opMul (clContext: ClContext) workGroupSize = - - let getNNZInRows = - CSR.Matrix.NNZInRows clContext workGroupSize - - let getSegmentPointers = - getSegmentPointers clContext workGroupSize - - let runOneStep = - runOneStep opAdd opMul clContext workGroupSize - - let concat = ClArray.concat clContext workGroupSize - - let concatData = ClArray.concat clContext workGroupSize - - let runManySteps = - runManySteps opAdd opMul clContext workGroupSize - - fun (processor: MailboxProcessor<_>) allocationMode maxAllocSize (leftMatrix: ClMatrix.CSR<'a>) (rightMatrix: ClMatrix.CSR<'b>) -> - - let rightMatrixRowsNNZ = - getNNZInRows processor DeviceOnly rightMatrix - - let generalLength, segmentLengths = - getSegmentPointers processor leftMatrix.Columns rightMatrixRowsNNZ - - if generalLength < maxAllocSize then - segmentLengths.Free processor - - runOneStep processor allocationMode leftMatrix rightMatrixRowsNNZ rightMatrix - else - let result = - runManySteps - processor - allocationMode - maxAllocSize - generalLength - leftMatrix - segmentLengths - rightMatrixRowsNNZ - rightMatrix - - rightMatrixRowsNNZ.Free processor - segmentLengths.Free processor - - match result with - | _ :: _ -> - let valuesList, columnsList, rowsList = result |> List.unzip3 - - let values = - concatData processor allocationMode valuesList - - let columns = - concat processor allocationMode columnsList - - let rows = concat processor allocationMode rowsList - - // TODO(overhead: compute result length 3 time) - // release resources - valuesList - |> List.iter (fun array -> array.Free processor) - - columnsList - |> List.iter (fun array -> array.Free processor) - - rowsList - |> List.iter (fun array -> array.Free processor) - - { Context = clContext - RowCount = leftMatrix.RowCount - ColumnCount = rightMatrix.ColumnCount - Rows = rows - Columns = columns - Values = values } - |> Some - | _ -> None diff --git a/src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Masked.fs b/src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Masked.fs deleted file mode 100644 index 1a75fc45..00000000 --- a/src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Masked.fs +++ /dev/null @@ -1,187 +0,0 @@ -namespace GraphBLAS.FSharp.Backend.Matrix.SpGeMM - -open GraphBLAS.FSharp.Backend.Common -open Brahma.FSharp -open Microsoft.FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions - -module internal Masked = - let private calculate - (opAdd: Expr<'c -> 'c -> 'c option>) - (opMul: Expr<'a -> 'b -> 'c option>) - (context: ClContext) - workGroupSize - = - - let run = - <@ fun (ndRange: Range1D) (leftRowPointers: ClArray) (leftColumns: ClArray) (leftValues: ClArray<'a>) (rightRows: ClArray) (rightColumnPointers: ClArray) (rightValues: ClArray<'b>) (maskRows: ClArray) (maskColumns: ClArray) (resultValues: ClArray<'c>) (resultValuesBitmap: ClArray) -> - - let gid = ndRange.GlobalID0 - let groupId = gid / workGroupSize - let row = maskRows.[groupId] - let col = maskColumns.[groupId] - - let rowBeginIdx = leftRowPointers.[row] - let nnzPerRow = leftRowPointers.[row + 1] - rowBeginIdx - - let colBeginIdx = rightColumnPointers.[col] - - let nnzPerCol = - rightColumnPointers.[col + 1] - colBeginIdx - - let lid = ndRange.LocalID0 - - let products = localArray<'c option> workGroupSize - products.[lid] <- None - - let threadProcessedSize = - (nnzPerRow + workGroupSize - 1) / workGroupSize - - let mutable start = threadProcessedSize * lid - let mutable i = threadProcessedSize * lid - - while i - start < threadProcessedSize && i < nnzPerRow do - let indexToFind = leftColumns.[rowBeginIdx + i] - - // Binary search - let mutable leftEdge = colBeginIdx - let mutable rightEdge = leftEdge + nnzPerCol - - while leftEdge < rightEdge do - let middle = (leftEdge + rightEdge) / 2 - let foundIdx = rightRows.[middle] - - if foundIdx < indexToFind then - leftEdge <- middle + 1 - elif foundIdx > indexToFind then - rightEdge <- middle - else - // Found needed index - let a = leftValues.[rowBeginIdx + i] - let b = rightValues.[middle] - let increase = (%opMul) a b - - let product = products.[lid] - - match product, increase with - | Some x, Some y -> - let buff = (%opAdd) x y - products.[lid] <- buff - | None, Some _ -> products.[lid] <- increase - | _ -> () - - // Break alternative - leftEdge <- rightEdge - - i <- i + 1 - - // Sum up all products - let mutable step = 2 - - while step <= workGroupSize do - barrierLocal () - - if lid < workGroupSize / step then - let i = step * (lid + 1) - 1 - - let increase = products.[i - (step >>> 1)] - - match increase, products.[i] with - | Some x, Some y -> - let buff = (%opAdd) x y - products.[i] <- buff - | Some _, None -> products.[i] <- increase - | _ -> () - - step <- step <<< 1 - - if lid = 0 then - match products.[workGroupSize - 1] with - | Some p -> - resultValues.[groupId] <- p - resultValuesBitmap.[groupId] <- 1 - | None -> resultValuesBitmap.[groupId] <- 0 @> - - let program = context.Compile(run) - - fun (queue: MailboxProcessor<_>) (matrixLeft: ClMatrix.CSR<'a>) (matrixRight: ClMatrix.CSC<'b>) (mask: ClMatrix.COO<_>) -> - - let values = - context.CreateClArrayWithSpecificAllocationMode<'c>(DeviceOnly, mask.NNZ) - - let bitmap = - context.CreateClArrayWithSpecificAllocationMode(DeviceOnly, mask.NNZ) - - let kernel = program.GetKernel() - - let ndRange = - Range1D.CreateValid(workGroupSize * mask.NNZ, workGroupSize) - - queue.Post( - Msg.MsgSetArguments - (fun () -> - kernel.KernelFunc - ndRange - matrixLeft.RowPointers - matrixLeft.Columns - matrixLeft.Values - matrixRight.Rows - matrixRight.ColumnPointers - matrixRight.Values - mask.Rows - mask.Columns - values - bitmap) - ) - - queue.Post(Msg.CreateRunMsg<_, _>(kernel)) - - values, bitmap - - let run - (opAdd: Expr<'c -> 'c -> 'c option>) - (opMul: Expr<'a -> 'b -> 'c option>) - (context: ClContext) - workGroupSize - = - - let calculate = - calculate opAdd opMul context workGroupSize - - let scatter = - Scatter.lastOccurrence context workGroupSize - - let scatterData = - Scatter.lastOccurrence context workGroupSize - - let scanInPlace = - PrefixSum.standardExcludeInPlace context workGroupSize - - fun (queue: MailboxProcessor<_>) (matrixLeft: ClMatrix.CSR<'a>) (matrixRight: ClMatrix.CSC<'b>) (mask: ClMatrix.COO<_>) -> - - let values, positions = - calculate queue matrixLeft matrixRight mask - - let resultNNZ = - (scanInPlace queue positions).ToHostAndFree(queue) - - let resultRows = context.CreateClArray resultNNZ - let resultColumns = context.CreateClArray resultNNZ - let resultValues = context.CreateClArray<'c> resultNNZ - - scatter queue positions mask.Rows resultRows - scatter queue positions mask.Columns resultColumns - scatterData queue positions values resultValues - - queue.Post(Msg.CreateFreeMsg<_>(values)) - queue.Post(Msg.CreateFreeMsg<_>(positions)) - - { Context = context - RowCount = matrixLeft.RowCount - ColumnCount = matrixRight.ColumnCount - Rows = resultRows - Columns = resultColumns - Values = resultValues } diff --git a/src/GraphBLAS-sharp.Backend/Objects/ArraysExtentions.fs b/src/GraphBLAS-sharp.Backend/Objects/ArraysExtentions.fs index 29aad544..5f5da3ae 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/ArraysExtentions.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/ArraysExtentions.fs @@ -1,4 +1,4 @@ -namespace GraphBLAS.FSharp.Backend.Objects +namespace GraphBLAS.FSharp.Objects open Brahma.FSharp diff --git a/src/GraphBLAS-sharp.Backend/Objects/AtLeastOne.fs b/src/GraphBLAS-sharp.Backend/Objects/AtLeastOne.fs index 758b2a4e..d0ab5aa5 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/AtLeastOne.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/AtLeastOne.fs @@ -1,4 +1,4 @@ -namespace GraphBLAS.FSharp.Backend.Objects +namespace GraphBLAS.FSharp.Objects type AtLeastOne<'a, 'b when 'a: struct and 'b: struct> = | Both of 'a * 'b diff --git a/src/GraphBLAS-sharp.Backend/Objects/ClCellExtensions.fs b/src/GraphBLAS-sharp.Backend/Objects/ClCellExtensions.fs index 3800ebc6..20334aae 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/ClCellExtensions.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/ClCellExtensions.fs @@ -1,4 +1,4 @@ -namespace GraphBLAS.FSharp.Backend.Objects +namespace GraphBLAS.FSharp.Objects open Brahma.FSharp diff --git a/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs b/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs index f72c71c4..a5cb6579 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs @@ -1,4 +1,4 @@ -namespace GraphBLAS.FSharp.Backend.Objects +namespace GraphBLAS.FSharp.Objects open Brahma.FSharp diff --git a/src/GraphBLAS-sharp.Backend/Objects/Common.fs b/src/GraphBLAS-sharp.Backend/Objects/Common.fs index 2c1d83ab..9efb172a 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/Common.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/Common.fs @@ -1,4 +1,4 @@ -namespace GraphBLAS.FSharp.Backend.Objects +namespace GraphBLAS.FSharp.Objects open Brahma.FSharp diff --git a/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs b/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs index 650c40b3..502acd8f 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs @@ -1,6 +1,7 @@ -namespace GraphBLAS.FSharp.Backend.Objects +namespace GraphBLAS.FSharp.Objects open Brahma.FSharp +open GraphBLAS.FSharp.Objects type MatrixFormat = | CSR diff --git a/src/GraphBLAS-sharp.Backend/Objects/Vector.fs b/src/GraphBLAS-sharp.Backend/Objects/Vector.fs index f7430242..8ffeb752 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/Vector.fs @@ -1,7 +1,7 @@ -namespace GraphBLAS.FSharp.Backend.Objects +namespace GraphBLAS.FSharp.Objects open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions type VectorFormat = | Sparse diff --git a/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs b/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs index ca0b8f81..f9e60097 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs @@ -1,17 +1,18 @@ -namespace GraphBLAS.FSharp.Backend.Matrix.CSR +namespace GraphBLAS.FSharp.Backend.Operations open FSharpx.Collections open Microsoft.FSharp.Quotations open FSharp.Quotations.Evaluator.QuotationEvaluationExtensions open Brahma.FSharp +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Backend.Matrix.COO open GraphBLAS.FSharp.Backend.Matrix.CSR -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions -open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClMatrix +open GraphBLAS.FSharp.Objects.ClCellExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions module internal Kronecker = let private updateBitmap (clContext: ClContext) workGroupSize op = @@ -430,7 +431,7 @@ module internal Kronecker = let mapAll = mapAll clContext workGroupSize op let bitonic = - Sort.Bitonic.sortKeyValuesInplace clContext workGroupSize + Bitonic.sortKeyValuesInplace clContext workGroupSize fun (queue: MailboxProcessor<_>) allocationMode (matrixLeft: CSR<'a>) (matrixRight: CSR<'b>) -> diff --git a/src/GraphBLAS-sharp.Backend/Operations/Operations.fs b/src/GraphBLAS-sharp.Backend/Operations/Operations.fs index f2722fa5..4e5ac9c7 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/Operations.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/Operations.fs @@ -1,11 +1,12 @@ -namespace GraphBLAS.FSharp.Backend +namespace GraphBLAS.FSharp open Brahma.FSharp open Microsoft.FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Backend.Vector -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Backend.Operations module Operations = module Vector = @@ -146,25 +147,31 @@ module Operations = /// /// Matrix-vector multiplication. + /// Vector, that is going to be the result of the operation, should be passed as an argument. /// /// Type of binary function to reduce entries. /// Type of binary function to combine entries. /// OpenCL context. /// Should be a power of 2 and greater than 1. - let SpMV + let SpMVInplace (add: Expr<'c option -> 'c option -> 'c option>) (mul: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) workGroupSize = - let run = SpMV.run add mul clContext workGroupSize + let runTo = + SpMV.runTo add mul clContext workGroupSize - fun (queue: MailboxProcessor<_>) allocationMode (matrix: ClMatrix<'a>) (vector: ClVector<'b>) -> - match matrix, vector with - | ClMatrix.CSR m, ClVector.Dense v -> run queue allocationMode m v |> ClVector.Dense + fun (queue: MailboxProcessor<_>) (matrix: ClMatrix<'a>) (vector: ClVector<'b>) (result: ClVector<'c>) -> + match matrix, vector, result with + | ClMatrix.CSR m, ClVector.Dense v, ClVector.Dense r -> runTo queue m v r | _ -> failwith "Not implemented yet" + /// + /// Matrix-vector multiplication. + /// + let SpMV = SpMV.run /// /// Kronecker product for matrices. @@ -176,8 +183,7 @@ module Operations = /// OpenCL context. /// Should be a power of 2 and greater than 1. let kronecker (op: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) workGroupSize = - let run = - CSR.Matrix.kronecker clContext workGroupSize op + let run = Kronecker.run clContext workGroupSize op fun (queue: MailboxProcessor<_>) allocationFlag (matrix1: ClMatrix<'a>) (matrix2: ClMatrix<'b>) -> match matrix1, matrix2 with @@ -243,4 +249,3 @@ module Operations = run processor allocationMode resultCapacity leftMatrix rightMatrix | _ -> failwith "Matrix formats are not matching" - diff --git a/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs index ea15ca75..1bb100d6 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs @@ -1,16 +1,16 @@ -namespace GraphBLAS.FSharp.Backend.Matrix.SpGeMM +namespace GraphBLAS.FSharp.Backend.Operations.SpGeMM open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Common.Sort +open FSharp.Quotations +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClMatrix +open GraphBLAS.FSharp.Objects.ClCellExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions -open FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects.ClMatrix module internal Expand = let getSegmentPointers (clContext: ClContext) workGroupSize = @@ -216,7 +216,7 @@ module internal Expand = PrefixSum.standardExcludeInPlace clContext workGroupSize let idScatter = - Scatter.initFirsOccurrence Map.id clContext workGroupSize + Scatter.initFirstOccurrence Map.id clContext workGroupSize fun (processor: MailboxProcessor<_>) allocationMode (values: ClArray<'a>) (columns: ClArray) (rows: ClArray) -> diff --git a/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Masked.fs b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Masked.fs index 1a75fc45..e86f3a8c 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Masked.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Masked.fs @@ -1,12 +1,12 @@ -namespace GraphBLAS.FSharp.Backend.Matrix.SpGeMM +namespace GraphBLAS.FSharp.Backend.Operations.SpGeMM -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp.Common open Brahma.FSharp open Microsoft.FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClMatrix -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClMatrix +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClCellExtensions module internal Masked = let private calculate diff --git a/src/GraphBLAS-sharp.Backend/Operations/SpMV.fs b/src/GraphBLAS-sharp.Backend/Operations/SpMV.fs index fbe08bd9..91750728 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/SpMV.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/SpMV.fs @@ -1,10 +1,10 @@ -namespace GraphBLAS.FSharp.Backend.Vector +namespace GraphBLAS.FSharp.Backend.Operations open Brahma.FSharp open GraphBLAS.FSharp.Backend.Common open Microsoft.FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClContextExtensions module internal SpMV = let runTo diff --git a/src/GraphBLAS-sharp.Backend/Quotes/Arithmetic.fs b/src/GraphBLAS-sharp.Backend/Quotes/Arithmetic.fs index f7d51a89..3430f373 100644 --- a/src/GraphBLAS-sharp.Backend/Quotes/Arithmetic.fs +++ b/src/GraphBLAS-sharp.Backend/Quotes/Arithmetic.fs @@ -1,6 +1,6 @@ namespace GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Objects +open GraphBLAS.FSharp.Objects module ArithmeticOperations = let inline mkUnaryOp zero unaryOp = diff --git a/src/GraphBLAS-sharp.Backend/Quotes/Convert.fs b/src/GraphBLAS-sharp.Backend/Quotes/Convert.fs index d779ba5a..3491dfa8 100644 --- a/src/GraphBLAS-sharp.Backend/Quotes/Convert.fs +++ b/src/GraphBLAS-sharp.Backend/Quotes/Convert.fs @@ -1,7 +1,7 @@ namespace GraphBLAS.FSharp.Backend.Quotes open FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects +open GraphBLAS.FSharp.Objects module Convert = let atLeastOneToOption op = diff --git a/src/GraphBLAS-sharp.Backend/Vector/Dense/Vector.fs b/src/GraphBLAS-sharp.Backend/Vector/Dense/Vector.fs index ff522be3..6f3968c4 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Dense/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Dense/Vector.fs @@ -1,12 +1,13 @@ namespace GraphBLAS.FSharp.Backend.Vector.Dense open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Quotes open Microsoft.FSharp.Quotations -open GraphBLAS.FSharp.Backend.Objects.ClVector -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp.Backend.Quotes +open GraphBLAS.FSharp.Objects.ClVector +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClCellExtensions module Vector = let map<'a, 'b when 'a: struct and 'b: struct> @@ -15,8 +16,7 @@ module Vector = workGroupSize = - let map = - ClArray.map op clContext workGroupSize + let map = ClArray.map op clContext workGroupSize fun (processor: MailboxProcessor<_>) allocationMode (leftVector: ClArray<'a option>) -> diff --git a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Common.fs b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Common.fs index 002b4f9e..465102d5 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Common.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Common.fs @@ -1,11 +1,12 @@ namespace GraphBLAS.FSharp.Backend.Vector.Sparse open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Objects.ClVector open Microsoft.FSharp.Control -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp.Objects.ClVector +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClCellExtensions module internal Common = let setPositions<'a when 'a: struct> (clContext: ClContext) workGroupSize = diff --git a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map.fs b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map.fs index 6259c3c7..329e5484 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map.fs @@ -1,17 +1,17 @@ namespace GraphBLAS.FSharp.Backend.Vector.Sparse open FSharp.Quotations.Evaluator.QuotationEvaluationExtensions -open GraphBLAS.FSharp.Backend.Objects open Microsoft.FSharp.Quotations open Brahma.FSharp +open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Backend.Vector.Sparse -open GraphBLAS.FSharp.Backend.Objects.ClVector -open GraphBLAS.FSharp.Backend.Common.ClArray -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClVector +open GraphBLAS.FSharp.Objects.ClCellExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions module internal Map = let preparePositions<'a, 'b> opAdd (clContext: ClContext) workGroupSize = @@ -48,8 +48,7 @@ module internal Map = let resultValues = clContext.CreateClArrayWithSpecificAllocationMode<'b>(DeviceOnly, size) - let ndRange = - Range1D.CreateValid(size, workGroupSize) + let ndRange = Range1D.CreateValid(size, workGroupSize) let kernel = kernel.GetKernel() @@ -172,9 +171,10 @@ module internal Map = let setPositions = Common.setPositionsOption<'c> clContext workGroupSize - let create = create clContext workGroupSize + let create = ClArray.create clContext workGroupSize - let init = init <@ id @> clContext workGroupSize + let init = + ClArray.init <@ id @> clContext workGroupSize fun (queue: MailboxProcessor<_>) allocationMode (value: 'a option) size -> function diff --git a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map2.fs b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map2.fs index 5cd60600..feb6e484 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map2.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Map2.fs @@ -3,9 +3,9 @@ namespace GraphBLAS.FSharp.Backend.Vector.Sparse open Brahma.FSharp open FSharp.Quotations open Microsoft.FSharp.Control -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClVector -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClVector +open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Quotes module internal Map2 = diff --git a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Merge.fs b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Merge.fs index 87351087..4c310edf 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Merge.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Merge.fs @@ -1,8 +1,8 @@ namespace GraphBLAS.FSharp.Backend.Vector.Sparse open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClContextExtensions module internal Merge = let run<'a, 'b when 'a: struct and 'b: struct> (clContext: ClContext) workGroupSize = diff --git a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs index 06121194..80e7895c 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs @@ -3,10 +3,11 @@ namespace GraphBLAS.FSharp.Backend.Vector.Sparse open Brahma.FSharp open Microsoft.FSharp.Control open Microsoft.FSharp.Quotations -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClVector open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClVector open GraphBLAS.FSharp.Backend.Vector.Sparse module Vector = diff --git a/src/GraphBLAS-sharp.Backend/Vector/Primitives.fs b/src/GraphBLAS-sharp.Backend/Vector/Vector.fs similarity index 94% rename from src/GraphBLAS-sharp.Backend/Vector/Primitives.fs rename to src/GraphBLAS-sharp.Backend/Vector/Vector.fs index 5fef5f57..b7375865 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Primitives.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Vector.fs @@ -1,15 +1,17 @@ -namespace GraphBLAS.FSharp.Backend.Vector +namespace GraphBLAS.FSharp open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Quotes open Microsoft.FSharp.Control open Microsoft.FSharp.Quotations -open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ClVector +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClVector +open GraphBLAS.FSharp.Backend.Quotes +open GraphBLAS.FSharp.Backend.Vector -module Primitives = +module Vector = /// /// Builds vector of given format with fixed size and fills it with the default values of desired type. /// @@ -165,8 +167,12 @@ module Primitives = fun (processor: MailboxProcessor<_>) allocationMode matrix -> match matrix with - | ClVector.Sparse v -> mapSparse processor allocationMode v |> ClVector.Sparse - | ClVector.Dense v -> mapDense processor allocationMode v |> ClVector.Dense + | ClVector.Sparse v -> + mapSparse processor allocationMode v + |> ClVector.Sparse + | ClVector.Dense v -> + mapDense processor allocationMode v + |> ClVector.Dense let private assignByMaskGeneral<'a, 'b when 'a: struct and 'b: struct> op (clContext: ClContext) workGroupSize = diff --git a/src/GraphBLAS-sharp/Objects/Matrix.fs b/src/GraphBLAS-sharp/Objects/Matrix.fs index 45754431..e74e9153 100644 --- a/src/GraphBLAS-sharp/Objects/Matrix.fs +++ b/src/GraphBLAS-sharp/Objects/Matrix.fs @@ -1,8 +1,8 @@ namespace GraphBLAS.FSharp.Objects open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClMatrix +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClMatrix module Matrix = type CSR<'a when 'a: struct> = diff --git a/src/GraphBLAS-sharp/Objects/MatrixExtensions.fs b/src/GraphBLAS-sharp/Objects/MatrixExtensions.fs index f310ca31..a0e8332a 100644 --- a/src/GraphBLAS-sharp/Objects/MatrixExtensions.fs +++ b/src/GraphBLAS-sharp/Objects/MatrixExtensions.fs @@ -1,9 +1,9 @@ namespace GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Backend.Objects open Brahma.FSharp open Matrix -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ArraysExtensions open GraphBLAS.FSharp.Objects.ClVectorExtensions module MatrixExtensions = diff --git a/src/GraphBLAS-sharp/Objects/Vector.fs b/src/GraphBLAS-sharp/Objects/Vector.fs index 19b7e01a..6462109d 100644 --- a/src/GraphBLAS-sharp/Objects/Vector.fs +++ b/src/GraphBLAS-sharp/Objects/Vector.fs @@ -1,9 +1,9 @@ namespace GraphBLAS.FSharp.Objects open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClVector +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClVector module Vector = type Sparse<'a> = diff --git a/src/GraphBLAS-sharp/Objects/VectorExtensions.fs b/src/GraphBLAS-sharp/Objects/VectorExtensions.fs index 4bdb6a01..cfe098e7 100644 --- a/src/GraphBLAS-sharp/Objects/VectorExtensions.fs +++ b/src/GraphBLAS-sharp/Objects/VectorExtensions.fs @@ -1,8 +1,8 @@ namespace GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects +open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.Vector +open GraphBLAS.FSharp.Objects.ArraysExtensions module ClVectorExtensions = type ClVector.Sparse<'a> with diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs index a85d8424..5ab48d72 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs @@ -1,14 +1,12 @@ module GraphBLAS.FSharp.Tests.Backend.Algorithms.BFS open Expecto -open GraphBLAS.FSharp.Backend -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp.Tests.Backend.QuickGraph.Algorithms open GraphBLAS.FSharp.Tests.Backend.QuickGraph.CreateGraph -open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions open GraphBLAS.FSharp.Objects @@ -22,7 +20,7 @@ let testFixtures (testContext: TestContext) = sprintf "Test on %A" testContext.ClContext let bfs = - Algorithms.BFS.singleSource + Algorithms.singleSourceBFS ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption context @@ -50,7 +48,8 @@ let testFixtures (testContext: TestContext) = match matrix with | ClMatrix.CSR mtx -> - let res = bfs queue mtx source |> ClVector.Dense + let res = + bfs queue matrix source |> ClVector.Dense let resHost = res.ToHost queue diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Blit.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Blit.fs index 771f3501..f3548e1e 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Blit.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Blit.fs @@ -2,10 +2,11 @@ module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.Blit open Expecto open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs index 4ffcd21e..ea9e5c76 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs @@ -1,13 +1,13 @@ module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.Choose -open GraphBLAS.FSharp.Backend.Common open Expecto +open Brahma.FSharp +open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open Brahma.FSharp open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let workGroupSize = Utils.defaultWorkGroupSize diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ChunkBySize.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ChunkBySize.fs index 032fdc0d..2cc3133e 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ChunkBySize.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/ChunkBySize.fs @@ -2,11 +2,11 @@ module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.ChunkBySize open Expecto open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs index 381c03b1..3d7454d1 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs @@ -2,10 +2,11 @@ module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.Concat open Expecto open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Copy.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Copy.fs index c058f135..c36475a0 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Copy.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Copy.fs @@ -4,10 +4,10 @@ open Expecto open Expecto.Logging open Expecto.Logging.Message open Brahma.FSharp +open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions let logger = Log.create "ClArray.Copy.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Exists.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Exists.fs index 5d011c98..ac991951 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Exists.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Exists.fs @@ -2,13 +2,13 @@ module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.Exists open Expecto open Expecto.Logging -open GraphBLAS.FSharp.Backend.Common +open Brahma.FSharp +open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests open Context -open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClCellExtensions open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions let logger = Log.create "ClArray.containsNonZero.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Fill.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Fill.fs index a0d65654..8a285a2f 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Fill.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Fill.fs @@ -2,11 +2,10 @@ module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.Fill open Expecto open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Item.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Item.fs index 4de050f5..a3786832 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Item.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Item.fs @@ -2,11 +2,11 @@ module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.Item open Expecto open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClCellExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map.fs index ca1b2024..1cb85d29 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map.fs @@ -1,12 +1,12 @@ module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.Map +open Expecto open Brahma.FSharp open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend.Quotes -open Expecto -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let context = defaultContext.Queue diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map2.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map2.fs index 23e5b70a..0b5ab49b 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map2.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Map2.fs @@ -1,11 +1,12 @@ module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.Map2 +open Expecto open Brahma.FSharp open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context -open GraphBLAS.FSharp.Backend.Common -open Expecto -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Objects.ClContextExtensions + let context = defaultContext.Queue diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Pairwise.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Pairwise.fs index 8fa3bb07..12db7aa8 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Pairwise.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Pairwise.fs @@ -2,11 +2,11 @@ module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.Pairwise open Expecto open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/RemoveDuplicates.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/RemoveDuplicates.fs index 1f8e3f7d..276cf286 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/RemoveDuplicates.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/RemoveDuplicates.fs @@ -4,8 +4,8 @@ open Expecto open Expecto.Logging open Expecto.Logging.Message open Brahma.FSharp +open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Common let logger = Log.create "RemoveDuplicates.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Replicate.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Replicate.fs index 1a1d5ff8..2d6ecc6b 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Replicate.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Replicate.fs @@ -4,10 +4,10 @@ open Expecto open Expecto.Logging open Expecto.Logging.Message open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions let logger = Log.create "Replicate.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Set.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Set.fs index a393b499..cf1d09e5 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Set.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Set.fs @@ -2,10 +2,10 @@ module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.Set open Expecto open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Objects.ArraysExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/UpperBound.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/UpperBound.fs index 8b19da9b..7f1f2c81 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/UpperBound.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/UpperBound.fs @@ -2,10 +2,10 @@ module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.UpperBound open Expecto open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions +open GraphBLAS.FSharp.Objects.ClCellExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs index 8129fce2..8c257be9 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs @@ -1,11 +1,11 @@ module GraphBLAS.FSharp.Tests.Backend.Common.Gather -open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Tests open Expecto open Microsoft.FSharp.Collections -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp.Tests +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Backend.Quotes let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Merge.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Merge.fs deleted file mode 100644 index d937da3c..00000000 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Merge.fs +++ /dev/null @@ -1,54 +0,0 @@ -module GraphBLAS.FSharp.Tests.Common.Merge - -open Expecto -open Brahma.FSharp -open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions - -let context = Context.defaultContext.ClContext - -let processor = Context.defaultContext.Queue - -let config = - { Utils.defaultConfig with - endSize = 10000000 } - -let makeTest isEqual testFun (leftArray: 'a []) (rightArray: 'a []) = - if leftArray.Length > 0 && rightArray.Length > 0 then - - let leftArray = Array.sort leftArray |> Array.distinct - - let rightArray = Array.sort rightArray |> Array.distinct - - let clLeftArray = context.CreateClArray leftArray - let clRightArray = context.CreateClArray rightArray - - let clResult: ClArray<'a> = - testFun processor clLeftArray clRightArray - - let result = clResult.ToHostAndFree processor - clLeftArray.Free processor - clRightArray.Free processor - - let expected = - Array.concat [ leftArray; rightArray ] - |> Array.sort - - "Results must be the same" - |> Utils.compareArrays isEqual result expected - -let createTest<'a> isEqual = - Merge.run context Utils.defaultWorkGroupSize - |> makeTest isEqual - |> testPropertyWithConfig config $"test on {typeof<'a>}" - -let tests = - [ createTest (=) - - if Utils.isFloat64Available context.ClDevice then - createTest (=) - - createTest (=) - createTest (=) ] - |> testList "Merge" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs index 931f7bae..05c12487 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs @@ -4,10 +4,10 @@ open Expecto open Expecto.Logging open Expecto.Logging.Message open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common +open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClCellExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions let logger = Log.create "Reduce.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs index e17e59cb..e7194b39 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs @@ -1,13 +1,13 @@ module GraphBLAS.FSharp.Tests.Backend.Common.Reduce.ByKey open Expecto -open GraphBLAS.FSharp.Backend.Common +open Brahma.FSharp +open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Sum.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Sum.fs index 8011d1fc..d10c214d 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Sum.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Sum.fs @@ -3,13 +3,13 @@ module GraphBLAS.FSharp.Tests.Backend.Common.Reduce.Sum open Expecto open Expecto.Logging open Expecto.Logging.Message +open FSharp.Quotations open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Tests -open FSharp.Quotations open Context -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions +open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClCellExtensions let logger = Log.create "Sum.Test" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs index ff3f8aba..e9ec90a2 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs @@ -1,10 +1,10 @@ module GraphBLAS.FSharp.Tests.Backend.Common.Scan.ByKey -open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open Expecto +open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/PrefixSum.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/PrefixSum.fs index ebff059d..4a9cba02 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/PrefixSum.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/PrefixSum.fs @@ -4,11 +4,11 @@ open Expecto open Expecto.Logging open Expecto.Logging.Message open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp.Tests.Context +open GraphBLAS.FSharp.Objects.ClCellExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions let logger = Log.create "ClArray.PrefixSum.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scatter.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scatter.fs index a72de22b..3f8e960a 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scatter.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scatter.fs @@ -3,11 +3,12 @@ module GraphBLAS.FSharp.Tests.Backend.Common.Scatter open Expecto open Expecto.Logging open Brahma.FSharp +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions let logger = Log.create "Scatter.Tests" @@ -100,8 +101,8 @@ let initTests = let inc = ((+) 1) let firstOccurrence = - [ createInitTest Scatter.initFirsOccurrence HostPrimitives.scatterFirstOccurrence "id" id Map.id - createInitTest Scatter.initFirsOccurrence HostPrimitives.scatterFirstOccurrence "inc" inc Map.inc ] + [ createInitTest Scatter.initFirstOccurrence HostPrimitives.scatterFirstOccurrence "id" id Map.id + createInitTest Scatter.initFirstOccurrence HostPrimitives.scatterFirstOccurrence "inc" inc Map.inc ] |> testList "first occurrence" let lastOccurrence = diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs index 60705e76..94cf18e1 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs @@ -3,11 +3,11 @@ namespace GraphBLAS.FSharp.Tests.Backend.Common.Sort open Expecto open Expecto.Logging open Expecto.Logging.Message -open GraphBLAS.FSharp.Backend.Common open Brahma.FSharp +open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions module Bitonic = let logger = Log.create "BitonicSort.Tests" @@ -62,7 +62,7 @@ module Bitonic = |> Utils.compareArrays (=) actualValues expectedValues let testFixtures<'a when 'a: equality> = - Sort.Bitonic.sortKeyValuesInplace context wgSize + Bitonic.sortKeyValuesInplace context wgSize |> makeTest |> testPropertyWithConfig config $"Correctness on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs index 7aa7fde8..413edc17 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs @@ -1,11 +1,11 @@ module GraphBLAS.FSharp.Tests.Backend.Common.Sort.Radix open Expecto -open GraphBLAS.FSharp.Backend.Common.Sort -open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp.Tests +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let config = { Utils.defaultConfig with diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs index d16c5523..00a85449 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs @@ -2,11 +2,11 @@ module GraphBLAS.FSharp.Tests.Matrix.ByRows open Expecto open GraphBLAS.FSharp.Tests +open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend -open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.ClVectorExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Convert.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Convert.fs index cab5a09a..8e88e216 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Convert.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Convert.fs @@ -3,14 +3,13 @@ module GraphBLAS.FSharp.Tests.Backend.Matrix.Convert open Expecto open Expecto.Logging open Expecto.Logging.Message +open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Objects.MatrixExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let logger = Log.create "Convert.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ExpandRows.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ExpandRows.fs index fee57240..63cd8bee 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ExpandRows.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ExpandRows.fs @@ -1,13 +1,13 @@ module GraphBLAS.FSharp.Tests.Backend.Matrix.ExpandRows open Expecto +open Brahma.FSharp open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs index 12bbafa5..b04d91c5 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs @@ -2,15 +2,13 @@ open Expecto open Expecto.Logging +open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp.Tests.TestCases -open GraphBLAS.FSharp.Backend -open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.MatrixExtensions +open GraphBLAS.FSharp.Backend.Quotes let config = { Utils.defaultConfig with @@ -65,7 +63,7 @@ let makeTest testContext zero isEqual op kroneckerFun (leftMatrix: 'a [,], right |> Expect.equal actual expectedOption let createGeneralTest testContext (zero: 'a) isEqual op opQ testName = - Matrix.kronecker opQ testContext.ClContext workGroupSize + kronecker opQ testContext.ClContext workGroupSize |> makeTest testContext zero isEqual op |> testPropertyWithConfig config $"test on %A{typeof<'a>} %s{testName}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs index 801a1ea4..fdb655ce 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs @@ -4,15 +4,14 @@ open Expecto open Expecto.Logging open Expecto.Logging.Message open Microsoft.FSharp.Collections +open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Backend open GraphBLAS.FSharp.Tests.TestCases open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.MatrixExtensions let logger = Log.create "Map.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs index aca527da..452aed9f 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs @@ -3,17 +3,17 @@ module GraphBLAS.FSharp.Tests.Backend.Matrix.Map2 open Expecto open Expecto.Logging open Expecto.Logging.Message +open Microsoft.FSharp.Collections +open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Backend.Quotes +open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.TestCases -open Microsoft.FSharp.Collections -open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Tests.Backend +open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.MatrixExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let logger = Log.create "Map2.Tests" @@ -135,7 +135,13 @@ let testFixturesMap2AddAtLeastOne case = createTestMap2Add case 0 (+) (=) ArithmeticOperations.intSumAtLeastOne Matrix.map2AtLeastOne if Utils.isFloat64Available context.ClDevice then - createTestMap2Add case 0.0 (+) Utils.floatIsEqual ArithmeticOperations.floatSumAtLeastOne Matrix.map2AtLeastOne + createTestMap2Add + case + 0.0 + (+) + Utils.floatIsEqual + ArithmeticOperations.floatSumAtLeastOne + Matrix.map2AtLeastOne createTestMap2Add case @@ -160,7 +166,13 @@ let testFixturesMap2MulAtLeastOne case = createTestMap2Add case 0 (*) (=) ArithmeticOperations.intMulAtLeastOne Matrix.map2AtLeastOne if Utils.isFloat64Available context.ClDevice then - createTestMap2Add case 0.0 (*) Utils.floatIsEqual ArithmeticOperations.floatMulAtLeastOne Matrix.map2AtLeastOne + createTestMap2Add + case + 0.0 + (*) + Utils.floatIsEqual + ArithmeticOperations.floatMulAtLeastOne + Matrix.map2AtLeastOne createTestMap2Add case diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Merge.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Merge.fs index fef357de..0639c4d9 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Merge.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Merge.fs @@ -4,11 +4,10 @@ open Brahma.FSharp open Expecto open Microsoft.FSharp.Collections open GraphBLAS.FSharp.Backend -open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Backend open GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions let context = Context.defaultContext.ClContext diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/RowsLengths.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/RowsLengths.fs index 35245698..f690ca3e 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/RowsLengths.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/RowsLengths.fs @@ -2,14 +2,14 @@ module GraphBLAS.FSharp.Tests.Backend.Matrix.RowsLengths open Expecto open Microsoft.FSharp.Collections +open Brahma.FSharp open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Backend open GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let processor = Context.defaultContext.Queue diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs index 30949a6d..77c4994f 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs @@ -1,20 +1,19 @@ module GraphBLAS.FSharp.Tests.Matrix.SpGeMM.Expand open Expecto -open GraphBLAS.FSharp.Backend.Matrix.SpGeMM +open Microsoft.FSharp.Collections +open Brahma.FSharp +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Backend.Quotes +open GraphBLAS.FSharp.Backend.Operations.SpGeMM +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.MatrixExtensions open GraphBLAS.FSharp.Test -open Microsoft.FSharp.Collections -open GraphBLAS.FSharp.Backend -open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Backend -open GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions -open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Objects.MatrixExtensions let context = Context.defaultContext.ClContext @@ -215,7 +214,7 @@ let createGeneralTest (zero: 'a) isEqual (opAddQ, opAdd) (opMulQ, opMul) testFun |> testPropertyWithConfig config $"test on %A{typeof<'a>}" let generalTests = - [ createGeneralTest 0 (=) ArithmeticOperations.intAdd ArithmeticOperations.intMul Matrix.SpGeMM.expand + [ createGeneralTest 0 (=) ArithmeticOperations.intAdd ArithmeticOperations.intMul SpGeMM.expand if Utils.isFloat64Available context.ClDevice then createGeneralTest @@ -223,13 +222,13 @@ let generalTests = Utils.floatIsEqual ArithmeticOperations.floatAdd ArithmeticOperations.floatMul - Matrix.SpGeMM.expand + SpGeMM.expand createGeneralTest 0.0f Utils.float32IsEqual ArithmeticOperations.float32Add ArithmeticOperations.float32Mul - Matrix.SpGeMM.expand - createGeneralTest false (=) ArithmeticOperations.boolAdd ArithmeticOperations.boolMul Matrix.SpGeMM.expand ] + SpGeMM.expand + createGeneralTest false (=) ArithmeticOperations.boolAdd ArithmeticOperations.boolMul SpGeMM.expand ] |> testList "general" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Masked.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Masked.fs index 7304b96e..20180188 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Masked.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Masked.fs @@ -2,14 +2,12 @@ module GraphBLAS.FSharp.Tests.Backend.Matrix.SpGeMM.Masked open Expecto open Expecto.Logging -open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Tests.Context -open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects +open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Objects.MatrixExtensions open GraphBLAS.FSharp.Test +open GraphBLAS.FSharp.Tests +open GraphBLAS.FSharp.Tests.Context let logger = Log.create "SpGeMM.Masked.Tests" @@ -79,7 +77,7 @@ let tests = let mult = <@ fun x y -> Some(x * y) @> let mxmFun = - Matrix.SpGeMM.masked add mult context workGroupSize + SpGeMM.masked add mult context workGroupSize makeTest context q 0 (=) (+) (*) mxmFun |> testPropertyWithConfig config (getCorrectnessTestName "int") @@ -105,7 +103,7 @@ let tests = res @> let mxmFun = - Matrix.SpGeMM.masked logicalOr logicalAnd context workGroupSize + SpGeMM.masked logicalOr logicalAnd context workGroupSize makeTest context q false (=) (||) (&&) mxmFun |> testPropertyWithConfig config (getCorrectnessTestName "bool") ] diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs index 66c4a8eb..0c5399c3 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs @@ -4,10 +4,9 @@ open Expecto open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Backend -open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions -open GraphBLAS.FSharp.Backend.Objects +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.MatrixExtensions open GraphBLAS.FSharp.Objects.Matrix diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Transpose.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Transpose.fs index 1a3a1e83..e7308335 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Transpose.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Transpose.fs @@ -3,14 +3,12 @@ module GraphBLAS.FSharp.Tests.Backend.Matrix.Transpose open Expecto open Expecto.Logging open Expecto.Logging.Message -open GraphBLAS.FSharp.Backend +open GraphBLAS.FSharp open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.TestCases -open GraphBLAS.FSharp.Backend.Matrix -open GraphBLAS.FSharp.Backend.Objects open GraphBLAS.FSharp.Objects.MatrixExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let logger = Log.create "Transpose.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/AssignByMask.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/AssignByMask.fs index 54f69e9a..737c5831 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/AssignByMask.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/AssignByMask.fs @@ -2,16 +2,15 @@ module GraphBLAS.FSharp.Tests.Backend.Vector.AssignByMask open Expecto open Expecto.Logging +open Brahma.FSharp +open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Tests -open Brahma.FSharp open TestCases -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Vector open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let logger = Log.create "Vector.assignByMask.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Convert.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Convert.fs index 8220564e..d184bc47 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Convert.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Convert.fs @@ -3,14 +3,13 @@ module GraphBLAS.FSharp.Tests.Backend.Vector.Convert open Expecto open Expecto.Logging open Expecto.Logging.Message +open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend open TestCases -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Vector +open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let logger = Log.create "Backend.Vector.Convert.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs index d912ad11..a5d04d1a 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs @@ -2,14 +2,15 @@ module GraphBLAS.FSharp.Tests.Backend.Vector.Copy open Expecto open Expecto.Logging +open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Tests open TestCases -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Vector +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Vector open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let logger = Log.create "Vector.copy.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs index 122e28a4..6f76336b 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs @@ -2,15 +2,15 @@ module GraphBLAS.FSharp.Tests.Backend.Vector.Map2 open Expecto open Expecto.Logging +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Tests.TestCases open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Vector open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let logger = Log.create "Vector.ElementWise.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Merge.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Merge.fs index af693c80..36594743 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Merge.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Merge.fs @@ -1,13 +1,12 @@ module GraphBLAS.FSharp.Tests.Vector.Merge -open GraphBLAS.FSharp.Backend.Vector -open GraphBLAS.FSharp.Backend.Common -open GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions open Brahma.FSharp open Expecto +open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend +open GraphBLAS.FSharp.Tests +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ArraysExtensions let processor = Context.defaultContext.Queue diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/OfList.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/OfList.fs index 3f282e6e..9623073f 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/OfList.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/OfList.fs @@ -2,15 +2,14 @@ module GraphBLAS.FSharp.Tests.Backend.Vector.OfList open Expecto open Expecto.Logging +open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests -open GraphBLAS.FSharp.Backend open Context open TestCases -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Vector +open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let logger = Log.create "Vector.ofList.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Reduce.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Reduce.fs index c512b7c3..7775d541 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Reduce.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Reduce.fs @@ -2,13 +2,12 @@ module GraphBLAS.FSharp.Tests.Backend.Vector.Reduce open Expecto open Expecto.Logging +open Brahma.FSharp +open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Tests -open Brahma.FSharp -open FSharp.Quotations open TestCases -open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions -open GraphBLAS.FSharp.Backend.Vector +open GraphBLAS.FSharp.Objects.ClCellExtensions let logger = Log.create "Vector.reduce.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs index a6995069..a9158cac 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs @@ -1,18 +1,17 @@ module GraphBLAS.FSharp.Tests.Backend.Vector.SpMV -open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions open Expecto +open Microsoft.FSharp.Collections +open Microsoft.FSharp.Core open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Quotes +open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp.Tests.TestCases -open Microsoft.FSharp.Collections -open Microsoft.FSharp.Core -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Vector open GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ArraysExtensions +open GraphBLAS.FSharp.Backend.Quotes let config = Utils.defaultConfig @@ -92,7 +91,7 @@ let createTest testContext (zero: 'a) isEqual add mul addQ mulQ = let getCorrectnessTestName datatype = $"Correctness on %s{datatype}, %A{testContext.ClContext}" - let spMV = SpMV.run addQ mulQ context wgSize + let spMV = SpMV addQ mulQ context wgSize testContext |> correctnessGenericTest zero add mul spMV isEqual q diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs index f310a506..79c1e4d9 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/ZeroCreate.fs @@ -2,15 +2,14 @@ module GraphBLAS.FSharp.Tests.Backend.Vector.ZeroCreate open Expecto open Expecto.Logging +open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Tests open Context open TestCases -open GraphBLAS.FSharp.Backend.Objects -open GraphBLAS.FSharp.Backend.Vector open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions -open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClContextExtensions let logger = Log.create "Vector.zeroCreate.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Generators.fs b/tests/GraphBLAS-sharp.Tests/Generators.fs index 38d3e388..fec8f61e 100644 --- a/tests/GraphBLAS-sharp.Tests/Generators.fs +++ b/tests/GraphBLAS-sharp.Tests/Generators.fs @@ -1,10 +1,8 @@ namespace GraphBLAS.FSharp.Test open FsCheck -open GraphBLAS.FSharp open Expecto.Logging open Expecto.Logging.Message -open FSharp.Quotations.Evaluator module Generators = let logger = Log.create "Generators" diff --git a/tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj b/tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj index 75a4f492..6bbf3f99 100644 --- a/tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj +++ b/tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj @@ -41,7 +41,6 @@ - diff --git a/tests/GraphBLAS-sharp.Tests/Helpers.fs b/tests/GraphBLAS-sharp.Tests/Helpers.fs index 1811c40b..5f8d043b 100644 --- a/tests/GraphBLAS-sharp.Tests/Helpers.fs +++ b/tests/GraphBLAS-sharp.Tests/Helpers.fs @@ -1,15 +1,13 @@ namespace GraphBLAS.FSharp.Tests -open Brahma.FSharp.OpenCL.Translator +open Expecto open Microsoft.FSharp.Reflection -open Brahma.FSharp -open OpenCL.Net -open GraphBLAS.FSharp.Test open System.Text.RegularExpressions -open Expecto +open Brahma.FSharp +open Brahma.FSharp.OpenCL.Translator open GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Backend.Objects - +open GraphBLAS.FSharp.Test +open OpenCL.Net [] module Utils = diff --git a/tests/GraphBLAS-sharp.Tests/Program.fs b/tests/GraphBLAS-sharp.Tests/Program.fs index 9049b03e..1bcc04d3 100644 --- a/tests/GraphBLAS-sharp.Tests/Program.fs +++ b/tests/GraphBLAS-sharp.Tests/Program.fs @@ -64,7 +64,6 @@ let commonTests = "Common" [ Common.Scatter.allTests Common.Gather.allTests - Common.Merge.tests clArrayTests sortTests reduceTests From 4c21e7e1083421cadad2c1b3b105edd999b70ac7 Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Sat, 22 Jul 2023 21:44:47 +0700 Subject: [PATCH 04/22] refactor: add comments --- src/GraphBLAS-sharp.Backend/Common/ClArray.fs | 62 +++++++++- src/GraphBLAS-sharp.Backend/Common/Common.fs | 112 ++++++++++++++++-- .../Quotes/Arithmetic.fs | 12 +- src/GraphBLAS-sharp.Backend/Quotes/Search.fs | 34 +++--- .../Vector/Sparse/Vector.fs | 1 - .../Backend/Matrix/ByRows.fs | 2 +- .../Backend/Matrix/Merge.fs | 2 +- .../Backend/Matrix/SpGeMM/Expand.fs | 2 +- .../Backend/Vector/Merge.fs | 2 +- tests/GraphBLAS-sharp.Tests/Program.fs | 2 +- 10 files changed, 189 insertions(+), 42 deletions(-) diff --git a/src/GraphBLAS-sharp.Backend/Common/ClArray.fs b/src/GraphBLAS-sharp.Backend/Common/ClArray.fs index 2470989c..3ff13094 100644 --- a/src/GraphBLAS-sharp.Backend/Common/ClArray.fs +++ b/src/GraphBLAS-sharp.Backend/Common/ClArray.fs @@ -328,11 +328,19 @@ module ClArray = bitmap + /// + /// Gets the bitmap that indicates the first elements of the sequences of consecutive identical elements + /// + /// OpenCL context. let firstOccurrence clContext = getUniqueBitmapGeneral <| Predicates.firstOccurrence () <| clContext + /// + /// Gets the bitmap that indicates the last elements of the sequences of consecutive identical elements + /// + /// OpenCL context. let lastOccurrence clContext = getUniqueBitmapGeneral <| Predicates.lastOccurrence () @@ -360,9 +368,19 @@ module ClArray = result + /// + /// Gets the bitmap that indicates the first elements of the sequences + /// of consecutive identical elements from either first array or second array. + /// + /// OpenCL context. let firstOccurrence2 clContext = getUniqueBitmap2General firstOccurrence clContext + /// + /// Gets the bitmap that indicates the last elements of the sequences + /// of consecutive identical elements from either first array or second array. + /// + /// OpenCL context. let lastOccurrence2 clContext = getUniqueBitmap2General lastOccurrence clContext @@ -436,6 +454,14 @@ module ClArray = result + /// + /// Maps every value from the given value array and, if the result of applying function is Some, + /// places the result to a specific position from the input array of positions. + /// If the result of mapping is None, it is just ignored. + /// + /// Function that maps elements from value array. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let private assignOption (op: Expr<'a -> 'b option>) (clContext: ClContext) workGroupSize = let assign = @@ -474,7 +500,8 @@ module ClArray = /// /// Applies the given function to each element of the array. - /// Returns the array comprised of the results x for each element where the function returns Some(x). + /// Returns the array comprised of the results x + /// for each element where the function returns Some(x). /// /// The function to generate options from the elements. /// OpenCL context. @@ -512,6 +539,14 @@ module ClArray = Some result + /// + /// Maps pair of values from the given value arrays and, if the result of applying function is Some, + /// places the result to a specific position from the input array of positions. + /// If the result of mapping is None, it is just ignored. + /// + /// Function that maps pairs of elements from value arrays. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let assignOption2 (op: Expr<'a -> 'b -> 'c option>) (clContext: ClContext) workGroupSize = let assign = @@ -559,6 +594,14 @@ module ClArray = processor.Post(Msg.CreateRunMsg<_, _>(kernel)) + /// + /// Applies the given function to each pair of elements of the two given arrays. + /// Returns the array comprised of the results x + /// for each pairs where the function returns Some(x). + /// + /// The function to generate options from the pairs of elements. + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let choose2 (predicate: Expr<'a -> 'b -> 'c option>) (clContext: ClContext) workGroupSize = let getBitmap = map2<'a, 'b, int> (Map.choose2Bitmap predicate) clContext workGroupSize @@ -830,7 +873,7 @@ module ClArray = None let private bound<'a, 'b when 'a: equality and 'a: comparison> - (lowerBound: Expr<(int -> 'a -> ClArray<'a> -> 'b)>) + (lowerBound: Expr 'a -> ClArray<'a> -> 'b>) (clContext: ClContext) workGroupSize = @@ -860,9 +903,24 @@ module ClArray = result + /// + /// Finds the position of the largest value and the value itself + /// that is less than the given one. + /// + /// + /// Array of values should be sorted. + /// + /// OpenCL context. let upperBoundAndValue<'a when 'a: comparison> clContext = bound<'a, int * 'a> Search.Bin.lowerBoundAndValue clContext + /// + /// Finds the position of the largest value that is less than the given one. + /// + /// + /// Array of values should be sorted. + /// + /// OpenCL context. let upperBound<'a when 'a: comparison> clContext = bound<'a, int> Search.Bin.lowerBound clContext diff --git a/src/GraphBLAS-sharp.Backend/Common/Common.fs b/src/GraphBLAS-sharp.Backend/Common/Common.fs index 8576fe78..e497a61f 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Common.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Common.fs @@ -6,11 +6,52 @@ open GraphBLAS.FSharp.Backend.Common module Common = module Bitonic = + /// + /// Sorts in-place input array of values by their 2d indices, + /// which are stored in two given arrays of keys: rows and columns. + /// When comparing, it first looks at rows, then columns. + /// + /// + /// + /// let rows = [| 0; 0; 3; 2; 1; 0; 5 |] + /// let columns = [| 0; 2; 1; 2; 0; 3; 5; |] + /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; |] + /// sortKeyValuesInplace clContext 32 processor rows columns values + /// ... + /// > val rows = [| 0; 0; 0; 1; 2; 3; 5 |] + /// > let columns = [| 0; 2; 3; 0; 2; 1; 5; |] + /// > val values = [| 1.9; 2.8; 6.4; 5.5; 4.6; 3.7; 7.3 |] + /// + /// let sortKeyValuesInplace = Sort.Bitonic.sortKeyValuesInplace module Radix = + /// + /// Sorts stable input array of values by given integer keys. + /// + /// + /// + /// let keys = [| 0; 4; 3; 1; 2; 6; 5 |] + /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; |] + /// runByKeysStandard clContext 32 processor keys values + /// ... + /// > val keys = [| 0; 1; 2; 3; 4; 5; 6 |] + /// > val values = [| 1.9; 4.6; 5.5; 3.7; 2.8; 7.3; 6.4 |] + /// + /// let runByKeysStandard = Sort.Radix.runByKeysStandard + /// + /// Sorts stable input array of integer keys. + /// + /// + /// + /// let keys = [| 0; 4; 3; 1; 2; 6; 5 |] + /// standardRunKeysOnly clContext 32 processor keys + /// ... + /// > val keys = [| 0; 1; 2; 3; 4; 5; 6 |] + /// + /// let standardRunKeysOnly = Sort.Radix.standardRunKeysOnly module Gather = @@ -53,7 +94,8 @@ module Common = module Scatter = /// - /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array + /// Creates a new array from the given one where it is indicated + /// by the array of positions at which position in the new array /// should be a value from the given one. /// /// @@ -135,18 +177,68 @@ module Common = let initLastOccurrence valueMap = Scatter.initLastOccurrence valueMap module PrefixSum = + /// + /// Exclude in-place prefix sum. + /// + /// + /// + /// let arr = [| 1; 1; 1; 1 |] + /// let sum = [| 0 |] + /// runExcludeInplace clContext workGroupSize processor arr sum (+) 0 + /// |> ignore + /// ... + /// > val arr = [| 0; 1; 2; 3 |] + /// > val sum = [| 4 |] + /// + /// + /// ClContext. + /// Should be a power of 2 and greater than 1. + /// Associative binary operation. + /// Zero element for binary operation. let runExcludeInPlace plus = PrefixSum.runExcludeInPlace plus + /// + /// Include in-place prefix sum. + /// + /// + /// + /// let arr = [| 1; 1; 1; 1 |] + /// let sum = [| 0 |] + /// runExcludeInplace clContext workGroupSize processor arr sum (+) 0 + /// |> ignore + /// ... + /// > val arr = [| 0; 1; 2; 3 |] + /// > val sum = [| 4 |] + /// + /// + /// ClContext. + /// Should be a power of 2 and greater than 1. + /// Associative binary operation. + /// Zero element for binary operation. let runIncludeInPlace plus = PrefixSum.runIncludeInPlace plus + /// + /// Exclude in-place prefix sum. Array is scanned starting from the end. + /// + /// ClContext. + /// Should be a power of 2 and greater than 1. + /// Associative binary operation. + /// Zero element for binary operation. let runBackwardsExcludeInPlace plus = PrefixSum.runBackwardsExcludeInPlace plus + /// + /// Include in-place prefix sum. Array is scanned starting from the end. + /// + /// ClContext. + /// Should be a power of 2 and greater than 1. + /// Associative binary operation. + /// Zero element for binary operation. let runBackwardsIncludeInPlace plus = PrefixSum.runBackwardsIncludeInPlace plus /// - /// Exclude inplace prefix sum. + /// Exclude in-place prefix sum of integer array with addition operation and start value that is equal to 0. /// /// /// @@ -159,10 +251,8 @@ module Common = /// > val sum = [| 4 |] /// /// - ///ClContext. - ///Should be a power of 2 and greater than 1. - ///Associative binary operation. - ///Zero element for binary operation. + /// ClContext. + /// Should be a power of 2 and greater than 1. let standardExcludeInPlace (clContext: ClContext) workGroupSize = let scan = @@ -173,23 +263,21 @@ module Common = scan processor inputArray 0 /// - /// Include inplace prefix sum. + /// Include in-place prefix sum of integer array with addition operation and start value that is equal to 0. /// /// /// /// let arr = [| 1; 1; 1; 1 |] /// let sum = [| 0 |] - /// runExcludeInplace clContext workGroupSize processor arr sum (+) 0 + /// runIncludeInplace clContext workGroupSize processor arr sum (+) 0 /// |> ignore /// ... /// > val arr = [| 1; 2; 3; 4 |] /// > val sum = [| 4 |] /// /// - ///ClContext. - ///Should be a power of 2 and greater than 1. - ///Associative binary operation. - ///Zero element for binary operation. + /// ClContext. + /// Should be a power of 2 and greater than 1. let standardIncludeInPlace (clContext: ClContext) workGroupSize = let scan = diff --git a/src/GraphBLAS-sharp.Backend/Quotes/Arithmetic.fs b/src/GraphBLAS-sharp.Backend/Quotes/Arithmetic.fs index 3430f373..f79a2193 100644 --- a/src/GraphBLAS-sharp.Backend/Quotes/Arithmetic.fs +++ b/src/GraphBLAS-sharp.Backend/Quotes/Arithmetic.fs @@ -3,7 +3,7 @@ open GraphBLAS.FSharp.Objects module ArithmeticOperations = - let inline mkUnaryOp zero unaryOp = + let inline private mkUnaryOp zero unaryOp = <@ fun x -> let mutable res = zero @@ -13,7 +13,7 @@ module ArithmeticOperations = if res = zero then None else Some res @> - let inline mkNumericSum zero = + let inline private mkNumericSum zero = <@ fun (x: 't option) (y: 't option) -> let mutable res = zero @@ -25,7 +25,7 @@ module ArithmeticOperations = if res = zero then None else Some res @> - let inline mkNumericSumAtLeastOne zero = + let inline private mkNumericSumAtLeastOne zero = <@ fun (values: AtLeastOne<'t, 't>) -> let mutable res = zero @@ -36,7 +36,7 @@ module ArithmeticOperations = if res = zero then None else Some res @> - let inline mkNumericMul zero = + let inline private mkNumericMul zero = <@ fun (x: 't option) (y: 't option) -> let mutable res = zero @@ -46,7 +46,7 @@ module ArithmeticOperations = if res = zero then None else Some res @> - let inline mkNumericMulAtLeastOne zero = + let inline private mkNumericMulAtLeastOne zero = <@ fun (values: AtLeastOne<'t, 't>) -> let mutable res = zero @@ -197,7 +197,7 @@ module ArithmeticOperations = else Some result - let inline createPair zero op opQ = binOpQ zero opQ, binOp zero op + let inline private createPair zero op opQ = binOpQ zero opQ, binOp zero op // addition let intAdd = createPair 0 (+) <@ (+) @> diff --git a/src/GraphBLAS-sharp.Backend/Quotes/Search.fs b/src/GraphBLAS-sharp.Backend/Quotes/Search.fs index d2ea346a..c56bf6f7 100644 --- a/src/GraphBLAS-sharp.Backend/Quotes/Search.fs +++ b/src/GraphBLAS-sharp.Backend/Quotes/Search.fs @@ -5,8 +5,10 @@ open Brahma.FSharp module Search = module Bin = /// - /// Searches a section of the array of indices, bounded by the given left and right edges, for an index, using a binary search algorithm. - /// In case searched section contains source index, the value at the same position in the array of values is returned. + /// Searches a section of the array of indices, bounded by the given left and right edges, + /// for an index, using a binary search algorithm. + /// In case searched section contains source index, + /// the value at the same position in the array of values is returned. /// /// /// Searched section of index array should be sorted in ascending order. @@ -42,10 +44,10 @@ module Search = /// In case there is a value at the given key position, it is returned. /// let byKey<'a> = - <@ fun lenght sourceIndex (keys: ClArray) (values: ClArray<'a>) -> + <@ fun length sourceIndex (keys: ClArray) (values: ClArray<'a>) -> let mutable leftEdge = 0 - let mutable rightEdge = lenght - 1 + let mutable rightEdge = length - 1 let mutable result = None @@ -69,10 +71,10 @@ module Search = /// In case there is a value at the given keys position, it is returned. /// let byKey2D<'a> = - <@ fun lenght sourceIndex (rowIndices: ClArray) (columnIndices: ClArray) (values: ClArray<'a>) -> + <@ fun length sourceIndex (rowIndices: ClArray) (columnIndices: ClArray) (values: ClArray<'a>) -> let mutable leftEdge = 0 - let mutable rightEdge = lenght - 1 + let mutable rightEdge = length - 1 let mutable result = None @@ -98,10 +100,10 @@ module Search = /// Find lower position of item in array. /// let lowerPosition<'a when 'a: equality and 'a: comparison> = - <@ fun lenght sourceItem (keys: 'a []) -> + <@ fun length sourceItem (keys: 'a []) -> let mutable leftEdge = 0 - let mutable rightEdge = lenght - 1 + let mutable rightEdge = length - 1 let mutable resultPosition = None @@ -138,15 +140,15 @@ module Search = /// /// let lowerBound<'a when 'a: comparison> = - <@ fun lenght sourceItem (keys: ClArray<'a>) -> + <@ fun length sourceItem (keys: ClArray<'a>) -> let mutable leftEdge = 0 - let mutable rightEdge = lenght - 1 + let mutable rightEdge = length - 1 let mutable resultPosition = 0 - if sourceItem >= keys.[lenght - 1] then - lenght - 1 + if sourceItem >= keys.[length - 1] then + length - 1 else while leftEdge <= rightEdge do let currentPosition = (leftEdge + rightEdge) / 2 @@ -164,15 +166,15 @@ module Search = let lowerBoundAndValue<'a when 'a: comparison> = let defaultValue = Unchecked.defaultof<'a> - <@ fun lenght sourceItem (keys: ClArray<'a>) -> + <@ fun length sourceItem (keys: ClArray<'a>) -> let mutable leftEdge = 0 - let mutable rightEdge = lenght - 1 + let mutable rightEdge = length - 1 let mutable resultPosition = 0, defaultValue - if sourceItem >= keys.[lenght - 1] then - (lenght - 1), keys.[lenght - 1] + if sourceItem >= keys.[length - 1] then + (length - 1), keys.[length - 1] else while leftEdge <= rightEdge do let currentPosition = (leftEdge + rightEdge) / 2 diff --git a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs index 80e7895c..b71dae4f 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs @@ -8,7 +8,6 @@ open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVector open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Backend.Vector.Sparse module Vector = let copy (clContext: ClContext) workGroupSize = diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs index 00a85449..caa86e58 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/ByRows.fs @@ -1,4 +1,4 @@ -module GraphBLAS.FSharp.Tests.Matrix.ByRows +module GraphBLAS.FSharp.Tests.Backend.Matrix.ByRows open Expecto open GraphBLAS.FSharp.Tests diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Merge.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Merge.fs index 0639c4d9..554fbff2 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Merge.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Merge.fs @@ -1,4 +1,4 @@ -module GraphBLAS.FSharp.Tests.Matrix.Merge +module GraphBLAS.FSharp.Tests.Backend.Matrix.Merge open Brahma.FSharp open Expecto diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs index 77c4994f..423441f4 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs @@ -1,4 +1,4 @@ -module GraphBLAS.FSharp.Tests.Matrix.SpGeMM.Expand +module GraphBLAS.FSharp.Tests.Backend.Matrix.SpGeMM.Expand open Expecto open Microsoft.FSharp.Collections diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Merge.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Merge.fs index 36594743..ae363e78 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Merge.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Merge.fs @@ -1,4 +1,4 @@ -module GraphBLAS.FSharp.Tests.Vector.Merge +module GraphBLAS.FSharp.Tests.Backend.Vector.Merge open Brahma.FSharp open Expecto diff --git a/tests/GraphBLAS-sharp.Tests/Program.fs b/tests/GraphBLAS-sharp.Tests/Program.fs index 1bcc04d3..864c59fb 100644 --- a/tests/GraphBLAS-sharp.Tests/Program.fs +++ b/tests/GraphBLAS-sharp.Tests/Program.fs @@ -1,6 +1,6 @@ open Expecto -open GraphBLAS.FSharp.Tests.Backend open GraphBLAS.FSharp.Tests +open GraphBLAS.FSharp.Tests.Backend let matrixTests = testList From be8c888d32bcfcd3248ff8b3fcd45e8ab31d8c10 Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Sun, 23 Jul 2023 02:09:02 +0700 Subject: [PATCH 05/22] refactor: namespace/module names --- .../Algorithms/BFS.fs | 6 +- .../Matrix/Map2/Map2.fs | 20 ++--- .../Matrix/SpGeMM/Expand.fs | 4 +- .../Matrix/SpGeMM/Masked.fs | 13 ++- .../GraphBLAS-sharp.Benchmarks/Vector/Map2.fs | 18 ++--- .../Algorithms/Algorithms.fs | 2 + src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs | 3 +- src/GraphBLAS-sharp.Backend/Common/ClArray.fs | 1 + src/GraphBLAS-sharp.Backend/Common/Common.fs | 1 + .../Matrix/COO/Matrix.fs | 5 +- .../Matrix/CSR/Matrix.fs | 1 - src/GraphBLAS-sharp.Backend/Matrix/Common.fs | 14 ++-- src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs | 1 + .../Operations/Kronecker.fs | 7 +- .../Operations/Operations.fs | 1 + .../Operations/SpGeMM/Expand.fs | 43 +++++----- .../Operations/SpGeMM/Masked.fs | 8 +- .../Operations/SpMV.fs | 2 +- .../Vector/Dense/Vector.fs | 9 +-- .../Vector/Sparse/Common.fs | 13 ++- .../Vector/Sparse/Vector.fs | 3 +- src/GraphBLAS-sharp.Backend/Vector/Vector.fs | 4 +- .../Backend/Common/ClArray/Blit.fs | 1 - .../Backend/Common/ClArray/Concat.fs | 1 - .../Backend/Common/Gather.fs | 32 ++++---- .../Backend/Common/Reduce/Reduce.fs | 5 +- .../Backend/Common/Reduce/ReduceByKey.fs | 16 ++-- .../Backend/Common/Reduce/Sum.fs | 4 +- .../Backend/Common/Scan/ByKey.fs | 22 ++--- .../Backend/Common/Scan/PrefixSum.fs | 3 +- .../Backend/Common/Scatter.fs | 13 ++- .../Backend/Common/Sort/Bitonic.fs | 4 +- .../Backend/Common/Sort/Radix.fs | 6 +- .../Backend/Matrix/Kronecker.fs | 4 +- .../Backend/Matrix/Map2.fs | 31 ++++--- .../Backend/Matrix/SpGeMM/Expand.fs | 9 +-- .../Backend/Matrix/SpGeMM/Masked.fs | 6 +- .../Backend/Vector/Copy.fs | 2 - .../Backend/Vector/Map2.fs | 81 +++++++++++++------ .../Backend/Vector/SpMV.fs | 4 +- 40 files changed, 224 insertions(+), 199 deletions(-) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs index ca2f9a07..ade88c58 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs @@ -4,8 +4,8 @@ open System.IO open BenchmarkDotNet.Attributes open Microsoft.FSharp.Core open Brahma.FSharp +open GraphBLAS.FSharp open GraphBLAS.FSharp.IO -open GraphBLAS.FSharp.Algorithms open GraphBLAS.FSharp.Benchmarks open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ArraysExtensions @@ -127,7 +127,7 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>( type BFSWithoutTransferBenchmarkInt32() = inherit WithoutTransferBenchmark( - (singleSourceBFS ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption), + (Algorithms.singleSourceBFS ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption), int32, (fun _ -> Utils.nextInt (System.Random())), 0, @@ -173,7 +173,7 @@ type WithTransferBenchmark<'elem when 'elem : struct>( type BFSWithTransferBenchmarkInt32() = inherit WithTransferBenchmark( - (singleSourceBFS ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption), + (Algorithms.singleSourceBFS ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption), int32, (fun _ -> Utils.nextInt (System.Random())), 0, diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs index 144d7552..975e8a72 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs @@ -3,8 +3,8 @@ namespace GraphBLAS.FSharp.Benchmarks.Matrix.Map2 open System.IO open BenchmarkDotNet.Attributes open Brahma.FSharp +open GraphBLAS.FSharp open GraphBLAS.FSharp.IO -open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.MatrixExtensions open GraphBLAS.FSharp.Objects.ClContextExtensions @@ -137,7 +137,7 @@ module WithoutTransfer = type Float32() = inherit Benchmark,float32>( - (Matrix.map2 ArithmeticOperations.float32SumOption), + (Operations.Matrix.map2 ArithmeticOperations.float32SumOption), float32, (fun _ -> Utils.nextSingle (System.Random())), Matrix.COO @@ -149,7 +149,7 @@ module WithoutTransfer = type Bool() = inherit Benchmark,bool>( - (Matrix.map2 ArithmeticOperations.boolSumOption), + (Operations.Matrix.map2 ArithmeticOperations.boolSumOption), (fun _ -> true), (fun _ -> true), Matrix.COO @@ -162,7 +162,7 @@ module WithoutTransfer = type Float32() = inherit Benchmark,float32>( - (Matrix.map2 ArithmeticOperations.float32SumOption), + (Operations.Matrix.map2 ArithmeticOperations.float32SumOption), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun matrix -> Matrix.CSR matrix.ToCSR) @@ -174,7 +174,7 @@ module WithoutTransfer = type Bool() = inherit Benchmark,bool>( - (Matrix.map2 ArithmeticOperations.boolSumOption), + (Operations.Matrix.map2 ArithmeticOperations.boolSumOption), (fun _ -> true), (fun _ -> true), (fun matrix -> Matrix.CSR matrix.ToCSR) @@ -188,7 +188,7 @@ module WithoutTransfer = type Bool() = inherit Benchmark,bool>( - (Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne), + (Operations.Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne), (fun _ -> true), (fun _ -> true), Matrix.COO @@ -200,7 +200,7 @@ module WithoutTransfer = type Float32() = inherit Benchmark,float32>( - (Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne), + (Operations.Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne), float32, (fun _ -> Utils.nextSingle (System.Random())), Matrix.COO @@ -213,7 +213,7 @@ module WithoutTransfer = type Bool() = inherit Benchmark,bool>( - (Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne), + (Operations.Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne), (fun _ -> true), (fun _ -> true), (fun matrix -> Matrix.CSR matrix.ToCSR) @@ -225,7 +225,7 @@ module WithoutTransfer = type Float32() = inherit Benchmark,float32>( - (Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne), + (Operations.Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun matrix -> Matrix.CSR matrix.ToCSR) @@ -272,7 +272,7 @@ module WithTransfer = type Float32() = inherit Benchmark,float32>( - (Matrix.map2 ArithmeticOperations.float32SumOption), + (Operations.Matrix.map2 ArithmeticOperations.float32SumOption), float32, (fun _ -> Utils.nextSingle (System.Random())), Matrix.COO, diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs index 5c1110da..0eb398cd 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs @@ -3,8 +3,8 @@ module GraphBLAS.FSharp.Benchmarks.Matrix.SpGeMM.Expand open System.IO open BenchmarkDotNet.Attributes open Brahma.FSharp +open GraphBLAS.FSharp open GraphBLAS.FSharp.IO -open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClContextExtensions @@ -137,7 +137,7 @@ module WithoutTransfer = type Float32() = inherit Benchmark( - SpGeMM.expand (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), + Operations.SpGeMM.expand (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs index 936ab398..69f0c399 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs @@ -6,7 +6,6 @@ open GraphBLAS.FSharp.IO open BenchmarkDotNet.Attributes open Brahma.FSharp open GraphBLAS.FSharp -open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Benchmarks @@ -203,7 +202,7 @@ type MxmBenchmarksWithTransposing<'elem when 'elem : struct>( type Mxm4Float32MultiplicationOnlyBenchmark() = inherit MxmBenchmarksMultiplicationOnly( - SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), + Operations.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) @@ -215,7 +214,7 @@ type Mxm4Float32MultiplicationOnlyBenchmark() = type Mxm4Float32WithTransposingBenchmark() = inherit MxmBenchmarksWithTransposing( - SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), + Operations.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) @@ -227,7 +226,7 @@ type Mxm4Float32WithTransposingBenchmark() = type Mxm4BoolMultiplicationOnlyBenchmark() = inherit MxmBenchmarksMultiplicationOnly( - (SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)), + (Operations.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)), (fun _ -> true), (fun _ -> true), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) @@ -239,7 +238,7 @@ type Mxm4BoolMultiplicationOnlyBenchmark() = type Mxm4BoolWithTransposingBenchmark() = inherit MxmBenchmarksWithTransposing( - (SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)), + (Operations.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)), (fun _ -> true), (fun _ -> true), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) @@ -251,7 +250,7 @@ type Mxm4BoolWithTransposingBenchmark() = type Mxm4Float32MultiplicationOnlyWithZerosFilterBenchmark() = inherit MxmBenchmarksMultiplicationOnly( - (SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul)), + (Operations.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul)), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) @@ -263,7 +262,7 @@ type Mxm4Float32MultiplicationOnlyWithZerosFilterBenchmark() = type Mxm4Float32WithTransposingWithZerosFilterBenchmark() = inherit MxmBenchmarksWithTransposing( - SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), + Operations.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul), float32, (fun _ -> Utils.nextSingle (System.Random())), (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs index 6ee7ce7f..d4e0078c 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs @@ -4,7 +4,7 @@ open FsCheck open BenchmarkDotNet.Attributes open Brahma.FSharp open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Operations +open GraphBLAS.FSharp open GraphBLAS.FSharp.Benchmarks open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Objects @@ -120,26 +120,26 @@ module WithoutTransfer = type Float() = inherit Benchmark( - (Vector.map2 ArithmeticOperations.floatSumOption), + (Operations.Vector.map2 ArithmeticOperations.floatSumOption), VectorGenerator.floatPair Sparse) type Int32() = inherit Benchmark( - (Vector.map2 ArithmeticOperations.intSumOption), + (Operations.Vector.map2 ArithmeticOperations.intSumOption), VectorGenerator.intPair Sparse) module AtLeastOne = type Float() = inherit Benchmark( - (Vector.map2AtLeastOne ArithmeticOperations.floatSumAtLeastOne), + (Operations.Vector.map2AtLeastOne ArithmeticOperations.floatSumAtLeastOne), VectorGenerator.floatPair Sparse) type Int32() = inherit Benchmark( - (Vector.map2AtLeastOne ArithmeticOperations.intSumAtLeastOne), + (Operations.Vector.map2AtLeastOne ArithmeticOperations.intSumAtLeastOne), VectorGenerator.intPair Sparse) module WithTransfer = @@ -176,24 +176,24 @@ module WithTransfer = type Float() = inherit Benchmark( - (Vector.map2 ArithmeticOperations.floatSumOption), + (Operations.Vector.map2 ArithmeticOperations.floatSumOption), VectorGenerator.floatPair Sparse) type Int32() = inherit Benchmark( - (Vector.map2 ArithmeticOperations.intSumOption), + (Operations.Vector.map2 ArithmeticOperations.intSumOption), VectorGenerator.intPair Sparse) module AtLeastOne = type Float() = inherit Benchmark( - (Vector.map2AtLeastOne ArithmeticOperations.floatSumAtLeastOne), + (Operations.Vector.map2AtLeastOne ArithmeticOperations.floatSumAtLeastOne), VectorGenerator.floatPair Sparse) type Int32() = inherit Benchmark( - (Vector.map2AtLeastOne ArithmeticOperations.intSumAtLeastOne), + (Operations.Vector.map2AtLeastOne ArithmeticOperations.intSumAtLeastOne), VectorGenerator.intPair Sparse) diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs b/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs index e45bbc3a..2f442e81 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs @@ -1,6 +1,8 @@ namespace GraphBLAS.FSharp +open Microsoft.FSharp.Core open GraphBLAS.FSharp.Backend.Algorithms +[] module Algorithms = let singleSourceBFS = BFS.singleSource diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs b/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs index 30ecf994..de7f0cc8 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs @@ -5,7 +5,6 @@ open FSharp.Quotations open GraphBLAS.FSharp open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Backend.Vector.Dense open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.ArraysExtensions @@ -20,7 +19,7 @@ module internal BFS = = let spMVTo = - SpMVInplace add mul clContext workGroupSize + Operations.SpMVInplace add mul clContext workGroupSize let zeroCreate = ClArray.zeroCreate clContext workGroupSize diff --git a/src/GraphBLAS-sharp.Backend/Common/ClArray.fs b/src/GraphBLAS-sharp.Backend/Common/ClArray.fs index 3ff13094..c983415a 100644 --- a/src/GraphBLAS-sharp.Backend/Common/ClArray.fs +++ b/src/GraphBLAS-sharp.Backend/Common/ClArray.fs @@ -8,6 +8,7 @@ open GraphBLAS.FSharp.Objects.ArraysExtensions open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.ClCellExtensions +[] module ClArray = /// /// Creates an array given the dimension and a generator function to compute the elements. diff --git a/src/GraphBLAS-sharp.Backend/Common/Common.fs b/src/GraphBLAS-sharp.Backend/Common/Common.fs index e497a61f..ee06f56e 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Common.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Common.fs @@ -4,6 +4,7 @@ open Brahma.FSharp open Microsoft.FSharp.Quotations open GraphBLAS.FSharp.Backend.Common +[] module Common = module Bitonic = /// diff --git a/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs b/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs index 38c70060..c0cebacc 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs @@ -2,7 +2,6 @@ namespace GraphBLAS.FSharp.Backend.Matrix.COO open Brahma.FSharp open GraphBLAS.FSharp -open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Backend.Quotes open Microsoft.FSharp.Quotations open GraphBLAS.FSharp.Objects @@ -63,7 +62,7 @@ module Matrix = let create = ClArray.create clContext workGroupSize let scan = - PrefixSum.runBackwardsIncludeInPlace <@ min @> clContext workGroupSize + Common.PrefixSum.runBackwardsIncludeInPlace <@ min @> clContext workGroupSize fun (processor: MailboxProcessor<_>) allocationMode (rowIndices: ClArray) rowCount -> @@ -125,7 +124,7 @@ module Matrix = let transposeInPlace (clContext: ClContext) workGroupSize = let sort = - Bitonic.sortKeyValuesInplace clContext workGroupSize + Common.Bitonic.sortKeyValuesInplace clContext workGroupSize fun (queue: MailboxProcessor<_>) (matrix: ClMatrix.COO<'a>) -> sort queue matrix.Columns matrix.Rows matrix.Values diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs index 30fc2ddc..f0fc9f32 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs @@ -11,7 +11,6 @@ open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.ClVector open GraphBLAS.FSharp.Objects.ArraysExtensions - module Matrix = let expandRowPointers (clContext: ClContext) workGroupSize = diff --git a/src/GraphBLAS-sharp.Backend/Matrix/Common.fs b/src/GraphBLAS-sharp.Backend/Matrix/Common.fs index 604e1d72..e13b889e 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/Common.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/Common.fs @@ -1,7 +1,7 @@ namespace GraphBLAS.FSharp.Backend.Matrix open Brahma.FSharp -open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.ClCellExtensions @@ -11,13 +11,13 @@ module internal Common = let setPositions<'a when 'a: struct> (clContext: ClContext) workGroupSize = let indicesScatter = - Scatter.lastOccurrence clContext workGroupSize + Common.Scatter.lastOccurrence clContext workGroupSize let valuesScatter = - Scatter.lastOccurrence clContext workGroupSize + Common.Scatter.lastOccurrence clContext workGroupSize let sum = - PrefixSum.standardExcludeInPlace clContext workGroupSize + Common.PrefixSum.standardExcludeInPlace clContext workGroupSize fun (processor: MailboxProcessor<_>) allocationMode (allRows: ClArray) (allColumns: ClArray) (allValues: ClArray<'a>) (positions: ClArray) -> @@ -46,13 +46,13 @@ module internal Common = let setPositionsOption<'a when 'a: struct> (clContext: ClContext) workGroupSize = let indicesScatter = - Scatter.lastOccurrence clContext workGroupSize + Common.Scatter.lastOccurrence clContext workGroupSize let valuesScatter = - Scatter.lastOccurrence clContext workGroupSize + Common.Scatter.lastOccurrence clContext workGroupSize let sum = - PrefixSum.standardExcludeInPlace clContext workGroupSize + Common.PrefixSum.standardExcludeInPlace clContext workGroupSize fun (processor: MailboxProcessor<_>) allocationMode (allRows: ClArray) (allColumns: ClArray) (allValues: ClArray<'a>) (positions: ClArray) -> diff --git a/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs b/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs index 2d479f87..736c2951 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs @@ -8,6 +8,7 @@ open GraphBLAS.FSharp.Backend.Vector open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClMatrix +[] module Matrix = /// /// Creates new matrix with the values from the given one. diff --git a/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs b/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs index f9e60097..0343ddc3 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs @@ -5,7 +5,6 @@ open Microsoft.FSharp.Quotations open FSharp.Quotations.Evaluator.QuotationEvaluationExtensions open Brahma.FSharp open GraphBLAS.FSharp -open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Backend.Matrix.COO open GraphBLAS.FSharp.Backend.Matrix.CSR @@ -68,7 +67,7 @@ module internal Kronecker = let updateBitmap = updateBitmap clContext workGroupSize op let sum = - Reduce.sum <@ fun x y -> x + y @> 0 clContext workGroupSize + Common.Reduce.sum <@ fun x y -> x + y @> 0 clContext workGroupSize let item = ClArray.item clContext workGroupSize @@ -192,7 +191,7 @@ module internal Kronecker = let kernel = clContext.Compile <| setPositions let scan = - PrefixSum.standardIncludeInPlace clContext workGroupSize + Common.PrefixSum.standardIncludeInPlace clContext workGroupSize fun (processor: MailboxProcessor<_>) rowCount columnCount (rowOffset: int) (columnOffset: int) (startIndex: int) (resultMatrix: COO<'c>) (values: ClArray<'c>) (bitmap: ClArray) -> @@ -431,7 +430,7 @@ module internal Kronecker = let mapAll = mapAll clContext workGroupSize op let bitonic = - Bitonic.sortKeyValuesInplace clContext workGroupSize + Common.Bitonic.sortKeyValuesInplace clContext workGroupSize fun (queue: MailboxProcessor<_>) allocationMode (matrixLeft: CSR<'a>) (matrixRight: CSR<'b>) -> diff --git a/src/GraphBLAS-sharp.Backend/Operations/Operations.fs b/src/GraphBLAS-sharp.Backend/Operations/Operations.fs index 4e5ac9c7..d086ffd2 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/Operations.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/Operations.fs @@ -8,6 +8,7 @@ open GraphBLAS.FSharp.Backend.Matrix open GraphBLAS.FSharp.Backend.Vector open GraphBLAS.FSharp.Backend.Operations +[] module Operations = module Vector = /// diff --git a/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs index 1bb100d6..c67be18b 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs @@ -3,7 +3,7 @@ namespace GraphBLAS.FSharp.Backend.Operations.SpGeMM open Brahma.FSharp open FSharp.Quotations open GraphBLAS.FSharp -open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClMatrix open GraphBLAS.FSharp.Objects.ClCellExtensions @@ -15,10 +15,11 @@ open GraphBLAS.FSharp.Backend.Quotes module internal Expand = let getSegmentPointers (clContext: ClContext) workGroupSize = - let gather = Gather.run clContext workGroupSize + let gather = + Common.Gather.run clContext workGroupSize let prefixSum = - PrefixSum.standardExcludeInPlace clContext workGroupSize + Common.PrefixSum.standardExcludeInPlace clContext workGroupSize fun (processor: MailboxProcessor<_>) (leftMatrixColumns: ClArray) (rightMatrixRowsLengths: ClArray) -> @@ -40,13 +41,13 @@ module internal Expand = ClArray.map2<'a, 'b, int> (Map.choose2Bitmap predicate) clContext workGroupSize let prefixSum = - PrefixSum.standardExcludeInPlace clContext workGroupSize + Common.PrefixSum.standardExcludeInPlace clContext workGroupSize let assignValues = ClArray.assignOption2 predicate clContext workGroupSize let scatter = - Scatter.lastOccurrence clContext workGroupSize + Common.Scatter.lastOccurrence clContext workGroupSize fun (processor: MailboxProcessor<_>) (firstValues: ClArray<'a>) (secondValues: ClArray<'b>) (columns: ClArray) (rows: ClArray) -> @@ -84,30 +85,33 @@ module internal Expand = let expand (clContext: ClContext) workGroupSize = let idScatter = - Scatter.initLastOccurrence Map.id clContext workGroupSize + Common.Scatter.initLastOccurrence Map.id clContext workGroupSize let scatter = - Scatter.lastOccurrence clContext workGroupSize + Common.Scatter.lastOccurrence clContext workGroupSize let zeroCreate = ClArray.zeroCreate clContext workGroupSize let maxPrefixSum = - PrefixSum.runIncludeInPlace <@ max @> clContext workGroupSize + Common.PrefixSum.runIncludeInPlace <@ max @> clContext workGroupSize let create = ClArray.create clContext workGroupSize - let gather = Gather.run clContext workGroupSize + let gather = + Common.Gather.run clContext workGroupSize let segmentPrefixSum = - PrefixSum.ByKey.sequentialInclude <@ (+) @> 0 clContext workGroupSize + Common.PrefixSum.ByKey.sequentialInclude <@ (+) @> 0 clContext workGroupSize let removeDuplicates = ClArray.removeDuplications clContext workGroupSize - let leftMatrixGather = Gather.run clContext workGroupSize + let leftMatrixGather = + Common.Gather.run clContext workGroupSize - let rightMatrixGather = Gather.run clContext workGroupSize + let rightMatrixGather = + Common.Gather.run clContext workGroupSize fun (processor: MailboxProcessor<_>) (lengths: int) (segmentsPointers: ClArray) (leftMatrix: ClMatrix.COO<'a>) (rightMatrix: ClMatrix.CSR<'b>) -> // Compute left matrix positions @@ -171,13 +175,13 @@ module internal Expand = let sortByColumnsAndRows (clContext: ClContext) workGroupSize = let sortByKeyIndices = - Radix.runByKeysStandard clContext workGroupSize + Common.Radix.runByKeysStandard clContext workGroupSize let sortByKeyValues = - Radix.runByKeysStandard clContext workGroupSize + Common.Radix.runByKeysStandard clContext workGroupSize let sortKeys = - Radix.standardRunKeysOnly clContext workGroupSize + Common.Radix.standardRunKeysOnly clContext workGroupSize fun (processor: MailboxProcessor<_>) (values: ClArray<'a>) (columns: ClArray) (rows: ClArray) -> // sort by columns @@ -207,16 +211,16 @@ module internal Expand = let reduce opAdd (clContext: ClContext) workGroupSize = let reduce = - Reduce.ByKey2D.Option.segmentSequential opAdd clContext workGroupSize + Common.Reduce.ByKey2D.Option.segmentSequential opAdd clContext workGroupSize let getUniqueBitmap = ClArray.Bitmap.lastOccurrence2 clContext workGroupSize let prefixSum = - PrefixSum.standardExcludeInPlace clContext workGroupSize + Common.PrefixSum.standardExcludeInPlace clContext workGroupSize let idScatter = - Scatter.initFirstOccurrence Map.id clContext workGroupSize + Common.Scatter.initFirstOccurrence Map.id clContext workGroupSize fun (processor: MailboxProcessor<_>) allocationMode (values: ClArray<'a>) (columns: ClArray) (rows: ClArray) -> @@ -343,7 +347,8 @@ module internal Expand = let runManySteps opAdd opMul (clContext: ClContext) workGroupSize = - let gather = Gather.run clContext workGroupSize + let gather = + Common.Gather.run clContext workGroupSize let upperBound = ClArray.upperBound clContext workGroupSize diff --git a/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Masked.fs b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Masked.fs index e86f3a8c..8c4e600a 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Masked.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Masked.fs @@ -1,8 +1,8 @@ namespace GraphBLAS.FSharp.Backend.Operations.SpGeMM -open GraphBLAS.FSharp.Common open Brahma.FSharp open Microsoft.FSharp.Quotations +open GraphBLAS.FSharp open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClMatrix open GraphBLAS.FSharp.Objects.ClContextExtensions @@ -152,13 +152,13 @@ module internal Masked = calculate opAdd opMul context workGroupSize let scatter = - Scatter.lastOccurrence context workGroupSize + Common.Scatter.lastOccurrence context workGroupSize let scatterData = - Scatter.lastOccurrence context workGroupSize + Common.Scatter.lastOccurrence context workGroupSize let scanInPlace = - PrefixSum.standardExcludeInPlace context workGroupSize + Common.PrefixSum.standardExcludeInPlace context workGroupSize fun (queue: MailboxProcessor<_>) (matrixLeft: ClMatrix.CSR<'a>) (matrixRight: ClMatrix.CSC<'b>) (mask: ClMatrix.COO<_>) -> diff --git a/src/GraphBLAS-sharp.Backend/Operations/SpMV.fs b/src/GraphBLAS-sharp.Backend/Operations/SpMV.fs index 91750728..34b5f821 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/SpMV.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/SpMV.fs @@ -1,8 +1,8 @@ namespace GraphBLAS.FSharp.Backend.Operations open Brahma.FSharp -open GraphBLAS.FSharp.Backend.Common open Microsoft.FSharp.Quotations +open GraphBLAS.FSharp.Backend.Common open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClContextExtensions diff --git a/src/GraphBLAS-sharp.Backend/Vector/Dense/Vector.fs b/src/GraphBLAS-sharp.Backend/Vector/Dense/Vector.fs index 6f3968c4..cbc515de 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Dense/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Dense/Vector.fs @@ -3,7 +3,6 @@ namespace GraphBLAS.FSharp.Backend.Vector.Dense open Brahma.FSharp open Microsoft.FSharp.Quotations open GraphBLAS.FSharp -open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Objects.ClVector open GraphBLAS.FSharp.Objects.ClContextExtensions @@ -101,16 +100,16 @@ module Vector = let toSparse<'a when 'a: struct> (clContext: ClContext) workGroupSize = let scatterValues = - Scatter.lastOccurrence clContext workGroupSize + Common.Scatter.lastOccurrence clContext workGroupSize let scatterIndices = - Scatter.lastOccurrence clContext workGroupSize + Common.Scatter.lastOccurrence clContext workGroupSize let getBitmap = ClArray.map (Map.option 1 0) clContext workGroupSize let prefixSum = - PrefixSum.standardExcludeInPlace clContext workGroupSize + Common.PrefixSum.standardExcludeInPlace clContext workGroupSize let allIndices = ClArray.init Map.id clContext workGroupSize @@ -160,7 +159,7 @@ module Vector = ClArray.choose Map.id clContext workGroupSize let reduce = - Reduce.reduce opAdd clContext workGroupSize + Common.Reduce.reduce opAdd clContext workGroupSize fun (processor: MailboxProcessor<_>) (vector: ClArray<'a option>) -> choose processor DeviceOnly vector diff --git a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Common.fs b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Common.fs index 465102d5..07e6e5e7 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Common.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Common.fs @@ -3,7 +3,6 @@ namespace GraphBLAS.FSharp.Backend.Vector.Sparse open Brahma.FSharp open Microsoft.FSharp.Control open GraphBLAS.FSharp -open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Objects.ClVector open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.ClCellExtensions @@ -12,13 +11,13 @@ module internal Common = let setPositions<'a when 'a: struct> (clContext: ClContext) workGroupSize = let sum = - PrefixSum.standardExcludeInPlace clContext workGroupSize + Common.PrefixSum.standardExcludeInPlace clContext workGroupSize let valuesScatter = - Scatter.lastOccurrence clContext workGroupSize + Common.Scatter.lastOccurrence clContext workGroupSize let indicesScatter = - Scatter.lastOccurrence clContext workGroupSize + Common.Scatter.lastOccurrence clContext workGroupSize fun (processor: MailboxProcessor<_>) allocationMode (allValues: ClArray<'a>) (allIndices: ClArray) (positions: ClArray) -> @@ -40,13 +39,13 @@ module internal Common = let setPositionsOption<'a when 'a: struct> (clContext: ClContext) workGroupSize = let sum = - PrefixSum.standardExcludeInPlace clContext workGroupSize + Common.PrefixSum.standardExcludeInPlace clContext workGroupSize let valuesScatter = - Scatter.lastOccurrence clContext workGroupSize + Common.Scatter.lastOccurrence clContext workGroupSize let indicesScatter = - Scatter.lastOccurrence clContext workGroupSize + Common.Scatter.lastOccurrence clContext workGroupSize fun (processor: MailboxProcessor<_>) allocationMode (allValues: ClArray<'a>) (allIndices: ClArray) (positions: ClArray) -> diff --git a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs index b71dae4f..fed8bad6 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs @@ -4,7 +4,6 @@ open Brahma.FSharp open Microsoft.FSharp.Control open Microsoft.FSharp.Quotations open GraphBLAS.FSharp -open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVector open GraphBLAS.FSharp.Backend.Quotes @@ -70,6 +69,6 @@ module Vector = let reduce<'a when 'a: struct> (opAdd: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = let reduce = - Reduce.reduce opAdd clContext workGroupSize + Common.Reduce.reduce opAdd clContext workGroupSize fun (processor: MailboxProcessor<_>) (vector: ClVector.Sparse<'a>) -> reduce processor vector.Values diff --git a/src/GraphBLAS-sharp.Backend/Vector/Vector.fs b/src/GraphBLAS-sharp.Backend/Vector/Vector.fs index b7375865..b19dc617 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Vector.fs @@ -4,13 +4,13 @@ open Brahma.FSharp open Microsoft.FSharp.Control open Microsoft.FSharp.Quotations open GraphBLAS.FSharp -open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.ClVector open GraphBLAS.FSharp.Backend.Quotes 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. @@ -44,7 +44,7 @@ module Vector = /// Should be a power of 2 and greater than 1. let ofList (clContext: ClContext) workGroupSize = let scatter = - Scatter.lastOccurrence clContext workGroupSize + Common.Scatter.lastOccurrence clContext workGroupSize let zeroCreate = ClArray.zeroCreate clContext workGroupSize diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Blit.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Blit.fs index f3548e1e..8387bdcc 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Blit.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Blit.fs @@ -3,7 +3,6 @@ module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.Blit open Expecto open Brahma.FSharp open GraphBLAS.FSharp -open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Objects.ArraysExtensions diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs index 3d7454d1..48dcb77c 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Concat.fs @@ -3,7 +3,6 @@ module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.Concat open Expecto open Brahma.FSharp open GraphBLAS.FSharp -open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Objects.ArraysExtensions open GraphBLAS.FSharp.Objects.ClContextExtensions diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs index 8c257be9..b82b65d6 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Gather.fs @@ -2,7 +2,7 @@ module GraphBLAS.FSharp.Tests.Backend.Common.Gather open Expecto open Microsoft.FSharp.Collections -open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Objects.ArraysExtensions open GraphBLAS.FSharp.Objects.ClContextExtensions @@ -55,14 +55,14 @@ let createTest<'a> (isEqual: 'a -> 'a -> bool) testFun = |> testPropertyWithConfig Utils.defaultConfig $"test on %A{typeof<'a>}" let tests = - [ createTest (=) Gather.run + [ createTest (=) Common.Gather.run if Utils.isFloat64Available context.ClDevice then - createTest Utils.floatIsEqual Gather.run + createTest Utils.floatIsEqual Common.Gather.run - createTest Utils.float32IsEqual Gather.run - createTest (=) Gather.run - createTest (=) Gather.run ] + createTest Utils.float32IsEqual Common.Gather.run + createTest (=) Common.Gather.run + createTest (=) Common.Gather.run ] |> testList "Gather" @@ -98,27 +98,27 @@ let createTestInit<'a> (isEqual: 'a -> 'a -> bool) testFun indexMapQ indexMap = let initTests = let idTests = - [ createTestInit (=) Gather.runInit Map.id id + [ createTestInit (=) Common.Gather.runInit Map.id id if Utils.isFloat64Available context.ClDevice then - createTestInit Utils.floatIsEqual Gather.runInit Map.id id + createTestInit Utils.floatIsEqual Common.Gather.runInit Map.id id - createTestInit Utils.float32IsEqual Gather.runInit Map.id id - createTestInit (=) Gather.runInit Map.id id - createTestInit (=) Gather.runInit Map.id id ] + createTestInit Utils.float32IsEqual Common.Gather.runInit Map.id id + createTestInit (=) Common.Gather.runInit Map.id id + createTestInit (=) Common.Gather.runInit Map.id id ] |> testList "id" let inc = ((+) 1) let incTests = - [ createTestInit (=) Gather.runInit Map.inc inc + [ createTestInit (=) Common.Gather.runInit Map.inc inc if Utils.isFloat64Available context.ClDevice then - createTestInit Utils.floatIsEqual Gather.runInit Map.inc inc + createTestInit Utils.floatIsEqual Common.Gather.runInit Map.inc inc - createTestInit Utils.float32IsEqual Gather.runInit Map.inc inc - createTestInit (=) Gather.runInit Map.inc inc - createTestInit (=) Gather.runInit Map.inc inc ] + createTestInit Utils.float32IsEqual Common.Gather.runInit Map.inc inc + createTestInit (=) Common.Gather.runInit Map.inc inc + createTestInit (=) Common.Gather.runInit Map.inc inc ] |> testList "inc" testList "init" [ idTests; incTests ] diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs index 05c12487..54dfee30 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Reduce.fs @@ -4,7 +4,7 @@ open Expecto open Expecto.Logging open Expecto.Logging.Message open Brahma.FSharp -open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Objects.ClCellExtensions open GraphBLAS.FSharp.Objects.ArraysExtensions @@ -52,7 +52,8 @@ let makeTest (reduce: MailboxProcessor<_> -> ClArray<'a> -> ClCell<'a>) plus zer |> Expect.equal actualSum expectedSum let testFixtures plus plusQ zero name = - let reduce = Reduce.reduce plusQ context wgSize + let reduce = + Common.Reduce.reduce plusQ context wgSize makeTest reduce plus zero |> testPropertyWithConfig config $"Correctness on %s{name}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs index e7194b39..0e58f323 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/ReduceByKey.fs @@ -2,7 +2,7 @@ module GraphBLAS.FSharp.Tests.Backend.Common.Reduce.ByKey open Expecto open Brahma.FSharp -open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests @@ -63,7 +63,7 @@ let makeTest isEqual reduce reduceOp (arrayAndKeys: (int * 'a) []) = let createTestSequential<'a> (isEqual: 'a -> 'a -> bool) reduceOp reduceOpQ = let reduce = - Reduce.ByKey.sequential reduceOpQ context Utils.defaultWorkGroupSize + Common.Reduce.ByKey.sequential reduceOpQ context Utils.defaultWorkGroupSize makeTest isEqual reduce reduceOp |> testPropertyWithConfig config $"test on {typeof<'a>}" @@ -97,7 +97,7 @@ let sequentialTest = let createTestOneWorkGroup<'a> (isEqual: 'a -> 'a -> bool) reduceOp reduceOpQ = let reduce = - Reduce.ByKey.oneWorkGroupSegments reduceOpQ context Utils.defaultWorkGroupSize + Common.Reduce.ByKey.oneWorkGroupSegments reduceOpQ context Utils.defaultWorkGroupSize makeTest isEqual reduce reduceOp |> testPropertyWithConfig @@ -166,7 +166,7 @@ let makeTestSequentialSegments isEqual reduce reduceOp (valuesAndKeys: (int * 'a let createTestSequentialSegments<'a> (isEqual: 'a -> 'a -> bool) reduceOp reduceOpQ = let reduce = - Reduce.ByKey.segmentSequential reduceOpQ context Utils.defaultWorkGroupSize + Common.Reduce.ByKey.segmentSequential reduceOpQ context Utils.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 = - Reduce.ByKey2D.sequential reduceOpQ context Utils.defaultWorkGroupSize + Common.Reduce.ByKey2D.sequential reduceOpQ context Utils.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 = - Reduce.ByKey2D.segmentSequential reduceOpQ context Utils.defaultWorkGroupSize + Common.Reduce.ByKey2D.segmentSequential reduceOpQ context Utils.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) = - Reduce.ByKey.Option.segmentSequential reduceOpQ context Utils.defaultWorkGroupSize + Common.Reduce.ByKey.Option.segmentSequential reduceOpQ context Utils.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) = - Reduce.ByKey2D.Option.segmentSequential reduceOpQ context Utils.defaultWorkGroupSize + Common.Reduce.ByKey2D.Option.segmentSequential reduceOpQ context Utils.defaultWorkGroupSize |> test2DOption<'a> isEqual reduceOp |> testPropertyWithConfig { config with diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Sum.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Sum.fs index d10c214d..3953c3c0 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Sum.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Reduce/Sum.fs @@ -7,7 +7,7 @@ open FSharp.Quotations open Brahma.FSharp open GraphBLAS.FSharp.Tests open Context -open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Objects.ArraysExtensions open GraphBLAS.FSharp.Objects.ClCellExtensions @@ -51,7 +51,7 @@ let makeTest plus zero sum (array: 'a []) = |> Expect.equal actualSum expectedSum let testFixtures plus (plusQ: Expr<'a -> 'a -> 'a>) zero name = - Reduce.sum plusQ zero context wgSize + Common.Reduce.sum plusQ zero context wgSize |> makeTest plus zero |> testPropertyWithConfig config (sprintf "Correctness on %s" name) diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs index e9ec90a2..fd8ffe4f 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs @@ -1,7 +1,7 @@ module GraphBLAS.FSharp.Tests.Backend.Common.Scan.ByKey open Expecto -open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Objects.ArraysExtensions open GraphBLAS.FSharp.Objects.ClContextExtensions @@ -60,7 +60,7 @@ let createTest (zero: 'a) opAddQ opAdd isEqual deviceScan hostScan = let sequentialSegmentsTests = let excludeTests = - [ createTest 0 <@ (+) @> (+) (=) PrefixSum.ByKey.sequentialExclude HostPrimitives.prefixSumExclude + [ createTest 0 <@ (+) @> (+) (=) Common.PrefixSum.ByKey.sequentialExclude HostPrimitives.prefixSumExclude if Utils.isFloat64Available context.ClDevice then createTest @@ -68,7 +68,7 @@ let sequentialSegmentsTests = <@ (+) @> (+) Utils.floatIsEqual - PrefixSum.ByKey.sequentialExclude + Common.PrefixSum.ByKey.sequentialExclude HostPrimitives.prefixSumExclude createTest @@ -76,15 +76,15 @@ let sequentialSegmentsTests = <@ (+) @> (+) Utils.float32IsEqual - PrefixSum.ByKey.sequentialExclude + Common.PrefixSum.ByKey.sequentialExclude HostPrimitives.prefixSumExclude - createTest false <@ (||) @> (||) (=) PrefixSum.ByKey.sequentialExclude HostPrimitives.prefixSumExclude - createTest 0u <@ (+) @> (+) (=) PrefixSum.ByKey.sequentialExclude HostPrimitives.prefixSumExclude ] + createTest false <@ (||) @> (||) (=) Common.PrefixSum.ByKey.sequentialExclude HostPrimitives.prefixSumExclude + createTest 0u <@ (+) @> (+) (=) Common.PrefixSum.ByKey.sequentialExclude HostPrimitives.prefixSumExclude ] |> testList "exclude" let includeTests = - [ createTest 0 <@ (+) @> (+) (=) PrefixSum.ByKey.sequentialInclude HostPrimitives.prefixSumInclude + [ createTest 0 <@ (+) @> (+) (=) Common.PrefixSum.ByKey.sequentialInclude HostPrimitives.prefixSumInclude if Utils.isFloat64Available context.ClDevice then createTest @@ -92,7 +92,7 @@ let sequentialSegmentsTests = <@ (+) @> (+) Utils.floatIsEqual - PrefixSum.ByKey.sequentialInclude + Common.PrefixSum.ByKey.sequentialInclude HostPrimitives.prefixSumInclude createTest @@ -100,11 +100,11 @@ let sequentialSegmentsTests = <@ (+) @> (+) Utils.float32IsEqual - PrefixSum.ByKey.sequentialInclude + Common.PrefixSum.ByKey.sequentialInclude HostPrimitives.prefixSumInclude - createTest false <@ (||) @> (||) (=) PrefixSum.ByKey.sequentialInclude HostPrimitives.prefixSumInclude - createTest 0u <@ (+) @> (+) (=) PrefixSum.ByKey.sequentialInclude HostPrimitives.prefixSumInclude ] + createTest false <@ (||) @> (||) (=) Common.PrefixSum.ByKey.sequentialInclude HostPrimitives.prefixSumInclude + createTest 0u <@ (+) @> (+) (=) Common.PrefixSum.ByKey.sequentialInclude HostPrimitives.prefixSumInclude ] |> testList "include" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/PrefixSum.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/PrefixSum.fs index 4a9cba02..f94b0564 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/PrefixSum.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/PrefixSum.fs @@ -5,7 +5,6 @@ open Expecto.Logging open Expecto.Logging.Message open Brahma.FSharp open GraphBLAS.FSharp -open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp.Objects.ClCellExtensions open GraphBLAS.FSharp.Objects.ArraysExtensions @@ -61,7 +60,7 @@ let makeTest plus zero isEqual scan (array: 'a []) = |> Tests.Utils.compareArrays isEqual actual expected let testFixtures plus plusQ zero isEqual name = - PrefixSum.runIncludeInPlace plusQ context wgSize + Common.PrefixSum.runIncludeInPlace plusQ context wgSize |> makeTest plus zero isEqual |> testPropertyWithConfig config $"Correctness on %s{name}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scatter.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scatter.fs index 3f8e960a..c1d71dca 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scatter.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scatter.fs @@ -4,7 +4,6 @@ open Expecto open Expecto.Logging open Brahma.FSharp open GraphBLAS.FSharp -open GraphBLAS.FSharp.Common open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp.Backend.Quotes @@ -42,12 +41,12 @@ let makeTest<'a when 'a: equality> hostScatter scatter (array: (int * 'a) []) (r |> Utils.compareArrays (=) actual expected let testFixturesLast<'a when 'a: equality> = - Scatter.lastOccurrence context wgSize + Common.Scatter.lastOccurrence context wgSize |> makeTest<'a> HostPrimitives.scatterLastOccurrence |> testPropertyWithConfig config $"Correctness on %A{typeof<'a>}" let testFixturesFirst<'a when 'a: equality> = - Scatter.firstOccurrence context wgSize + Common.Scatter.firstOccurrence context wgSize |> makeTest<'a> HostPrimitives.scatterFirstOccurrence |> testPropertyWithConfig config $"Correctness on %A{typeof<'a>}" @@ -101,13 +100,13 @@ let initTests = let inc = ((+) 1) let firstOccurrence = - [ createInitTest Scatter.initFirstOccurrence HostPrimitives.scatterFirstOccurrence "id" id Map.id - createInitTest Scatter.initFirstOccurrence HostPrimitives.scatterFirstOccurrence "inc" inc Map.inc ] + [ createInitTest Common.Scatter.initFirstOccurrence HostPrimitives.scatterFirstOccurrence "id" id Map.id + createInitTest Common.Scatter.initFirstOccurrence HostPrimitives.scatterFirstOccurrence "inc" inc Map.inc ] |> testList "first occurrence" let lastOccurrence = - [ createInitTest Scatter.initLastOccurrence HostPrimitives.scatterLastOccurrence "id" id Map.id - createInitTest Scatter.initLastOccurrence HostPrimitives.scatterLastOccurrence "inc" inc Map.inc ] + [ createInitTest Common.Scatter.initLastOccurrence HostPrimitives.scatterLastOccurrence "id" id Map.id + createInitTest Common.Scatter.initLastOccurrence HostPrimitives.scatterLastOccurrence "inc" inc Map.inc ] |> testList "last occurrence" testList "init" [ firstOccurrence; lastOccurrence ] diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs index 94cf18e1..a76a8a64 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs @@ -4,7 +4,7 @@ open Expecto open Expecto.Logging open Expecto.Logging.Message open Brahma.FSharp -open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp.Objects.ArraysExtensions @@ -62,7 +62,7 @@ module Bitonic = |> Utils.compareArrays (=) actualValues expectedValues let testFixtures<'a when 'a: equality> = - Bitonic.sortKeyValuesInplace context wgSize + Common.Bitonic.sortKeyValuesInplace context wgSize |> makeTest |> testPropertyWithConfig config $"Correctness on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs index 413edc17..c27cb639 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs @@ -2,7 +2,7 @@ module GraphBLAS.FSharp.Tests.Backend.Common.Sort.Radix open Expecto open Brahma.FSharp -open GraphBLAS.FSharp.Common +open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Objects.ArraysExtensions open GraphBLAS.FSharp.Objects.ClContextExtensions @@ -41,7 +41,7 @@ let makeTestByKeys<'a when 'a: equality> sortFun (array: (int * 'a) []) = let createTestByKeys<'a when 'a: equality and 'a: struct> = let sort = - Radix.runByKeysStandard context workGroupSize + Common.Radix.runByKeysStandard context workGroupSize makeTestByKeys<'a> sort |> testPropertyWithConfig config $"test on {typeof<'a>}" @@ -74,7 +74,7 @@ let makeTestKeysOnly sort (keys: uint []) = let testKeysOnly = let sort = - Radix.standardRunKeysOnly context workGroupSize + Common.Radix.standardRunKeysOnly context workGroupSize makeTestKeysOnly sort |> testPropertyWithConfig config $"keys only" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs index b04d91c5..6d0f8d01 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs @@ -2,7 +2,7 @@ open Expecto open Expecto.Logging -open GraphBLAS.FSharp.Operations +open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp.Tests.TestCases @@ -63,7 +63,7 @@ let makeTest testContext zero isEqual op kroneckerFun (leftMatrix: 'a [,], right |> Expect.equal actual expectedOption let createGeneralTest testContext (zero: 'a) isEqual op opQ testName = - kronecker opQ testContext.ClContext workGroupSize + Operations.kronecker opQ testContext.ClContext workGroupSize |> makeTest testContext zero isEqual op |> testPropertyWithConfig config $"test on %A{typeof<'a>} %s{testName}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs index 452aed9f..9d746f11 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map2.fs @@ -7,7 +7,6 @@ open Microsoft.FSharp.Collections open GraphBLAS.FSharp open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Backend.Quotes -open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.TestCases open GraphBLAS.FSharp.Tests.Backend @@ -114,14 +113,14 @@ let testFixturesMap2Add case = let q = case.TestContext.Queue q.Error.Add(fun e -> failwithf "%A" e) - createTestMap2Add case false (||) (=) ArithmeticOperations.boolSumOption Matrix.map2 - createTestMap2Add case 0 (+) (=) ArithmeticOperations.intSumOption Matrix.map2 + createTestMap2Add case false (||) (=) ArithmeticOperations.boolSumOption Operations.Matrix.map2 + createTestMap2Add case 0 (+) (=) ArithmeticOperations.intSumOption Operations.Matrix.map2 if Utils.isFloat64Available context.ClDevice then - createTestMap2Add case 0.0 (+) Utils.floatIsEqual ArithmeticOperations.floatSumOption Matrix.map2 + createTestMap2Add case 0.0 (+) Utils.floatIsEqual ArithmeticOperations.floatSumOption Operations.Matrix.map2 - createTestMap2Add case 0.0f (+) Utils.float32IsEqual ArithmeticOperations.float32SumOption Matrix.map2 - createTestMap2Add case 0uy (+) (=) ArithmeticOperations.byteSumOption Matrix.map2 ] + createTestMap2Add case 0.0f (+) Utils.float32IsEqual ArithmeticOperations.float32SumOption Operations.Matrix.map2 + createTestMap2Add case 0uy (+) (=) ArithmeticOperations.byteSumOption Operations.Matrix.map2 ] let addTests = operationGPUTests "Backend.Matrix.map2 add tests" testFixturesMap2Add @@ -131,8 +130,8 @@ let testFixturesMap2AddAtLeastOne case = let q = case.TestContext.Queue q.Error.Add(fun e -> failwithf "%A" e) - createTestMap2Add case false (||) (=) ArithmeticOperations.boolSumAtLeastOne Matrix.map2AtLeastOne - createTestMap2Add case 0 (+) (=) ArithmeticOperations.intSumAtLeastOne Matrix.map2AtLeastOne + createTestMap2Add case false (||) (=) ArithmeticOperations.boolSumAtLeastOne Operations.Matrix.map2AtLeastOne + createTestMap2Add case 0 (+) (=) ArithmeticOperations.intSumAtLeastOne Operations.Matrix.map2AtLeastOne if Utils.isFloat64Available context.ClDevice then createTestMap2Add @@ -141,7 +140,7 @@ let testFixturesMap2AddAtLeastOne case = (+) Utils.floatIsEqual ArithmeticOperations.floatSumAtLeastOne - Matrix.map2AtLeastOne + Operations.Matrix.map2AtLeastOne createTestMap2Add case @@ -149,9 +148,9 @@ let testFixturesMap2AddAtLeastOne case = (+) Utils.float32IsEqual ArithmeticOperations.float32SumAtLeastOne - Matrix.map2AtLeastOne + Operations.Matrix.map2AtLeastOne - createTestMap2Add case 0uy (+) (=) ArithmeticOperations.byteSumAtLeastOne Matrix.map2AtLeastOne ] + createTestMap2Add case 0uy (+) (=) ArithmeticOperations.byteSumAtLeastOne Operations.Matrix.map2AtLeastOne ] let addAtLeastOneTests = @@ -162,8 +161,8 @@ let testFixturesMap2MulAtLeastOne case = let q = case.TestContext.Queue q.Error.Add(fun e -> failwithf "%A" e) - createTestMap2Add case false (&&) (=) ArithmeticOperations.boolMulAtLeastOne Matrix.map2AtLeastOne - createTestMap2Add case 0 (*) (=) ArithmeticOperations.intMulAtLeastOne Matrix.map2AtLeastOne + createTestMap2Add case false (&&) (=) ArithmeticOperations.boolMulAtLeastOne Operations.Matrix.map2AtLeastOne + createTestMap2Add case 0 (*) (=) ArithmeticOperations.intMulAtLeastOne Operations.Matrix.map2AtLeastOne if Utils.isFloat64Available context.ClDevice then createTestMap2Add @@ -172,7 +171,7 @@ let testFixturesMap2MulAtLeastOne case = (*) Utils.floatIsEqual ArithmeticOperations.floatMulAtLeastOne - Matrix.map2AtLeastOne + Operations.Matrix.map2AtLeastOne createTestMap2Add case @@ -180,9 +179,9 @@ let testFixturesMap2MulAtLeastOne case = (*) Utils.float32IsEqual ArithmeticOperations.float32MulAtLeastOne - Matrix.map2AtLeastOne + Operations.Matrix.map2AtLeastOne - createTestMap2Add case 0uy (*) (=) ArithmeticOperations.byteMulAtLeastOne Matrix.map2AtLeastOne ] + createTestMap2Add case 0uy (*) (=) ArithmeticOperations.byteMulAtLeastOne Operations.Matrix.map2AtLeastOne ] let mulAtLeastOneTests = operationGPUTests "Backend.Matrix.map2AtLeastOne multiplication tests" testFixturesMap2MulAtLeastOne diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs index 423441f4..79bad1ce 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs @@ -4,7 +4,6 @@ open Expecto open Microsoft.FSharp.Collections open Brahma.FSharp open GraphBLAS.FSharp -open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Backend.Operations.SpGeMM open GraphBLAS.FSharp.Objects @@ -214,7 +213,7 @@ let createGeneralTest (zero: 'a) isEqual (opAddQ, opAdd) (opMulQ, opMul) testFun |> testPropertyWithConfig config $"test on %A{typeof<'a>}" let generalTests = - [ createGeneralTest 0 (=) ArithmeticOperations.intAdd ArithmeticOperations.intMul SpGeMM.expand + [ createGeneralTest 0 (=) ArithmeticOperations.intAdd ArithmeticOperations.intMul Operations.SpGeMM.expand if Utils.isFloat64Available context.ClDevice then createGeneralTest @@ -222,13 +221,13 @@ let generalTests = Utils.floatIsEqual ArithmeticOperations.floatAdd ArithmeticOperations.floatMul - SpGeMM.expand + Operations.SpGeMM.expand createGeneralTest 0.0f Utils.float32IsEqual ArithmeticOperations.float32Add ArithmeticOperations.float32Mul - SpGeMM.expand - createGeneralTest false (=) ArithmeticOperations.boolAdd ArithmeticOperations.boolMul SpGeMM.expand ] + Operations.SpGeMM.expand + createGeneralTest false (=) ArithmeticOperations.boolAdd ArithmeticOperations.boolMul Operations.SpGeMM.expand ] |> testList "general" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Masked.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Masked.fs index 20180188..18cc44c4 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Masked.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Masked.fs @@ -2,8 +2,8 @@ module GraphBLAS.FSharp.Tests.Backend.Matrix.SpGeMM.Masked open Expecto open Expecto.Logging +open GraphBLAS.FSharp open GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Objects.MatrixExtensions open GraphBLAS.FSharp.Test open GraphBLAS.FSharp.Tests @@ -77,7 +77,7 @@ let tests = let mult = <@ fun x y -> Some(x * y) @> let mxmFun = - SpGeMM.masked add mult context workGroupSize + Operations.SpGeMM.masked add mult context workGroupSize makeTest context q 0 (=) (+) (*) mxmFun |> testPropertyWithConfig config (getCorrectnessTestName "int") @@ -103,7 +103,7 @@ let tests = res @> let mxmFun = - SpGeMM.masked logicalOr logicalAnd context workGroupSize + Operations.SpGeMM.masked logicalOr logicalAnd context workGroupSize makeTest context q false (=) (||) (&&) mxmFun |> testPropertyWithConfig config (getCorrectnessTestName "bool") ] diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs index a5d04d1a..a83a1f3f 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Copy.fs @@ -7,8 +7,6 @@ open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Tests open TestCases open GraphBLAS.FSharp.Objects -open GraphBLAS.FSharp.Vector -open GraphBLAS.FSharp.Objects open GraphBLAS.FSharp.Objects.ClVectorExtensions open GraphBLAS.FSharp.Objects.ClContextExtensions diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs index 6f76336b..aac15b20 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map2.fs @@ -3,7 +3,6 @@ module GraphBLAS.FSharp.Tests.Backend.Vector.Map2 open Expecto open Expecto.Logging open GraphBLAS.FSharp -open GraphBLAS.FSharp.Operations open GraphBLAS.FSharp.Backend open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Tests.TestCases @@ -101,42 +100,54 @@ let createTest case isEqual (zero: 'a) plus plusQ map2 = let addTestFixtures case = let context = case.TestContext.ClContext - [ createTest case (=) 0 (+) ArithmeticOperations.intSumOption Vector.map2 + [ createTest case (=) 0 (+) ArithmeticOperations.intSumOption Operations.Vector.map2 if Utils.isFloat64Available context.ClDevice then - createTest case Utils.floatIsEqual 0.0 (+) ArithmeticOperations.floatSumOption Vector.map2 + createTest case Utils.floatIsEqual 0.0 (+) ArithmeticOperations.floatSumOption Operations.Vector.map2 - createTest case Utils.float32IsEqual 0.0f (+) ArithmeticOperations.float32SumOption Vector.map2 - createTest case (=) false (||) ArithmeticOperations.boolSumOption Vector.map2 - createTest case (=) 0uy (+) ArithmeticOperations.byteSumOption Vector.map2 ] + createTest case Utils.float32IsEqual 0.0f (+) ArithmeticOperations.float32SumOption Operations.Vector.map2 + createTest case (=) false (||) ArithmeticOperations.boolSumOption Operations.Vector.map2 + createTest case (=) 0uy (+) ArithmeticOperations.byteSumOption Operations.Vector.map2 ] let addTests = operationGPUTests "add" addTestFixtures let mulTestFixtures case = let context = case.TestContext.ClContext - [ createTest case (=) 0 (*) ArithmeticOperations.intMulOption Vector.map2 + [ createTest case (=) 0 (*) ArithmeticOperations.intMulOption Operations.Vector.map2 if Utils.isFloat64Available context.ClDevice then - createTest case Utils.floatIsEqual 0.0 (*) ArithmeticOperations.floatMulOption Vector.map2 + createTest case Utils.floatIsEqual 0.0 (*) ArithmeticOperations.floatMulOption Operations.Vector.map2 - createTest case Utils.float32IsEqual 0.0f (*) ArithmeticOperations.float32MulOption Vector.map2 - createTest case (=) false (&&) ArithmeticOperations.boolMulOption Vector.map2 - createTest case (=) 0uy (*) ArithmeticOperations.byteMulOption Vector.map2 ] + createTest case Utils.float32IsEqual 0.0f (*) ArithmeticOperations.float32MulOption Operations.Vector.map2 + createTest case (=) false (&&) ArithmeticOperations.boolMulOption Operations.Vector.map2 + createTest case (=) 0uy (*) ArithmeticOperations.byteMulOption Operations.Vector.map2 ] let mulTests = operationGPUTests "mul" addTestFixtures let addAtLeastOneTestFixtures case = let context = case.TestContext.ClContext - [ createTest case (=) 0 (+) ArithmeticOperations.intSumAtLeastOne Vector.map2AtLeastOne + [ createTest case (=) 0 (+) ArithmeticOperations.intSumAtLeastOne Operations.Vector.map2AtLeastOne if Utils.isFloat64Available context.ClDevice then - createTest case Utils.floatIsEqual 0.0 (+) ArithmeticOperations.floatSumAtLeastOne Vector.map2AtLeastOne + createTest + case + Utils.floatIsEqual + 0.0 + (+) + ArithmeticOperations.floatSumAtLeastOne + Operations.Vector.map2AtLeastOne - createTest case Utils.float32IsEqual 0.0f (+) ArithmeticOperations.float32SumAtLeastOne Vector.map2AtLeastOne - createTest case (=) false (||) ArithmeticOperations.boolSumAtLeastOne Vector.map2AtLeastOne - createTest case (=) 0uy (+) ArithmeticOperations.byteSumAtLeastOne Vector.map2AtLeastOne ] + createTest + case + Utils.float32IsEqual + 0.0f + (+) + ArithmeticOperations.float32SumAtLeastOne + Operations.Vector.map2AtLeastOne + createTest case (=) false (||) ArithmeticOperations.boolSumAtLeastOne Operations.Vector.map2AtLeastOne + createTest case (=) 0uy (+) ArithmeticOperations.byteSumAtLeastOne Operations.Vector.map2AtLeastOne ] let addAtLeastOneTests = operationGPUTests "addAtLeastOne" addTestFixtures @@ -144,14 +155,26 @@ let addAtLeastOneTests = let mulAtLeastOneTestFixtures case = let context = case.TestContext.ClContext - [ createTest case (=) 0 (*) ArithmeticOperations.intMulAtLeastOne Vector.map2AtLeastOne + [ createTest case (=) 0 (*) ArithmeticOperations.intMulAtLeastOne Operations.Vector.map2AtLeastOne if Utils.isFloat64Available context.ClDevice then - createTest case Utils.floatIsEqual 0.0 (*) ArithmeticOperations.floatMulAtLeastOne Vector.map2AtLeastOne + createTest + case + Utils.floatIsEqual + 0.0 + (*) + ArithmeticOperations.floatMulAtLeastOne + Operations.Vector.map2AtLeastOne - createTest case Utils.float32IsEqual 0.0f (*) ArithmeticOperations.float32MulAtLeastOne Vector.map2AtLeastOne - createTest case (=) false (&&) ArithmeticOperations.boolMulAtLeastOne Vector.map2AtLeastOne - createTest case (=) 0uy (*) ArithmeticOperations.byteMulAtLeastOne Vector.map2AtLeastOne ] + createTest + case + Utils.float32IsEqual + 0.0f + (*) + ArithmeticOperations.float32MulAtLeastOne + Operations.Vector.map2AtLeastOne + createTest case (=) false (&&) ArithmeticOperations.boolMulAtLeastOne Operations.Vector.map2AtLeastOne + createTest case (=) 0uy (*) ArithmeticOperations.byteMulAtLeastOne Operations.Vector.map2AtLeastOne ] let mulAtLeastOneTests = operationGPUTests "mulAtLeastOne" mulTestFixtures @@ -172,7 +195,7 @@ let fillSubVectorFun value zero isEqual = let complementedGeneralTestFixtures case = let context = case.TestContext.ClContext - [ createTest case (=) 0 (fillSubVectorFun 1 0 (=)) (fillSubVectorComplementedQ 1) Vector.map2 + [ createTest case (=) 0 (fillSubVectorFun 1 0 (=)) (fillSubVectorComplementedQ 1) Operations.Vector.map2 if Utils.isFloat64Available context.ClDevice then createTest @@ -181,7 +204,7 @@ let complementedGeneralTestFixtures case = 0.0 (fillSubVectorFun 1.0 0.0 Utils.floatIsEqual) (fillSubVectorComplementedQ 1.0) - Vector.map2 + Operations.Vector.map2 createTest case @@ -189,11 +212,17 @@ let complementedGeneralTestFixtures case = 0.0f (fillSubVectorFun 1.0f 0.0f Utils.float32IsEqual) (fillSubVectorComplementedQ 1.0f) - Vector.map2 + Operations.Vector.map2 - createTest case (=) false (fillSubVectorFun true false (=)) (fillSubVectorComplementedQ true) Vector.map2 + createTest + case + (=) + false + (fillSubVectorFun true false (=)) + (fillSubVectorComplementedQ true) + Operations.Vector.map2 - createTest case (=) 0uy (fillSubVectorFun 1uy 0uy (=)) (fillSubVectorComplementedQ 1uy) Vector.map2 ] + createTest case (=) 0uy (fillSubVectorFun 1uy 0uy (=)) (fillSubVectorComplementedQ 1uy) Operations.Vector.map2 ] let complementedGeneralTests = diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs index a9158cac..aed7ea50 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/SpMV.fs @@ -4,7 +4,7 @@ open Expecto open Microsoft.FSharp.Collections open Microsoft.FSharp.Core open Brahma.FSharp -open GraphBLAS.FSharp.Operations +open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp.Tests.TestCases @@ -91,7 +91,7 @@ let createTest testContext (zero: 'a) isEqual add mul addQ mulQ = let getCorrectnessTestName datatype = $"Correctness on %s{datatype}, %A{testContext.ClContext}" - let spMV = SpMV addQ mulQ context wgSize + let spMV = Operations.SpMV addQ mulQ context wgSize testContext |> correctnessGenericTest zero add mul spMV isEqual q From 40e3e3a0903cd3a03e8bcc41332c7c5789045ef3 Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Sun, 23 Jul 2023 15:14:28 +0700 Subject: [PATCH 06/22] refactor: assembly attributes --- src/GraphBLAS-sharp.Backend/AssemblyInfo.fs | 2 ++ src/GraphBLAS-sharp.Backend/Common/Common.fs | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GraphBLAS-sharp.Backend/AssemblyInfo.fs b/src/GraphBLAS-sharp.Backend/AssemblyInfo.fs index beeaabeb..12bc67b0 100644 --- a/src/GraphBLAS-sharp.Backend/AssemblyInfo.fs +++ b/src/GraphBLAS-sharp.Backend/AssemblyInfo.fs @@ -4,6 +4,8 @@ namespace System open System.Reflection open System.Runtime.CompilerServices +[] +[] [] [] [] diff --git a/src/GraphBLAS-sharp.Backend/Common/Common.fs b/src/GraphBLAS-sharp.Backend/Common/Common.fs index ee06f56e..e497a61f 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Common.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Common.fs @@ -4,7 +4,6 @@ open Brahma.FSharp open Microsoft.FSharp.Quotations open GraphBLAS.FSharp.Backend.Common -[] module Common = module Bitonic = /// From d587397db645636da4c9e2e764f464bd4ce4996a Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Sun, 23 Jul 2023 15:28:56 +0700 Subject: [PATCH 07/22] refactor: readme.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b2b17f0c..8f1004a1 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ GraphBLAS# is a GPGPU-based [GraphBLAS](https://graphblas.org/)-like API impleme - [x] COO-COO `map2` - [x] COO-COO `map2AtLeastOne` - [x] CSR-CSR multiplication + - [x] CSR-CSR Kronecker product - **Vector-Matrix** - [x] Dense-CSR multiplication - [ ] Sparse-CSR multiplication From 4c5dedef0b605ee96036cb8c5938042f4c251b1b Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Sun, 23 Jul 2023 23:06:56 +0700 Subject: [PATCH 08/22] refactor: objects comments --- src/GraphBLAS-sharp.Backend/Objects/Matrix.fs | 15 +++++++++++++++ src/GraphBLAS-sharp.Backend/Objects/Vector.fs | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs b/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs index 502acd8f..7e218f06 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs @@ -113,6 +113,9 @@ module ClMatrix = member this.NNZ = this.Values.Length +/// +/// Represents an abstraction over matrix, whose values and indices are in OpenCL device memory. +/// [] type ClMatrix<'a when 'a: struct> = | CSR of ClMatrix.CSR<'a> @@ -120,6 +123,9 @@ type ClMatrix<'a when 'a: struct> = | CSC of ClMatrix.CSC<'a> | LIL of ClMatrix.LIL<'a> + /// + /// Row count. + /// member this.RowCount = match this with | ClMatrix.CSR matrix -> matrix.RowCount @@ -127,6 +133,9 @@ type ClMatrix<'a when 'a: struct> = | ClMatrix.CSC matrix -> matrix.RowCount | ClMatrix.LIL matrix -> matrix.RowCount + /// + /// Column count. + /// member this.ColumnCount = match this with | ClMatrix.CSR matrix -> matrix.ColumnCount @@ -134,6 +143,9 @@ type ClMatrix<'a when 'a: struct> = | ClMatrix.CSC matrix -> matrix.ColumnCount | ClMatrix.LIL matrix -> matrix.ColumnCount + /// + /// Release resources allocated for the matrix. + /// member this.Dispose q = match this with | ClMatrix.CSR matrix -> (matrix :> IDeviceMemObject).Dispose q @@ -141,6 +153,9 @@ type ClMatrix<'a when 'a: struct> = | ClMatrix.CSC matrix -> (matrix :> IDeviceMemObject).Dispose q | ClMatrix.LIL matrix -> (matrix :> IDeviceMemObject).Dispose q + /// + /// Number of non-zero elements in matrix. + /// member this.NNZ = match this with | ClMatrix.CSR matrix -> matrix.NNZ diff --git a/src/GraphBLAS-sharp.Backend/Objects/Vector.fs b/src/GraphBLAS-sharp.Backend/Objects/Vector.fs index 8ffeb752..8cebe58c 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/Vector.fs @@ -24,15 +24,25 @@ module ClVector = member this.NNZ = this.Values.Length +/// +/// Represents an abstraction over vector, whose values and indices are in OpenCL device memory. +/// [] type ClVector<'a when 'a: struct> = | Sparse of ClVector.Sparse<'a> | Dense of ClArray<'a option> + + /// + /// Gets the number of elements in vector. + /// member this.Size = match this with | Sparse vector -> vector.Size | Dense vector -> vector.Size + /// + /// Release resources allocated for the matrix. + /// member this.Dispose(q) = match this with | Sparse vector -> vector.Dispose(q) From 45baacdc0f54969800929c088be0797f18eba1df Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Mon, 24 Jul 2023 15:48:46 +0700 Subject: [PATCH 09/22] refactor: move Matrix.map, Vector.map; add: Vector.map tests --- src/GraphBLAS-sharp.Backend/Matrix/COO/Map.fs | 2 +- .../Matrix/COO/Map2.fs | 4 +- src/GraphBLAS-sharp.Backend/Matrix/CSR/Map.fs | 4 +- .../Matrix/CSR/Map2.fs | 4 +- src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs | 30 ---- .../Operations/Operations.fs | 56 +++++++ src/GraphBLAS-sharp.Backend/Vector/Vector.fs | 26 --- .../Backend/Matrix/Map.fs | 3 +- .../Backend/Vector/Map.fs | 148 ++++++++++++++++++ .../GraphBLAS-sharp.Tests.fsproj | 1 + 10 files changed, 214 insertions(+), 64 deletions(-) create mode 100644 tests/GraphBLAS-sharp.Tests/Backend/Vector/Map.fs diff --git a/src/GraphBLAS-sharp.Backend/Matrix/COO/Map.fs b/src/GraphBLAS-sharp.Backend/Matrix/COO/Map.fs index 0d1ed5aa..9b9377f0 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/COO/Map.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/COO/Map.fs @@ -11,7 +11,7 @@ open GraphBLAS.FSharp.Objects.ClMatrix open GraphBLAS.FSharp.Objects.ClContextExtensions module internal Map = - let preparePositions<'a, 'b> opAdd (clContext: ClContext) workGroupSize = + let private preparePositions<'a, 'b> opAdd (clContext: ClContext) workGroupSize = let preparePositions (op: Expr<'a option -> 'b option>) = <@ fun (ndRange: Range1D) rowCount columnCount valuesLength (values: ClArray<'a>) (rows: ClArray) (columns: ClArray) (resultBitmap: ClArray) (resultValues: ClArray<'b>) (resultRows: ClArray) (resultColumns: ClArray) -> diff --git a/src/GraphBLAS-sharp.Backend/Matrix/COO/Map2.fs b/src/GraphBLAS-sharp.Backend/Matrix/COO/Map2.fs index 8e5134bf..a728d546 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/COO/Map2.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/COO/Map2.fs @@ -11,7 +11,7 @@ open GraphBLAS.FSharp.Backend.Matrix module internal Map2 = - let preparePositions<'a, 'b, 'c> opAdd (clContext: ClContext) workGroupSize = + let private preparePositions<'a, 'b, 'c> opAdd (clContext: ClContext) workGroupSize = let preparePositions (op: Expr<'a option -> 'b option -> 'c option>) = <@ fun (ndRange: Range1D) rowCount columnCount leftValuesLength rightValuesLength (leftValues: ClArray<'a>) (leftRows: ClArray) (leftColumns: ClArray) (rightValues: ClArray<'b>) (rightRows: ClArray) (rightColumn: ClArray) (resultBitmap: ClArray) (resultValues: ClArray<'c>) (resultRows: ClArray) (resultColumns: ClArray) -> @@ -135,7 +135,7 @@ module internal Map2 = Values = resultValues } module AtLeastOne = - let preparePositionsAtLeastOne<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality> + let private preparePositionsAtLeastOne<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality> (clContext: ClContext) (opAdd: Expr<'a option -> 'b option -> 'c option>) workGroupSize diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map.fs index a89989db..8d068d09 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map.fs @@ -12,7 +12,7 @@ open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.ArraysExtensions module internal Map = - let preparePositions<'a, 'b> op (clContext: ClContext) workGroupSize = + let private preparePositions<'a, 'b> op (clContext: ClContext) workGroupSize = let preparePositions (op: Expr<'a option -> 'b option>) = <@ fun (ndRange: Range1D) rowCount columnCount (values: ClArray<'a>) (rowPointers: ClArray) (columns: ClArray) (resultBitmap: ClArray) (resultValues: ClArray<'b>) (resultRows: ClArray) (resultColumns: ClArray) -> @@ -115,7 +115,7 @@ module internal Map = Values = resultValues } module WithValue = - let preparePositions<'a, 'b, 'c when 'b: struct> (clContext: ClContext) workGroupSize op = + let private preparePositions<'a, 'b, 'c when 'b: struct> (clContext: ClContext) workGroupSize op = let preparePositions (op: Expr<'a option -> 'b option -> 'c option>) = <@ fun (ndRange: Range1D) (operand: ClCell<'a option>) rowCount columnCount (values: ClArray<'b>) (rowPointers: ClArray) (columns: ClArray) (resultBitmap: ClArray) (resultValues: ClArray<'c>) (resultRows: ClArray) (resultColumns: ClArray) -> diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs index 5737477f..c0ba47c3 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs @@ -10,7 +10,7 @@ open GraphBLAS.FSharp.Objects.ClMatrix open GraphBLAS.FSharp.Objects.ClContextExtensions module internal Map2 = - let preparePositions<'a, 'b, 'c> opAdd (clContext: ClContext) workGroupSize = + let private preparePositions<'a, 'b, 'c> opAdd (clContext: ClContext) workGroupSize = let preparePositions (op: Expr<'a option -> 'b option -> 'c option>) = <@ fun (ndRange: Range1D) rowCount columnCount (leftValues: ClArray<'a>) (leftRowPointers: ClArray) (leftColumns: ClArray) (rightValues: ClArray<'b>) (rightRowPointers: ClArray) (rightColumn: ClArray) (resultBitmap: ClArray) (resultValues: ClArray<'c>) (resultRows: ClArray) (resultColumns: ClArray) -> @@ -135,7 +135,7 @@ module internal Map2 = Values = resultValues } module AtLeastOne = - let preparePositions<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality> + let private preparePositions<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality> (opAdd: Expr<'a option -> 'b option -> 'c option>) (clContext: ClContext) workGroupSize diff --git a/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs b/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs index 736c2951..c56ec5ea 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs @@ -266,36 +266,6 @@ module Matrix = |> ClMatrix.LIL | ClMatrix.LIL _ -> copy processor allocationMode matrix - /// - /// Builds a new matrix whose elements are the results of applying the given function - /// to each of the elements of the matrix. - /// - /// - /// A function to transform values of the input matrix. - /// Operand and result types should be optional to distinguish explicit and implicit zeroes - /// - /// OpenCL context. - /// Should be a power of 2 and greater than 1. - let map (op: Expr<'a option -> 'b option>) (clContext: ClContext) workGroupSize = - let mapCOO = - COO.Matrix.map op clContext workGroupSize - - let mapCSR = - CSR.Matrix.map op clContext workGroupSize - - let transposeCOO = - COO.Matrix.transposeInPlace clContext workGroupSize - - fun (processor: MailboxProcessor<_>) allocationMode matrix -> - match matrix with - | ClMatrix.COO m -> mapCOO processor allocationMode m |> ClMatrix.COO - | ClMatrix.CSR m -> mapCSR processor allocationMode m |> ClMatrix.COO - | ClMatrix.CSC m -> - (mapCSR processor allocationMode m.ToCSR) - |> transposeCOO processor - |> ClMatrix.COO - | _ -> failwith "Not yet implemented" - /// /// Transposes the given matrix and returns result. /// The given matrix should neither be used afterwards nor be disposed. diff --git a/src/GraphBLAS-sharp.Backend/Operations/Operations.fs b/src/GraphBLAS-sharp.Backend/Operations/Operations.fs index d086ffd2..9dc27d85 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/Operations.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/Operations.fs @@ -11,6 +11,32 @@ open GraphBLAS.FSharp.Backend.Operations [] module Operations = module Vector = + /// + /// Builds a new vector whose elements are the results of applying the given function + /// to each of the elements of the vector. + /// + /// + /// A function to transform values of the input vector. + /// Operand and result types should be optional to distinguish explicit and implicit zeroes. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let map (op: Expr<'a option -> 'b option>) (clContext: ClContext) workGroupSize = + let mapSparse = + Sparse.Vector.map op clContext workGroupSize + + let mapDense = + Dense.Vector.map op clContext workGroupSize + + fun (processor: MailboxProcessor<_>) allocationMode matrix -> + match matrix with + | ClVector.Sparse v -> + mapSparse processor allocationMode v + |> ClVector.Sparse + | ClVector.Dense v -> + mapDense processor allocationMode v + |> ClVector.Dense + /// /// Builds a new vector whose values are the results of applying the given function /// to the corresponding pairs of values from the two vectors. @@ -72,6 +98,36 @@ module Operations = | _ -> failwith "Vector formats are not matching." module Matrix = + /// + /// Builds a new matrix whose elements are the results of applying the given function + /// to each of the elements of the matrix. + /// + /// + /// A function to transform values of the input matrix. + /// Operand and result types should be optional to distinguish explicit and implicit zeroes + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. + let map (op: Expr<'a option -> 'b option>) (clContext: ClContext) workGroupSize = + let mapCOO = + COO.Matrix.map op clContext workGroupSize + + let mapCSR = + CSR.Matrix.map op clContext workGroupSize + + let transposeCOO = + COO.Matrix.transposeInPlace clContext workGroupSize + + fun (processor: MailboxProcessor<_>) allocationMode matrix -> + match matrix with + | ClMatrix.COO m -> mapCOO processor allocationMode m |> ClMatrix.COO + | ClMatrix.CSR m -> mapCSR processor allocationMode m |> ClMatrix.COO + | ClMatrix.CSC m -> + (mapCSR processor allocationMode m.ToCSR) + |> transposeCOO processor + |> ClMatrix.COO + | _ -> failwith "Not yet implemented" + /// /// Builds a new matrix whose values are the results of applying the given function /// to the corresponding pairs of values from the two matrices. diff --git a/src/GraphBLAS-sharp.Backend/Vector/Vector.fs b/src/GraphBLAS-sharp.Backend/Vector/Vector.fs index b19dc617..a9192eff 100644 --- a/src/GraphBLAS-sharp.Backend/Vector/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Vector/Vector.fs @@ -148,32 +148,6 @@ module Vector = ClVector.Dense <| toDense processor allocationMode vector - /// - /// Builds a new vector whose elements are the results of applying the given function - /// to each of the elements of the vector. - /// - /// - /// A function to transform values of the input vector. - /// Operand and result types should be optional to distinguish explicit and implicit zeroes. - /// - /// OpenCL context. - /// Should be a power of 2 and greater than 1. - let map (op: Expr<'a option -> 'b option>) (clContext: ClContext) workGroupSize = - let mapSparse = - Sparse.Vector.map op clContext workGroupSize - - let mapDense = - Dense.Vector.map op clContext workGroupSize - - fun (processor: MailboxProcessor<_>) allocationMode matrix -> - match matrix with - | ClVector.Sparse v -> - mapSparse processor allocationMode v - |> ClVector.Sparse - | ClVector.Dense v -> - mapDense processor allocationMode v - |> ClVector.Dense - let private assignByMaskGeneral<'a, 'b when 'a: struct and 'b: struct> op (clContext: ClContext) workGroupSize = let sparseFillVector = diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs index fdb655ce..e61d65bf 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Map.fs @@ -97,7 +97,8 @@ let createTestMap case (zero: 'a) (constant: 'a) binOp isEqual opQ = let unaryOp = binOp constant let unaryOpQ = opQ zero constant - let map = Matrix.map unaryOpQ context wgSize + let map = + Operations.Matrix.map unaryOpQ context wgSize let toCOO = Matrix.toCOO context wgSize diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map.fs new file mode 100644 index 00000000..a182b72e --- /dev/null +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map.fs @@ -0,0 +1,148 @@ +module GraphBLAS.FSharp.Tests.Backend.Vector.Map + +open Expecto +open Expecto.Logging +open Expecto.Logging.Message +open Microsoft.FSharp.Collections +open GraphBLAS.FSharp +open GraphBLAS.FSharp.Backend +open GraphBLAS.FSharp.Backend.Quotes +open GraphBLAS.FSharp.Tests +open GraphBLAS.FSharp.Tests.Backend +open GraphBLAS.FSharp.Tests.TestCases +open GraphBLAS.FSharp.Objects +open GraphBLAS.FSharp.Objects.ClContextExtensions +open GraphBLAS.FSharp.Objects.ClVectorExtensions +open Mono.CompilerServices.SymbolWriter + +let logger = Log.create "Vector.Map.Tests" + +let config = Utils.defaultConfig +let wgSize = Utils.defaultWorkGroupSize + +let getCorrectnessTestName case datatype = + $"Correctness on %s{datatype}, %A{case}" + +let checkResult isEqual op zero (baseVector: 'a []) (actual: Vector<'b>) = + + let expectedArrayLength = baseVector.Length + + let expectedArray = + Array.create expectedArrayLength zero + + for i in 0 .. expectedArrayLength - 1 do + expectedArray.[i] <- op baseVector.[i] + + let expected = + Utils.createVectorFromArray Dense expectedArray (isEqual zero) + |> Utils.vectorToDenseVector + + match actual with + | Vector.Dense actual -> + "arrays must have the same values" + |> Expect.equal actual expected + | _ -> failwith "Vector format must be Sparse." + +let correctnessGenericTest + zero + op + (addFun: MailboxProcessor<_> -> AllocationFlag -> ClVector<'a> -> ClVector<'a>) + (toDense: MailboxProcessor<_> -> AllocationFlag -> ClVector<'a> -> ClVector<'a>) + (isEqual: 'a -> 'a -> bool) + (case: OperationCase) + (array: 'a []) + = + + let isZero = (isEqual zero) + + let vectorHost = + Utils.createVectorFromArray case.Format array isZero + + if vectorHost.NNZ > 0 then + + let context = case.TestContext.ClContext + let q = case.TestContext.Queue + + let vector = vectorHost.ToDevice context + + try + let res = + addFun q HostInterop vector + + vector.Dispose q + + let denseActual = toDense q HostInterop res + + let actual = denseActual.ToHost q + + res.Dispose q + denseActual.Dispose q + + checkResult isEqual op zero array actual + with + | ex when ex.Message = "InvalidBufferSize" -> () + | ex -> raise ex + +let createTestMap case (zero: 'a) (constant: 'a) binOp isEqual opQ = + let getCorrectnessTestName = getCorrectnessTestName case + + let context = case.TestContext.ClContext + let q = case.TestContext.Queue + + let unaryOp = binOp constant + let unaryOpQ = opQ zero constant + + let map = + Operations.Vector.map unaryOpQ context wgSize + + let toDense = Vector.toDense context wgSize + + case + |> correctnessGenericTest zero unaryOp map toDense isEqual + |> testPropertyWithConfig config (getCorrectnessTestName $"{typeof<'a>}") + +let testFixturesMapNot case = + [ let q = case.TestContext.Queue + q.Error.Add(fun e -> failwithf "%A" e) + + createTestMap case false true (fun _ -> not) (=) (fun _ _ -> ArithmeticOperations.notOption) ] + +let notTests = + operationGPUTests "not" testFixturesMapNot + +let testFixturesMapAdd case = + [ let context = case.TestContext.ClContext + let q = case.TestContext.Queue + q.Error.Add(fun e -> failwithf "%A" e) + + createTestMap case 0 10 (+) (=) ArithmeticOperations.addLeftConst + + if Utils.isFloat64Available context.ClDevice then + createTestMap case 0.0 10.0 (+) Utils.floatIsEqual ArithmeticOperations.addLeftConst + + createTestMap case 0.0f 10.0f (+) Utils.float32IsEqual ArithmeticOperations.addLeftConst + + createTestMap case 0uy 10uy (+) (=) ArithmeticOperations.addLeftConst ] + +let addTests = + operationGPUTests "add" testFixturesMapAdd + +let testFixturesMapMul case = + [ let context = case.TestContext.ClContext + let q = case.TestContext.Queue + q.Error.Add(fun e -> failwithf "%A" e) + + createTestMap case 0 10 (*) (=) ArithmeticOperations.mulLeftConst + + if Utils.isFloat64Available context.ClDevice then + createTestMap case 0.0 10.0 (*) Utils.floatIsEqual ArithmeticOperations.mulLeftConst + + createTestMap case 0.0f 10.0f (*) Utils.float32IsEqual ArithmeticOperations.mulLeftConst + + createTestMap case 0uy 10uy (*) (=) ArithmeticOperations.mulLeftConst ] + +let mulTests = + operationGPUTests "mul" testFixturesMapMul + +let allTests = + testList "Map" [ addTests; mulTests; notTests ] diff --git a/tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj b/tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj index 6bbf3f99..5e2185f9 100644 --- a/tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj +++ b/tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj @@ -62,6 +62,7 @@ + From 4841a03e6c8e62862325b68e4dbfefd458f2a33b Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Mon, 24 Jul 2023 18:07:23 +0700 Subject: [PATCH 10/22] refactor: vector.map tests --- tests/GraphBLAS-sharp.Tests/Backend/Vector/Map.fs | 6 ++---- tests/GraphBLAS-sharp.Tests/Program.fs | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map.fs b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map.fs index a182b72e..c3cfeab7 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Vector/Map.fs @@ -27,8 +27,7 @@ let checkResult isEqual op zero (baseVector: 'a []) (actual: Vector<'b>) = let expectedArrayLength = baseVector.Length - let expectedArray = - Array.create expectedArrayLength zero + let expectedArray = Array.create expectedArrayLength zero for i in 0 .. expectedArrayLength - 1 do expectedArray.[i] <- op baseVector.[i] @@ -66,8 +65,7 @@ let correctnessGenericTest let vector = vectorHost.ToDevice context try - let res = - addFun q HostInterop vector + let res = addFun q HostInterop vector vector.Dispose q diff --git a/tests/GraphBLAS-sharp.Tests/Program.fs b/tests/GraphBLAS-sharp.Tests/Program.fs index 864c59fb..ee70e1ad 100644 --- a/tests/GraphBLAS-sharp.Tests/Program.fs +++ b/tests/GraphBLAS-sharp.Tests/Program.fs @@ -78,6 +78,7 @@ let vectorTests = Vector.OfList.tests Vector.Copy.tests Vector.Convert.tests + Vector.Map.allTests Vector.Map2.allTests Vector.AssignByMask.tests Vector.AssignByMask.complementedTests From da2d1bd601ab18c20e587cd7c74dee804cd027b0 Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Mon, 24 Jul 2023 18:27:24 +0700 Subject: [PATCH 11/22] fix: exception related to the use of bitonic --- src/GraphBLAS-sharp.Backend/Common/Common.fs | 3 ++- tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/GraphBLAS-sharp.Backend/Common/Common.fs b/src/GraphBLAS-sharp.Backend/Common/Common.fs index e497a61f..ca9f06e2 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Common.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Common.fs @@ -23,7 +23,8 @@ module Common = /// > val values = [| 1.9; 2.8; 6.4; 5.5; 4.6; 3.7; 7.3 |] /// /// - let sortKeyValuesInplace = Sort.Bitonic.sortKeyValuesInplace + let sortKeyValuesInplace<'n, 'a when 'n: comparison> = + Sort.Bitonic.sortKeyValuesInplace<'n, 'a> module Radix = /// diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs index a76a8a64..468383c5 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs @@ -62,7 +62,7 @@ module Bitonic = |> Utils.compareArrays (=) actualValues expectedValues let testFixtures<'a when 'a: equality> = - Common.Bitonic.sortKeyValuesInplace context wgSize + Common.Bitonic.sortKeyValuesInplace context wgSize |> makeTest |> testPropertyWithConfig config $"Correctness on %A{typeof<'a>}" From 203d641effefbb262c24e421e84bd1af04787d73 Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Wed, 26 Jul 2023 20:21:20 +0700 Subject: [PATCH 12/22] refactor: returned internal comments --- src/GraphBLAS-sharp.Backend/Common/Common.fs | 22 +----- .../Common/PrefixSum.fs | 54 +++++++++++++ src/GraphBLAS-sharp.Backend/Common/Scatter.fs | 77 ++++++++++++++++++- src/GraphBLAS-sharp.Backend/Common/Sum.fs | 77 +++++++++++++++++++ 4 files changed, 210 insertions(+), 20 deletions(-) diff --git a/src/GraphBLAS-sharp.Backend/Common/Common.fs b/src/GraphBLAS-sharp.Backend/Common/Common.fs index ca9f06e2..919809a9 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Common.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Common.fs @@ -154,7 +154,7 @@ module Common = /// /// /// Maps global id to a value - let initFirstOccurrence valueMap = Scatter.initFirsOccurrence valueMap + let initFirstOccurrence valueMap = Scatter.initFirstOccurrence valueMap /// /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array @@ -252,16 +252,7 @@ module Common = /// > val sum = [| 4 |] /// /// - /// ClContext. - /// Should be a power of 2 and greater than 1. - let standardExcludeInPlace (clContext: ClContext) workGroupSize = - - let scan = - runExcludeInPlace <@ (+) @> clContext workGroupSize - - fun (processor: MailboxProcessor<_>) (inputArray: ClArray) -> - - scan processor inputArray 0 + let standardExcludeInPlace = PrefixSum.standardExcludeInPlace /// /// Include in-place prefix sum of integer array with addition operation and start value that is equal to 0. @@ -279,14 +270,7 @@ module Common = /// /// ClContext. /// Should be a power of 2 and greater than 1. - let standardIncludeInPlace (clContext: ClContext) workGroupSize = - - let scan = - runIncludeInPlace <@ (+) @> clContext workGroupSize - - fun (processor: MailboxProcessor<_>) (inputArray: ClArray) -> - - scan processor inputArray 0 + let standardIncludeInPlace = PrefixSum.runIncludeInPlace module ByKey = /// diff --git a/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs b/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs index 9d241e6b..b34b39c1 100644 --- a/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs +++ b/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs @@ -208,6 +208,22 @@ module internal PrefixSum = let runBackwardsIncludeInPlace plus = runInPlace plus true scanInclusive + /// + /// Exclude in-place prefix sum of integer array with addition operation and start value that is equal to 0. + /// + /// + /// + /// let arr = [| 1; 1; 1; 1 |] + /// let sum = [| 0 |] + /// runExcludeInplace clContext workGroupSize processor arr sum (+) 0 + /// |> ignore + /// ... + /// > val arr = [| 0; 1; 2; 3 |] + /// > val sum = [| 4 |] + /// + /// + /// ClContext. + /// Should be a power of 2 and greater than 1. let standardExcludeInPlace (clContext: ClContext) workGroupSize = let scan = @@ -217,6 +233,22 @@ module internal PrefixSum = scan processor inputArray 0 + /// + /// Include in-place prefix sum of integer array with addition operation and start value that is equal to 0. + /// + /// + /// + /// let arr = [| 1; 1; 1; 1 |] + /// let sum = [| 0 |] + /// runIncludeInplace clContext workGroupSize processor arr sum (+) 0 + /// |> ignore + /// ... + /// > val arr = [| 1; 2; 3; 4 |] + /// > val sum = [| 4 |] + /// + /// + /// ClContext. + /// Should be a power of 2 and greater than 1. let standardIncludeInPlace (clContext: ClContext) workGroupSize = let scan = @@ -268,6 +300,28 @@ module internal PrefixSum = processor.Post(Msg.CreateRunMsg<_, _> kernel) + /// + /// Exclude scan by key. + /// + /// + /// + /// let arr = [| 1; 1; 1; 1; 1; 1|] + /// let keys = [| 1; 2; 2; 2; 3; 3 |] + /// ... + /// > val result = [| 0; 0; 1; 2; 0; 1 |] + /// + /// let sequentialExclude op = sequentialSegments (Map.fst ()) op + /// + /// Include scan by key. + /// + /// + /// + /// let arr = [| 1; 1; 1; 1; 1; 1|] + /// let keys = [| 1; 2; 2; 2; 3; 3 |] + /// ... + /// > val result = [| 1; 1; 2; 3; 1; 2 |] + /// + /// let sequentialInclude op = sequentialSegments (Map.snd ()) op diff --git a/src/GraphBLAS-sharp.Backend/Common/Scatter.fs b/src/GraphBLAS-sharp.Backend/Common/Scatter.fs index cc74677d..ca2ea516 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Scatter.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Scatter.fs @@ -45,11 +45,48 @@ module internal Scatter = processor.Post(Msg.CreateRunMsg<_, _>(kernel)) + /// + /// Creates a new array from the given one where it is indicated + /// by the array of positions at which position in the new array + /// should be a value from the given one. + /// + /// + /// Every element of the positions array must not be less than the previous one. + /// If there are several elements with the same indices, the FIRST one of them will be at the common index. + /// If index is out of bounds, the value will be ignored. + /// + /// + /// + /// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |] + /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; 8.2; 9.1 |] + /// run clContext 32 processor positions values result + /// ... + /// > val result = [| 1,9; 3.7; 6.4; 7.3; 9.1 |] + /// + /// let firstOccurrence clContext = general <| Predicates.firstOccurrence () <| clContext + /// + /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array + /// should be a value from the given one. + /// + /// + /// Every element of the positions array must not be less than the previous one. + /// If there are several elements with the same indices, the LAST one of them will be at the common index. + /// If index is out of bounds, the value will be ignored. + /// + /// + /// + /// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |] + /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; 8.2; 9.1 |] + /// run clContext 32 processor positions values result + /// ... + /// > val result = [| 2.8; 5.5; 6.4; 8.2; 9.1 |] + /// + /// let lastOccurrence clContext = general <| Predicates.lastOccurrence () @@ -92,11 +129,49 @@ module internal Scatter = processor.Post(Msg.CreateRunMsg<_, _>(kernel)) - let initFirsOccurrence<'a> valueMap = + /// + /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array + /// should be a values obtained by applying the mapping to the global id. + /// + /// + /// Every element of the positions array must not be less than the previous one. + /// If there are several elements with the same indices, the FIRST one of them will be at the common index. + /// If index is out of bounds, the value will be ignored. + /// + /// + /// + /// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |] + /// let valueMap = id + /// run clContext 32 processor positions values result + /// ... + /// > val result = [| 0; 2; 5; 6; 8 |] + /// + /// + /// Maps global id to a value + let initFirstOccurrence<'a> valueMap = generalInit<'a> <| Predicates.firstOccurrence () <| valueMap + /// + /// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array + /// should be a values obtained by applying the mapping to the global id. + /// + /// + /// Every element of the positions array must not be less than the previous one. + /// If there are several elements with the same indices, the LAST one of them will be at the common index. + /// If index is out of bounds, the value will be ignored. + /// + /// + /// + /// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |] + /// let valueMap = id + /// run clContext 32 processor positions values result + /// ... + /// > val result = [| 1; 4; 5; 7; 8 |] + /// + /// + /// Maps global id to a value let initLastOccurrence<'a> valueMap = generalInit<'a> <| Predicates.lastOccurrence () diff --git a/src/GraphBLAS-sharp.Backend/Common/Sum.fs b/src/GraphBLAS-sharp.Backend/Common/Sum.fs index 7df6beee..e1df0cfd 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Sum.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Sum.fs @@ -132,6 +132,13 @@ module internal Reduce = resultCell + /// + /// Summarizes array elements. + /// + /// ClContext. + /// Work group size. + /// Summation operation. + /// Neutral element for summation. let sum op zero (clContext: ClContext) workGroupSize = let scan = scanSum op clContext workGroupSize zero @@ -229,6 +236,12 @@ module internal Reduce = resultCell + /// + /// Reduces an array of values. + /// + /// ClContext. + /// Work group size. + /// Reduction operation. let reduce op (clContext: ClContext) workGroupSize = let scan = scanReduce op clContext workGroupSize @@ -245,6 +258,15 @@ module internal Reduce = /// Reduction of an array of values by an array of keys. /// module ByKey = + /// + /// Reduces an array of values by key using a single work item. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// The length of the result must be calculated in advance. + /// let sequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = let kernel = @@ -295,6 +317,15 @@ module internal Reduce = reducedValues, reducedKeys + /// + /// Reduces values by key. Each segment is reduced by one work item. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// The length of the result must be calculated in advance. + /// let segmentSequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = let kernel = @@ -352,6 +383,16 @@ module internal Reduce = reducedValues, reducedKeys + /// + /// Reduces values by key. One work group participates in the reduction. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// Reduces an array of values that does not exceed the size of the workgroup. + /// The length of the result must be calculated in advance. + /// let oneWorkGroupSegments (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = let kernel = @@ -432,6 +473,15 @@ module internal Reduce = reducedValues, reducedKeys module Option = + /// + /// Reduces values by key. Each segment is reduced by one work item. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// The length of the result must be calculated in advance. + /// let segmentSequential<'a> (reduceOp: Expr<'a -> 'a -> 'a option>) (clContext: ClContext) workGroupSize = let kernel = @@ -540,6 +590,15 @@ module internal Reduce = Some(resultValues, resultKeys) module ByKey2D = + /// + /// Reduces an array of values by 2D keys using a single work item. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// The length of the result must be calculated in advance. + /// let sequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = let kernel = @@ -610,6 +669,15 @@ module internal Reduce = reducedValues, firstReducedKeys, secondReducedKeys + /// + /// Reduces values by key. Each segment is reduced by one work item. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// The length of the result must be calculated in advance. + /// let segmentSequential<'a> (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = let kernel = @@ -677,6 +745,15 @@ module internal Reduce = reducedValues, firstReducedKeys, secondReducedKeys module Option = + /// + /// Reduces values by key. Each segment is reduced by one work item. + /// + /// ClContext. + /// Work group size. + /// Operation for reducing values. + /// + /// The length of the result must be calculated in advance. + /// let segmentSequential<'a> (reduceOp: Expr<'a -> 'a -> 'a option>) (clContext: ClContext) workGroupSize = let kernel = From 04efa1e795c2a9fb128aad7a69877add98000852 Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Wed, 26 Jul 2023 20:28:43 +0700 Subject: [PATCH 13/22] fix: common --- src/GraphBLAS-sharp.Backend/Common/Common.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GraphBLAS-sharp.Backend/Common/Common.fs b/src/GraphBLAS-sharp.Backend/Common/Common.fs index 919809a9..f23880a7 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Common.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Common.fs @@ -270,7 +270,7 @@ module Common = /// /// ClContext. /// Should be a power of 2 and greater than 1. - let standardIncludeInPlace = PrefixSum.runIncludeInPlace + let standardIncludeInPlace = PrefixSum.standardIncludeInPlace module ByKey = /// From b9d202fb6e16d39aff8ac9e48d87ec30858c6ef4 Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Fri, 28 Jul 2023 00:13:15 +0700 Subject: [PATCH 14/22] refactor: common; docs for matrix --- .../Algorithms/Algorithms.fs | 3 +- src/GraphBLAS-sharp.Backend/Common/Common.fs | 101 +++++++++--------- src/GraphBLAS-sharp.Backend/Common/Gather.fs | 34 +++++- .../Common/PrefixSum.fs | 2 +- src/GraphBLAS-sharp.Backend/Common/Scatter.fs | 2 +- .../Common/Sort/Bitonic.fs | 2 +- src/GraphBLAS-sharp.Backend/Common/Sum.fs | 2 +- .../GraphBLAS-sharp.Backend.fsproj | 2 +- .../Matrix/COO/Matrix.fs | 65 ++++++++++- .../Matrix/CSR/Map2.fs | 2 +- .../Matrix/CSR/Matrix.fs | 88 +++++++++++++++ src/GraphBLAS-sharp.Backend/Objects/Matrix.fs | 8 +- src/GraphBLAS-sharp.Backend/Objects/Vector.fs | 2 +- .../Operations/Kronecker.fs | 2 +- .../Operations/SpGeMM/Expand.fs | 6 +- .../Backend/Common/Sort/Bitonic.fs | 3 +- .../Backend/Common/Sort/Radix.fs | 5 +- .../Backend/Matrix/Kronecker.fs | 2 +- tests/GraphBLAS-sharp.Tests/Helpers.fs | 2 +- tests/GraphBLAS-sharp.Tests/Program.fs | 10 +- 20 files changed, 260 insertions(+), 83 deletions(-) diff --git a/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs b/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs index 2f442e81..e412d186 100644 --- a/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs +++ b/src/GraphBLAS-sharp.Backend/Algorithms/Algorithms.fs @@ -5,4 +5,5 @@ open GraphBLAS.FSharp.Backend.Algorithms [] module Algorithms = - let singleSourceBFS = BFS.singleSource + module BFS = + let singleSource = BFS.singleSource diff --git a/src/GraphBLAS-sharp.Backend/Common/Common.fs b/src/GraphBLAS-sharp.Backend/Common/Common.fs index f23880a7..53777d33 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Common.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Common.fs @@ -5,55 +5,56 @@ open Microsoft.FSharp.Quotations open GraphBLAS.FSharp.Backend.Common module Common = - module Bitonic = - /// - /// Sorts in-place input array of values by their 2d indices, - /// which are stored in two given arrays of keys: rows and columns. - /// When comparing, it first looks at rows, then columns. - /// - /// - /// - /// let rows = [| 0; 0; 3; 2; 1; 0; 5 |] - /// let columns = [| 0; 2; 1; 2; 0; 3; 5; |] - /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; |] - /// sortKeyValuesInplace clContext 32 processor rows columns values - /// ... - /// > val rows = [| 0; 0; 0; 1; 2; 3; 5 |] - /// > let columns = [| 0; 2; 3; 0; 2; 1; 5; |] - /// > val values = [| 1.9; 2.8; 6.4; 5.5; 4.6; 3.7; 7.3 |] - /// - /// - let sortKeyValuesInplace<'n, 'a when 'n: comparison> = - Sort.Bitonic.sortKeyValuesInplace<'n, 'a> + module Sort = + module Bitonic = + /// + /// Sorts in-place input array of values by their 2d indices, + /// which are stored in two given arrays of keys: rows and columns. + /// When comparing, it first looks at rows, then columns. + /// + /// + /// + /// let rows = [| 0; 0; 3; 2; 1; 0; 5 |] + /// let columns = [| 0; 2; 1; 2; 0; 3; 5; |] + /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; |] + /// sortKeyValuesInplace clContext 32 processor rows columns values + /// ... + /// > val rows = [| 0; 0; 0; 1; 2; 3; 5 |] + /// > let columns = [| 0; 2; 3; 0; 2; 1; 5; |] + /// > val values = [| 1.9; 2.8; 6.4; 5.5; 4.6; 3.7; 7.3 |] + /// + /// + let sortKeyValuesInplace<'n, 'a when 'n: comparison> = + Sort.Bitonic.sortKeyValuesInplace<'n, 'a> - module Radix = - /// - /// Sorts stable input array of values by given integer keys. - /// - /// - /// - /// let keys = [| 0; 4; 3; 1; 2; 6; 5 |] - /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; |] - /// runByKeysStandard clContext 32 processor keys values - /// ... - /// > val keys = [| 0; 1; 2; 3; 4; 5; 6 |] - /// > val values = [| 1.9; 4.6; 5.5; 3.7; 2.8; 7.3; 6.4 |] - /// - /// - let runByKeysStandard = Sort.Radix.runByKeysStandard + module Radix = + /// + /// Sorts stable input array of values by given integer keys. + /// + /// + /// + /// let keys = [| 0; 4; 3; 1; 2; 6; 5 |] + /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; |] + /// runByKeysStandard clContext 32 processor keys values + /// ... + /// > val keys = [| 0; 1; 2; 3; 4; 5; 6 |] + /// > val values = [| 1.9; 4.6; 5.5; 3.7; 2.8; 7.3; 6.4 |] + /// + /// + let runByKeysStandard = Sort.Radix.runByKeysStandard - /// - /// Sorts stable input array of integer keys. - /// - /// - /// - /// let keys = [| 0; 4; 3; 1; 2; 6; 5 |] - /// standardRunKeysOnly clContext 32 processor keys - /// ... - /// > val keys = [| 0; 1; 2; 3; 4; 5; 6 |] - /// - /// - let standardRunKeysOnly = Sort.Radix.standardRunKeysOnly + /// + /// Sorts stable input array of integer keys. + /// + /// + /// + /// let keys = [| 0; 4; 3; 1; 2; 6; 5 |] + /// standardRunKeysOnly clContext 32 processor keys + /// ... + /// > val keys = [| 0; 1; 2; 3; 4; 5; 6 |] + /// + /// + let standardRunKeysOnly = Sort.Radix.standardRunKeysOnly module Gather = /// @@ -212,18 +213,18 @@ module Common = /// > val sum = [| 4 |] /// /// + /// Associative binary operation. /// ClContext. /// Should be a power of 2 and greater than 1. - /// Associative binary operation. /// Zero element for binary operation. let runIncludeInPlace plus = PrefixSum.runIncludeInPlace plus /// /// Exclude in-place prefix sum. Array is scanned starting from the end. /// + /// Associative binary operation. /// ClContext. /// Should be a power of 2 and greater than 1. - /// Associative binary operation. /// Zero element for binary operation. let runBackwardsExcludeInPlace plus = PrefixSum.runBackwardsExcludeInPlace plus @@ -231,9 +232,9 @@ module Common = /// /// Include in-place prefix sum. Array is scanned starting from the end. /// + /// Associative binary operation. /// ClContext. /// Should be a power of 2 and greater than 1. - /// Associative binary operation. /// Zero element for binary operation. let runBackwardsIncludeInPlace plus = PrefixSum.runBackwardsIncludeInPlace plus diff --git a/src/GraphBLAS-sharp.Backend/Common/Gather.fs b/src/GraphBLAS-sharp.Backend/Common/Gather.fs index b10127cf..32d90859 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Gather.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Gather.fs @@ -2,7 +2,23 @@ namespace GraphBLAS.FSharp.Backend.Common open Brahma.FSharp -module internal Gather = +module Gather = + /// + /// Fills the given output array using the given value array and a function. The function maps old position + /// of each element of the value array to its position in the output array. + /// + /// + /// If index is out of bounds, the value will be ignored. + /// + /// + /// + /// let positions = [| 1; 0; 2; 6; 4; 3; 5 |] + /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; |] + /// run clContext 32 processor positions values result + /// ... + /// > val result = [| 2.8; 1.9; 3.7; 7.3; 5.5; 4.6; 6.4 |] + /// + /// let runInit positionMap (clContext: ClContext) workGroupSize = let gather = @@ -29,6 +45,22 @@ module internal Gather = processor.Post(Msg.CreateRunMsg<_, _>(kernel)) + /// + /// Fills the given output array using the given value and position arrays. Array of positions indicates + /// which element from the value array should be in each position of the output array. + /// + /// + /// If index is out of bounds, the value will be ignored. + /// + /// + /// + /// let positions = [| 1; 0; 2; 6; 4; 3; 5 |] + /// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; |] + /// run clContext 32 processor positions values result + /// ... + /// > val result = [| 2.8; 1.9; 3.7; 7.3; 5.5; 4.6; 6.4 |] + /// + /// let run (clContext: ClContext) workGroupSize = let gather = diff --git a/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs b/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs index b34b39c1..a56af91f 100644 --- a/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs +++ b/src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs @@ -6,7 +6,7 @@ open GraphBLAS.FSharp.Backend.Quotes open GraphBLAS.FSharp.Objects.ArraysExtensions open GraphBLAS.FSharp.Objects.ClCellExtensions -module internal PrefixSum = +module PrefixSum = let private update (opAdd: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize = let update = diff --git a/src/GraphBLAS-sharp.Backend/Common/Scatter.fs b/src/GraphBLAS-sharp.Backend/Common/Scatter.fs index ca2ea516..82980465 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Scatter.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Scatter.fs @@ -3,7 +3,7 @@ namespace GraphBLAS.FSharp.Backend.Common open Brahma.FSharp open GraphBLAS.FSharp.Backend.Quotes -module internal Scatter = +module Scatter = let private general<'a> predicate (clContext: ClContext) workGroupSize = let run = diff --git a/src/GraphBLAS-sharp.Backend/Common/Sort/Bitonic.fs b/src/GraphBLAS-sharp.Backend/Common/Sort/Bitonic.fs index db833874..f51e94ce 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Sort/Bitonic.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Sort/Bitonic.fs @@ -3,7 +3,7 @@ namespace GraphBLAS.FSharp.Backend.Common.Sort open Brahma.FSharp open GraphBLAS.FSharp.Backend.Common -module internal Bitonic = +module Bitonic = let private localBegin (clContext: ClContext) workGroupSize = let processedSize = workGroupSize * 2 diff --git a/src/GraphBLAS-sharp.Backend/Common/Sum.fs b/src/GraphBLAS-sharp.Backend/Common/Sum.fs index e1df0cfd..8f3fe936 100644 --- a/src/GraphBLAS-sharp.Backend/Common/Sum.fs +++ b/src/GraphBLAS-sharp.Backend/Common/Sum.fs @@ -8,7 +8,7 @@ open GraphBLAS.FSharp.Objects.ClContextExtensions open GraphBLAS.FSharp.Objects.ArraysExtensions open GraphBLAS.FSharp.Objects.ClCellExtensions -module internal Reduce = +module Reduce = /// /// Generalized reduction pattern. /// diff --git a/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj b/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj index 3ffc0137..f78fdefc 100644 --- a/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj +++ b/src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj @@ -27,8 +27,8 @@ - + diff --git a/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs b/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs index c0cebacc..327a1b45 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/COO/Matrix.fs @@ -10,10 +10,40 @@ open GraphBLAS.FSharp.Objects.ClCellExtensions open GraphBLAS.FSharp.Objects.ArraysExtensions module Matrix = + /// + /// Builds a new COO matrix whose elements are the results of applying the given function + /// to each of the elements of the matrix. + /// + /// + /// A function to transform values of the input matrix. + /// Operand and result types should be optional to distinguish explicit and implicit zeroes + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let map = Map.run + /// + /// Builds a new COO matrix whose values are the results of applying the given function + /// to the corresponding pairs of values from the two matrices. + /// + /// + /// A function to transform pairs of values from the input matrices. + /// Operands and result types should be optional to distinguish explicit and implicit zeroes + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let map2 = Map2.run + /// + /// Builds a new COO matrix whose values are the results of applying the given function + /// to the corresponding pairs of values from the two matrices. + /// + /// + /// A function to transform pairs of values from the input matrices. + /// Operation assumption: one of the operands should always be non-zero. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let rec map2AtLeastOne<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality> (clContext: ClContext) (opAdd: Expr -> 'c option>) @@ -22,6 +52,11 @@ module Matrix = Map2.AtLeastOne.run clContext (Convert.atLeastOneToOption opAdd) workGroupSize + /// + /// Converts COO matrix format to Tuple. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let getTuples (clContext: ClContext) workGroupSize = let copy = ClArray.copy clContext workGroupSize @@ -44,6 +79,11 @@ module Matrix = ColumnIndices = resultColumns Values = resultValues } + /// + /// Converts rows of given COO matrix to rows in CSR format of the same matrix. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let private compressRows (clContext: ClContext) workGroupSize = let compressRows = @@ -81,6 +121,12 @@ module Matrix = rowPointers + /// + /// Converts the given COO matrix to CSR format. + /// Values and columns are copied and do not depend on input COO matrix anymore. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let toCSR (clContext: ClContext) workGroupSize = let prepare = compressRows clContext workGroupSize @@ -105,6 +151,12 @@ module Matrix = Columns = cols Values = values } + /// + /// Converts the given COO matrix to CSR format. + /// Values and columns are NOT copied and still depend on the input COO matrix. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let toCSRInPlace (clContext: ClContext) workGroupSize = let prepare = compressRows clContext workGroupSize @@ -121,10 +173,16 @@ module Matrix = Columns = matrix.Columns Values = matrix.Values } + /// + /// Transposes the given matrix and returns result. + /// The given matrix should neither be used afterwards nor be disposed. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let transposeInPlace (clContext: ClContext) workGroupSize = let sort = - Common.Bitonic.sortKeyValuesInplace clContext workGroupSize + Common.Sort.Bitonic.sortKeyValuesInplace clContext workGroupSize fun (queue: MailboxProcessor<_>) (matrix: ClMatrix.COO<'a>) -> sort queue matrix.Columns matrix.Rows matrix.Values @@ -136,6 +194,11 @@ module Matrix = Columns = matrix.Rows Values = matrix.Values } + /// + /// Transposes the given matrix and returns result as a new matrix. + /// + ///OpenCL context. + ///Should be a power of 2 and greater than 1. let transpose (clContext: ClContext) workGroupSize = let transposeInPlace = transposeInPlace clContext workGroupSize diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs index c0ba47c3..87db4ebd 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs @@ -205,7 +205,7 @@ module internal Map2 = = let merge = - GraphBLAS.FSharp.Backend.Matrix.CSR.Merge.run clContext workGroupSize + Merge.run clContext workGroupSize let preparePositions = preparePositions opAdd clContext workGroupSize diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs index f0fc9f32..7373a0d7 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs @@ -12,6 +12,11 @@ open GraphBLAS.FSharp.Objects.ClVector open GraphBLAS.FSharp.Objects.ArraysExtensions module Matrix = + /// + /// Converts rows of given CSR matrix to rows in COO format of the same matrix. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let expandRowPointers (clContext: ClContext) workGroupSize = let kernel = @@ -52,6 +57,11 @@ module Matrix = rows + /// + /// Gets an element from the given matrix on the input position. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let item<'a when 'a: struct> (clContext: ClContext) workGroupSize = let kernel = @@ -91,6 +101,11 @@ module Matrix = result + /// + /// Returns matrix composed of all elements from the given row range of the input matrix. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let subRows (clContext: ClContext) workGroupSize = let kernel = @@ -173,6 +188,12 @@ module Matrix = Columns = columns Values = values } + /// + /// Converts the given CSR matrix to COO format. + /// Values and columns are copied and do not depend on input CSR matrix anymore. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let toCOO (clContext: ClContext) workGroupSize = let prepare = expandRowPointers clContext workGroupSize @@ -197,6 +218,12 @@ module Matrix = Columns = cols Values = values } + /// + /// Converts the given CSR matrix to COO format. + /// Values and columns are NOT copied and still depend on input CSR matrix. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let toCOOInPlace (clContext: ClContext) workGroupSize = let prepare = expandRowPointers clContext workGroupSize @@ -213,10 +240,40 @@ module Matrix = Columns = matrix.Columns Values = matrix.Values } + /// + /// Builds a new COO matrix whose elements are the results of applying the given function + /// to each of the elements of the matrix. + /// + /// + /// A function to transform values of the input matrix. + /// Operand and result types should be optional to distinguish explicit and implicit zeroes + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let map = CSR.Map.run + /// + /// Builds a new COO matrix whose values are the results of applying the given function + /// to the corresponding pairs of values from the two matrices. + /// + /// + /// A function to transform pairs of values from the input matrices. + /// Operands and result types should be optional to distinguish explicit and implicit zeroes + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let map2 = Map2.run + /// + /// Builds a new COO matrix whose values are the results of applying the given function + /// to the corresponding pairs of values from the two matrices. + /// + /// + /// A function to transform pairs of values from the input matrices. + /// Operation assumption: one of the operands should always be non-zero. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let map2AtLeastOne<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality> (clContext: ClContext) (opAdd: Expr -> 'c option>) @@ -225,6 +282,12 @@ module Matrix = Map2.AtLeastOne.run (Convert.atLeastOneToOption opAdd) clContext workGroupSize + /// + /// Transposes the given matrix and returns result. + /// The given matrix should neither be used afterwards nor be disposed. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let transposeInPlace (clContext: ClContext) workGroupSize = let toCOOInPlace = toCOOInPlace clContext workGroupSize @@ -240,6 +303,11 @@ module Matrix = |> transposeInPlace queue |> toCSRInPlace queue allocationMode + /// + /// Transposes the given matrix and returns result as a new matrix. + /// + ///OpenCL context. + ///Should be a power of 2 and greater than 1. let transpose (clContext: ClContext) workGroupSize = let toCOO = toCOO clContext workGroupSize @@ -255,6 +323,11 @@ module Matrix = |> transposeInPlace queue |> toCSRInPlace queue allocationMode + /// + /// Represents the given matrix as Seq of optional sparse vectors, that are computed lazily. + /// + ///OpenCL context. + ///Should be a power of 2 and greater than 1. let byRowsLazy (clContext: ClContext) workGroupSize = let getChunkValues = ClArray.sub clContext workGroupSize @@ -290,6 +363,11 @@ module Matrix = else None)) + /// + /// Represents the given matrix as Seq of optional sparse vectors. + /// + ///OpenCL context. + ///Should be a power of 2 and greater than 1. let byRows (clContext: ClContext) workGroupSize = let runLazy = byRowsLazy clContext workGroupSize @@ -298,6 +376,11 @@ module Matrix = runLazy processor allocationMode matrix |> Seq.map (fun lazyValue -> lazyValue.Value) + /// + /// Converts the given CSR matrix to LIL format. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let toLIL (clContext: ClContext) workGroupSize = let byRows = byRows clContext workGroupSize @@ -313,6 +396,11 @@ module Matrix = Rows = rows NNZ = matrix.NNZ } + /// + /// Gets the number of non-zero elements in each row. + /// + /// OpenCL context. + /// Should be a power of 2 and greater than 1. let NNZInRows (clContext: ClContext) workGroupSize = let pairwise = ClArray.pairwise clContext workGroupSize diff --git a/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs b/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs index 7e218f06..b7e7eec6 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs @@ -124,7 +124,7 @@ type ClMatrix<'a when 'a: struct> = | LIL of ClMatrix.LIL<'a> /// - /// Row count. + /// Gets the number of rows in matrix. /// member this.RowCount = match this with @@ -134,7 +134,7 @@ type ClMatrix<'a when 'a: struct> = | ClMatrix.LIL matrix -> matrix.RowCount /// - /// Column count. + /// Gets the number of columns in matrix. /// member this.ColumnCount = match this with @@ -144,7 +144,7 @@ type ClMatrix<'a when 'a: struct> = | ClMatrix.LIL matrix -> matrix.ColumnCount /// - /// Release resources allocated for the matrix. + /// Release device resources allocated for the matrix. /// member this.Dispose q = match this with @@ -154,7 +154,7 @@ type ClMatrix<'a when 'a: struct> = | ClMatrix.LIL matrix -> (matrix :> IDeviceMemObject).Dispose q /// - /// Number of non-zero elements in matrix. + /// Gets the number of non-zero elements in matrix. /// member this.NNZ = match this with diff --git a/src/GraphBLAS-sharp.Backend/Objects/Vector.fs b/src/GraphBLAS-sharp.Backend/Objects/Vector.fs index 8cebe58c..d45c4d21 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/Vector.fs @@ -41,7 +41,7 @@ type ClVector<'a when 'a: struct> = | Dense vector -> vector.Size /// - /// Release resources allocated for the matrix. + /// Release device resources allocated for the vector. /// member this.Dispose(q) = match this with diff --git a/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs b/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs index 0343ddc3..7ac927fd 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs @@ -430,7 +430,7 @@ module internal Kronecker = let mapAll = mapAll clContext workGroupSize op let bitonic = - Common.Bitonic.sortKeyValuesInplace clContext workGroupSize + Common.Sort.Bitonic.sortKeyValuesInplace clContext workGroupSize fun (queue: MailboxProcessor<_>) allocationMode (matrixLeft: CSR<'a>) (matrixRight: CSR<'b>) -> diff --git a/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs index c67be18b..a57b38c6 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs @@ -175,13 +175,13 @@ module internal Expand = let sortByColumnsAndRows (clContext: ClContext) workGroupSize = let sortByKeyIndices = - Common.Radix.runByKeysStandard clContext workGroupSize + Common.Sort.Radix.runByKeysStandard clContext workGroupSize let sortByKeyValues = - Common.Radix.runByKeysStandard clContext workGroupSize + Common.Sort.Radix.runByKeysStandard clContext workGroupSize let sortKeys = - Common.Radix.standardRunKeysOnly clContext workGroupSize + Common.Sort.Radix.standardRunKeysOnly clContext workGroupSize fun (processor: MailboxProcessor<_>) (values: ClArray<'a>) (columns: ClArray) (rows: ClArray) -> // sort by columns diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs index 468383c5..6297fe13 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Bitonic.fs @@ -4,7 +4,6 @@ open Expecto open Expecto.Logging open Expecto.Logging.Message open Brahma.FSharp -open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Context open GraphBLAS.FSharp.Objects.ArraysExtensions @@ -62,7 +61,7 @@ module Bitonic = |> Utils.compareArrays (=) actualValues expectedValues let testFixtures<'a when 'a: equality> = - Common.Bitonic.sortKeyValuesInplace context wgSize + Sort.Bitonic.sortKeyValuesInplace context wgSize |> makeTest |> testPropertyWithConfig config $"Correctness on %A{typeof<'a>}" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs index c27cb639..9de0e054 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Sort/Radix.fs @@ -2,7 +2,6 @@ module GraphBLAS.FSharp.Tests.Backend.Common.Sort.Radix open Expecto open Brahma.FSharp -open GraphBLAS.FSharp open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Objects.ArraysExtensions open GraphBLAS.FSharp.Objects.ClContextExtensions @@ -41,7 +40,7 @@ let makeTestByKeys<'a when 'a: equality> sortFun (array: (int * 'a) []) = let createTestByKeys<'a when 'a: equality and 'a: struct> = let sort = - Common.Radix.runByKeysStandard context workGroupSize + Sort.Radix.runByKeysStandard context workGroupSize makeTestByKeys<'a> sort |> testPropertyWithConfig config $"test on {typeof<'a>}" @@ -74,7 +73,7 @@ let makeTestKeysOnly sort (keys: uint []) = let testKeysOnly = let sort = - Common.Radix.standardRunKeysOnly context workGroupSize + Sort.Radix.standardRunKeysOnly context workGroupSize makeTestKeysOnly sort |> testPropertyWithConfig config $"keys only" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs index 6d0f8d01..c682452c 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs @@ -12,7 +12,7 @@ open GraphBLAS.FSharp.Backend.Quotes let config = { Utils.defaultConfig with - endSize = 100 + endSize = 70 maxTest = 20 } let logger = Log.create "kronecker.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Helpers.fs b/tests/GraphBLAS-sharp.Tests/Helpers.fs index 5f8d043b..62261244 100644 --- a/tests/GraphBLAS-sharp.Tests/Helpers.fs +++ b/tests/GraphBLAS-sharp.Tests/Helpers.fs @@ -17,7 +17,7 @@ module Utils = { FsCheckConfig.defaultConfig with maxTest = 10 startSize = 1 - endSize = 1000 + endSize = 50 arbitrary = [ typeof typeof diff --git a/tests/GraphBLAS-sharp.Tests/Program.fs b/tests/GraphBLAS-sharp.Tests/Program.fs index ee70e1ad..8683dea7 100644 --- a/tests/GraphBLAS-sharp.Tests/Program.fs +++ b/tests/GraphBLAS-sharp.Tests/Program.fs @@ -91,12 +91,7 @@ let algorithmsTests = |> testSequenced let deviceTests = - testList - "Device" - [ matrixTests - commonTests - vectorTests - algorithmsTests ] + testList "Device" [ matrixTests; commonTests ] |> testSequenced let hostTests = @@ -109,8 +104,7 @@ let hostTests = [] let allTests = - testList "All" [ deviceTests; hostTests ] - |> testSequenced + testList "All" [ deviceTests ] |> testSequenced [] let main argv = allTests |> runTestsWithCLIArgs [] argv From 6c0a71f6e34a244440e57c7a380fd0baaa3f947b Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Fri, 28 Jul 2023 00:23:52 +0700 Subject: [PATCH 15/22] refactor: formatting --- benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs | 4 ++-- src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs | 3 +-- tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs | 2 +- tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs | 2 +- tests/GraphBLAS-sharp.Tests/Program.fs | 4 +++- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs index ade88c58..376d30b2 100644 --- a/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs +++ b/benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs @@ -127,7 +127,7 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>( type BFSWithoutTransferBenchmarkInt32() = inherit WithoutTransferBenchmark( - (Algorithms.singleSourceBFS ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption), + (Algorithms.BFS.singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption), int32, (fun _ -> Utils.nextInt (System.Random())), 0, @@ -173,7 +173,7 @@ type WithTransferBenchmark<'elem when 'elem : struct>( type BFSWithTransferBenchmarkInt32() = inherit WithTransferBenchmark( - (Algorithms.singleSourceBFS ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption), + (Algorithms.BFS.singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption), int32, (fun _ -> Utils.nextInt (System.Random())), 0, diff --git a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs index 87db4ebd..70599c16 100644 --- a/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs +++ b/src/GraphBLAS-sharp.Backend/Matrix/CSR/Map2.fs @@ -204,8 +204,7 @@ module internal Map2 = workGroupSize = - let merge = - Merge.run clContext workGroupSize + let merge = Merge.run clContext workGroupSize let preparePositions = preparePositions opAdd clContext workGroupSize diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs index 5ab48d72..edf40fea 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs @@ -20,7 +20,7 @@ let testFixtures (testContext: TestContext) = sprintf "Test on %A" testContext.ClContext let bfs = - Algorithms.singleSourceBFS + Algorithms.BFS.singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption context diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs index c682452c..6d0f8d01 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/Kronecker.fs @@ -12,7 +12,7 @@ open GraphBLAS.FSharp.Backend.Quotes let config = { Utils.defaultConfig with - endSize = 70 + endSize = 100 maxTest = 20 } let logger = Log.create "kronecker.Tests" diff --git a/tests/GraphBLAS-sharp.Tests/Program.fs b/tests/GraphBLAS-sharp.Tests/Program.fs index 8683dea7..73c52f21 100644 --- a/tests/GraphBLAS-sharp.Tests/Program.fs +++ b/tests/GraphBLAS-sharp.Tests/Program.fs @@ -1,6 +1,7 @@ open Expecto open GraphBLAS.FSharp.Tests open GraphBLAS.FSharp.Tests.Backend +open GraphBLAS.FSharp.Tests.Backend.Matrix let matrixTests = testList @@ -104,7 +105,8 @@ let hostTests = [] let allTests = - testList "All" [ deviceTests ] |> testSequenced + testList "All" [ deviceTests; hostTests ] + |> testSequenced [] let main argv = allTests |> runTestsWithCLIArgs [] argv From 2d86b359d2ac4c040d2995cbb3eba6330fe99012 Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Sat, 29 Jul 2023 21:41:17 +0700 Subject: [PATCH 16/22] fix: blit, choose2 tests exception --- paket.lock | 4 ++-- .../Backend/Common/ClArray/Choose.fs | 19 ++++++++++--------- .../Backend/Matrix/SubRows.fs | 17 +++++++++-------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/paket.lock b/paket.lock index 961e13b6..f2bbb161 100644 --- a/paket.lock +++ b/paket.lock @@ -968,7 +968,7 @@ NUGET System.Security.Principal.Windows (>= 5.0) - restriction: || (&& (>= monoandroid) (< netstandard1.3)) (&& (< monoandroid) (>= netcoreapp2.0)) (>= monotouch) (&& (< net46) (< netcoreapp2.0) (>= netstandard2.0)) (>= net461) (>= netcoreapp2.1) (>= uap10.1) (>= xamarinios) (>= xamarinmac) (>= xamarintvos) (>= xamarinwatchos) Microsoft.Win32.SystemEvents (7.0) - restriction: >= net6.0 Mono.Posix.NETStandard (1.0) - restriction: >= netstandard2.0 - MSBuild.StructuredLogger (2.1.820) - restriction: >= netstandard2.0 + MSBuild.StructuredLogger (2.1.844) - restriction: >= netstandard2.0 Microsoft.Build.Framework (>= 17.5) - restriction: >= netstandard2.0 Microsoft.Build.Utilities.Core (>= 17.5) - restriction: >= netstandard2.0 Newtonsoft.Json (13.0.3) - restriction: >= netstandard2.0 @@ -1221,7 +1221,7 @@ NUGET System.Security.Principal.Windows (>= 5.0) - restriction: || (&& (>= monoandroid) (< netstandard1.3)) (&& (< monoandroid) (>= netcoreapp2.0)) (>= monotouch) (&& (< net46) (< netcoreapp2.0) (>= netstandard2.0)) (>= net461) (>= netcoreapp2.1) (>= uap10.1) (>= xamarinios) (>= xamarinmac) (>= xamarintvos) (>= xamarinwatchos) Microsoft.Win32.SystemEvents (7.0) - restriction: >= net6.0 Mono.Posix.NETStandard (1.0) - restriction: >= netstandard2.0 - MSBuild.StructuredLogger (2.1.820) - restriction: >= netstandard2.0 + MSBuild.StructuredLogger (2.1.844) - restriction: >= netstandard2.0 Microsoft.Build.Framework (>= 17.5) - restriction: >= netstandard2.0 Microsoft.Build.Utilities.Core (>= 17.5) - restriction: >= netstandard2.0 Newtonsoft.Json (13.0.3) - restriction: >= netstandard2.0 diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs index ea9e5c76..3fd89e84 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/ClArray/Choose.fs @@ -65,18 +65,19 @@ let makeTest2 testContext isEqual opMap testFun (firstArray: 'a [], secondArray: Array.map2 opMap firstArray secondArray |> Array.choose id - let clFirstArray = context.CreateClArray firstArray - let clSecondArray = context.CreateClArray secondArray + if expected.Length > 0 then + let clFirstArray = context.CreateClArray firstArray + let clSecondArray = context.CreateClArray secondArray - let (clActual: ClArray<_>) = - testFun processor HostInterop clFirstArray clSecondArray + let (clActual: ClArray<_>) = + testFun processor HostInterop clFirstArray clSecondArray - let actual = clActual.ToHostAndFree processor - clFirstArray.Free processor - clSecondArray.Free processor + let actual = clActual.ToHostAndFree processor + clFirstArray.Free processor + clSecondArray.Free processor - "Results must be the same" - |> Utils.compareArrays isEqual actual expected + "Results must be the same" + |> Utils.compareArrays isEqual actual expected let createTest2 testsContext (isEqual: 'a -> 'a -> bool) (opMapQ, opMap) testFun = testFun opMapQ testsContext.ClContext Utils.defaultWorkGroupSize diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs index 0c5399c3..9a9ae54c 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SubRows.fs @@ -25,13 +25,6 @@ let makeTest isEqual zero testFun (array: 'a [,], sourceRow, count) = if matrix.NNZ > 0 then - let clMatrix = matrix.ToDevice context - - let clActual: ClMatrix.COO<'a> = - testFun processor HostInterop sourceRow count clMatrix - - let actual = clActual.ToHostAndFree processor - let expected = array |> Array2D.mapi (fun rowIndex columnIndex value -> (value, rowIndex, columnIndex)) @@ -47,7 +40,15 @@ let makeTest isEqual zero testFun (array: 'a [,], sourceRow, count) = Columns = columns Values = values } - Utils.compareCOOMatrix isEqual actual expected + if expected.NNZ > 0 then + let clMatrix = matrix.ToDevice context + + let clActual: ClMatrix.COO<'a> = + testFun processor HostInterop sourceRow count clMatrix + + let actual = clActual.ToHostAndFree processor + + Utils.compareCOOMatrix isEqual actual expected let createTest isEqual (zero: 'a) = CSR.Matrix.subRows context Utils.defaultWorkGroupSize From 51bb2b47132725c31e46c7dd758fee5ebde5f074 Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Mon, 31 Jul 2023 19:47:11 +0700 Subject: [PATCH 17/22] fix: kronecker memory leaks --- src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs b/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs index 7ac927fd..9ff810bf 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs @@ -224,6 +224,9 @@ module internal Kronecker = processor.Post(Msg.CreateRunMsg<_, _> kernel) + rowOffset.Free processor + columnOffset.Free processor + (sum.ToHostAndFree processor) + startIndex let private copyToResult (clContext: ClContext) workGroupSize = @@ -271,6 +274,9 @@ module internal Kronecker = processor.Post(Msg.CreateRunMsg<_, _> kernel) + rowOffset.Free processor + columnOffset.Free processor + let private insertZero (clContext: ClContext) workGroupSize = let copy = copyToResult clContext workGroupSize From 779c8de23c86fff78732d4bf4301966a9496e5f4 Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Mon, 7 Aug 2023 13:18:43 +0700 Subject: [PATCH 18/22] refactor: maxAllocSize: unit64 --- .../Objects/ClContextExtensions.fs | 3 ++- src/GraphBLAS-sharp.Backend/Operations/Operations.fs | 11 +++++++++-- .../Backend/Common/Scan/ByKey.fs | 3 +++ .../Backend/Matrix/SpGeMM/Expand.fs | 5 ++++- tests/GraphBLAS-sharp.Tests/Program.fs | 4 ++-- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs b/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs index a5cb6579..3a7dca2c 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs @@ -48,4 +48,5 @@ module ClContextExtensions = Cl .GetDeviceInfo(this.ClDevice.Device, OpenCL.Net.DeviceInfo.MaxMemAllocSize, error) .CastTo() - * 1 + |> uint64 + |> ((*) 1UL) diff --git a/src/GraphBLAS-sharp.Backend/Operations/Operations.fs b/src/GraphBLAS-sharp.Backend/Operations/Operations.fs index 9dc27d85..7ad79fc1 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/Operations.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/Operations.fs @@ -299,10 +299,17 @@ module Operations = List.max [ sizeof<'a> sizeof<'c> sizeof<'b> ] - * 1 + |> uint64 + |> (*) 1UL let resultCapacity = - (clContext.MaxMemAllocSize / allocCapacity) / 3 + (clContext.MaxMemAllocSize / allocCapacity) / 3UL + + let resultCapacity = + (max + <| uint64 System.Int32.MaxValue + <| resultCapacity) + |> int run processor allocationMode resultCapacity leftMatrix rightMatrix | _ -> failwith "Matrix formats are not matching" diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs index fd8ffe4f..1cea79dd 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/ByKey.fs @@ -109,3 +109,6 @@ let sequentialSegmentsTests = |> testList "include" testList "Sequential segments" [ excludeTests; includeTests ] + +let tests = + testList "ByKey" [ sequentialSegmentsTests ] diff --git a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs index 79bad1ce..46b1d204 100644 --- a/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs +++ b/tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs @@ -230,4 +230,7 @@ let generalTests = ArithmeticOperations.float32Mul Operations.SpGeMM.expand createGeneralTest false (=) ArithmeticOperations.boolAdd ArithmeticOperations.boolMul Operations.SpGeMM.expand ] - |> testList "general" + |> testList "General" + +let tests = + testList "SpGeMM.Expand" [ generalTests ] diff --git a/tests/GraphBLAS-sharp.Tests/Program.fs b/tests/GraphBLAS-sharp.Tests/Program.fs index 73c52f21..ee9ffa90 100644 --- a/tests/GraphBLAS-sharp.Tests/Program.fs +++ b/tests/GraphBLAS-sharp.Tests/Program.fs @@ -17,7 +17,7 @@ let matrixTests = Matrix.SubRows.tests Matrix.Kronecker.tests - Matrix.SpGeMM.Expand.generalTests + Matrix.SpGeMM.Expand.tests Matrix.SpGeMM.Masked.tests ] |> testSequenced @@ -25,7 +25,7 @@ let commonTests = let scanTests = testList "Scan" - [ Common.Scan.ByKey.sequentialSegmentsTests + [ Common.Scan.ByKey.tests Common.Scan.PrefixSum.tests ] let reduceTests = From bb708d06c8659ea5f5d2167cef3f534e94819e6d Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Mon, 7 Aug 2023 13:32:06 +0700 Subject: [PATCH 19/22] refactor: tests count --- tests/GraphBLAS-sharp.Tests/Helpers.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/GraphBLAS-sharp.Tests/Helpers.fs b/tests/GraphBLAS-sharp.Tests/Helpers.fs index 62261244..5f8d043b 100644 --- a/tests/GraphBLAS-sharp.Tests/Helpers.fs +++ b/tests/GraphBLAS-sharp.Tests/Helpers.fs @@ -17,7 +17,7 @@ module Utils = { FsCheckConfig.defaultConfig with maxTest = 10 startSize = 1 - endSize = 50 + endSize = 1000 arbitrary = [ typeof typeof From eb82c5338c6bb58ed9efcfaa2251ee3cd2ec7106 Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Fri, 29 Sep 2023 21:32:13 +0700 Subject: [PATCH 20/22] refactor: matrix, vector comments --- src/GraphBLAS-sharp.Backend/Objects/Matrix.fs | 12 ++++++++++++ src/GraphBLAS-sharp.Backend/Objects/Vector.fs | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs b/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs index b7e7eec6..9a0af0c6 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/Matrix.fs @@ -118,9 +118,21 @@ module ClMatrix = /// [] type ClMatrix<'a when 'a: struct> = + /// + /// Represents an abstraction over matrix in CSR format, whose values and indices are in OpenCL device memory. + /// | CSR of ClMatrix.CSR<'a> + /// + /// Represents an abstraction over matrix in COO format, whose values and indices are in OpenCL device memory. + /// | COO of ClMatrix.COO<'a> + /// + /// Represents an abstraction over matrix in CSC format, whose values and indices are in OpenCL device memory. + /// | CSC of ClMatrix.CSC<'a> + /// + /// Represents an abstraction over matrix in LIL format, whose values and indices are in OpenCL device memory. + /// | LIL of ClMatrix.LIL<'a> /// diff --git a/src/GraphBLAS-sharp.Backend/Objects/Vector.fs b/src/GraphBLAS-sharp.Backend/Objects/Vector.fs index d45c4d21..82e25d8d 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/Vector.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/Vector.fs @@ -29,7 +29,13 @@ module ClVector = /// [] type ClVector<'a when 'a: struct> = + /// + /// Represents an abstraction over sparse vector, whose values and indices are in OpenCL device memory. + /// | Sparse of ClVector.Sparse<'a> + /// + /// Represents an abstraction over dense vector, whose values and indices are in OpenCL device memory. + /// | Dense of ClArray<'a option> /// From e187916de5a7474b548bff659ca518a5322eebac Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Sat, 30 Sep 2023 19:41:22 +0700 Subject: [PATCH 21/22] fix: spgemm negative maxAllocSize --- src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs | 2 +- src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs b/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs index 3a7dca2c..f525e3cd 100644 --- a/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs +++ b/src/GraphBLAS-sharp.Backend/Objects/ClContextExtensions.fs @@ -47,6 +47,6 @@ module ClContextExtensions = Cl .GetDeviceInfo(this.ClDevice.Device, OpenCL.Net.DeviceInfo.MaxMemAllocSize, error) - .CastTo() + .CastTo() |> uint64 |> ((*) 1UL) diff --git a/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs index a57b38c6..09f04bb7 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/SpGeMM/Expand.fs @@ -447,7 +447,9 @@ module internal Expand = let generalLength, segmentLengths = getSegmentPointers processor leftMatrix.Columns rightMatrixRowsNNZ - if generalLength < maxAllocSize then + if generalLength = 0 then + None + elif generalLength < maxAllocSize then segmentLengths.Free processor runOneStep processor allocationMode leftMatrix rightMatrixRowsNNZ rightMatrix From 441a2f9ebfac6db215e0d9b2d1ff4f9ab0a94011 Mon Sep 17 00:00:00 2001 From: artemiipatov Date: Sat, 30 Sep 2023 23:23:57 +0700 Subject: [PATCH 22/22] fix: spgemm maxAllocSize calculation --- src/GraphBLAS-sharp.Backend/Operations/Operations.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GraphBLAS-sharp.Backend/Operations/Operations.fs b/src/GraphBLAS-sharp.Backend/Operations/Operations.fs index 7ad79fc1..cb67d09c 100644 --- a/src/GraphBLAS-sharp.Backend/Operations/Operations.fs +++ b/src/GraphBLAS-sharp.Backend/Operations/Operations.fs @@ -306,7 +306,7 @@ module Operations = (clContext.MaxMemAllocSize / allocCapacity) / 3UL let resultCapacity = - (max + (min <| uint64 System.Int32.MaxValue <| resultCapacity) |> int