Skip to content

Radix #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 2 additions & 78 deletions src/GraphBLAS-sharp.Backend/Common/ClArray.fs
Original file line number Diff line number Diff line change
Expand Up @@ -129,82 +129,6 @@ module ClArray =

outputArray

/// <summary>
/// Exclude inplace prefix sum.
/// </summary>
/// <example>
/// <code>
/// 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 |]
/// </code>
/// </example>
///<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 prefixSumExcludeInplace = PrefixSum.runExcludeInplace

/// <summary>
/// Include inplace prefix sum.
/// </summary>
/// <example>
/// <code>
/// 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 |]
/// </code>
/// </example>
///<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 prefixSumIncludeInplace = PrefixSum.runIncludeInplace

let prefixSumExclude plus (clContext: ClContext) workGroupSize =

let runExcludeInplace =
prefixSumExcludeInplace plus clContext workGroupSize

let copy = copy clContext workGroupSize

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

let outputArray = copy processor allocationMode inputArray

let totalSum =
runExcludeInplace processor outputArray zero

outputArray, totalSum

let prefixSumInclude plus (clContext: ClContext) workGroupSize =

let runIncludeInplace =
prefixSumIncludeInplace plus clContext workGroupSize

let copy = copy clContext workGroupSize

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

let outputArray = copy processor allocationMode inputArray

let totalSum =
runIncludeInplace processor outputArray zero

outputArray, totalSum

let prefixSumBackwardsExcludeInplace plus =
PrefixSum.runBackwardsExcludeInplace plus

let prefixSumBackwardsIncludeInplace plus =
PrefixSum.runBackwardsIncludeInplace plus

let getUniqueBitmap (clContext: ClContext) workGroupSize =

let getUniqueBitmap =
Expand Down Expand Up @@ -250,7 +174,7 @@ module ClArray =
let getUniqueBitmap = getUniqueBitmap clContext workGroupSize

let prefixSumExclude =
prefixSumExcludeInplace <@ (+) @> clContext workGroupSize
PrefixSum.runExcludeInplace <@ (+) @> clContext workGroupSize

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

Expand Down Expand Up @@ -380,7 +304,7 @@ module ClArray =
<| Map.optionToValueOrZero Unchecked.defaultof<'b>

let prefixSum =
prefixSumExcludeInplace <@ (+) @> clContext workGroupSize
PrefixSum.runExcludeInplace <@ (+) @> clContext workGroupSize

let scatter =
Scatter.runInplace clContext workGroupSize
Expand Down
52 changes: 52 additions & 0 deletions src/GraphBLAS-sharp.Backend/Common/PrefixSum.fs
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,55 @@ module PrefixSum =
let runBackwardsExcludeInplace plus = runInplace true scanExclusive plus

let runBackwardsIncludeInplace plus = runInplace true scanInclusive plus

/// <summary>
/// Exclude inplace prefix sum.
/// </summary>
/// <example>
/// <code>
/// 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 |]
/// </code>
/// </example>
///<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 standardExcludeInplace (clContext: ClContext) workGroupSize =

let scan =
runExcludeInplace <@ (+) @> clContext workGroupSize

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

scan processor inputArray 0

/// <summary>
/// Include inplace prefix sum.
/// </summary>
/// <example>
/// <code>
/// 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 |]
/// </code>
/// </example>
///<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 standardIncludeInplace (clContext: ClContext) workGroupSize =

let scan =
runIncludeInplace <@ (+) @> clContext workGroupSize

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

scan processor inputArray 0
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace GraphBLAS.FSharp.Backend.Common
namespace GraphBLAS.FSharp.Backend.Common.Sort

open Brahma.FSharp
open GraphBLAS.FSharp.Backend.Common

module internal BitonicSort =
module internal Bitonic =
let private localBegin (clContext: ClContext) workGroupSize =

let processedSize = workGroupSize * 2
Expand Down
Loading