@@ -141,11 +141,7 @@ module ClArray =
141141 /// > val sum = [ | 4 |]
142142 /// </code>
143143 /// </example>
144- ///<param name="clContext"> .</param >
145144 ///<param name="workGroupSize"> Should be a power of 2 and greater than 1.</param >
146- ///<param name="processor"> .</param >
147- ///<param name="inputArray"> .</param >
148- ///<param name="totalSum"> .</param >
149145 ///<param name="plus"> Associative binary operation.</param >
150146 ///<param name="zero"> Zero element for binary operation.</param >
151147 let prefixSumExcludeInplace = PrefixSum.runExcludeInplace
@@ -164,11 +160,7 @@ module ClArray =
164160 /// > val sum = [ | 4 |]
165161 /// </code>
166162 /// </example>
167- ///<param name="clContext"> .</param >
168163 ///<param name="workGroupSize"> Should be a power of 2 and greater than 1.</param >
169- ///<param name="processor"> .</param >
170- ///<param name="inputArray"> .</param >
171- ///<param name="totalSum"> .</param >
172164 ///<param name="plus"> Associative binary operation.</param >
173165 ///<param name="zero"> Zero element for binary operation.</param >
174166 let prefixSumIncludeInplace = PrefixSum.runIncludeInplace
@@ -335,3 +327,31 @@ module ClArray =
335327 processor.Post( Msg.CreateRunMsg<_, _>( kernel))
336328
337329 result
330+
331+ let map2 < 'a , 'b , 'c > ( clContext : ClContext ) workGroupSize ( map : Expr < 'a -> 'b -> 'c >) =
332+
333+ let kernel =
334+ <@ fun ( ndRange : Range1D ) length ( leftArray : ClArray < 'a >) ( rightArray : ClArray < 'b >) ( resultArray : ClArray < 'c >) ->
335+
336+ let gid = ndRange.GlobalID0
337+
338+ if gid < length then
339+
340+ resultArray.[ gid] <- (% map) leftArray.[ gid] rightArray.[ gid] @>
341+
342+ let kernel = clContext.Compile kernel
343+
344+ fun ( processor : MailboxProcessor < _ >) flag ( leftArray : ClArray < 'a >) ( rightArray : ClArray < 'b >) ->
345+
346+ let resultArray =
347+ clContext.CreateClArrayWithSpecificAllocationMode( flag, leftArray.Length)
348+
349+ let ndRange = Range1D.CreateValid( resultArray.Length, workGroupSize)
350+
351+ let kernel = kernel.GetKernel()
352+
353+ processor.Post( Msg.MsgSetArguments( fun () -> kernel.KernelFunc ndRange resultArray.Length leftArray rightArray resultArray))
354+
355+ processor.Post( Msg.CreateRunMsg<_, _>( kernel))
356+
357+ resultArray
0 commit comments