Skip to content
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

PageRank #88

Merged
merged 13 commits into from
Mar 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Benchmarks(

let mutable funToBenchmark = None
let mutable matrix = Unchecked.defaultof<ClMatrix<float32>>
let mutable matrixPrepared = Unchecked.defaultof<ClMatrix<float32>>
let mutable matrixPrepared = Unchecked.defaultof<PageRankMatrix<float32>>
let mutable matrixHost = Unchecked.defaultof<_>

let accuracy = 0.00000001f
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are predefined constants in Expecto.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still, why is it necessary separately? Perhaps we need to create a module with constants and actions on them in order to avoid mistakes in the future?

Abstract types could also be used here, so that they could be used only with the help of this most magical module.

Expand Down
4 changes: 2 additions & 2 deletions src/GraphBLAS-sharp.Backend/Algorithms/PageRank.fs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ module internal PageRank =

transposeInPlace queue DeviceOnly newMatrix
|> ClMatrix.CSR
|> PageRankMatrix
| _ -> failwith "Not implemented"

let run (clContext: ClContext) workGroupSize =
Expand All @@ -154,8 +155,7 @@ module internal PageRank =
let create =
GraphBLAS.FSharp.Vector.create clContext workGroupSize

fun (queue: MailboxProcessor<Msg>) (matrix: ClMatrix<float32>) accuracy ->

fun (queue: MailboxProcessor<Msg>) (PageRankMatrix matrix) accuracy ->
let vertexCount = matrix.RowCount

//None is 0
Expand Down
33 changes: 33 additions & 0 deletions src/GraphBLAS-sharp.Backend/Objects/Matrix.fs
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,36 @@ type ClMatrix<'a when 'a: struct> =
| ClMatrix.COO matrix -> matrix.NNZ
| ClMatrix.CSC matrix -> matrix.NNZ
| ClMatrix.LIL matrix -> matrix.NNZ

/// <summary>
/// Represents an abstraction over matrix, which is converted to correct format for PageRank algorithm
/// </summary>
type PageRankMatrix<'a when 'a: struct> =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. But it needs to be even stronger. Abstract types are needed here. Like here in the first example.

https://okmij.org/ftp/Computation/lightweight-static-guarantees.html

I was told that this can be done using signatures. The idea is that we should not allow anyone to use this type unless they have passed some kind of verification. It seems to me that this also applies to disjoint matrices, @artemiipatov .

Of course, this can be disabled during benchmarking.

In the same way, we will add another functional and at the same time zero abstraction. This is exactly what is needed on FHPNC

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signatures are not working?

| PageRankMatrix of ClMatrix<'a>
/// <summary>
/// Gets the number of rows in matrix.
/// </summary>
member this.RowCount =
match this with
| PageRankMatrix matrix -> matrix.RowCount

/// <summary>
/// Gets the number of columns in matrix.
/// </summary>
member this.ColumnCount =
match this with
| PageRankMatrix matrix -> matrix.ColumnCount

/// <summary>
/// Release device resources allocated for the matrix.
/// </summary>
member this.Dispose q =
match this with
| PageRankMatrix matrix -> matrix.Dispose q

/// <summary>
/// Gets the number of non-zero elements in matrix.
/// </summary>
member this.NNZ =
match this with
| PageRankMatrix matrix -> matrix.NNZ
3 changes: 2 additions & 1 deletion tests/GraphBLAS-sharp.Tests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ let algorithmsTests =
testList
"Algorithms tests"
[ Algorithms.BFS.tests
Algorithms.SSSP.tests ]
Algorithms.SSSP.tests
Algorithms.PageRank.tests ]
|> testSequenced

let deviceTests =
Expand Down
Loading