File tree Expand file tree Collapse file tree
src/GraphBLAS-sharp.Backend Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ namespace GraphBLAS.FSharp.Backend.Common.Gather
2+
3+ open Brahma.FSharp
4+
5+ module internal Gather =
6+ /// <summary >
7+ /// Creates a new array obtained from positions replaced with values from the given array at these positions (indices).
8+ /// </summary >
9+ /// <example >
10+ /// <code >
11+ /// let positions = [ | 2; 0; 2; 1 |]
12+ /// let array = [ | 1.4; 2.5; 3.6 |]
13+ /// ...
14+ /// > val result = [ | 3.6; 1.4; 3.6; 2.5 |]
15+ /// </code>
16+ /// </example>
17+ let run ( clContext : ClContext ) workGroupSize =
18+
19+ let gather =
20+ <@ fun ( ndRange : Range1D ) ( positions : ClArray < int >) ( inputArray : ClArray < 'a >) ( outputArray : ClArray < 'a >) ( size : int ) ->
21+
22+ let i = ndRange.GlobalID0
23+
24+ if i < size then
25+ outputArray.[ i] <- inputArray.[ positions.[ i]] @>
26+
27+ let program = clContext.Compile( gather)
28+
29+ fun ( processor : MailboxProcessor < _ >) ( positions : ClArray < int >) ( inputArray : ClArray < 'a >) ( outputArray : ClArray < 'a >) ->
30+
31+ let size = outputArray.Length
32+
33+ let kernel = program.GetKernel()
34+
35+ let ndRange = Range1D.CreateValid( size, workGroupSize)
36+
37+ processor.Post(
38+ Msg.MsgSetArguments( fun () -> kernel.KernelFunc ndRange positions inputArray outputArray size)
39+ )
40+
41+ processor.Post( Msg.CreateRunMsg<_, _>( kernel))
Original file line number Diff line number Diff line change 3232 <Compile Include =" Common/PrefixSum.fs" />
3333 <Compile Include =" Common/ClArray.fs" />
3434 <Compile Include =" Common/BitonicSort.fs" />
35+ <Compile Include =" Common\Gather.fs" />
3536 <Compile Include =" Predefined/PrefixSum.fs" />
3637 <!-- Compile Include="Matrices.fs" /-->
3738 <Compile Include =" Matrix/Common.fs" />
You can’t perform that action at this time.
0 commit comments