@@ -121,6 +121,37 @@ module ClArray =
121121
122122 outputArray
123123
124+ /// <summary >
125+ /// Copies all elements from source to destination array.
126+ /// </summary >
127+ /// <param name =" clContext " >OpenCL context.</param >
128+ /// <param name =" workGroupSize " >Should be a power of 2 and greater than 1.</param >
129+ let copyTo ( clContext : ClContext ) workGroupSize =
130+ let copy =
131+ <@ fun ( ndRange : Range1D ) ( source : ClArray < 'a >) ( destination : ClArray < 'a >) inputArrayLength ->
132+
133+ let i = ndRange.GlobalID0
134+
135+ if i < inputArrayLength then
136+ source.[ i] <- destination.[ i] @>
137+
138+ let program = clContext.Compile( copy)
139+
140+ fun ( processor : MailboxProcessor < _ >) ( source : ClArray < 'a >) ( destination : ClArray < 'a >) ->
141+ if source.Length <> destination.Length then
142+ failwith " The source array length differs from the destination array length."
143+
144+ let ndRange =
145+ Range1D.CreateValid( source.Length, workGroupSize)
146+
147+ let kernel = program.GetKernel()
148+
149+ processor.Post(
150+ Msg.MsgSetArguments( fun () -> kernel.KernelFunc ndRange source destination source.Length)
151+ )
152+
153+ processor.Post( Msg.CreateRunMsg<_, _> kernel)
154+
124155 /// <summary >
125156 /// Creates an array of the given size by replicating the values of the given initial array.
126157 /// </summary >
@@ -781,3 +812,83 @@ module ClArray =
781812 bitmap.Free processor
782813
783814 result
815+
816+ /// <summary >
817+ /// Builds a new array whose elements are the results of applying the given function
818+ /// to each of the elements of the array.
819+ /// </summary >
820+ /// <param name =" op " >The function to transform elements of the array.</param >
821+ /// <param name =" clContext " >OpenCL context.</param >
822+ /// <param name =" workGroupSize " >Should be a power of 2 and greater than 1.</param >
823+ let map < 'a , 'b > ( op : Expr < 'a -> 'b >) ( clContext : ClContext ) workGroupSize = Map.map op clContext workGroupSize
824+
825+ /// <summary >
826+ /// Builds a new array whose elements are the results of applying the given function
827+ /// to each of the elements of the array.
828+ /// </summary >
829+ /// <param name =" op " >The function to transform elements of the array.</param >
830+ /// <param name =" clContext " >OpenCL context.</param >
831+ /// <param name =" workGroupSize " >Should be a power of 2 and greater than 1.</param >
832+ let mapInPlace < 'a > ( op : Expr < 'a -> 'a >) ( clContext : ClContext ) workGroupSize = Map.mapInPlace op clContext workGroupSize
833+
834+ /// <summary >
835+ /// Builds a new array whose elements are the results of applying the given function
836+ /// to the corresponding pairs of values, where the first element of pair is from the given array
837+ /// and the second element is the given value.
838+ /// </summary >
839+ /// <param name =" op " >The function to transform elements of the array.</param >
840+ /// <param name =" clContext " >OpenCL context.</param >
841+ /// <param name =" workGroupSize " >Should be a power of 2 and greater than 1.</param >
842+ let mapWithValue < 'a , 'b , 'c > ( clContext : ClContext ) workGroupSize ( op : Expr < 'a -> 'b -> 'c >) = Map.mapWithValue clContext workGroupSize op
843+
844+ /// <summary >
845+ /// Builds a new array whose elements are the results of applying the given function
846+ /// to the corresponding elements of the two given arrays pairwise.
847+ /// </summary >
848+ /// <remarks >
849+ /// The two input arrays must have the same lengths.
850+ /// </remarks >
851+ /// <param name =" map " >The function to transform the pairs of the input elements.</param >
852+ /// <param name =" clContext " >OpenCL context.</param >
853+ /// <param name =" workGroupSize " >Should be a power of 2 and greater than 1.</param >
854+ let map2 < 'a , 'b , 'c > ( map : Expr < 'a -> 'b -> 'c >) ( clContext : ClContext ) workGroupSize = Map.map2 map clContext workGroupSize
855+
856+ /// <summary >
857+ /// Fills the third given array with the results of applying the given function
858+ /// to the corresponding elements of the first two given arrays pairwise.
859+ /// </summary >
860+ /// <remarks >
861+ /// The first two input arrays must have the same lengths.
862+ /// </remarks >
863+ /// <param name =" map " >The function to transform the pairs of the input elements.</param >
864+ /// <param name =" clContext " >OpenCL context.</param >
865+ /// <param name =" workGroupSize " >Should be a power of 2 and greater than 1.</param >
866+ let map2InPlace < 'a , 'b , 'c > ( map : Expr < 'a -> 'b -> 'c >) ( clContext : ClContext ) workGroupSize = Map.map2InPlace map clContext workGroupSize
867+
868+ /// <summary >
869+ /// Excludes elements, pointed by the bitmap.
870+ /// </summary >
871+ /// <param name =" clContext " >OpenCL context.</param >
872+ /// <param name =" workGroupSize " >Should be a power of 2 and greater than 1.</param >
873+ let excludeElements ( clContext : ClContext ) workGroupSize =
874+
875+ let invert = mapInPlace ArithmeticOperations.intNotQ clContext workGroupSize
876+
877+ let prefixSum = PrefixSum.standardExcludeInPlace clContext workGroupSize
878+
879+ let scatter = Scatter.lastOccurrence clContext workGroupSize
880+
881+ fun ( queue : MailboxProcessor < _ >) allocationMode ( excludeBitmap : ClArray < int >) ( inputArray : ClArray < 'a >) ->
882+
883+ invert queue excludeBitmap
884+
885+ let length = ( prefixSum queue excludeBitmap) .ToHostAndFree queue
886+
887+ if length = 0 then
888+ None
889+ else
890+ let result = clContext.CreateClArrayWithSpecificAllocationMode( allocationMode, length)
891+
892+ scatter queue excludeBitmap inputArray result
893+
894+ Some result
0 commit comments