Skip to content

Commit 0c5db3f

Browse files
committed
refactor: comments; common api
1 parent f02ef72 commit 0c5db3f

76 files changed

Lines changed: 847 additions & 370 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ open Brahma.FSharp
88
open GraphBLAS.FSharp.Objects
99
open GraphBLAS.FSharp.Backend.Objects
1010
open GraphBLAS.FSharp.Objects.MatrixExtensions
11-
open GraphBLAS.FSharp.Backend.Objects.ClContext
11+
open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions
1212
open GraphBLAS.FSharp.Backend.Matrix
1313
open GraphBLAS.FSharp.Benchmarks
1414

benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ open Brahma.FSharp
88
open GraphBLAS.FSharp.Objects
99
open GraphBLAS.FSharp.Backend.Objects
1010
open GraphBLAS.FSharp.Backend.Matrix
11-
open GraphBLAS.FSharp.Backend.Objects.ClContext
11+
open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions
1212
open GraphBLAS.FSharp.Benchmarks
1313
open GraphBLAS.FSharp.Backend
1414

benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ open Brahma.FSharp
88
open GraphBLAS.FSharp.Objects
99
open GraphBLAS.FSharp.Backend.Objects
1010
open GraphBLAS.FSharp.Backend.Matrix
11-
open GraphBLAS.FSharp.Backend.Objects.ClContext
11+
open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions
1212
open GraphBLAS.FSharp.Benchmarks
1313
open GraphBLAS.FSharp.Backend
1414

benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ open GraphBLAS.FSharp.Tests
1111
open GraphBLAS.FSharp.Objects
1212
open GraphBLAS.FSharp.Objects.ClVectorExtensions
1313
open GraphBLAS.FSharp.Backend.Vector
14-
open GraphBLAS.FSharp.Backend.Objects.ClContext
14+
open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions
1515

1616
[<AbstractClass>]
1717
[<IterationCount(100)>]

src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ open GraphBLAS.FSharp.Backend.Common
88
open GraphBLAS.FSharp.Backend.Quotes
99
open GraphBLAS.FSharp.Backend.Vector
1010
open GraphBLAS.FSharp.Backend.Vector.Dense
11-
open GraphBLAS.FSharp.Backend.Objects.ClContext
11+
open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions
1212
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
13-
open GraphBLAS.FSharp.Backend.Objects.ClCell
13+
open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions
1414

1515
module BFS =
1616
let singleSource

src/GraphBLAS-sharp.Backend/Common/ClArray.fs

Lines changed: 125 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
namespace GraphBLAS.FSharp.Backend.Common
22

3-
open System.Collections.Generic
43
open Brahma.FSharp
54
open Microsoft.FSharp.Quotations
6-
open GraphBLAS.FSharp.Backend.Objects.ClContext
7-
open GraphBLAS.FSharp.Backend.Objects.ClCell
5+
open GraphBLAS.FSharp.Backend.Common
6+
open GraphBLAS.FSharp.Backend.Objects.ClContextExtensions
7+
open GraphBLAS.FSharp.Backend.Objects.ClCellExtensions
88
open GraphBLAS.FSharp.Backend.Quotes
99
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
10-
open GraphBLAS.FSharp.Backend.Quotes
1110

