Skip to content

Commit 4c21e7e

Browse files
committed
refactor: add comments
1 parent 5d900f5 commit 4c21e7e

10 files changed

Lines changed: 189 additions & 42 deletions

File tree

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

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,19 @@ module ClArray =
328328

329329
bitmap
330330

331+
/// <summary>
332+
/// Gets the bitmap that indicates the first elements of the sequences of consecutive identical elements
333+
/// </summary>
334+
/// <param name="clContext">OpenCL context.</param>
331335
let firstOccurrence clContext =
332336
getUniqueBitmapGeneral
333337
<| Predicates.firstOccurrence ()
334338
<| clContext
335339

340+
/// <summary>
341+
/// Gets the bitmap that indicates the last elements of the sequences of consecutive identical elements
342+
/// </summary>
343+
/// <param name="clContext">OpenCL context.</param>
336344
let lastOccurrence clContext =
337345
getUniqueBitmapGeneral
338346
<| Predicates.lastOccurrence ()
@@ -360,9 +368,19 @@ module ClArray =
360368

361369
result
362370

371+
/// <summary>
372+
/// Gets the bitmap that indicates the first elements of the sequences
373+
/// of consecutive identical elements from either first array or second array.
374+
/// </summary>
375+
/// <param name="clContext">OpenCL context.</param>
363376
let firstOccurrence2 clContext =
364377
getUniqueBitmap2General firstOccurrence clContext
365378

379+
/// <summary>
380+
/// Gets the bitmap that indicates the last elements of the sequences
381+
/// of consecutive identical elements from either first array or second array.
382+
/// </summary>
383+
/// <param name="clContext">OpenCL context.</param>
366384
let lastOccurrence2 clContext =
367385
getUniqueBitmap2General lastOccurrence clContext
368386

@@ -436,6 +454,14 @@ module ClArray =
436454

437455
result
438456

457+
/// <summary>
458+
/// Maps every value from the given value array and, if the result of applying function is <c>Some</c>,
459+
/// places the result to a specific position from the input array of positions.
460+
/// If the result of mapping is <c>None</c>, it is just ignored.
461+
/// </summary>
462+
/// <param name="op">Function that maps elements from value array.</param>
463+
/// <param name="clContext">OpenCL context.</param>
464+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
439465
let private assignOption (op: Expr<'a -> 'b option>) (clContext: ClContext) workGroupSize =
440466

441467
let assign =
@@ -474,7 +500,8 @@ module ClArray =
474500

475501
/// <summary>
476502
/// 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>.
503+
/// Returns the array comprised of the results <c>x</c>
504+
/// for each element where the function returns <c>Some(x)</c>.
478505
/// </summary>
479506
/// <param name="predicate">The function to generate options from the elements.</param>
480507
/// <param name="clContext">OpenCL context.</param>
@@ -512,6 +539,14 @@ module ClArray =
512539

513540
Some result
514541

