@@ -143,6 +143,14 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
143143 yield ( uint64 rows.[ i]) <<< 32 ||| ( uint64 columns.[ i]) |]
144144 COOMatrix( rowCount, columnCount, indices, values)
145145
146+ override this.ToString () =
147+ [
148+ sprintf " COO Matrix %i x%i \n " rowCount columnCount
149+ sprintf " Indices: %A \n " indices
150+ sprintf " Values: %A \n " values
151+ ]
152+ |> String.concat " "
153+
146154 override this.Clear () = failwith " Not Implemented"
147155 override this.Copy () = failwith " Not Implemented"
148156 override this.Resize a b = failwith " Not Implemented"
@@ -246,7 +254,7 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
246254
247255 let allIndicesLength = allIndices.Length
248256
249- let createSortedConcatenation =
257+ let merge =
250258 <@
251259 fun ( ndRange : _1D )
252260 ( firstIndicesBuffer : uint64 [])
@@ -259,7 +267,8 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
259267 let i = ndRange.GlobalID0
260268
261269 if i < allIndicesLength then
262- let knots = localArray< int> 2
270+ let mutable beginIdxLocal = local ()
271+ let mutable endIdxLocal = local ()
263272 let localID = ndRange.LocalID0
264273 if localID < 2 then
265274 let mutable x = localID * ( workGroupSize - 1 ) + i - 1
@@ -278,11 +287,12 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
278287 let secondIndex = secondIndicesBuffer.[ diagonalNumber - middleIdx]
279288 if firstIndex < secondIndex then leftEdge <- middleIdx + 1 else rightEdge <- middleIdx - 1
280289
281- knots.[ localID] <- leftEdge
290+ // Here localID equals either 0 or 1
291+ if localID = 0 then beginIdxLocal <- leftEdge else endIdxLocal <- leftEdge
282292 barrier ()
283293
284- let beginIdx = knots .[ 0 ] // BANK CONFLICTS?
285- let endIdx = knots .[ 1 ]
294+ let beginIdx = beginIdxLocal
295+ let endIdx = endIdxLocal
286296 let firstLocalLength = endIdx - beginIdx
287297 let mutable x = workGroupSize - firstLocalLength
288298 if endIdx = longSide then x <- shortSide - i + localID + beginIdx
@@ -331,7 +341,7 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
331341 allValuesBuffer.[ i] <- firstValuesBuffer.[ beginIdx + boundaryX]
332342 @>
333343
334- let createSortedConcatenation =
344+ let merge =
335345 opencl {
336346 let binder kernelP =
337347 let ndRange = _ 1D( workSize allIndices.Length, workGroupSize)
@@ -343,7 +353,7 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
343353 secondValues
344354 allIndices
345355 allValues
346- do ! RunCommand createSortedConcatenation binder
356+ do ! RunCommand merge binder
347357 }
348358
349359 let auxiliaryArray = Array.create allIndices.Length 1
@@ -400,29 +410,25 @@ and COOMatrix<'a when 'a : struct and 'a : equality>(rowCount: int, columnCount:
400410 resultValuesBuffer.[ index] <- allValuesBuffer.[ i]
401411 @>
402412
403- let resultIndices = Array.zeroCreate allIndices.Length
404- let resultValues = Array.create allValues.Length zero
405-
406- let createUnion =
407- opencl {
408- let! prefixSumArray = prefixSum3 auxiliaryArray
409- let binder kernelP =
410- let ndRange = _ 1D( workSize auxiliaryArray.Length, workGroupSize)
411- kernelP
412- ndRange
413- allIndices
414- allValues
415- prefixSumArray
416- resultIndices
417- resultValues
418- do ! RunCommand createUnion binder
419- }
420-
421413 opencl {
422- do ! createSortedConcatenation
414+ do ! merge
423415 do ! filterThroughMask
424416 do ! fillAuxiliaryArray
425- do ! createUnion
417+ let! prefixSumArray , resultLength = prefixSum auxiliaryArray
418+ let! _ = ToHost resultLength
419+ let resultLength = resultLength.[ 0 ]
420+ let resultIndices = Array.zeroCreate resultLength
421+ let resultValues = Array.create resultLength zero
422+ let binder kernelP =
423+ let ndRange = _ 1D( workSize prefixSumArray.Length, workGroupSize)
424+ kernelP
425+ ndRange
426+ allIndices
427+ allValues
428+ prefixSumArray
429+ resultIndices
430+ resultValues
431+ do ! RunCommand createUnion binder
426432
427433 return upcast COOMatrix< 'a>( this.RowCount, this.ColumnCount, resultIndices, resultValues)
428434 }
@@ -638,7 +644,7 @@ and SparseVector<'a when 'a : struct and 'a : equality>(size: int, indices: int[
638644
639645 let createUnion =
640646 opencl {
641- let! prefixSumArray = Toolbox.prefixSum2 auxiliaryArray
647+ let! prefixSumArray , _ = prefixSum auxiliaryArray
642648 let binder kernelP =
643649 let ndRange = _ 1D( workSize auxiliaryArray.Length, workGroupSize)
644650 kernelP
0 commit comments