Skip to content

Commit 203d641

Browse files
committed
refactor: returned internal comments
1 parent da2d1bd commit 203d641

4 files changed

Lines changed: 210 additions & 20 deletions

File tree

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ module Common =
154154
/// </code>
155155
/// </example>
156156
/// <param name="valueMap">Maps global id to a value</param>
157-
let initFirstOccurrence valueMap = Scatter.initFirsOccurrence valueMap
157+
let initFirstOccurrence valueMap = Scatter.initFirstOccurrence valueMap
158158

159159
/// <summary>
160160
/// 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 =
252252
/// > val sum = [| 4 |]
253253
/// </code>
254254
/// </example>
255-
/// <param name="clContext">ClContext.</param>
256-
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
257-
let standardExcludeInPlace (clContext: ClContext) workGroupSize =
258-
259-
let scan =
260-
runExcludeInPlace <@ (+) @> clContext workGroupSize
261-
262-
fun (processor: MailboxProcessor<_>) (inputArray: ClArray<int>) ->
263-
264-
scan processor inputArray 0
255+
let standardExcludeInPlace = PrefixSum.standardExcludeInPlace
265256

266257
/// <summary>
267258
/// 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 =
279270
/// </example>
280271
/// <param name="clContext">ClContext.</param>
281272
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
282-
let standardIncludeInPlace (clContext: ClContext) workGroupSize =
283-
284-
let scan =
285-
runIncludeInPlace <@ (+) @> clContext workGroupSize
286-
287-
fun (processor: MailboxProcessor<_>) (inputArray: ClArray<int>) ->
288-
289-
scan processor inputArray 0
273+
let standardIncludeInPlace = PrefixSum.runIncludeInPlace
290274

291275
module ByKey =
292276
/// <summary>

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,22 @@ module internal PrefixSum =
208208

209209
let runBackwardsIncludeInPlace plus = runInPlace plus true scanInclusive
210210

211+
/// <summary>
212+
/// Exclude in-place prefix sum of integer array with addition operation and start value that is equal to 0.
213+
/// </summary>
214+
/// <example>
215+
/// <code>
216+
/// let arr = [| 1; 1; 1; 1 |]
217+
/// let sum = [| 0 |]
218+
/// runExcludeInplace clContext workGroupSize processor arr sum (+) 0
219+
/// |> ignore
220+
/// ...
221+
/// > val arr = [| 0; 1; 2; 3 |]
222+
/// > val sum = [| 4 |]
223+
/// </code>
224+
/// </example>
225+
/// <param name="clContext">ClContext.</param>
226+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
211227
let standardExcludeInPlace (clContext: ClContext) workGroupSize =
212228

213229
let scan =
@@ -217,6 +233,22 @@ module internal PrefixSum =
217233

218234
scan processor inputArray 0
219235

236+
/// <summary>
237+
/// Include in-place prefix sum of integer array with addition operation and start value that is equal to 0.
238+
/// </summary>
239+
/// <example>
240+
/// <code>
241+
/// let arr = [| 1; 1; 1; 1 |]
242+
/// let sum = [| 0 |]
243+
/// runIncludeInplace clContext workGroupSize processor arr sum (+) 0
244+
/// |> ignore
245+
/// ...
246+
/// > val arr = [| 1; 2; 3; 4 |]
247+
/// > val sum = [| 4 |]
248+
/// </code>
249+
/// </example>
250+
/// <param name="clContext">ClContext.</param>
251+
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
220252
let standardIncludeInPlace (clContext: ClContext) workGroupSize =
221253

222254
let scan =
@@ -268,6 +300,28 @@ module internal PrefixSum =
268300

269301
processor.Post(Msg.CreateRunMsg<_, _> kernel)
270302

303+
/// <summary>
304+
/// Exclude scan by key.
305+
/// </summary>
306+
/// <example>
307+
/// <code>
308+
/// let arr = [| 1; 1; 1; 1; 1; 1|]
309+
/// let keys = [| 1; 2; 2; 2; 3; 3 |]
310+
/// ...
311+
/// > val result = [| 0; 0; 1; 2; 0; 1 |]
312+
/// </code>
313+
/// </example>
271314
let sequentialExclude op = sequentialSegments (Map.fst ()) op
272315

316+
/// <summary>
317+
/// Include scan by key.
318+
/// </summary>
319+
/// <example>
320+
/// <code>
321+
/// let arr = [| 1; 1; 1; 1; 1; 1|]
322+
/// let keys = [| 1; 2; 2; 2; 3; 3 |]
323+
/// ...
324+
/// > val result = [| 1; 1; 2; 3; 1; 2 |]
325+
/// </code>
326+
/// </example>
273327
let sequentialInclude op = sequentialSegments (Map.snd ()) op

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

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,48 @@ module internal Scatter =
4545

