Skip to content

Commit fb1909c

Browse files
authored
Merge pull request #75 from IgorErin/split
Split
2 parents cb8a791 + 45e4536 commit fb1909c

File tree

145 files changed

+4344
-5556
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+4344
-5556
lines changed

.github/workflows/build-and-benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
with:
3737
name: BFS
3838
tool: 'benchmarkdotnet'
39-
output-file-path: BenchmarkDotNet.Artifacts/results/GraphBLAS.FSharp.Benchmarks.BFSBenchmarksWithoutDataTransfer-report-brief.json
39+
output-file-path: BenchmarkDotNet.Artifacts/results/GraphBLAS.FSharp.Benchmarks.BFSWithoutTransferBenchmarkInt32-report-brief.json
4040
# Access token to deploy GitHub Pages branch
4141
github-token: ${{ secrets._GITHUB_TOKEN }}
4242
# Push and deploy GitHub pages branch automatically

README.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,38 @@ GraphBLAS# is a GPGPU-based [GraphBLAS](https://graphblas.org/)-like API impleme
1919
| Left of 't1
2020
| Right of 't2
2121
```
22-
So, type of matrix-matrix elementwise oertion is ```Matrix<Option<'t1>> -> Matrix<Option<'t2>> -> (AtLeastOne<'t1,'t2> -> Option<'t3>) -> Matrix<Option<'t3>>```.
23-
- No semirings. Just functions. Ofcourse one can implement semirings on the top of provided API.
22+
So, type of matrix-matrix elementwise operation is ```Matrix<Option<'t1>> -> Matrix<Option<'t2>> -> (AtLeastOne<'t1,'t2> -> Option<'t3>) -> Matrix<Option<'t3>>```.
23+
- No semirings. Just functions. Of course one can implement semirings on the top of provided API.
2424
- Minimal core: high-order functions allows us to minimaze core by functions unification. For example, such functions as matrix-matrix addition, matrix-matrix element-wise multiplication, masking all are partial case of `map2` function.
2525

2626
### Operations
2727
- **Matrix-Matrix**
28-
- [x] COO-COO element-wize
29-
- [x] CSR-CSR element-wize
30-
- [ ] CSR-CSR multiplication
31-
- [ ] COO transpose
32-
- [ ] CSR transpose
28+
- [x] CSR-CSR `map2`
29+
- [x] CSR-CSR `map2AtLeastOne`
30+
- [x] COO-COO `map2`
31+
- [x] COO-COO `map2AtLeastOne`
32+
- [x] CSR-CSR multiplication
3333
- **Vector-Matrix**
3434
- [x] Dense-CSR multiplication
35-
- [ ] COO-CSR multiplication
35+
- [ ] Sparse-CSR multiplication
3636
- **Vector-Vector**
37-
- [x] Dense-Dense element-wise
37+
- [x] Dense-Dense `map2`
38+
- [x] Dense-Dense `map2AtLeastOne`
39+
- [x] Sparse-Sparse `map2`
40+
- [x] Sparse-Sparse `map2AtLeastOne`
3841
- [ ] ...
3942
- **Matrix**
40-
- [ ] `map`
41-
- [ ] `iter`
43+
- [x] `copy`
44+
- [x] `map`
45+
- [x] COO transpose
46+
- [x] CSR transpose
47+
- [x] CSC transpose
4248
- [ ] ...
4349
- **Vector**
44-
- [ ] `map`
45-
- [ ] `iter`
46-
- [ ] `filter`
47-
- [ ] `contains`
50+
- [x] `zeroCreate`
51+
- [x] `ofList`
52+
- [x] `copy`
53+
- [x] `reduce`
4854
- [ ] ...
4955

5056
### Graph Analysis Algorithms
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
namespace GraphBLAS.FSharp.Benchmarks.Algorithms.BFS
2+
3+
open System.IO
4+
open BenchmarkDotNet.Attributes
5+
open GraphBLAS.FSharp
6+
open GraphBLAS.FSharp.Backend.Quotes
7+
open GraphBLAS.FSharp.IO
8+
open Brahma.FSharp
9+
open Backend.Algorithms.BFS
10+
open Microsoft.FSharp.Core
11+
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
12+
open GraphBLAS.FSharp.Benchmarks
13+
open GraphBLAS.FSharp.Backend.Objects
14+
15+
[<AbstractClass>]
16+
[<IterationCount(100)>]
17+
[<WarmupCount(10)>]
18+
[<Config(typeof<Configs.Matrix>)>]
19+
type Benchmarks<'elem when 'elem : struct>(
20+
buildFunToBenchmark,
21+
converter: string -> 'elem,
22+
binaryConverter,
23+
vertex: int)
24+
=
25+
26+
let mutable funToBenchmark = None
27+
let mutable matrix = Unchecked.defaultof<ClMatrix.CSR<'elem>>
28+
let mutable matrixHost = Unchecked.defaultof<_>
29+
30+
member val ResultLevels = Unchecked.defaultof<ClArray<'elem option>> with get,set
31+
32+
[<ParamsSource("AvailableContexts")>]
33+
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set
34+
35+
[<ParamsSource("InputMatrixProvider")>]
36+
member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set
37+
38+
member this.OclContext = (fst this.OclContextInfo).ClContext
39+
member this.WorkGroupSize = snd this.OclContextInfo
40+
41+
member this.Processor =
42+
let p = (fst this.OclContextInfo).Queue
43+
p.Error.Add(fun e -> failwithf "%A" e)
44+
p
45+
46+
static member AvailableContexts = Utils.availableContexts
47+
48+
static member InputMatrixProviderBuilder pathToConfig =
49+
let datasetFolder = "BFS"
50+
pathToConfig
51+
|> Utils.getMatricesFilenames
52+
|> Seq.map
53+
(fun matrixFilename ->
54+
printfn "%A" matrixFilename
55+
56+
match Path.GetExtension matrixFilename with
57+
| ".mtx" -> MtxReader(Utils.getFullPathToMatrix datasetFolder matrixFilename)
58+
| _ -> failwith "Unsupported matrix format")
59+
60+
member this.FunToBenchmark =
61+
match funToBenchmark with
62+
| None ->
63+
let x = buildFunToBenchmark this.OclContext this.WorkGroupSize
64+
funToBenchmark <- Some x
65+
x
66+
| Some x -> x
67+
68+
member this.BFS() =
69+
this.ResultLevels <- this.FunToBenchmark this.Processor matrix vertex
70+
71+
member this.ClearInputMatrix() =
72+
(matrix :> IDeviceMemObject).Dispose this.Processor
73+
74+
member this.ClearResult() = this.ResultLevels.FreeAndWait this.Processor
75+
76+
member this.ReadMatrix() =
77+
let converter =
78+
match this.InputMatrixReader.Field with
79+
| Pattern -> binaryConverter
80+
| _ -> converter
81+
82+
matrixHost <- this.InputMatrixReader.ReadMatrix converter
83+
84+
member this.LoadMatrixToGPU() =
85+
matrix <- matrixHost.ToCSR.ToDevice this.OclContext
86+
87+
abstract member GlobalSetup : unit -> unit
88+
89+
abstract member IterationCleanup : unit -> unit
90+
91+
abstract member GlobalCleanup : unit -> unit
92+
93+
abstract member Benchmark : unit -> unit
94+
95+
type WithoutTransferBenchmark<'elem when 'elem : struct>(
96+
buildFunToBenchmark,
97+
converter: string -> 'elem,
98+
boolConverter,
99+
vertex) =
100+
101+
inherit Benchmarks<'elem>(
102+
buildFunToBenchmark,
103+
converter,
104+
boolConverter,
105+
vertex)
106+
107+
[<GlobalSetup>]
108+
override this.GlobalSetup() =
109+
this.ReadMatrix()
110+
this.LoadMatrixToGPU()
111+
112+
[<IterationCleanup>]
113+
override this.IterationCleanup() =
114+
this.ClearResult()
115+
116+
[<GlobalCleanup>]
117+
override this.GlobalCleanup() =
118+
this.ClearInputMatrix()
119+
120+
[<Benchmark>]
121+
override this.Benchmark() =
122+
this.BFS()
123+
this.Processor.PostAndReply Msg.MsgNotifyMe
124+
125+
type BFSWithoutTransferBenchmarkInt32() =
126+
127+
inherit WithoutTransferBenchmark<int>(
128+
(singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
129+
int32,
130+
(fun _ -> Utils.nextInt (System.Random())),
131+
0)
132+
133+
static member InputMatrixProvider =
134+
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
135+
136+
type WithTransferBenchmark<'elem when 'elem : struct>(
137+
buildFunToBenchmark,
138+
converter: string -> 'elem,
139+
boolConverter,
140+
vertex) =
141+
142+
inherit Benchmarks<'elem>(
143+
buildFunToBenchmark,
144+
converter,
145+
boolConverter,
146+
vertex)
147+
148+
[<GlobalSetup>]
149+
override this.GlobalSetup() =
150+
this.ReadMatrix()
151+
152+
[<GlobalCleanup>]
153+
override this.GlobalCleanup() =
154+
this.ClearResult()
155+
156+
[<IterationCleanup>]
157+
override this.IterationCleanup() =
158+
this.ClearInputMatrix()
159+
this.ClearResult()
160+
161+
[<Benchmark>]
162+
override this.Benchmark() =
163+
this.LoadMatrixToGPU()
164+
this.BFS()
165+
this.ResultLevels.ToHost this.Processor |> ignore
166+
this.Processor.PostAndReply Msg.MsgNotifyMe
167+
168+
type BFSWithTransferBenchmarkInt32() =
169+
170+
inherit WithTransferBenchmark<int>(
171+
(singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
172+
int32,
173+
(fun _ -> Utils.nextInt (System.Random())),
174+
0)
175+
176+
static member InputMatrixProvider =
177+
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
178+

0 commit comments

Comments
 (0)