1211
module ClArray =
12+
/// <summary>
13+
/// Creates an array given the dimension and a generator function to compute the elements.
14+
/// </summary>
15+
/// <param name="initializer">The function to generate the initial values for each index.</param>
16+
/// <param name="clContext">OpenCL context.</param>
17+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
1318
let init (initializer: Expr<int -> 'a>) (clContext: ClContext) workGroupSize =
1419

1520
let init =
@@ -36,6 +41,11 @@ module ClArray =
3641

3742
outputArray
3843

44+
/// <summary>
45+
/// Creates an array whose elements are all initially the given value.
46+
/// </summary>
47+
/// <param name="clContext">OpenCL context.</param>
48+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
3949
let create (clContext: ClContext) workGroupSize =
4050

4151
let create =
@@ -65,13 +75,23 @@ module ClArray =
6575

6676
outputArray
6777

78+
/// <summary>
79+
/// Creates an array where the entries are initially the default value of desired type.
80+
/// </summary>
81+
/// <param name="clContext">OpenCL context.</param>
82+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
6883
let zeroCreate<'a> (clContext: ClContext) workGroupSize =
6984

7085
let create = create clContext workGroupSize
7186

7287
fun (processor: MailboxProcessor<_>) allocationMode length ->
7388
create processor allocationMode length Unchecked.defaultof<'a>
7489

90+
/// <summary>
91+
/// Builds a new array that contains the elements of the given array.
92+
/// </summary>
93+
/// <param name="clContext">OpenCL context.</param>
94+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
7595
let copy (clContext: ClContext) workGroupSize =
7696
let copy =
7797
<@ fun (ndRange: Range1D) (inputArrayBuffer: ClArray<'a>) (outputArrayBuffer: ClArray<'a>) inputArrayLength ->
@@ -100,6 +120,11 @@ module ClArray =
100120

101121
outputArray
102122

123+
/// <summary>
124+
/// Creates an array of the given size by replicating the values of the given initial array.
125+
/// </summary>
126+
/// <param name="clContext">OpenCL context.</param>
127+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
103128
let replicate (clContext: ClContext) workGroupSize =
104129

105130
let replicate =
@@ -132,6 +157,13 @@ module ClArray =
132157

133158
outputArray
134159

160+
/// <summary>
161+
/// Builds a new array whose elements are the results of applying the given function
162+
/// to each of the elements of the array.
163+
/// </summary>
164+
/// <param name="op">The function to transform elements of the array.</param>
165+
/// <param name="clContext">OpenCL context.</param>
166+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
135167
let map<'a, 'b> (op: Expr<'a -> 'b>) (clContext: ClContext) workGroupSize =
136168

137169
let map =
@@ -160,6 +192,14 @@ module ClArray =
160192

161193
result
162194

195+
/// <summary>
196+
/// Builds a new array whose elements are the results of applying the given function
197+
/// to the corresponding pairs of values, where the first element of pair is from the given array
198+
/// and the second element is the given value.
199+
/// </summary>
200+
/// <param name="op">The function to transform elements of the array.</param>
201+
/// <param name="clContext">OpenCL context.</param>
202+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
163203
let mapWithValue<'a, 'b, 'c> (clContext: ClContext) workGroupSize (op: Expr<'a -> 'b -> 'c>) =
164204

165205
let map =
@@ -192,6 +232,16 @@ module ClArray =
192232

193233
result
194234

235+
/// <summary>
236+
/// Fills the third given array with the results of applying the given function
237+
/// to the corresponding elements of the first two given arrays pairwise.
238+
/// </summary>
239+
/// <remarks>
240+
/// The first two input arrays must have the same lengths.
241+
/// </remarks>
242+
/// <param name="map">The function to transform the pairs of the input elements.</param>
243+
/// <param name="clContext">OpenCL context.</param>
244+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
195245
let map2InPlace<'a, 'b, 'c> (map: Expr<'a -> 'b -> 'c>) (clContext: ClContext) workGroupSize =
196246

197247
let kernel =
@@ -219,6 +269,16 @@ module ClArray =
219269

220270
processor.Post(Msg.CreateRunMsg<_, _>(kernel))
221271

272+
/// <summary>
273+
/// Builds a new array whose elements are the results of applying the given function
274+
/// to the corresponding elements of the two given arrays pairwise.
275+
/// </summary>
276+
/// <remarks>
277+
/// The two input arrays must have the same lengths.
278+
/// </remarks>
279+
/// <param name="map">The function to transform the pairs of the input elements.</param>
280+
/// <param name="clContext">OpenCL context.</param>
281+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
222282
let map2<'a, 'b, 'c> map (clContext: ClContext) workGroupSize =
223283
let map2 =
224284
map2InPlace<'a, 'b, 'c> map clContext workGroupSize
@@ -306,10 +366,12 @@ module ClArray =
306366
let lastOccurrence2 clContext =
307367
getUniqueBitmap2General lastOccurrence clContext
308368

309-
///<description>Remove duplicates form the given array.</description>
310-
///<param name="clContext">Computational context</param>
311-
///<param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
312-
///<param name="inputArray">Should be sorted.</param>
369+
/// <summary>
370+
/// Removes duplicates form the given array.
371+
/// </summary>
372+
/// <param name="clContext">Computational context</param>
373+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
374+
/// <param name="inputArray">Should be sorted.</param>
313375
let removeDuplications (clContext: ClContext) workGroupSize =
314376

315377
let scatter =
@@ -339,6 +401,12 @@ module ClArray =
339401

340402
outputArray
341403

