Skip to content

Elementwise#46

Merged
gsvgit merged 42 commits intoSparseLinearAlgebra:net5from
kirillgarbar:elementwise
Oct 31, 2022
Merged

Elementwise#46
gsvgit merged 42 commits intoSparseLinearAlgebra:net5from
kirillgarbar:elementwise

Conversation

@kirillgarbar
Copy link
Copy Markdown
Contributor

Proposed Changes

  • EWiseAdd renamed to elementwise
  • New elementwise for CSR
  • Vector types for GPU

Types of changes

What types of changes does your code introduce to GraphBLAS-sharp?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • Build and tests pass locally
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)

let CSReWiseAdd =
CSRMatrix.eWiseAdd clContext opAdd workGroupSize
let CSRElementwise =
Elementwise.elementwise clContext opAdd workGroupSize
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why for COO name is COOMatrix.elementwise, but for CSR Elementwise.elemenwise, not CSRMatrix.elementwise?

let CSReWiseAdd =
CSRMatrix.eWiseAddAtLeastOne clContext opAdd workGroupSize
let CSRElementwise =
Elementwise.elementwiseAtLeastOne clContext opAdd workGroupSize
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why for COO name is COOMatrix.elementwiseAtLeastOne, but for CSR Elementwise.elementwiseAtLeastOne, not CSRMatrix.elementwiseAtLeastOne?


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

type DenseVector<'a> =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What the differrence from ClArray? Can we unify these types? Or make DenceVector (or clDenceVector) an extension of ClArray?

Comment thread tests/GraphBLAS-sharp.Tests/Program.fs Outdated
Backend.EwiseAdd.tests
Backend.EwiseAdd.tests2
//Backend.EwiseAdd.tests3
Backend.Elementwise.tests
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you propose more user-friendly names than tests, tests2, tests3. What the difference betwee these tests?


let row = globalID / workGroupSize

if row < rows then
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It seems to be always true

+ secondLocalOffset
+ i

if resY = 1 || resX = 0 then
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Code duplication can be eliminated by reducing this with one conditional expression

//Init with zeroes
if i < numberOfRows then
rowPointers.[i] <- 0
elif i = numberOfRows then
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's not necessary to handle this case separately because prefix sum is exclusive

let merge = merge clContext workGroupSize

let preparePositions =
preparePositions clContext opAdd Utils.defaultWorkGroupSize
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why Utils.defaultWorkGroupSize but not workGroupSize ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

All steps of the elementwise except merge are working with the best performance for a relatively large workGroupSize regardless of the characteristics of the matrices. On the other hand, the choice of the best workGroupSize for merge may depend on matrices and it makes sense to vary it. It is possible to add a second parameter for workGroupSize, but since its choice is not so important, it was decided to apply the standard size.

let index = prefixSumArray.[i]

resultColumns.[index] <- allColumns.[i]
resultValues.[index] <- allValues.[i] @>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You could fill resultRows here as well and get result matrix in COO without further conversion. If it's not convenient to get result in COO, I think current conversion from COO to CSR is more optimal since it launches only one prefix sum algorithm

@kirillgarbar
Copy link
Copy Markdown
Contributor Author

I think ClDenseVector should not inherit ClArray due to the fact that it is impossible to create ClDenseVector from ClArray because of ClArray's private constructor

@gsvgit
Copy link
Copy Markdown
Member

gsvgit commented Oct 17, 2022

@kirillgarbar Strange reason. May it be etter to modify ClArray? Or maybe ClDenseVector should aggregate ClArray. Anyway, I guess these two structures should be unified.


module ArraysExtensions =

type ClArray<'a> with
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It does not respect the invariant that the type must be 'a option.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dpanfilyonok Why must? In my opinion in may be Option<'t>, but may be not.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If not, we won't be able to determine if the value is 0 or not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dpanfilyonok But it is required only for ClVector, not for ClArray. But for ClVector it is specified that value is Option<'t>: https://github.com/YaccConstructor/GraphBLAS-sharp/pull/46/files#diff-fd9366b267db07ee1f0db1c7d4a56f1d2c91fee0be1da169aa171166eb294f87R131

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

But its not specified for ClDenseVector itself. Therefore, problems can arise if we want to use a dense vector by itself.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dpanfilyonok What is Cl DenseVector? I cannot find declaration of this type.

| COO
| Dense

type COOVector<'a> =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I thought COO is for matrix format, and vector should better be something like SparseVector. But COO may probably be convenient for vector as well, I'm not sure


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

type TuplesVector<'a> =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we need this type? It looks exactly like COOVector

>> fun x -> x ||| (x >>> 16)
>> fun x -> x + 1

let toHost (processor: MailboxProcessor<_>) (src: ClArray<_>) =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this already exist in ArraysExtentions?

open Microsoft.FSharp.Quotations

module internal Elementwise =
let expandCompressedRowPointers (clContext: ClContext) workGroupSize =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this used? If not, it probably should be removed


resultRows, resultColumns, resultValues, positions, resultLength

let getCompressedRowPointers (clContext: ClContext) workGroupSize =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As far as I know this is also not used

type 'a ``[]`` with
member this.Size = this.Length

member this.ToString() =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks oddish for me. We may have an array that we don't treat as a dense vector


member this.ToDevice(context: ClContext) = context.CreateClArray this

let FromArray (array: 'a [], isZero: 'a -> bool) =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks also oddish for me. It's not obvious that this function is related to dense vector

@gsvgit gsvgit merged commit 835e7bf into SparseLinearAlgebra:net5 Oct 31, 2022
@kirillgarbar kirillgarbar deleted the elementwise branch March 24, 2024 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants