@@ -6,6 +6,46 @@ open GraphBLAS.FSharp.Backend.Common
66open Microsoft.FSharp .Quotations
77
88module DenseVector =
9+ let elementWise < 'a , 'b , 'c when 'a : struct and 'b : struct and 'c : struct >
10+ ( clContext : ClContext )
11+ ( opAdd : Expr < 'a option -> 'b option -> 'c option >)
12+ ( workGroupSize : int )
13+ =
14+
15+ let eWiseAdd =
16+ <@ fun ( ndRange : Range1D ) resultLength ( leftVector : ClArray < 'a option >) ( rightVector : ClArray < 'b option >) ( resultVector : ClArray < 'c option >) ->
17+
18+ let gid = ndRange.GlobalID0
19+
20+ if gid < resultLength then
21+ resultVector.[ gid] <- (% opAdd) leftVector.[ gid] rightVector.[ gid] @>
22+
23+ let kernel = clContext.Compile( eWiseAdd)
24+
25+ fun ( processor : MailboxProcessor < _ >) ( leftVector : ClArray < 'a option >) ( rightVector : ClArray < 'b option >) ->
26+
27+ let resultVector =
28+ clContext.CreateClArray(
29+ leftVector.Length,
30+ hostAccessMode = HostAccessMode.NotAccessible,
31+ deviceAccessMode = DeviceAccessMode.ReadWrite,
32+ allocationMode = AllocationMode.Default
33+ )
34+
35+ let ndRange =
36+ Range1D.CreateValid( leftVector.Length, workGroupSize)
37+
38+ let kernel = kernel.GetKernel()
39+
40+ processor.Post(
41+ Msg.MsgSetArguments
42+ ( fun () -> kernel.KernelFunc ndRange leftVector.Length leftVector rightVector resultVector)
43+ )
44+
45+ processor.Post( Msg.CreateRunMsg<_, _>( kernel))
46+
47+ resultVector
48+
949 let elementWiseAtLeastOne < 'a , 'b , 'c when 'a : struct and 'b : struct and 'c : struct >
1050 ( clContext : ClContext )
1151 ( opAdd : Expr < AtLeastOne < 'a , 'b > -> 'c option >)
0 commit comments