404+
/// <summary>
405+
/// Tests if any element of the array satisfies the given predicate.
406+
/// </summary>
407+
/// <param name="predicate">The function to test the input elements.</param>
408+
/// <param name="clContext">OpenCL context.</param>
409+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
342410
let exists (predicate: Expr<'a -> bool>) (clContext: ClContext) workGroupSize =
343411

344412
let exists =
@@ -368,7 +436,7 @@ module ClArray =
368436

369437
result
370438

371-
let assignOption (op: Expr<'a -> 'b option>) (clContext: ClContext) workGroupSize =
439+
let private assignOption (op: Expr<'a -> 'b option>) (clContext: ClContext) workGroupSize =
372440

373441
let assign =
374442
<@ fun (ndRange: Range1D) length (values: ClArray<'a>) (positions: ClArray<int>) (result: ClArray<'b>) resultLength ->
@@ -404,6 +472,13 @@ module ClArray =
404472

405473
processor.Post(Msg.CreateRunMsg<_, _>(kernel))
406474

475+
/// <summary>
476+
/// Applies the given function to each element of the array.
477+
/// Returns the array comprised of the results <c>x</c> for each element where the function returns <c>Some(x)</c>.
478+
/// </summary>
479+
/// <param name="predicate">The function to generate options from the elements.</param>
480+
/// <param name="clContext">OpenCL context.</param>
481+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
407482
let choose<'a, 'b> (predicate: Expr<'a -> 'b option>) (clContext: ClContext) workGroupSize =
408483
let getBitmap =
409484
map<'a, int> (Map.chooseBitmap predicate) clContext workGroupSize
@@ -510,6 +585,11 @@ module ClArray =
510585

511586
result
512587

588+
/// <summary>
589+
/// Builds a new array that contains the given subrange specified by starting index and length.
590+
/// </summary>
591+
/// <param name="clContext">OpenCL context.</param>
592+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
513593
let sub (clContext: ClContext) workGroupSize =
514594

515595
let kernel =
@@ -549,10 +629,10 @@ module ClArray =
549629
result
550630

551631
/// <summary>
552-
/// Lazy divides the input array into chunks of size at most chunkSize.
632+
/// Divides lazily the input array into chunks of size at most chunkSize.
553633
/// </summary>
554-
/// <param name="clContext">Cl context.</param>
555-
/// <param name="workGroupSize">Work group size.</param>
634+
/// <param name="clContext">OpenCL context.</param>
635+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
556636
/// <remarks>
557637
/// Since calculations are performed lazily, the array should not change.
558638
/// </remarks>
@@ -581,8 +661,8 @@ module ClArray =
581661
/// <summary>
582662
/// Divides the input array into chunks of size at most chunkSize.
583663
/// </summary>
584-
/// <param name="clContext">Cl context.</param>
585-
/// <param name="workGroupSize">Work group size.</param>
664+
/// <param name="clContext">OpenCL context.</param>
665+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
586666
let chunkBySize (clContext: ClContext) workGroupSize =
587667

588668
let chunkBySizeLazy = lazyChunkBySize clContext workGroupSize
@@ -592,6 +672,11 @@ module ClArray =
592672
|> Seq.map (fun lazyValue -> lazyValue.Value)
593673
|> Seq.toArray
594674

675+
/// <summary>
676+
/// Reads a range of elements from the first array and write them into the second.
677+
/// </summary>
678+
/// <param name="clContext">OpenCL context.</param>
679+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
595680
let blit<'a> (clContext: ClContext) workGroupSize =
596681

597682
let assign =
@@ -635,6 +720,11 @@ module ClArray =
635720

636721
processor.Post(Msg.CreateRunMsg<_, _>(kernel))
637722

723+
/// <summary>
724+
/// Builds a new array that contains the elements of each of the given sequence of arrays.
725+
/// </summary>
726+
/// <param name="clContext">OpenCL context.</param>
727+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
638728
let concat (clContext: ClContext) workGroupSize =
639729

640730
let blit = blit clContext workGroupSize
@@ -659,6 +749,11 @@ module ClArray =
659749

660750
result
661751

752+
/// <summary>
753+
/// Fills a range of elements of the array with the given value.
754+
/// </summary>
755+
/// <param name="clContext">OpenCL context.</param>
756+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
662757
let fill (clContext: ClContext) workGroupSize =
663758

664759
let fill =
@@ -693,6 +788,12 @@ module ClArray =
693788

694789
processor.Post(Msg.CreateRunMsg<_, _>(kernel))
695790

791+
/// <summary>
792+
/// Returns an array of each element in the input array and its predecessor,
793+
/// with the exception of the first element which is only returned as the predecessor of the second element.
794+
/// </summary>
795+
/// <param name="clContext">OpenCL context.</param>
796+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
696797
let pairwise (clContext: ClContext) workGroupSize =
697798

698799
let idGather =
@@ -765,6 +866,11 @@ module ClArray =
765866
let upperBound<'a when 'a: comparison> clContext =
766867
bound<'a, int> Search.Bin.lowerBound clContext
767868

869+
/// <summary>
870+
/// Gets the value at the specified position from the input array.
871+
/// </summary>
872+
/// <param name="clContext">OpenCL context.</param>
873+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
768874
let item<'a> (clContext: ClContext) workGroupSize =
769875

770876
let kernel =
@@ -794,6 +900,11 @@ module ClArray =
794900

795901
result
796902

903+
/// <summary>
904+
/// Sets an element of an array.
905+
/// </summary>
906+
/// <param name="clContext">OpenCL context.</param>
907+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
797908
let set<'a> (clContext: ClContext) workGroupSize =
798909

799910
let kernel =

0 commit comments

Comments
 (0)