@@ -367,125 +367,38 @@ module SparseVector =
367367 fun ( processor : MailboxProcessor < _ >) ( leftVector : ClSparseVector < 'a >) ( rightVector : ClSparseVector < 'b >) ->
368368 eWiseAdd processor leftVector rightVector
369369
370- let preparePositionsComplemented ( clContext : ClContext ) ( workGroupSize : int ) =
371-
372- let preparePositions =
373- <@ fun ( ndRange : Range1D ) indicesArrayLength ( inputIndices : ClArray < int >) ( positions : ClArray < int >) ->
370+ let toDense ( clContext : ClContext ) ( workGroupSize : int ) =
374371
372+ let toDense =
373+ <@ fun ( ndRange : Range1D ) length ( values : ClArray < 'a >) ( indices : ClArray < int >) ( resultArray : ClArray < 'a option >) ->
375374 let gid = ndRange.GlobalID0
376375
377- if gid < indicesArrayLength then
378- let index = inputIndices.[ gid]
379-
380- positions.[ index] <- 0 @>
381-
382- let kernel = clContext.Compile( preparePositions)
383-
384- let creat = ClArray.create clContext workGroupSize
385-
386- fun ( processor : MailboxProcessor < _ >) ( inputIndices : ClArray < int >) ( vectorSize : int ) ->
387-
388- let positions = creat processor vectorSize 1
389-
390- let ndRange =
391- Range1D.CreateValid( inputIndices.Length, workGroupSize)
376+ if gid < length then
377+ let index = indices.[ gid]
392378
393- let kernel = kernel.GetKernel ()
379+ resultArray .[ index ] <- Some values .[ gid ] @>
394380
395- processor.Post(
396- Msg.MsgSetArguments( fun () -> kernel.KernelFunc ndRange inputIndices.Length inputIndices positions)
397- )
381+ let kernel = clContext.Compile( toDense)
398382
399- processor.Post ( Msg.CreateRunMsg <_, _>( kernel ))
383+ let zeroCreate = ClArray.zeroCreate clContext workGroupSize
400384
401- positions
402-
403- let setPositionsComplemented ( clContext : ClContext ) ( workGroupSize : int ) =
404-
405- let setPositions =
406- <@ fun ( ndRange : Range1D ) length ( positions : ClArray < int >) ( resultIndices : ClArray < int >) ->
407-
408- let gid = ndRange.GlobalID0
409-
410- if gid = length - 1
411- || gid < length
412- && positions.[ gid] <> positions.[ gid + 1 ] then
413- let index = positions.[ gid]
414-
415- resultIndices.[ index] <- gid @>
416-
417- let kernel = clContext.Compile( setPositions)
418-
419- let sum =
420- ClArray.prefixSumExcludeInplace clContext workGroupSize
421-
422- let resultLength = Array.zeroCreate 1
423-
424- fun ( processor : MailboxProcessor < _ >) ( positions : ClArray < int >) ->
425-
426- let prefixArrayLenght = positions.Length
427-
428- let resultLengthGpu = clContext.CreateClCell 0
429-
430- let _ , r = sum processor positions resultLengthGpu
431-
432- let resultLength =
433- let res =
434- processor.PostAndReply( fun ch -> Msg.CreateToHostMsg<_>( r, resultLength, ch))
385+ fun ( processor : MailboxProcessor < _ >) ( vector : ClSparseVector < 'a >) ->
435386
436- processor.Post ( Msg.CreateFreeMsg <_>( r ))
387+ let resultArray = zeroCreate processor vector.Size
437388
438- res.[ 0 ]
439-
440- let resultIndices =
441- clContext.CreateClArray< int>(
442- resultLength,
443- hostAccessMode = HostAccessMode.NotAccessible,
444- deviceAccessMode = DeviceAccessMode.ReadWrite,
445- allocationMode = AllocationMode.Default
446- )
447-
448- let ndRange =
449- Range1D.CreateValid( prefixArrayLenght, workGroupSize)
389+ let ndRange = Range1D.CreateValid( vector.Indices.Length, workGroupSize)
450390
451391 let kernel = kernel.GetKernel()
452392
453393 processor.Post(
454- Msg.MsgSetArguments( fun () -> kernel.KernelFunc ndRange prefixArrayLenght positions resultIndices)
394+ Msg.MsgSetArguments
395+ ( fun () ->
396+ kernel.KernelFunc ndRange vector.Indices.Length vector.Values vector.Indices resultArray)
455397 )
456398
457- processor.Post( Msg.CreateRunMsg<_, _>( kernel))
458-
459- resultIndices
460-
461- let complemented < 'a when 'a : struct > ( clContext : ClContext ) ( workGroupSize : int ) =
462-
463- let preparePositions =
464- preparePositionsComplemented clContext workGroupSize
465-
466- let create =
467- ClArray.zeroCreate clContext workGroupSize
399+ processor.Post( Msg.CreateRunMsg( kernel))
468400
469- let setPositions =
470- setPositionsComplemented clContext workGroupSize
471-
472- fun ( processor : MailboxProcessor < _ >) ( vector : ClSparseVector < 'a >) ->
473-
474- let positions =
475- preparePositions processor vector.Indices vector.Size
476-
477- let resultIndices = setPositions processor positions
478-
479- let resultLenght = resultIndices.Length
480-
481- let ( ResultValues : ClArray < 'a >) = create processor resultLenght
482-
483- processor.Post( Msg.CreateFreeMsg<_>( positions))
484-
485- { Context = clContext
486- Indices = resultIndices
487- Values = ResultValues
488- Size = vector.Size }
401+ resultArray
489402
490403 let reduce < 'a when 'a : struct > ( clContext : ClContext ) ( workGroupSize : int ) ( opAdd : Expr < 'a -> 'a -> 'a >) =
491404
0 commit comments