Skip to content

Commit 9d25601

Browse files
committed
refactor: globalMap
1 parent d22621e commit 9d25601

8 files changed

Lines changed: 237 additions & 112 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksBFS.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type BFSBenchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem :
8383
(matrix :> IDeviceMemObject).Dispose this.Processor
8484

8585
member this.ClearResult() =
86-
this.ResultVector.Dispose this.Processor
86+
this.ResultVector.Free this.Processor
8787

8888
member this.ReadMatrix() =
8989
let matrixReader = this.InputMatrixReader

src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module BFS =
6767
not
6868
<| (containsNonZero queue front).ToHostAndFree queue
6969

70-
front.Dispose queue
70+
front.Free queue
7171

7272
levels
7373
| _ -> failwith "Not implemented"

src/GraphBLAS-sharp.Backend/Matrix/CSRMatrix/SpGEMM/Expand.fs

Lines changed: 183 additions & 100 deletions
Large diffs are not rendered by default.

src/GraphBLAS-sharp.Backend/Objects/ArraysExtentions.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ open Brahma.FSharp
55
module ArraysExtensions =
66

77
type ClArray<'a> with
8-
member this.Dispose(q: MailboxProcessor<Msg>) =
8+
member this.Free(q: MailboxProcessor<Msg>) =
99
q.Post(Msg.CreateFreeMsg this)
1010
q.PostAndReply(Msg.MsgNotifyMe)
1111

@@ -15,7 +15,7 @@ module ArraysExtensions =
1515

1616
member this.ToHostAndFree(q: MailboxProcessor<Msg>) =
1717
let result = this.ToHost q
18-
this.Dispose q
18+
this.Free q
1919

2020
result
2121

src/GraphBLAS-sharp.Backend/Objects/Vector.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ type ClVector<'a when 'a: struct> =
3434
member this.Dispose(q) =
3535
match this with
3636
| Sparse vector -> vector.Dispose(q)
37-
| Dense vector -> vector.Dispose(q)
37+
| Dense vector -> vector.Free(q)

tests/GraphBLAS-sharp.Tests/Matrix/SpGEMM/Expand.fs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open Expecto
88
open GraphBLAS.FSharp.Backend.Common
99
open GraphBLAS.FSharp.Backend.Predefined
1010
open GraphBLAS.FSharp.Backend.Objects.ClCell
11+
open GraphBLAS.FSharp.Backend.Objects.ClContext
1112

1213
let context = Context.defaultContext
1314

@@ -28,7 +29,7 @@ let leftMatrix =
2829
{ RowCount = 5
2930
ColumnCount = 5
3031
RowPointers = [| 0; 2; 2; 5; 6; 8 |]
31-
ColumnIndices = [| 2; 3; 1; 3; 4; 2; 0; 1|]
32+
ColumnIndices = [| 2; 3; 1; 3; 4; 2; 0; 1 |]
3233
Values = [| 2; 3; 8; 5; 4; 2; 1; 7 |] }
3334

3435
/// <remarks>
@@ -110,7 +111,7 @@ let getRequiredRightMatrixValuesPointersTest =
110111
|> Expect.equal result [| 3; 5; 0; 5; 8; 3; 0; 0; |]
111112

112113
let getGlobalPositions () =
113-
let getGlobalPositions = Expand.getGlobalPositions clContext Utils.defaultWorkGroupSize
114+
let getGlobalPositions = Expand.getGlobalMap clContext Utils.defaultWorkGroupSize
114115

115116
getGlobalPositions processor globalLength (getGlobalRightMatrixRawsStartPositions ())
116117

@@ -124,13 +125,13 @@ let getGlobalPositionsTest =
124125

125126
let getRightMatrixValuesPointers () =
126127
let getRightMatrixValuesPointers =
127-
Expand.getRightMatrixPointers clContext Utils.defaultWorkGroupSize
128+
Expand.expandRightMatrixValuesIndices clContext Utils.defaultWorkGroupSize
128129

129130
let globalPositions = getGlobalPositions ()
130131
let globalRightMatrixRawsStartPositions = getGlobalRightMatrixRawsStartPositions ()
131132
let requiredRightMatrixValuesPointers = getRequiredRightMatrixValuesPointers ()
132133