542+
/// <summary>
543+
/// Maps pair of values from the given value arrays and, if the result of applying function is <c>Some</c>,
544+
/// places the result to a specific position from the input array of positions.
545+
/// If the result of mapping is <c>None</c>, it is just ignored.
546+
/// </summary>
547+
/// <param name="op">Function that maps pairs of elements from value arrays.</param>
548+
/// <param name="clContext">OpenCL context.</param>
549+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
515550
let assignOption2 (op: Expr<'a -> 'b -> 'c option>) (clContext: ClContext) workGroupSize =
516551

517552
let assign =
@@ -559,6 +594,14 @@ module ClArray =
559594

560595
processor.Post(Msg.CreateRunMsg<_, _>(kernel))
561596

597+
/// <summary>
598+
/// Applies the given function to each pair of elements of the two given arrays.
599+
/// Returns the array comprised of the results <c>x</c>
600+
/// for each pairs where the function returns <c>Some(x)</c>.
601+
/// </summary>
602+
/// <param name="predicate">The function to generate options from the pairs of elements.</param>
603+
/// <param name="clContext">OpenCL context.</param>
604+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
562605
let choose2 (predicate: Expr<'a -> 'b -> 'c option>) (clContext: ClContext) workGroupSize =
563606
let getBitmap =
564607
map2<'a, 'b, int> (Map.choose2Bitmap predicate) clContext workGroupSize
@@ -830,7 +873,7 @@ module ClArray =
830873
None
831874

832875
let private bound<'a, 'b when 'a: equality and 'a: comparison>
833-
(lowerBound: Expr<(int -> 'a -> ClArray<'a> -> 'b)>)
876+
(lowerBound: Expr<int -> 'a -> ClArray<'a> -> 'b>)
834877
(clContext: ClContext)
835878
workGroupSize
836879
=
@@ -860,9 +903,24 @@ module ClArray =
860903

861904
result
862905

906+
/// <summary>
907+
/// Finds the position of the largest value and the value itself
908+
/// that is less than the given one.
909+
/// </summary>
910+
/// <remarks>
911+
/// Array of values should be sorted.
912+
/// </remarks>
913+
/// <param name="clContext">OpenCL context.</param>
863914
let upperBoundAndValue<'a when 'a: comparison> clContext =
864915
bound<'a, int * 'a> Search.Bin.lowerBoundAndValue clContext
865916

917+
/// <summary>
918+
/// Finds the position of the largest value that is less than the given one.
919+
/// </summary>
920+
/// <remarks>
921+
/// Array of values should be sorted.
922+
/// </remarks>
923+
/// <param name="clContext">OpenCL context.</param>
866924
let upperBound<'a when 'a: comparison> clContext =
867925
bound<'a, int> Search.Bin.lowerBound clContext
868926

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

Lines changed: 100 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,52 @@ open GraphBLAS.FSharp.Backend.Common
66

77
module Common =
88
module Bitonic =
9+
/// <summary>
10+
/// Sorts in-place input array of values by their 2d indices,
11+
/// which are stored in two given arrays of keys: rows and columns.
12+
/// When comparing, it first looks at rows, then columns.
13+
/// </summary>
14+
/// <example>
15+
/// <code>
16+
/// let rows = [| 0; 0; 3; 2; 1; 0; 5 |]
17+
/// let columns = [| 0; 2; 1; 2; 0; 3; 5; |]
18+
/// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; |]
19+
/// sortKeyValuesInplace clContext 32 processor rows columns values
20+
/// ...
21+
/// > val rows = [| 0; 0; 0; 1; 2; 3; 5 |]
22+
/// > let columns = [| 0; 2; 3; 0; 2; 1; 5; |]
23+
/// > val values = [| 1.9; 2.8; 6.4; 5.5; 4.6; 3.7; 7.3 |]
24+
/// </code>
25+
/// </example>
926
let sortKeyValuesInplace = Sort.Bitonic.sortKeyValuesInplace
1027

1128
module Radix =
29+
/// <summary>
30+
/// Sorts stable input array of values by given integer keys.
31+
/// </summary>
32+
/// <example>
33+
/// <code>
34+
/// let keys = [| 0; 4; 3; 1; 2; 6; 5 |]
35+
/// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; |]
36+
/// runByKeysStandard clContext 32 processor keys values
37+
/// ...
38+
/// > val keys = [| 0; 1; 2; 3; 4; 5; 6 |]
39+
/// > val values = [| 1.9; 4.6; 5.5; 3.7; 2.8; 7.3; 6.4 |]
40+
/// </code>
41+
/// </example>
1242
let runByKeysStandard = Sort.Radix.runByKeysStandard
1343

44+
/// <summary>
45+
/// Sorts stable input array of integer keys.
46+
/// </summary>
47+
/// <example>
48+
/// <code>
49+
/// let keys = [| 0; 4; 3; 1; 2; 6; 5 |]
50+
/// standardRunKeysOnly clContext 32 processor keys
51+
/// ...
52+
/// > val keys = [| 0; 1; 2; 3; 4; 5; 6 |]
53+
/// </code>
54+
/// </example>
1455
let standardRunKeysOnly = Sort.Radix.standardRunKeysOnly
1556

1657
module Gather =
@@ -53,7 +94,8 @@ module Common =
5394

5495
module Scatter =
5596
/// <summary>
56-
/// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array
97+
/// Creates a new array from the given one where it is indicated
98+
/// by the array of positions at which position in the new array
5799
/// should be a value from the given one.
58100
/// </summary>
59101
/// <remarks>
@@ -135,18 +177,68 @@ module Common =
135177
let initLastOccurrence valueMap = Scatter.initLastOccurrence valueMap
136178

137179
module PrefixSum =
180+
/// <summary>
181+
/// Exclude in-place prefix sum.
182+
/// </summary>
183+
/// <example>
184+
/// <code>
185+
/// let arr = [| 1; 1; 1; 1 |]
186+
/// let sum = [| 0 |]
187+
/// runExcludeInplace clContext workGroupSize processor arr sum (+) 0
188+
/// |> ignore
189+
/// ...
190+
/// > val arr = [| 0; 1; 2; 3 |]
191+
/// > val sum = [| 4 |]
192+
/// </code>
193+
/// </example>
194+
/// <param name="clContext">ClContext.</param>
195+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
196+
/// <param name="plus">Associative binary operation.</param>
197+
/// <param name="zero">Zero element for binary operation.</param>
138198
let runExcludeInPlace plus = PrefixSum.runExcludeInPlace plus
139199

200+
/// <summary>
201+
/// Include in-place prefix sum.
202+
/// </summary>
203+
/// <example>
204+
/// <code>
205+
/// let arr = [| 1; 1; 1; 1 |]
206+
/// let sum = [| 0 |]
207+
/// runExcludeInplace clContext workGroupSize processor arr sum (+) 0
208+
/// |> ignore
209+
/// ...
210+
/// > val arr = [| 0; 1; 2; 3 |]
211+
/// > val sum = [| 4 |]
212+
/// </code>
213+
/// </example>
214+
/// <param name="clContext">ClContext.</param>
215+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
216+
/// <param name="plus">Associative binary operation.</param>
217+
/// <param name="zero">Zero element for binary operation.</param>
140218
let runIncludeInPlace plus = PrefixSum.runIncludeInPlace plus
141219

220+
/// <summary>
221+
/// Exclude in-place prefix sum. Array is scanned starting from the end.
222+
/// </summary>
223+
/// <param name="clContext">ClContext.</param>
224+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
225+
/// <param name="plus">Associative binary operation.</param>
226+
/// <param name="zero">Zero element for binary operation.</param>
142227
let runBackwardsExcludeInPlace plus =
143228
PrefixSum.runBackwardsExcludeInPlace plus
144229

230+
/// <summary>
231+
/// Include in-place prefix sum. Array is scanned starting from the end.
232+
/// </summary>
233+
/// <param name="clContext">ClContext.</param>
234+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
235+
/// <param name="plus">Associative binary operation.</param>
236+
/// <param name="zero">Zero element for binary operation.</param>
145237
let runBackwardsIncludeInPlace plus =
146238
PrefixSum.runBackwardsIncludeInPlace plus
147239

148240
/// <summary>
149-
/// Exclude inplace prefix sum.
241+
/// Exclude in-place prefix sum of integer array with addition operation and start value that is equal to 0.
150242
/// </summary>
151243
/// <example>
152244
/// <code>
@@ -159,10 +251,8 @@ module Common =
159251
/// > val sum = [| 4 |]
160252
/// </code>
161253
/// </example>
162-
///<param name="clContext">ClContext.</param>
163-
///<param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
164-
///<param name="plus">Associative binary operation.</param>
165-
///<param name="zero">Zero element for binary operation.</param>
254+
/// <param name="clContext">ClContext.</param>
255+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
166256
let standardExcludeInPlace (clContext: ClContext) workGroupSize =
167257

168258
let scan =
@@ -173,23 +263,21 @@ module Common =
173263
scan processor inputArray 0
174264

175265
/// <summary>
176-
/// Include inplace prefix sum.
266+
/// Include in-place prefix sum of integer array with addition operation and start value that is equal to 0.
177267
/// </summary>
178268
/// <example>
179269
/// <code>
180270
/// let arr = [| 1; 1; 1; 1 |]
181271
/// let sum = [| 0 |]
182-
/// runExcludeInplace clContext workGroupSize processor arr sum (+) 0
272+
/// runIncludeInplace clContext workGroupSize processor arr sum (+) 0
183273
/// |> ignore
184274
/// ...
185275
/// > val arr = [| 1; 2; 3; 4 |]
186276
/// > val sum = [| 4 |]
187277
/// </code>
188278
/// </example>
189-
///<param name="clContext">ClContext.</param>
190-
///<param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
191-
///<param name="plus">Associative binary operation.</param>
192-
///<param name="zero">Zero element for binary operation.</param>
279+
/// <param name="clContext">ClContext.</param>
280+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
193281
let standardIncludeInPlace (clContext: ClContext) workGroupSize =
194282

195283
let scan =

src/GraphBLAS-sharp.Backend/Quotes/Arithmetic.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
open GraphBLAS.FSharp.Objects
44

55
module ArithmeticOperations =
6-
let inline mkUnaryOp zero unaryOp =
6+
let inline private mkUnaryOp zero unaryOp =
77
<@ fun x ->
88
let mutable res = zero
99

@@ -13,7 +13,7 @@ module ArithmeticOperations =
1313

1414
if res = zero then None else Some res @>
1515

16-
let inline mkNumericSum zero =
16+
let inline private mkNumericSum zero =
1717
<@ fun (x: 't option) (y: 't option) ->
1818
let mutable res = zero
1919

@@ -25,7 +25,7 @@ module ArithmeticOperations =
2525

2626
if res = zero then None else Some res @>
2727

28-
let inline mkNumericSumAtLeastOne zero =
28+
let inline private mkNumericSumAtLeastOne zero =
2929
<@ fun (values: AtLeastOne<'t, 't>) ->
3030
let mutable res = zero
3131

@@ -36,7 +36,7 @@ module ArithmeticOperations =
3636

3737
if res = zero then None else Some res @>
3838

39-
let inline mkNumericMul zero =
39+
let inline private mkNumericMul zero =
4040
<@ fun (x: 't option) (y: 't option) ->
4141
let mutable res = zero
4242

@@ -46,7 +46,7 @@ module ArithmeticOperations =
4646

4747
if res = zero then None else Some res @>
4848

49-
let inline mkNumericMulAtLeastOne zero =
49+
let inline private mkNumericMulAtLeastOne zero =
5050
<@ fun (values: AtLeastOne<'t, 't>) ->
5151
let mutable res = zero
5252

@@ -197,7 +197,7 @@ module ArithmeticOperations =
197197
else
198198
Some result
199199

200-
let inline createPair zero op opQ = binOpQ zero opQ, binOp zero op
200+
let inline private createPair zero op opQ = binOpQ zero opQ, binOp zero op
201201

202202
// addition
203203
let intAdd = createPair 0 (+) <@ (+) @>

0 commit comments

Comments
 (0)