@@ -8,51 +8,57 @@ open Brahma.OpenCL
88
99module internal GetComplemented =
1010 let mask1D ( mask : Mask1D ) = opencl {
11- let size = mask.Size
12- let nnz = mask.Indices.Length
13-
14- let bitmap = Array.create size 1
15- let getComplementedBitmap =
16- <@
17- fun ( range : _1D )
18- ( maskIndices : int [])
19- ( bitmap : int []) ->
20-
21- let gid = range.GlobalID0
22-
23- if gid < nnz then
24- let maskIdx = maskIndices.[ gid]
25- bitmap.[ maskIdx] <- 0
26- @>
27-
28- do ! RunCommand getComplementedBitmap <| fun kernelPrepare ->
29- kernelPrepare
30- <| _ 1D( Utils.getDefaultGlobalSize nnz, Utils.defaultWorkGroupSize)
31- <| mask.Indices
32- <| bitmap
33-
34- let! ( positions , _ ) = PrefixSum.runExclude bitmap
35-
36- let complementedIndices = Array.zeroCreate< int> ( size - nnz)
37- let setPosotions =
38- <@
39- fun ( range : _1D )
40- ( positions : int [])
41- ( bitmap : int [])
42- ( complementedIndices : int []) ->
43-
44- let gid = range.GlobalID0
45-
46- if gid < size && bitmap.[ gid] = 1 then
47- complementedIndices.[ positions.[ gid]] <- gid
48- @>
49-
50- do ! RunCommand setPosotions <| fun kernelPrepare ->
51- kernelPrepare
52- <| _ 1D( Utils.getDefaultGlobalSize size, Utils.defaultWorkGroupSize)
53- <| positions
54- <| bitmap
55- <| complementedIndices
56-
57- return Mask1D( complementedIndices, size, not mask.IsComplemented)
11+ if mask.Indices.Length = 0 then
12+ let indices = Array.init mask.Size id
13+ return Mask1D( indices, mask.Size, not mask.IsComplemented)
14+ elif mask.Indices.Length = mask.Size then
15+ return Mask1D([||], mask.Size, not mask.IsComplemented)
16+ else
17+ let size = mask.Size
18+ let nnz = mask.Indices.Length
19+
20+ let bitmap = Array.create size 1
21+ let getComplementedBitmap =
22+ <@
23+ fun ( range : _1D )
24+ ( maskIndices : int [])
25+ ( bitmap : int []) ->
26+
27+ let gid = range.GlobalID0
28+
29+ if gid < nnz then
30+ let maskIdx = maskIndices.[ gid]
31+ bitmap.[ maskIdx] <- 0
32+ @>
33+
34+ do ! RunCommand getComplementedBitmap <| fun kernelPrepare ->
35+ kernelPrepare
36+ <| _ 1D( Utils.getDefaultGlobalSize nnz, Utils.defaultWorkGroupSize)
37+ <| mask.Indices
38+ <| bitmap
39+
40+ let! ( positions , _ ) = PrefixSum.runExclude bitmap
41+
42+ let complementedIndices = Array.zeroCreate< int> ( size - nnz)
43+ let setPosotions =
44+ <@
45+ fun ( range : _1D )
46+ ( positions : int [])
47+ ( bitmap : int [])
48+ ( complementedIndices : int []) ->
49+
50+ let gid = range.GlobalID0
51+
52+ if gid < size && bitmap.[ gid] = 1 then
53+ complementedIndices.[ positions.[ gid]] <- gid
54+ @>
55+
56+ do ! RunCommand setPosotions <| fun kernelPrepare ->
57+ kernelPrepare
58+ <| _ 1D( Utils.getDefaultGlobalSize size, Utils.defaultWorkGroupSize)
59+ <| positions
60+ <| bitmap
61+ <| complementedIndices
62+
63+ return Mask1D( complementedIndices, size, not mask.IsComplemented)
5864 }
0 commit comments