|
1 | 1 | namespace GraphBLAS.FSharp.Backend.Common |
2 | 2 |
|
3 | | -open System.Collections.Generic |
4 | 3 | open Brahma.FSharp |
5 | 4 | open Microsoft.FSharp.Quotations |
6 | 5 | open GraphBLAS.FSharp.Backend.Objects.ClContext |
7 | 6 | open GraphBLAS.FSharp.Backend.Objects.ClCell |
8 | 7 | open GraphBLAS.FSharp.Backend.Quotes |
9 | 8 | open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions |
10 | | -open GraphBLAS.FSharp.Backend.Quotes |
11 | 9 |
|
12 | 10 | module ClArray = |
13 | 11 | let init (initializer: Expr<int -> 'a>) (clContext: ClContext) workGroupSize = |
@@ -132,180 +130,6 @@ module ClArray = |
132 | 130 |
|
133 | 131 | outputArray |
134 | 132 |
|
135 | | - let map<'a, 'b> (op: Expr<'a -> 'b>) (clContext: ClContext) workGroupSize = |
136 | | - |
137 | | - let map = |
138 | | - <@ fun (ndRange: Range1D) lenght (inputArray: ClArray<'a>) (result: ClArray<'b>) -> |
139 | | - |
140 | | - let gid = ndRange.GlobalID0 |
141 | | - |
142 | | - if gid < lenght then |
143 | | - result.[gid] <- (%op) inputArray.[gid] @> |
144 | | - |
145 | | - let kernel = clContext.Compile map |
146 | | - |
147 | | - fun (processor: MailboxProcessor<_>) allocationMode (inputArray: ClArray<'a>) -> |
148 | | - |
149 | | - let result = |
150 | | - clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, inputArray.Length) |
151 | | - |
152 | | - let ndRange = |
153 | | - Range1D.CreateValid(inputArray.Length, workGroupSize) |
154 | | - |
155 | | - let kernel = kernel.GetKernel() |
156 | | - |
157 | | - processor.Post(Msg.MsgSetArguments(fun () -> kernel.KernelFunc ndRange inputArray.Length inputArray result)) |
158 | | - |
159 | | - processor.Post(Msg.CreateRunMsg<_, _>(kernel)) |
160 | | - |
161 | | - result |
162 | | - |
163 | | - let mapWithValue<'a, 'b, 'c> (clContext: ClContext) workGroupSize (op: Expr<'a -> 'b -> 'c>) = |
164 | | - |
165 | | - let map = |
166 | | - <@ fun (ndRange: Range1D) lenght (value: ClCell<'a>) (inputArray: ClArray<'b>) (result: ClArray<'c>) -> |
167 | | - |
168 | | - let gid = ndRange.GlobalID0 |
169 | | - |
170 | | - if gid < lenght then |
171 | | - result.[gid] <- (%op) value.Value inputArray.[gid] @> |
172 | | - |
173 | | - let kernel = clContext.Compile map |
174 | | - |
175 | | - fun (processor: MailboxProcessor<_>) allocationMode (value: 'a) (inputArray: ClArray<'b>) -> |
176 | | - |
177 | | - let result = |
178 | | - clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, inputArray.Length) |
179 | | - |
180 | | - let valueClCell = value |> clContext.CreateClCell |
181 | | - |
182 | | - let ndRange = |
183 | | - Range1D.CreateValid(inputArray.Length, workGroupSize) |
184 | | - |
185 | | - let kernel = kernel.GetKernel() |
186 | | - |
187 | | - processor.Post( |
188 | | - Msg.MsgSetArguments(fun () -> kernel.KernelFunc ndRange inputArray.Length valueClCell inputArray result) |
189 | | - ) |
190 | | - |
191 | | - processor.Post(Msg.CreateRunMsg<_, _>(kernel)) |
192 | | - |
193 | | - result |
194 | | - |
195 | | - let map2InPlace<'a, 'b, 'c> (map: Expr<'a -> 'b -> 'c>) (clContext: ClContext) workGroupSize = |
196 | | - |
197 | | - let kernel = |
198 | | - <@ fun (ndRange: Range1D) length (leftArray: ClArray<'a>) (rightArray: ClArray<'b>) (resultArray: ClArray<'c>) -> |
199 | | - |
200 | | - let gid = ndRange.GlobalID0 |
201 | | - |
202 | | - if gid < length then |
203 | | - |
204 | | - resultArray.[gid] <- (%map) leftArray.[gid] rightArray.[gid] @> |
205 | | - |
206 | | - let kernel = clContext.Compile kernel |
207 | | - |
208 | | - fun (processor: MailboxProcessor<_>) (leftArray: ClArray<'a>) (rightArray: ClArray<'b>) (resultArray: ClArray<'c>) -> |
209 | | - |
210 | | - let ndRange = |
211 | | - Range1D.CreateValid(resultArray.Length, workGroupSize) |
212 | | - |
213 | | - let kernel = kernel.GetKernel() |
214 | | - |
215 | | - processor.Post( |
216 | | - Msg.MsgSetArguments |
217 | | - (fun () -> kernel.KernelFunc ndRange resultArray.Length leftArray rightArray resultArray) |
218 | | - ) |
219 | | - |
220 | | - processor.Post(Msg.CreateRunMsg<_, _>(kernel)) |
221 | | - |
222 | | - let map2<'a, 'b, 'c> map (clContext: ClContext) workGroupSize = |
223 | | - let map2 = |
224 | | - map2InPlace<'a, 'b, 'c> map clContext workGroupSize |
225 | | - |
226 | | - fun (processor: MailboxProcessor<_>) allocationMode (leftArray: ClArray<'a>) (rightArray: ClArray<'b>) -> |
227 | | - |
228 | | - let resultArray = |
229 | | - clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, leftArray.Length) |
230 | | - |
231 | | - map2 processor leftArray rightArray resultArray |
232 | | - |
233 | | - resultArray |
234 | | - |
235 | | - module Bitmap = |
236 | | - let private getUniqueBitmapGeneral predicate (clContext: ClContext) workGroupSize = |
237 | | - |
238 | | - let getUniqueBitmap = |
239 | | - <@ fun (ndRange: Range1D) (inputArray: ClArray<'a>) inputLength (isUniqueBitmap: ClArray<int>) -> |
240 | | - |
241 | | - let gid = ndRange.GlobalID0 |
242 | | - |
243 | | - if gid < inputLength then |
244 | | - let isUnique = (%predicate) gid inputLength inputArray // brahma error |
245 | | - |
246 | | - if isUnique then |
247 | | - isUniqueBitmap.[gid] <- 1 |
248 | | - else |
249 | | - isUniqueBitmap.[gid] <- 0 @> |
250 | | - |
251 | | - let kernel = clContext.Compile(getUniqueBitmap) |
252 | | - |
253 | | - fun (processor: MailboxProcessor<_>) allocationMode (inputArray: ClArray<'a>) -> |
254 | | - |
255 | | - let inputLength = inputArray.Length |
256 | | - |
257 | | - let ndRange = |
258 | | - Range1D.CreateValid(inputLength, workGroupSize) |
259 | | - |
260 | | - let bitmap = |
261 | | - clContext.CreateClArrayWithSpecificAllocationMode(allocationMode, inputLength) |
262 | | - |
263 | | - let kernel = kernel.GetKernel() |
264 | | - |
265 | | - processor.Post(Msg.MsgSetArguments(fun () -> kernel.KernelFunc ndRange inputArray inputLength bitmap)) |
266 | | - |
267 | | - processor.Post(Msg.CreateRunMsg<_, _> kernel) |
268 | | - |
269 | | - bitmap |
270 | | - |
271 | | - let firstOccurrence clContext = |
272 | | - getUniqueBitmapGeneral |
273 | | - <| Predicates.firstOccurrence () |
274 | | - <| clContext |
275 | | - |
276 | | - let lastOccurrence clContext = |
277 | | - getUniqueBitmapGeneral |
278 | | - <| Predicates.lastOccurrence () |
279 | | - <| clContext |
280 | | - |
281 | | - let private getUniqueBitmap2General<'a when 'a: equality> getUniqueBitmap (clContext: ClContext) workGroupSize = |
282 | | - |
283 | | - let map = |
284 | | - map2 <@ fun x y -> x ||| y @> clContext workGroupSize |
285 | | - |
286 | | - let firstGetBitmap = getUniqueBitmap clContext workGroupSize |
287 | | - |
288 | | - fun (processor: MailboxProcessor<_>) allocationMode (firstArray: ClArray<'a>) (secondArray: ClArray<'a>) -> |
289 | | - let firstBitmap = |
290 | | - firstGetBitmap processor DeviceOnly firstArray |
291 | | - |
292 | | - let secondBitmap = |
293 | | - firstGetBitmap processor DeviceOnly secondArray |
294 | | - |
295 | | - let result = |
296 | | - map processor allocationMode firstBitmap secondBitmap |
297 | | - |
298 | | - firstBitmap.Free processor |
299 | | - secondBitmap.Free processor |
300 | | - |
301 | | - result |
302 | | - |
303 | | - let firstOccurrence2 clContext = |
304 | | - getUniqueBitmap2General firstOccurrence clContext |
305 | | - |
306 | | - let lastOccurrence2 clContext = |
307 | | - getUniqueBitmap2General lastOccurrence clContext |
308 | | - |
309 | 133 | ///<description>Remove duplicates form the given array.</description> |
310 | 134 | ///<param name="clContext">Computational context</param> |
311 | 135 | ///<param name="workGroupSize">Should be a power of 2 and greater than 1.</param> |
@@ -406,7 +230,7 @@ module ClArray = |
406 | 230 |
|
407 | 231 | let choose<'a, 'b> (predicate: Expr<'a -> 'b option>) (clContext: ClContext) workGroupSize = |
408 | 232 | let getBitmap = |
409 | | - map<'a, int> (Map.chooseBitmap predicate) clContext workGroupSize |
| 233 | + Map.map<'a, int> (Map.chooseBitmap predicate) clContext workGroupSize |
410 | 234 |
|
411 | 235 | let prefixSum = |
412 | 236 | PrefixSum.standardExcludeInPlace clContext workGroupSize |
@@ -486,7 +310,7 @@ module ClArray = |
486 | 310 |
|
487 | 311 | let choose2 (predicate: Expr<'a -> 'b -> 'c option>) (clContext: ClContext) workGroupSize = |
488 | 312 | let getBitmap = |
489 | | - map2<'a, 'b, int> (Map.choose2Bitmap predicate) clContext workGroupSize |
| 313 | + Map.map2<'a, 'b, int> (Map.choose2Bitmap predicate) clContext workGroupSize |
490 | 314 |
|
491 | 315 | let prefixSum = |
492 | 316 | PrefixSum.standardExcludeInPlace clContext workGroupSize |
@@ -702,7 +526,7 @@ module ClArray = |
702 | 526 | Gather.runInit Map.inc clContext workGroupSize |
703 | 527 |
|
704 | 528 | let map = |
705 | | - map2 <@ fun first second -> (first, second) @> clContext workGroupSize |
| 529 | + Map.map2 <@ fun first second -> (first, second) @> clContext workGroupSize |
706 | 530 |
|
707 | 531 | fun (processor: MailboxProcessor<_>) allocationMode (values: ClArray<'a>) -> |
708 | 532 | if values.Length > 1 then |
@@ -826,7 +650,7 @@ module ClArray = |
826 | 650 | PrefixSum.standardExcludeInPlace clContext workGroupSize |
827 | 651 |
|
828 | 652 | let getBitmap = |
829 | | - map<'a, int> (Map.predicateBitmap predicate) clContext workGroupSize |
| 653 | + Map.map<'a, int> (Map.predicateBitmap predicate) clContext workGroupSize |
830 | 654 |
|
831 | 655 | fun (processor: MailboxProcessor<_>) (array: ClArray<'a>) -> |
832 | 656 |
|
|
0 commit comments