Skip to content

Commit 0ab7361

Browse files
committed
MailboxProcessor extensions
1 parent c8f3042 commit 0ab7361

File tree

10 files changed

+44
-29
lines changed

10 files changed

+44
-29
lines changed

benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ open GraphBLAS.FSharp.IO
99
open GraphBLAS.FSharp.Benchmarks
1010
open GraphBLAS.FSharp.Objects
1111
open GraphBLAS.FSharp.Objects.ArraysExtensions
12+
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
1213
open GraphBLAS.FSharp.Backend.Quotes
1314

1415
[<AbstractClass>]
@@ -113,12 +114,12 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>(
113114
override this.GlobalSetup() =
114115
this.ReadMatrix()
115116
this.LoadMatrixToGPU()
116-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
117+
finish this.Processor
117118

118119
[<IterationCleanup>]
119120
override this.IterationCleanup() =
120121
this.ClearResult()
121-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
122+
finish this.Processor
122123

123124
[<GlobalCleanup>]
124125
override this.GlobalCleanup() =
@@ -182,7 +183,7 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
182183
[<GlobalSetup>]
183184
override this.GlobalSetup() =
184185
this.ReadMatrix()
185-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
186+
finish this.Processor
186187

187188
[<GlobalCleanup>]
188189
override this.GlobalCleanup() =
@@ -192,7 +193,7 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
192193
override this.IterationCleanup() =
193194
this.ClearInputMatrix()
194195
this.ClearResult()
195-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
196+
finish this.Processor
196197

197198
[<Benchmark>]
198199
override this.Benchmark() =

benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open GraphBLAS.FSharp.IO
77
open Brahma.FSharp
88
open Microsoft.FSharp.Core
99
open GraphBLAS.FSharp.Objects.ArraysExtensions
10+
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
1011
open GraphBLAS.FSharp.Benchmarks
1112
open GraphBLAS.FSharp.Objects
1213

@@ -112,15 +113,15 @@ type PageRankWithoutTransferBenchmarkFloat32() =
112113
override this.GlobalSetup() =
113114
this.ReadMatrix()
114115
this.LoadMatrixToGPU()
115-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
116+
finish this.Processor
116117
this.PrepareMatrix()
117118
this.ClearInputMatrix()
118-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
119+
finish this.Processor
119120

120121
[<IterationCleanup>]
121122
override this.IterationCleanup() =
122123
this.ClearResult()
123-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
124+
finish this.Processor
124125

125126
[<GlobalCleanup>]
126127
override this.GlobalCleanup() =
@@ -129,4 +130,4 @@ type PageRankWithoutTransferBenchmarkFloat32() =
129130
[<Benchmark>]
130131
override this.Benchmark() =
131132
this.PageRank()
132-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
133+
finish this.Processor

benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open GraphBLAS.FSharp.IO
88
open GraphBLAS.FSharp.Objects
99
open GraphBLAS.FSharp.Objects.MatrixExtensions
1010
open GraphBLAS.FSharp.Objects.ClContextExtensions
11+
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
1112
open GraphBLAS.FSharp.Backend.Quotes
1213
open GraphBLAS.FSharp.Benchmarks
1314

@@ -118,12 +119,12 @@ module WithoutTransfer =
118119
override this.GlobalSetup() =
119120
this.ReadMatrices ()
120121
this.LoadMatricesToGPU ()
121-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
122+
finish this.Processor
122123

123124
[<Benchmark>]
124125
override this.Benchmark () =
125126
this.EWiseAddition()
126-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
127+
finish this.Processor
127128

128129
[<IterationCleanup>]
129130
override this.IterationCleanup () =
@@ -251,7 +252,7 @@ module WithTransfer =
251252
[<GlobalSetup>]
252253
override this.GlobalSetup() =
253254
this.ReadMatrices()
254-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
255+
finish this.Processor
255256

256257
[<GlobalCleanup>]
257258
override this.GlobalCleanup() = ()
@@ -260,7 +261,7 @@ module WithTransfer =
260261
override this.IterationCleanup() =
261262
this.ClearInputMatrices()
262263
this.ClearResult()
263-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
264+
finish this.Processor
264265

265266
[<Benchmark>]
266267
override this.Benchmark() =

benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open GraphBLAS.FSharp.IO
88
open GraphBLAS.FSharp.Backend.Quotes
99
open GraphBLAS.FSharp.Objects
1010
open GraphBLAS.FSharp.Objects.ClContextExtensions
11+
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
1112
open GraphBLAS.FSharp.Benchmarks
1213

1314
[<AbstractClass>]
@@ -115,17 +116,17 @@ module WithoutTransfer =
115116
override this.GlobalSetup() =
116117
this.ReadMatrices()
117118
this.LoadMatricesToGPU()
118-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
119+
finish this.Processor
119120

120121
[<Benchmark>]
121122
override this.Benchmark() =
122123
this.Mxm()
123-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
124+
finish this.Processor
124125

125126
[<IterationCleanup>]
126127
override this.IterationCleanup () =
127128
this.ClearResult()
128-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
129+
finish this.Processor
129130

130131
[<GlobalCleanup>]
131132
override this.GlobalCleanup () =

benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open Brahma.FSharp
88
open GraphBLAS.FSharp
99
open GraphBLAS.FSharp.Objects
1010
open GraphBLAS.FSharp.Objects.ClContextExtensions
11+
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
1112
open GraphBLAS.FSharp.Benchmarks
1213

1314
[<AbstractClass>]
@@ -152,17 +153,17 @@ type MxmBenchmarksMultiplicationOnly<'elem when 'elem : struct>(
152153
this.ReadMatrices ()
153154
this.LoadMatricesToGPU ()
154155
this.ConvertSecondMatrixToCSC()
155-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
156+
finish this.Processor
156157

157158
[<Benchmark>]
158159
override this.Benchmark () =
159160
this.Mxm()
160-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
161+
finish this.Processor
161162

162163
[<IterationCleanup>]
163164
override this.IterationCleanup () =
164165
this.ClearResult()
165-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
166+
finish this.Processor
166167

167168
[<GlobalCleanup>]
168169
override this.GlobalCleanup () =
@@ -184,20 +185,20 @@ type MxmBenchmarksWithTransposing<'elem when 'elem : struct>(
184185
override this.GlobalSetup() =
185186
this.ReadMatrices()
186187
this.LoadMatricesToGPU ()
187-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
188+
finish this.Processor
188189

189190
[<Benchmark>]
190191
override this.Benchmark() =
191192
this.ConvertSecondMatrixToCSC()
192193
this.Mxm()
193-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
194+
finish this.Processor
194195

195196

196197
[<IterationCleanup>]
197198
override this.IterationCleanup() =
198199
this.ClearResult()
199200
this.ConvertSecondMatrixToCSR()
200-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
201+
finish this.Processor
201202

202203
[<GlobalCleanup>]
203204
override this.GlobalCleanup() =

benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ open GraphBLAS.FSharp.Tests
1010
open GraphBLAS.FSharp.Objects
1111
open GraphBLAS.FSharp.Objects.ClVectorExtensions
1212
open GraphBLAS.FSharp.Objects.ClContextExtensions
13+
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
1314

1415
[<AbstractClass>]
1516
[<IterationCount(100)>]
@@ -115,7 +116,7 @@ module WithoutTransfer =
115116
override this.IterationCleanup() =
116117
this.ClearResult()
117118
this.ClearInputVectors()
118-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
119+
finish this.Processor
119120

120121
[<GlobalCleanup>]
121122
override this.GlobalCleanup() = ()
@@ -160,7 +161,7 @@ module WithTransfer =
160161
[<IterationSetup>]
161162
override this.IterationSetup() =
162163
this.CreateVectors()
163-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
164+
finish this.Processor
164165

165166
[<Benchmark>]
166167
override this.Benchmark () =
@@ -177,7 +178,7 @@ module WithTransfer =
177178
override this.IterationCleanup () =
178179
this.ClearInputVectors()
179180
this.ClearResult()
180-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
181+
finish this.Processor
181182

182183
[<GlobalCleanup>]
183184
override this.GlobalCleanup() = ()

src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>
@@ -13,6 +13,7 @@
1313
<Compile Include="AssemblyInfo.fs" />
1414
<Compile Include="Constants/Constants.fs" />
1515
<Compile Include="Objects/Common.fs" />
16+
<Compile Include="Objects/MailboxProcessorExtensions.fs" />
1617
<Compile Include="Objects/ArraysExtentions.fs" />
1718
<Compile Include="Objects/Vector.fs" />
1819
<Compile Include="Objects/Matrix.fs" />

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
namespace GraphBLAS.FSharp.Objects
22

33
open Brahma.FSharp
4+
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
45

56
module ArraysExtensions =
67
type ClArray<'a> with
78
member this.FreeAndWait(q: MailboxProcessor<Msg>) =
89
q.Post(Msg.CreateFreeMsg this)
9-
q.PostAndReply(Msg.MsgNotifyMe)
10+
finish q
1011

1112
member this.ToHost(q: MailboxProcessor<Msg>) =
1213
let dst = Array.zeroCreate this.Length
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace GraphBLAS.FSharp.Objects
2+
3+
open Brahma.FSharp
4+
5+
module MailboxProcessorExtensions =
6+
let finish (q: MailboxProcessor<Msg>) = q.PostAndReply(Msg.MsgNotifyMe)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace GraphBLAS.FSharp.Objects
22

33
open Brahma.FSharp
44
open GraphBLAS.FSharp.Objects
5+
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
56

67
type MatrixFormat =
78
| CSR
@@ -49,7 +50,7 @@ module ClMatrix =
4950
q.Post(Msg.CreateFreeMsg<_>(this.Values))
5051
q.Post(Msg.CreateFreeMsg<_>(this.Rows))
5152
q.Post(Msg.CreateFreeMsg<_>(this.ColumnPointers))
52-
q.PostAndReply(Msg.MsgNotifyMe)
53+
finish q
5354

5455
member this.Dispose q = (this :> IDeviceMemObject).Dispose q
5556

@@ -76,7 +77,7 @@ module ClMatrix =
7677
q.Post(Msg.CreateFreeMsg<_>(this.Values))
7778
q.Post(Msg.CreateFreeMsg<_>(this.Columns))
7879
q.Post(Msg.CreateFreeMsg<_>(this.Rows))
79-
q.PostAndReply(Msg.MsgNotifyMe)
80+
finish q
8081

8182
member this.Dispose q = (this :> IDeviceMemObject).Dispose q
8283

@@ -114,7 +115,7 @@ module ClMatrix =
114115
q.Post(Msg.CreateFreeMsg<_>(this.RowIndices))
115116
q.Post(Msg.CreateFreeMsg<_>(this.ColumnIndices))
116117
q.Post(Msg.CreateFreeMsg<_>(this.Values))
117-
q.PostAndReply(Msg.MsgNotifyMe)
118+
finish q
118119

119120
member this.Dispose q = (this :> IDeviceMemObject).Dispose q
120121

0 commit comments

Comments
 (0)