@@ -621,35 +621,36 @@ module ClArray =
621621 let fill ( clContext : ClContext ) workGroupSize =
622622
623623 let fill =
624- <@ fun ( ndRange : Range1D ) firstPosition endPosition ( value : ClCell < 'a >) ( targetArray : ClArray < 'a >) ->
624+ <@ fun ( ndRange : Range1D ) firstPosition count ( value : ClCell < 'a >) ( targetArray : ClArray < 'a >) ->
625625
626626 let gid = ndRange.GlobalID0
627627 let writePosition = gid + firstPosition
628628
629- if writePosition < endPosition then
630-
629+ if gid < count then
631630 targetArray.[ writePosition] <- value.Value @>
632631
633632 let kernel = clContext.Compile fill
634633
635634 fun ( processor : MailboxProcessor < _ >) value firstPosition count ( targetArray : ClArray < 'a >) ->
636- if firstPosition + count > targetArray.Length then
637- failwith " "
635+ if count = 0 then ()
636+ else
637+ if firstPosition + count > targetArray.Length then
638+ failwith " "
638639
639- if firstPosition < 0 then failwith " "
640- if count <= 0 then failwith " " // TODO()
640+ if firstPosition < 0 then failwith " "
641+ if count < 0 then failwith " " // TODO()
641642
642- let ndRange =
643- Range1D.CreateValid( count, workGroupSize)
643+ let ndRange =
644+ Range1D.CreateValid( count, workGroupSize)
644645
645- let kernel = kernel.GetKernel()
646+ let kernel = kernel.GetKernel()
646647
647- processor.Post(
648- Msg.MsgSetArguments
649- ( fun () -> kernel.KernelFunc ndRange firstPosition ( firstPosition + count) value targetArray)
650- )
648+ processor.Post(
649+ Msg.MsgSetArguments
650+ ( fun () -> kernel.KernelFunc ndRange firstPosition count value targetArray)
651+ )
651652
652- processor.Post( Msg.CreateRunMsg<_, _>( kernel))
653+ processor.Post( Msg.CreateRunMsg<_, _>( kernel))
653654
654655 let pairwise ( clContext : ClContext ) workGroupSize =
655656
@@ -659,18 +660,26 @@ module ClArray =
659660 let incGather =
660661 Gather.runInit Map.inc clContext workGroupSize
661662
663+ let map = map2 clContext workGroupSize <@ fun first second -> ( first, second) @>
664+
662665 fun ( processor : MailboxProcessor < _ >) allocationMode ( values : ClArray < 'a >) ->
666+ if values.Length > 1 then
667+ let resultLength = values.Length - 1
663668
664- let resultLength = values.Length - 1
669+ let firstItems =
670+ clContext.CreateClArrayWithSpecificAllocationMode( allocationMode, resultLength)
665671
666- let firstItems =
667- clContext.CreateClArrayWithSpecificAllocationMode( allocationMode, resultLength)
672+ idGather processor values firstItems
668673
669- idGather processor values firstItems
674+ let secondItems =
675+ clContext.CreateClArrayWithSpecificAllocationMode( allocationMode, resultLength)
670676
671- let secondItems =
672- clContext.CreateClArrayWithSpecificAllocationMode( allocationMode, resultLength)
677+ incGather processor values secondItems
678+
679+ let result = map processor allocationMode firstItems secondItems
673680
674- incGather processor values secondItems
681+ firstItems.Free processor
682+ secondItems.Free processor
675683
676- firstItems, secondItems
684+ Some result
685+ else None
0 commit comments