Elementwise#46
Conversation
| let CSReWiseAdd = | ||
| CSRMatrix.eWiseAdd clContext opAdd workGroupSize | ||
| let CSRElementwise = | ||
| Elementwise.elementwise clContext opAdd workGroupSize |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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> = |
There was a problem hiding this comment.
What the differrence from ClArray? Can we unify these types? Or make DenceVector (or clDenceVector) an extension of ClArray?
| Backend.EwiseAdd.tests | ||
| Backend.EwiseAdd.tests2 | ||
| //Backend.EwiseAdd.tests3 | ||
| Backend.Elementwise.tests |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
It seems to be always true
| + secondLocalOffset | ||
| + i | ||
|
|
||
| if resY = 1 || resX = 0 then |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Why Utils.defaultWorkGroupSize but not workGroupSize ?
There was a problem hiding this comment.
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] @> |
There was a problem hiding this comment.
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
|
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 |
|
@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 |
There was a problem hiding this comment.
It does not respect the invariant that the type must be 'a option.
There was a problem hiding this comment.
@dpanfilyonok Why must? In my opinion in may be Option<'t>, but may be not.
There was a problem hiding this comment.
If not, we won't be able to determine if the value is 0 or not.
There was a problem hiding this comment.
@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
There was a problem hiding this comment.
But its not specified for ClDenseVector itself. Therefore, problems can arise if we want to use a dense vector by itself.
There was a problem hiding this comment.
@dpanfilyonok What is Cl DenseVector? I cannot find declaration of this type.
| | COO | ||
| | Dense | ||
|
|
||
| type COOVector<'a> = |
There was a problem hiding this comment.
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> = |
There was a problem hiding this comment.
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<_>) = |
There was a problem hiding this comment.
Does this already exist in ArraysExtentions?
| open Microsoft.FSharp.Quotations | ||
|
|
||
| module internal Elementwise = | ||
| let expandCompressedRowPointers (clContext: ClContext) workGroupSize = |
There was a problem hiding this comment.
Is this used? If not, it probably should be removed
|
|
||
| resultRows, resultColumns, resultValues, positions, resultLength | ||
|
|
||
| let getCompressedRowPointers (clContext: ClContext) workGroupSize = |
There was a problem hiding this comment.
As far as I know this is also not used
| type 'a ``[]`` with | ||
| member this.Size = this.Length | ||
|
|
||
| member this.ToString() = |
There was a problem hiding this comment.
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) = |
There was a problem hiding this comment.
Looks also oddish for me. It's not obvious that this function is related to dense vector
Proposed Changes
EWiseAddrenamed toelementwiseelementwisefor CSRTypes of changes
What types of changes does your code introduce to GraphBLAS-sharp?
Put an
xin the boxes that applyChecklist
Put an
xin 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.