4646
processor.Post(Msg.CreateRunMsg<_, _>(kernel))
4747

48+
/// <summary>
49+
/// Creates a new array from the given one where it is indicated
50+
/// by the array of positions at which position in the new array
51+
/// should be a value from the given one.
52+
/// </summary>
53+
/// <remarks>
54+
/// Every element of the positions array must not be less than the previous one.
55+
/// If there are several elements with the same indices, the FIRST one of them will be at the common index.
56+
/// If index is out of bounds, the value will be ignored.
57+
/// </remarks>
58+
/// <example>
59+
/// <code>
60+
/// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |]
61+
/// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; 8.2; 9.1 |]
62+
/// run clContext 32 processor positions values result
63+
/// ...
64+
/// > val result = [| 1,9; 3.7; 6.4; 7.3; 9.1 |]
65+
/// </code>
66+
/// </example>
4867
let firstOccurrence clContext =
4968
general
5069
<| Predicates.firstOccurrence ()
5170
<| clContext
5271

72+
/// <summary>
73+
/// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array
74+
/// should be a value from the given one.
75+
/// </summary>
76+
/// <remarks>
77+
/// Every element of the positions array must not be less than the previous one.
78+
/// If there are several elements with the same indices, the LAST one of them will be at the common index.
79+
/// If index is out of bounds, the value will be ignored.
80+
/// </remarks>
81+
/// <example>
82+
/// <code>
83+
/// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |]
84+
/// let values = [| 1.9; 2.8; 3.7; 4.6; 5.5; 6.4; 7.3; 8.2; 9.1 |]
85+
/// run clContext 32 processor positions values result
86+
/// ...
87+
/// > val result = [| 2.8; 5.5; 6.4; 8.2; 9.1 |]
88+
/// </code>
89+
/// </example>
5390
let lastOccurrence clContext =
5491
general
5592
<| Predicates.lastOccurrence ()
@@ -92,11 +129,49 @@ module internal Scatter =
92129

93130
processor.Post(Msg.CreateRunMsg<_, _>(kernel))
94131

95-
let initFirsOccurrence<'a> valueMap =
132+
/// <summary>
133+
/// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array
134+
/// should be a values obtained by applying the mapping to the global id.
135+
/// </summary>
136+
/// <remarks>
137+
/// Every element of the positions array must not be less than the previous one.
138+
/// If there are several elements with the same indices, the FIRST one of them will be at the common index.
139+
/// If index is out of bounds, the value will be ignored.
140+
/// </remarks>
141+
/// <example>
142+
/// <code>
143+
/// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |]
144+
/// let valueMap = id
145+
/// run clContext 32 processor positions values result
146+
/// ...
147+
/// > val result = [| 0; 2; 5; 6; 8 |]
148+
/// </code>
149+
/// </example>
150+
/// <param name="valueMap">Maps global id to a value</param>
151+
let initFirstOccurrence<'a> valueMap =
96152
generalInit<'a>
97153
<| Predicates.firstOccurrence ()
98154
<| valueMap
99155

156+
/// <summary>
157+
/// Creates a new array from the given one where it is indicated by the array of positions at which position in the new array
158+
/// should be a values obtained by applying the mapping to the global id.
159+
/// </summary>
160+
/// <remarks>
161+
/// Every element of the positions array must not be less than the previous one.
162+
/// If there are several elements with the same indices, the LAST one of them will be at the common index.
163+
/// If index is out of bounds, the value will be ignored.
164+
/// </remarks>
165+
/// <example>
166+
/// <code>
167+
/// let positions = [| 0; 0; 1; 1; 1; 2; 3; 3; 4 |]
168+
/// let valueMap = id
169+
/// run clContext 32 processor positions values result
170+
/// ...
171+
/// > val result = [| 1; 4; 5; 7; 8 |]
172+
/// </code>
173+
/// </example>
174+
/// <param name="valueMap">Maps global id to a value</param>
100175
let initLastOccurrence<'a> valueMap =
101176
generalInit<'a>
102177
<| Predicates.lastOccurrence ()

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ module internal Reduce =
132132

133133
resultCell
134134

135+
/// <summary>
136+
/// Summarizes array elements.
137+
/// </summary>
138+
/// <param name="clContext">ClContext.</param>
139+
/// <param name="workGroupSize">Work group size.</param>
140+
/// <param name="op">Summation operation.</param>
141+
/// <param name="zero">Neutral element for summation.</param>
135142
let sum op zero (clContext: ClContext) workGroupSize =
136143

137144
let scan = scanSum op clContext workGroupSize zero
@@ -229,6 +236,12 @@ module internal Reduce =
229236

230237
resultCell
231238

239+
/// <summary>
240+
/// Reduces an array of values.
241+
/// </summary>
242+
/// <param name="clContext">ClContext.</param>
243+
/// <param name="workGroupSize">Work group size.</param>
244+
/// <param name="op">Reduction operation.</param>
232245
let reduce op (clContext: ClContext) workGroupSize =
233246

