@@ -15,46 +15,26 @@ module DenseVector =
1515 workGroupSize
1616 =
1717
18- let map2 =
19- <@ fun ( ndRange : Range1D ) resultLength ( leftVector : ClArray < 'a option >) ( rightVector : ClArray < 'b option >) ( resultVector : ClArray < 'c option >) ->
20-
21- let gid = ndRange.GlobalID0
22-
23- if gid < resultLength then
24- resultVector.[ gid] <- (% opAdd) leftVector.[ gid] rightVector.[ gid] @>
25-
26- let kernel = clContext.Compile( map2)
18+ let map2InPlace = ClArray.map2Inplace clContext workGroupSize opAdd
2719
2820 fun ( processor : MailboxProcessor < _ >) ( leftVector : ClArray < 'a option >) ( rightVector : ClArray < 'b option >) ( resultVector : ClArray < 'c option >) ->
2921
30- let ndRange =
31- Range1D.CreateValid( leftVector.Length, workGroupSize)
22+ map2InPlace processor leftVector rightVector resultVector
3223
33- let kernel = kernel.GetKernel()
34-
35- processor.Post(
36- Msg.MsgSetArguments
37- ( fun () -> kernel.KernelFunc ndRange leftVector.Length leftVector rightVector resultVector)
38- )
39-
40- processor.Post( Msg.CreateRunMsg<_, _>( kernel))
4124
4225 let map2 < 'a , 'b , 'c when 'a : struct and 'b : struct and 'c : struct >
4326 ( clContext : ClContext )
4427 ( opAdd : Expr < 'a option -> 'b option -> 'c option >)
4528 workGroupSize
4629 =
4730
48- let elementWiseTo =
49- map2Inplace clContext opAdd workGroupSize
31+ let map2 =
32+ ClArray.map2 clContext workGroupSize opAdd
5033
5134 fun ( processor : MailboxProcessor < _ >) allocationMode ( leftVector : ClArray < 'a option >) ( rightVector : ClArray < 'b option >) ->
52- let resultVector =
53- clContext.CreateClArrayWithSpecificAllocationMode( allocationMode, leftVector.Length)
5435
55- elementWiseTo processor leftVector rightVector resultVector
36+ map2 processor allocationMode leftVector rightVector
5637
57- resultVector
5838
5939 let map2AtLeastOne clContext op workGroupSize =
6040 map2 clContext ( Convert.atLeastOneToOption op) workGroupSize
0 commit comments