@@ -12,10 +12,17 @@ module DenseVector =
1212 ( workGroupSize : int )
1313 =
1414
15- let kernel = clContext.Compile( ElementwiseConstructor.kernel opAdd)
15+ let elementWise =
16+ <@ fun ( ndRange : Range1D ) resultLength ( leftVector : ClArray < 'a option >) ( rightVector : ClArray < 'b option >) ( resultVector : ClArray < 'c option >) ->
1617
17- fun ( processor : MailboxProcessor < _ >) ( leftVector : ClArray < 'a option >) ( rightVector : ClArray < 'b option >) ->
18+ let gid = ndRange.GlobalID0
19+
20+ if gid < resultLength then
21+ resultVector.[ gid] <- (% opAdd) leftVector.[ gid] rightVector.[ gid] @>
1822
23+ let kernel = clContext.Compile( elementWise)
24+
25+ fun ( processor : MailboxProcessor < _ >) ( leftVector : ClArray < 'a option >) ( rightVector : ClArray < 'b option >) ->
1926 let resultVector =
2027 clContext.CreateClArray(
2128 leftVector.Length,
@@ -39,18 +46,27 @@ module DenseVector =
3946 resultVector
4047
4148 let elementWiseAtLeastOne clContext op workGroupSize =
42- elementWise clContext ( ElementwiseConstructor .atLeastOneToNormalForm op) workGroupSize
49+ elementWise clContext ( StandardOperations .atLeastOneToNormalForm op) workGroupSize
4350
4451 let fillSubVector < 'a , 'b when 'a : struct and 'b : struct >
4552 ( clContext : ClContext )
4653 ( maskOp : Expr < 'a option -> 'b option -> 'a -> 'a option >)
47- ( workGroupSize : int ) =
54+ ( workGroupSize : int )
55+ =
56+
57+ let fillSubVectorKernel =
58+ <@ fun ( ndRange : Range1D ) resultLength ( leftVector : ClArray < 'a option >) ( maskVector : ClArray < 'b option >) ( value : ClCell < 'a >) ( resultVector : ClArray < 'a option >) ->
59+
60+ let gid = ndRange.GlobalID0
61+
62+ if gid < resultLength then
63+ resultVector.[ gid] <- (% maskOp) leftVector.[ gid] maskVector.[ gid] value.Value @>
4864
49- let kernel = clContext.Compile( ElementwiseConstructor. fillSubVectorKernel maskOp )
65+ let kernel = clContext.Compile( fillSubVectorKernel)
5066
5167 fun ( processor : MailboxProcessor < _ >) ( leftVector : ClArray < 'a option >) ( maskVector : ClArray < 'b option >) ( value : ClCell < 'a >) ->
52- let resultArray =
53- clContext.CreateClArray(
68+ let resultVector =
69+ clContext.CreateClArray< 'a option > (
5470 leftVector.Length,
5571 hostAccessMode = HostAccessMode.NotAccessible,
5672 deviceAccessMode = DeviceAccessMode.ReadWrite,
@@ -63,14 +79,16 @@ module DenseVector =
6379 let kernel = kernel.GetKernel()
6480
6581 processor.Post(
66- Msg.MsgSetArguments( fun () ->
67- kernel.KernelFunc ndRange leftVector.Length leftVector maskVector value resultArray )
82+ Msg.MsgSetArguments
83+ ( fun () -> kernel.KernelFunc ndRange leftVector.Length leftVector maskVector value resultVector )
6884 )
6985
70- resultArray
86+ processor.Post( Msg.CreateRunMsg<_, _>( kernel))
87+
88+ resultVector
7189
7290 let fillSubVectorAtLeasOne clContext opAdd workGroupSize =
73- fillSubVector clContext ( ElementwiseConstructor .fillSubVectorAtLeastOneToNormalForm opAdd) workGroupSize
91+ fillSubVector clContext ( StandardOperations .fillSubVectorAtLeastOneToNormalForm opAdd) workGroupSize
7492
7593 let private getBitmap < 'a when 'a : struct > ( clContext : ClContext ) ( workGroupSize : int ) =
7694
@@ -87,7 +105,6 @@ module DenseVector =
87105 let kernel = clContext.Compile( getPositions)
88106
89107 fun ( processor : MailboxProcessor < _ >) ( vector : ClArray < 'a option >) ->
90-
91108 let positions =
92109 clContext.CreateClArray(
93110 vector.Length,
0 commit comments