234247
let scan = scanReduce op clContext workGroupSize
@@ -245,6 +258,15 @@ module internal Reduce =
245258
/// Reduction of an array of values by an array of keys.
246259
/// </summary>
247260
module ByKey =
261+
/// <summary>
262+
/// Reduces an array of values by key using a single work item.
263+
/// </summary>
264+
/// <param name="clContext">ClContext.</param>
265+
/// <param name="workGroupSize">Work group size.</param>
266+
/// <param name="reduceOp">Operation for reducing values.</param>
267+
/// <remarks>
268+
/// The length of the result must be calculated in advance.
269+
/// </remarks>
248270
let sequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize =
249271

250272
let kernel =
@@ -295,6 +317,15 @@ module internal Reduce =
295317

296318
reducedValues, reducedKeys
297319

320+
/// <summary>
321+
/// Reduces values by key. Each segment is reduced by one work item.
322+
/// </summary>
323+
/// <param name="clContext">ClContext.</param>
324+
/// <param name="workGroupSize">Work group size.</param>
325+
/// <param name="reduceOp">Operation for reducing values.</param>
326+
/// <remarks>
327+
/// The length of the result must be calculated in advance.
328+
/// </remarks>
298329
let segmentSequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize =
299330

300331
let kernel =
@@ -352,6 +383,16 @@ module internal Reduce =
352383

353384
reducedValues, reducedKeys
354385

386+
/// <summary>
387+
/// Reduces values by key. One work group participates in the reduction.
388+
/// </summary>
389+
/// <param name="clContext">ClContext.</param>
390+
/// <param name="workGroupSize">Work group size.</param>
391+
/// <param name="reduceOp">Operation for reducing values.</param>
392+
/// <remarks>
393+
/// Reduces an array of values that does not exceed the size of the workgroup.
394+
/// The length of the result must be calculated in advance.
395+
/// </remarks>
355396
let oneWorkGroupSegments (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize =
356397

357398
let kernel =
@@ -432,6 +473,15 @@ module internal Reduce =
432473
reducedValues, reducedKeys
433474

434475
module Option =
476+
/// <summary>
477+
/// Reduces values by key. Each segment is reduced by one work item.
478+
/// </summary>
479+
/// <param name="clContext">ClContext.</param>
480+
/// <param name="workGroupSize">Work group size.</param>
481+
/// <param name="reduceOp">Operation for reducing values.</param>
482+
/// <remarks>
483+
/// The length of the result must be calculated in advance.
484+
/// </remarks>
435485
let segmentSequential<'a> (reduceOp: Expr<'a -> 'a -> 'a option>) (clContext: ClContext) workGroupSize =
436486

437487
let kernel =
@@ -540,6 +590,15 @@ module internal Reduce =
540590
Some(resultValues, resultKeys)
541591

542592
module ByKey2D =
593+
/// <summary>
594+
/// Reduces an array of values by 2D keys using a single work item.
595+
/// </summary>
596+
/// <param name="clContext">ClContext.</param>
597+
/// <param name="workGroupSize">Work group size.</param>
598+
/// <param name="reduceOp">Operation for reducing values.</param>
599+
/// <remarks>
600+
/// The length of the result must be calculated in advance.
601+
/// </remarks>
543602
let sequential (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize =
544603

545604
let kernel =
@@ -610,6 +669,15 @@ module internal Reduce =
610669

611670
reducedValues, firstReducedKeys, secondReducedKeys
612671

672+
/// <summary>
673+
/// Reduces values by key. Each segment is reduced by one work item.
674+
/// </summary>
675+
/// <param name="clContext">ClContext.</param>
676+
/// <param name="workGroupSize">Work group size.</param>
677+
/// <param name="reduceOp">Operation for reducing values.</param>
678+
/// <remarks>
679+
/// The length of the result must be calculated in advance.
680+
/// </remarks>
613681
let segmentSequential<'a> (reduceOp: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize =
614682

615683
let kernel =
@@ -677,6 +745,15 @@ module internal Reduce =
677745
reducedValues, firstReducedKeys, secondReducedKeys
678746

679747
module Option =
748+
/// <summary>
749+
/// Reduces values by key. Each segment is reduced by one work item.
750+
/// </summary>
751+
/// <param name="clContext">ClContext.</param>
752+
/// <param name="workGroupSize">Work group size.</param>
753+
/// <param name="reduceOp">Operation for reducing values.</param>
754+
/// <remarks>
755+
/// The length of the result must be calculated in advance.
756+
/// </remarks>
680757
let segmentSequential<'a> (reduceOp: Expr<'a -> 'a -> 'a option>) (clContext: ClContext) workGroupSize =
681758

682759
let kernel =

0 commit comments

Comments
 (0)