Skip to content

Commit 15b1ec8

Browse files
committed
Added operation assign sub vector through mask
1 parent 918edae commit 15b1ec8

17 files changed

Lines changed: 339 additions & 401 deletions

File tree

GraphBLAS-sharp.sln

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "GraphBLAS-sharp.Benchmarks"
1717
EndProject
1818
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "docsTool", "docsTool\docsTool.fsproj", "{8855EC73-F6A1-43D3-AFBC-04A3E09F9BD9}"
1919
EndProject
20-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "App", "src\App\App.fsproj", "{B2C13ACA-2BF7-4C9F-9C3A-94B2B0228BB6}"
21-
EndProject
2220
Global
2321
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2422
Debug|Any CPU = Debug|Any CPU
@@ -80,23 +78,10 @@ Global
8078
{4C6EB3D0-B6BF-4FF5-BC77-CC7CB3F307E6}.Release|x64.Build.0 = Release|Any CPU
8179
{4C6EB3D0-B6BF-4FF5-BC77-CC7CB3F307E6}.Release|x86.ActiveCfg = Release|Any CPU
8280
{4C6EB3D0-B6BF-4FF5-BC77-CC7CB3F307E6}.Release|x86.Build.0 = Release|Any CPU
83-
{B2C13ACA-2BF7-4C9F-9C3A-94B2B0228BB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
84-
{B2C13ACA-2BF7-4C9F-9C3A-94B2B0228BB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
85-
{B2C13ACA-2BF7-4C9F-9C3A-94B2B0228BB6}.Debug|x64.ActiveCfg = Debug|Any CPU
86-
{B2C13ACA-2BF7-4C9F-9C3A-94B2B0228BB6}.Debug|x64.Build.0 = Debug|Any CPU
87-
{B2C13ACA-2BF7-4C9F-9C3A-94B2B0228BB6}.Debug|x86.ActiveCfg = Debug|Any CPU
88-
{B2C13ACA-2BF7-4C9F-9C3A-94B2B0228BB6}.Debug|x86.Build.0 = Debug|Any CPU
89-
{B2C13ACA-2BF7-4C9F-9C3A-94B2B0228BB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
90-
{B2C13ACA-2BF7-4C9F-9C3A-94B2B0228BB6}.Release|Any CPU.Build.0 = Release|Any CPU
91-
{B2C13ACA-2BF7-4C9F-9C3A-94B2B0228BB6}.Release|x64.ActiveCfg = Release|Any CPU
92-
{B2C13ACA-2BF7-4C9F-9C3A-94B2B0228BB6}.Release|x64.Build.0 = Release|Any CPU
93-
{B2C13ACA-2BF7-4C9F-9C3A-94B2B0228BB6}.Release|x86.ActiveCfg = Release|Any CPU
94-
{B2C13ACA-2BF7-4C9F-9C3A-94B2B0228BB6}.Release|x86.Build.0 = Release|Any CPU
9581
EndGlobalSection
9682
GlobalSection(NestedProjects) = preSolution
9783
{5D30E174-2538-47AC-8443-318C8C5DC2C9} = {C397A34C-84F1-49E7-AEBC-2F9F2B196216}
9884
{1CA2E092-2320-451D-A4F0-9ED7C7C528CA} = {ACBEE43C-7A88-4FB1-9B06-DB064D22B29F}
9985
{4C6EB3D0-B6BF-4FF5-BC77-CC7CB3F307E6} = {DEF656DE-BCED-4C49-B5ED-950D4A29B78B}
100-
{B2C13ACA-2BF7-4C9F-9C3A-94B2B0228BB6} = {C397A34C-84F1-49E7-AEBC-2F9F2B196216}
10186
EndGlobalSection
10287
EndGlobal

src/App/App.fsproj

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/App/Program.fs

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace GraphBLAS.FSharp.Backend.COOVector
2+
3+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
4+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
5+
open GraphBLAS.FSharp.Backend.Common
6+
open GraphBLAS.FSharp.Backend.COOVector.Utilities
7+
open GraphBLAS.FSharp.Backend.COOVector.Utilities.AssignSubVector
8+
9+
module internal AssignSubVector =
10+
let private runNotEmpty (leftIndices: int[]) (leftValues: 'a[]) (rightIndices: int[]) (rightValues: 'a[]) (maskIndices: int[]) : OpenCLEvaluation<int[] * 'a[]> = opencl {
11+
let! bitmap, maskValues = intersect rightIndices rightValues maskIndices
12+
13+
let! resultIndices, resultValues, rawPositions = filter leftIndices leftValues maskIndices maskValues bitmap
14+
15+
let! rawPositions = preparePositions resultIndices rawPositions
16+
17+
return! setPositions resultIndices resultValues rawPositions
18+
}
19+
20+
let run (leftIndices: int[]) (leftValues: 'a[]) (rightIndices: int[]) (rightValues: 'a[]) (maskIndices: int[]) : OpenCLEvaluation<int[] * 'a[]> =
21+
if leftValues.Length = 0 then
22+
opencl {
23+
let! resultIndices = Copy.run rightIndices
24+
let! resultValues = Copy.run rightValues
25+
26+
return resultIndices, resultValues
27+
}
28+
29+
elif rightIndices.Length = 0 then
30+
opencl {
31+
return leftIndices, leftValues
32+
}
33+
34+
else
35+
runNotEmpty leftIndices leftValues rightIndices rightValues maskIndices

src/GraphBLAS-sharp/Backend/COOVector/EWiseAdd.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
55
open GraphBLAS.FSharp
66
open GraphBLAS.FSharp.Backend.Common
77
open GraphBLAS.FSharp.Backend.COOVector.Utilities
8+
open GraphBLAS.FSharp.Backend.COOVector.Utilities.EWiseAdd
89

910
module internal EWiseAdd =
1011
let private runNonEmpty (leftIndices: int[]) (leftValues: 'a[]) (rightIndices: int[]) (rightValues: 'a[]) (mask: Mask1D option) (semiring: ISemiring<'a>) : OpenCLEvaluation<int[] * 'a[]> = opencl {

src/GraphBLAS-sharp/Backend/COOVector/FillSubVector.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
44
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
55
open GraphBLAS.FSharp.Backend.Common
66
open GraphBLAS.FSharp.Backend.COOVector.Utilities
7+
open GraphBLAS.FSharp.Backend.COOVector.Utilities.FillSubVector
78

89
module internal FillSubVector =
910
let private runNotEmpty (leftIndices: int[]) (leftValues: 'a[]) (rightIndices: int[]) (scalar: 'a[]) : OpenCLEvaluation<int[] * 'a[]> = opencl {
10-
let! allIndices, allValues = mergeWithScalar leftIndices leftValues rightIndices scalar
11+
let! allIndices, allValues = merge leftIndices leftValues rightIndices scalar
1112

12-
let! rawPositions = preparePositionsWithoutPlus allIndices
13+
let! rawPositions = preparePositions allIndices
1314

1415
return! setPositions allIndices allValues rawPositions
1516
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
namespace GraphBLAS.FSharp.Backend.COOVector.Utilities.AssignSubVector
2+
3+
open Brahma.OpenCL
4+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
5+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
6+
open GraphBLAS.FSharp.Backend.Common
7+
8+
[<AutoOpen>]
9+
module internal Filter =
10+
let filter (leftIndices: int[]) (leftValues: 'a[]) (rightIndices: int[]) (rightValues: 'a[]) (bitmap: bool[]) : OpenCLEvaluation<int[] * 'a[] * int[]> = opencl {
11+
let workGroupSize = Utils.workGroupSize
12+
let firstSide = leftValues.Length
13+
let secondSide = rightIndices.Length
14+
let sumOfSides = firstSide + secondSide
15+
16+
let merge =
17+
<@
18+
fun (ndRange: _1D)
19+
(firstIndicesBuffer: int[])
20+
(firstValuesBuffer: 'a[])
21+
(secondIndicesBuffer: int[])
22+
(secondValuesBuffer: 'a[])
23+
(bitmapBuffer: bool[])
24+
(allIndicesBuffer: int[])
25+
(allValuesBuffer: 'a[])
26+
(rawPositionsBuffer: int[]) ->
27+
28+
let i = ndRange.GlobalID0
29+
30+
let mutable beginIdxLocal = local ()
31+
let mutable endIdxLocal = local ()
32+
let localID = ndRange.LocalID0
33+
if localID < 2 then
34+
let mutable x = localID * (workGroupSize - 1) + i - 1
35+
if x >= sumOfSides then x <- sumOfSides - 1
36+
let diagonalNumber = x
37+
38+
let mutable leftEdge = diagonalNumber + 1 - secondSide
39+
if leftEdge < 0 then leftEdge <- 0
40+
41+
let mutable rightEdge = firstSide - 1
42+
if rightEdge > diagonalNumber then rightEdge <- diagonalNumber
43+
44+
while leftEdge <= rightEdge do
45+
let middleIdx = (leftEdge + rightEdge) / 2
46+
let firstIndex = firstIndicesBuffer.[middleIdx]
47+
let secondIndex = secondIndicesBuffer.[diagonalNumber - middleIdx]
48+
if firstIndex <= secondIndex then leftEdge <- middleIdx + 1 else rightEdge <- middleIdx - 1
49+
50+
// Here localID equals either 0 or 1
51+
if localID = 0 then beginIdxLocal <- leftEdge else endIdxLocal <- leftEdge
52+
barrier ()
53+
54+
let beginIdx = beginIdxLocal
55+
let endIdx = endIdxLocal
56+
let firstLocalLength = endIdx - beginIdx
57+
let mutable x = workGroupSize - firstLocalLength
58+
if endIdx = firstSide then x <- secondSide - i + localID + beginIdx
59+
let secondLocalLength = x
60+
61+
//First indices are from 0 to firstLocalLength - 1 inclusive
62+
//Second indices are from firstLocalLength to firstLocalLength + secondLocalLength - 1 inclusive
63+
let localIndices = localArray<int> workGroupSize
64+
65+
if localID < firstLocalLength then
66+
localIndices.[localID] <- firstIndicesBuffer.[beginIdx + localID]
67+
if localID < secondLocalLength then
68+
localIndices.[firstLocalLength + localID] <- secondIndicesBuffer.[i - beginIdx]
69+
barrier ()
70+
71+
if i < sumOfSides then
72+
let mutable leftEdge = localID + 1 - secondLocalLength
73+
if leftEdge < 0 then leftEdge <- 0
74+
75+
let mutable rightEdge = firstLocalLength - 1
76+
if rightEdge > localID then rightEdge <- localID
77+
78+
while leftEdge <= rightEdge do
79+
let middleIdx = (leftEdge + rightEdge) / 2
80+
let firstIndex = localIndices.[middleIdx]
81+
let secondIndex = localIndices.[firstLocalLength + localID - middleIdx]
82+
if firstIndex <= secondIndex then leftEdge <- middleIdx + 1 else rightEdge <- middleIdx - 1
83+
84+
let boundaryX = rightEdge
85+
let boundaryY = localID - leftEdge
86+
87+
// boundaryX and boundaryY can't be off the right edge of array (only off the left edge)
88+
let isValidX = boundaryX >= 0
89+
let isValidY = boundaryY >= 0
90+
91+
let mutable fstIdx = 0
92+
if isValidX then fstIdx <- localIndices.[boundaryX]
93+
94+
let mutable sndIdx = 0
95+
if isValidY then sndIdx <- localIndices.[firstLocalLength + boundaryY]
96+
97+
if not isValidX || isValidY && fstIdx <= sndIdx then
98+
allIndicesBuffer.[i] <- sndIdx
99+
if bitmapBuffer.[i - localID - beginIdx + boundaryY] then
100+
allValuesBuffer.[i] <- secondValuesBuffer.[i - localID - beginIdx + boundaryY]
101+
else
102+
rawPositionsBuffer.[i] <- 0
103+
else
104+
allIndicesBuffer.[i] <- fstIdx
105+
allValuesBuffer.[i] <- firstValuesBuffer.[beginIdx + boundaryX]
106+
@>
107+
108+
let resultValues = Array.create sumOfSides Unchecked.defaultof<'a>
109+
let resultIndices = Array.zeroCreate sumOfSides
110+
let rawPositions = Array.create sumOfSides 1
111+
112+
do! RunCommand merge <| fun kernelPrepare ->
113+
let ndRange = _1D(Utils.workSize sumOfSides, workGroupSize)
114+
kernelPrepare
115+
ndRange
116+
leftIndices
117+
leftValues
118+
rightIndices
119+
rightValues
120+
bitmap
121+
resultIndices
122+
resultValues
123+
rawPositions
124+
125+
return resultIndices, resultValues, rawPositions
126+
}

0 commit comments

Comments
 (0)