@@ -20,7 +20,7 @@ module ClArray =
2020 fun ( processor : MailboxProcessor < _ >) ( length : int ) ->
2121 // TODO: Выставить нужные флаги
2222 let outputArray =
23- clContext.CreateClArrayWithGPUOnlyFlags ( length)
23+ clContext.CreateClArrayWithFlag ( GPUOnly , length)
2424
2525 let kernel = program.GetKernel()
2626
@@ -48,7 +48,7 @@ module ClArray =
4848 let value = clContext.CreateClCell( value)
4949
5050 let outputArray =
51- clContext.CreateClArrayWithGPUOnlyFlags ( length)
51+ clContext.CreateClArrayWithFlag ( GPUOnly , length)
5252
5353 let kernel = program.GetKernel()
5454
@@ -84,7 +84,7 @@ module ClArray =
8484 Range1D.CreateValid( inputArray.Length, workGroupSize)
8585
8686 let outputArray =
87- clContext.CreateClArrayWithGPUOnlyFlags inputArray.Length
87+ clContext.CreateClArrayWithFlag ( GPUOnly , inputArray.Length)
8888
8989 let kernel = program.GetKernel()
9090
@@ -112,7 +112,7 @@ module ClArray =
112112 let outputArrayLength = inputArray.Length * count
113113
114114 let outputArray =
115- clContext.CreateClArrayWithGPUOnlyFlags outputArrayLength
115+ clContext.CreateClArrayWithFlag ( GPUOnly , outputArrayLength)
116116
117117 let ndRange =
118118 Range1D.CreateValid( outputArray.Length, workGroupSize)
@@ -229,7 +229,7 @@ module ClArray =
229229 Range1D.CreateValid( inputLength, workGroupSize)
230230
231231 let bitmap =
232- clContext.CreateClArrayWithGPUOnlyFlags inputLength
232+ clContext.CreateClArrayWithFlag ( GPUOnly , inputLength)
233233
234234 let kernel = kernel.GetKernel()
235235
@@ -273,7 +273,7 @@ module ClArray =
273273 a.[ 0 ]
274274
275275 let outputArray =
276- clContext.CreateClArrayWithGPUOnlyFlags resultLength
276+ clContext.CreateClArrayWithFlag ( GPUOnly , resultLength)
277277
278278 scatter processor positions inputArray outputArray
279279
@@ -307,3 +307,31 @@ module ClArray =
307307 processor.Post( Msg.CreateRunMsg<_, _>( kernel))
308308
309309 result
310+
311+ let map < 'a , 'b > ( clContext : ClContext ) ( workGroupSize : int ) ( op : Expr < 'a -> 'b >) =
312+
313+ let map =
314+ <@ fun ( ndRange : Range1D ) ( lenght : int ) ( inputArray : ClArray < 'a >) ( result : ClArray < 'b >) ->
315+
316+ let gid = ndRange.GlobalID0
317+
318+ if gid < lenght then
319+ result.[ gid] <- (% op) inputArray.[ gid] @>
320+
321+ let kernel = clContext.Compile map
322+
323+ fun ( processor : MailboxProcessor < _ >) ( inputArray : ClArray < 'a >) flag ->
324+
325+ let result =
326+ clContext.CreateClArrayWithFlag( flag, inputArray.Length)
327+
328+ let ndRange =
329+ Range1D.CreateValid( workGroupSize, inputArray.Length)
330+
331+ let kernel = kernel.GetKernel()
332+
333+ processor.Post( Msg.MsgSetArguments( fun () -> kernel.KernelFunc ndRange inputArray.Length inputArray result))
334+
335+ processor.Post( Msg.CreateRunMsg<_, _>( kernel))
336+
337+ result
0 commit comments