133-
getRightMatrixValuesPointers processor globalLength globalPositions globalRightMatrixRawsStartPositions requiredRightMatrixValuesPointers
134+
getRightMatrixValuesPointers processor globalLength globalRightMatrixRawsStartPositions requiredRightMatrixValuesPointers globalPositions
134135

135136
let rightMatrixValuesPointersTest =
136137
testCase "RightMatrixValuesPointers"
@@ -139,3 +140,42 @@ let rightMatrixValuesPointersTest =
139140

140141
"Result must be the same"
141142
|> Expect.equal result [| 3; 4; 5; 6; 7; 0; 1; 2; 5; 6; 7; 8; 9; 3; 4; 0; 1; 2; |]
143+
144+
let gatherRightMatrixData () =
145+
let getRightMatrixColumnsAndValues =
146+
Expand.getRightMatrixColumnsAndValues clContext Utils.defaultWorkGroupSize
147+
148+
let rightMatrixValuesPointers = getRightMatrixValuesPointers ()
149+
150+
getRightMatrixColumnsAndValues processor globalLength rightMatrixValuesPointers deviceRightMatrix.Values deviceRightMatrix.Columns
151+
152+
let checkGatherRightMatrixData =
153+
testCase "gather right matrix data test"
154+
<| fun () ->
155+
let values, columns = gatherRightMatrixData ()
156+
157+
let hostValues = values.ToHostAndFree processor
158+
159+
"Result must be the same"
160+
|> Expect.equal hostValues [| 2; 2; 5; 9; 1; 3; 4; 4; 5; 9; 1; 1; 8; 2; 2; 3; 4; 4; |]
161+
162+
let hostColumns = columns.ToHostAndFree processor
163+
164+
"Result must be the same"
165+
|> Expect.equal hostColumns [| 2; 5; 1; 5; 6; 1; 4; 6; 1; 5; 6; 4; 6; 2; 5; 1; 4; 6; |]
166+
167+
let getLeftMatrixValues () =
168+
let getLeftMatrixValues =
169+
Expand.getLeftMatrixValuesCorrespondinglyToPositionsPattern clContext Utils.defaultWorkGroupSize
170+
171+
let globalPositions = getGlobalPositions ()
172+
173+
getLeftMatrixValues processor globalLength globalPositions deviceLeftMatrix.Values
174+
175+
let getLeftMatrixValuesTest =
176+
testCase "get left matrix values"
177+
<| fun () ->
178+
let result = (getLeftMatrixValues ()).ToHostAndFree processor
179+
180+
"Left matrix values must be the same"
181+
|> Expect.equal result [| 2; 2; 3; 3; 3; 8; 8; 8; 5; 5; 5; 4; 4; 2; 2; 7; 7; 7 |]

tests/GraphBLAS-sharp.Tests/Program.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ let allTests =
6969
Matrix.SpGEMM.Expand.globalRightMatrixRawsStartPositionsTest
7070
Matrix.SpGEMM.Expand.getRequiredRightMatrixValuesPointersTest
7171
Matrix.SpGEMM.Expand.getGlobalPositionsTest
72-
Matrix.SpGEMM.Expand.rightMatrixValuesPointersTest ]
72+
Matrix.SpGEMM.Expand.rightMatrixValuesPointersTest
73+
Matrix.SpGEMM.Expand.checkGatherRightMatrixData
74+
Matrix.SpGEMM.Expand.getLeftMatrixValuesTest ]
7375
|> testSequenced
7476

7577
[<EntryPoint>]

tests/GraphBLAS-sharp.Tests/Vector/SpMV.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ let correctnessGenericTest
7676
let res = spMV testContext.Queue HostInterop m v
7777

7878
(ClMatrix.CSR m).Dispose q
79-
v.Dispose q
79+
v.Free q
8080
let hostRes = res.ToHost q
81-
res.Dispose q
81+
res.Free q
8282

8383
checkResult isEqual sumOp mulOp zero matrix vector hostRes
8484
| _ -> failwith "Impossible"

0 commit comments

Comments
 (0)