-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kronecker optimization #91
Open
artemiipatov
wants to merge
8
commits into
SparseLinearAlgebra:dev
Choose a base branch
from
artemiipatov:mydev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ae663e7
perf: kronecker
artemiipatov 38d5846
refactor: kronecker
artemiipatov 2d2d0f0
add: kronecker benchmarks
artemiipatov ed6e5f2
add: kronecker benchmark config
artemiipatov 2cd1535
refactor: kronecker benchmarks
artemiipatov cdacf37
refactor: benchmarks
artemiipatov 39e36b0
merge: dev
artemiipatov b8696b7
refactor: formatting
artemiipatov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
can_634 | ||
Si2 | ||
lshp1561 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Kronecker.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
module GraphBLAS.FSharp.Benchmarks.Matrix.Kronecker | ||
|
||
open System.IO | ||
open BenchmarkDotNet.Attributes | ||
open Brahma.FSharp | ||
open GraphBLAS.FSharp | ||
open GraphBLAS.FSharp.IO | ||
open GraphBLAS.FSharp.Backend.Quotes | ||
open GraphBLAS.FSharp.Objects | ||
open GraphBLAS.FSharp.Objects.ClContextExtensions | ||
open GraphBLAS.FSharp.Benchmarks | ||
|
||
[<AbstractClass>] | ||
[<IterationCount(100)>] | ||
[<WarmupCount(10)>] | ||
[<Config(typeof<Configs.Matrix>)>] | ||
type Benchmarks<'elem when 'elem : struct>( | ||
buildFunToBenchmark, | ||
converter: string -> 'elem, | ||
converterBool, | ||
buildMatrix) = | ||
|
||
let mutable funToBenchmark = None | ||
|
||
let mutable matrix = Unchecked.defaultof<ClMatrix<'elem>> | ||
|
||
let mutable matrixHost = Unchecked.defaultof<_> | ||
|
||
member val ResultMatrix = Unchecked.defaultof<ClMatrix<'elem> option> with get, set | ||
|
||
[<ParamsSource("AvailableContexts")>] | ||
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set | ||
|
||
[<ParamsSource("InputMatrixProvider")>] | ||
member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set | ||
|
||
member this.OclContext: ClContext = (fst this.OclContextInfo).ClContext | ||
member this.WorkGroupSize = snd this.OclContextInfo | ||
|
||
member this.Processor = | ||
let p = (fst this.OclContextInfo).Queue | ||
p.Error.Add(fun e -> failwithf "%A" e) | ||
p | ||
|
||
static member AvailableContexts = Utils.availableContexts | ||
|
||
static member InputMatrixProviderBuilder pathToConfig = | ||
let datasetFolder = "" | ||
pathToConfig | ||
|> Utils.getMatricesFilenames | ||
|> Seq.map | ||
(fun matrixFilename -> | ||
printfn "%A" matrixFilename | ||
|
||
match Path.GetExtension matrixFilename with | ||
| ".mtx" -> | ||
MtxReader(Utils.getFullPathToMatrix datasetFolder matrixFilename) | ||
| _ -> failwith "Unsupported matrix format") | ||
|
||
member this.FunToBenchmark = | ||
match funToBenchmark with | ||
| None -> | ||
let x = buildFunToBenchmark this.OclContext this.WorkGroupSize | ||
funToBenchmark <- Some x | ||
x | ||
| Some x -> x | ||
|
||
member this.ReadMatrix (reader: MtxReader) = | ||
let converter = | ||
match reader.Field with | ||
| Pattern -> converterBool | ||
| _ -> converter | ||
|
||
reader.ReadMatrix converter | ||
|
||
member this.Mxm() = | ||
this.ResultMatrix <- this.FunToBenchmark this.Processor DeviceOnly matrix matrix | ||
|
||
member this.ClearInputMatrices() = | ||
matrix.Dispose this.Processor | ||
|
||
member this.ClearResult() = | ||
match this.ResultMatrix with | ||
| Some matrix -> matrix.Dispose this.Processor | ||
| None -> () | ||
|
||
member this.ReadMatrices() = | ||
matrixHost <- this.ReadMatrix this.InputMatrixReader | ||
|
||
member this.LoadMatricesToGPU () = | ||
matrix <- buildMatrix this.OclContext matrixHost | ||
|
||
abstract member GlobalSetup : unit -> unit | ||
|
||
abstract member Benchmark : unit -> unit | ||
|
||
abstract member IterationCleanup : unit -> unit | ||
|
||
abstract member GlobalCleanup : unit -> unit | ||
|
||
module WithoutTransfer = | ||
type Benchmark<'elem when 'elem : struct>( | ||
buildFunToBenchmark, | ||
converter: string -> 'elem, | ||
converterBool, | ||
buildMatrix) = | ||
|
||
inherit Benchmarks<'elem>( | ||
buildFunToBenchmark, | ||
converter, | ||
converterBool, | ||
buildMatrix) | ||
|
||
[<GlobalSetup>] | ||
override this.GlobalSetup() = | ||
this.ReadMatrices() | ||
this.LoadMatricesToGPU() | ||
|
||
[<Benchmark>] | ||
override this.Benchmark() = | ||
this.Mxm() | ||
this.Processor.PostAndReply(Msg.MsgNotifyMe) | ||
|
||
[<IterationCleanup>] | ||
override this.IterationCleanup () = | ||
this.ClearResult() | ||
|
||
[<GlobalCleanup>] | ||
override this.GlobalCleanup () = | ||
this.ClearInputMatrices() | ||
|
||
type Float32() = | ||
|
||
inherit Benchmark<float32>( | ||
Operations.kronecker (ArithmeticOperations.float32MulOption), | ||
float32, | ||
(fun _ -> Utils.nextSingle (System.Random())), | ||
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context) | ||
) | ||
|
||
static member InputMatrixProvider = | ||
Benchmarks<_>.InputMatrixProviderBuilder "Kronecker.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking as Kirill