Skip to content

Commit

Permalink
Merge pull request #93 from kirillgarbar/scan
Browse files Browse the repository at this point in the history
Improved scan performance
  • Loading branch information
kirillgarbar authored May 10, 2024
2 parents 2f5ba61 + b5ea523 commit 108c45c
Show file tree
Hide file tree
Showing 9 changed files with 330 additions and 41 deletions.
10 changes: 5 additions & 5 deletions src/GraphBLAS-sharp.Backend/Common/ClArray.fs
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ module ClArray =
Bitmap.lastOccurrence clContext workGroupSize

let prefixSumExclude =
PrefixSum.runExcludeInPlace <@ (+) @> clContext workGroupSize
ScanInternal.standardExcludeInPlace clContext workGroupSize

fun (processor: MailboxProcessor<_>) (inputArray: ClArray<'a>) ->

let bitmap =
getUniqueBitmap processor DeviceOnly inputArray

let resultLength =
(prefixSumExclude processor bitmap 0)
(prefixSumExclude processor bitmap)
.ToHostAndFree(processor)

let outputArray =
Expand Down Expand Up @@ -314,7 +314,7 @@ module ClArray =
Map.map<'a, int> (Map.chooseBitmap predicate) clContext workGroupSize

let prefixSum =
PrefixSum.standardExcludeInPlace clContext workGroupSize
ScanInternal.standardExcludeInPlace clContext workGroupSize

let assignValues =
assignOption predicate clContext workGroupSize
Expand Down Expand Up @@ -410,7 +410,7 @@ module ClArray =
Map.map2<'a, 'b, int> (Map.choose2Bitmap predicate) clContext workGroupSize

let prefixSum =
PrefixSum.standardExcludeInPlace clContext workGroupSize
ScanInternal.standardExcludeInPlace clContext workGroupSize

let assignValues =
assignOption2 predicate clContext workGroupSize
Expand Down Expand Up @@ -878,7 +878,7 @@ module ClArray =
mapInPlace ArithmeticOperations.intNotQ clContext workGroupSize

let prefixSum =
PrefixSum.standardExcludeInPlace clContext workGroupSize
ScanInternal.standardExcludeInPlace clContext workGroupSize

let scatter =
Scatter.lastOccurrence clContext workGroupSize
Expand Down
19 changes: 11 additions & 8 deletions src/GraphBLAS-sharp.Backend/Common/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ module Common =
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
/// <param name="plus">Associative binary operation.</param>
/// <param name="zero">Zero element for binary operation.</param>
let runExcludeInPlace plus = PrefixSum.runExcludeInPlace plus
let runExcludeInPlace plus = ScanInternal.runExcludeInPlace plus

/// <summary>
/// Include in-place prefix sum.
Expand All @@ -231,7 +231,8 @@ module Common =
/// <param name="clContext">ClContext.</param>
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
/// <param name="zero">Zero element for binary operation.</param>
let runIncludeInPlace plus = PrefixSum.runIncludeInPlace plus
let runIncludeInPlace plus =
PrefixSumInternal.runIncludeInPlace plus

/// <summary>
/// Exclude in-place prefix sum. Array is scanned starting from the end.
Expand All @@ -241,7 +242,7 @@ module Common =
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
/// <param name="zero">Zero element for binary operation.</param>
let runBackwardsExcludeInPlace plus =
PrefixSum.runBackwardsExcludeInPlace plus
PrefixSumInternal.runBackwardsExcludeInPlace plus

/// <summary>
/// Include in-place prefix sum. Array is scanned starting from the end.
Expand All @@ -251,7 +252,7 @@ module Common =
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
/// <param name="zero">Zero element for binary operation.</param>
let runBackwardsIncludeInPlace plus =
PrefixSum.runBackwardsIncludeInPlace plus
PrefixSumInternal.runBackwardsIncludeInPlace plus

/// <summary>
/// Exclude in-place prefix sum of integer array with addition operation and start value that is equal to 0.
Expand All @@ -267,7 +268,7 @@ module Common =
/// > val sum = [| 4 |]
/// </code>
/// </example>
let standardExcludeInPlace = PrefixSum.standardExcludeInPlace
let standardExcludeInPlace = ScanInternal.standardExcludeInPlace

/// <summary>
/// Include in-place prefix sum of integer array with addition operation and start value that is equal to 0.
Expand All @@ -285,7 +286,7 @@ module Common =
/// </example>
/// <param name="clContext">ClContext.</param>
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
let standardIncludeInPlace = PrefixSum.standardIncludeInPlace
let standardIncludeInPlace = PrefixSumInternal.standardIncludeInPlace

module ByKey =
/// <summary>
Expand All @@ -299,7 +300,8 @@ module Common =
/// > val result = [| 0; 0; 1; 2; 0; 1 |]
/// </code>
/// </example>
let sequentialExclude op = PrefixSum.ByKey.sequentialExclude op
let sequentialExclude op =
PrefixSumInternal.ByKey.sequentialExclude op

/// <summary>
/// Include scan by key.
Expand All @@ -312,7 +314,8 @@ module Common =
/// > val result = [| 1; 1; 2; 3; 1; 2 |]
/// </code>
/// </example>
let sequentialInclude op = PrefixSum.ByKey.sequentialInclude op
let sequentialInclude op =
PrefixSumInternal.ByKey.sequentialInclude op

module Reduce =
/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open GraphBLAS.FSharp.Backend.Quotes
open GraphBLAS.FSharp.Objects.ArraysExtensions
open GraphBLAS.FSharp.Objects.ClCellExtensions

module PrefixSum =
module internal PrefixSumInternal =
let private update (opAdd: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize =

let update =
Expand Down Expand Up @@ -224,6 +224,8 @@ module PrefixSum =
/// </example>
/// <param name="clContext">ClContext.</param>
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
[<System.ObsoleteAttribute("This method is deprecated due to bad perfomance. Use method from Scan module instead.",
false)>]
let standardExcludeInPlace (clContext: ClContext) workGroupSize =

let scan =
Expand Down
Loading

0 comments on commit 108c45c

Please sign in to comment.