-
Notifications
You must be signed in to change notification settings - Fork 6
Vector #48
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
Merged
Merged
Vector #48
Changes from all commits
Commits
Show all changes
78 commits
Select commit
Hold shift + click to select a range
e74ed9e
add: Vector, refactor: Utils
IgorErin cfa3920
add: zeroCreate, ofList vector funcs
IgorErin f7f40c8
separate: Vector opearations
IgorErin 816b4f7
add: DenseVector.mask
IgorErin e996077
add: toOptionArray
IgorErin a00be90
add: COOVector.mask
IgorErin 2f48101
refactor: DenseVector.getBitmap
IgorErin 97e5cfd
refactor: Vector zeroCreate, ofList
IgorErin 8b1a234
add: CooVector merge fun
IgorErin 01b4bd2
refactor: CooVector merge fun
IgorErin 7fab131
refactor: COOVector setPositions
IgorErin f92e158
add: CooVector.setPositions
IgorErin ddca856
add: CooVector.elementWiseAdd
IgorErin 8ab5d63
add: ClCooVector.fillSubVector
IgorErin 2b2092e
add: ClDenseVector.fillSubVector
IgorErin e0d47d6
add: DenseVector.fillSubVector
IgorErin a8bceb8
add: ClDenseVector.complemented
IgorErin 8553bac
add: reduce module
IgorErin 49360e0
add: ClCooVector.reduce
IgorErin 6987dc2
add: Vector generic funcs
IgorErin b97162d
refactor: Vector
IgorErin ab59f3c
add: Reduce.run tests
IgorErin 6c2b8f3
add: new TestCases
IgorErin 25b068b
add: Vector.zeroCreate tests
IgorErin 5d1482e
add: Vector.copy tests
IgorErin cc9f632
fix Reduce
IgorErin 4959176
refactor: Reduce.run, add: Reduce.atomicRun
IgorErin 462295e
add: Vector.ofList tests
IgorErin 50bd2b6
add: Vector.copy tests
IgorErin 0be850c
add: Vector.toCoo tests
IgorErin 17429c0
add: Vector.elementWiseAddAtLeastOne
IgorErin f33ca22
add: elementWiseAddAtLeatOne with error test
IgorErin f1c2f04
add: eWiseTests
IgorErin 4fc7466
add: Vector.reduce tests
IgorErin 0217624
add: StandartOperations.mask
IgorErin 7dd6d33
add: all tests pass localy
IgorErin eabf837
add: build pass localy
IgorErin 3eb9c52
add: dot in index
IgorErin 2e2e036
add: dots index fix
IgorErin f668dc1
fantomas formatting
IgorErin ce4a41c
fix: formatting
IgorErin a867ff0
fix: fantomas formatting
IgorErin cf235be
fix: fantomas formatting
IgorErin 787fdbd
resolve: merge conflict
IgorErin 126e925
build pass locally
IgorErin dd64f64
refactor: Utils
IgorErin 5bb71ab
refactor: Bennchmark
IgorErin a9fdfee
remove: redudant ClArray functions
IgorErin b250012
refactor: Vector, Helpers
IgorErin ac31ea1
refactor: COO -> Sparse, Reduce, paths, maskAtLeasOne
IgorErin 33bcb1f
add: getTestFromTestFixuter, refactor: Tests
IgorErin 1f18c2a
refactor: VectorFormat in Vector.Convert test
IgorErin 1cac128
merge: net5 -> vector
IgorErin 1994a81
fix GraphBLAS-sharp.Test proj file
IgorErin 210672d
fix: build
IgorErin 4908361
fix: length in VectorDense.elementwiseAtLeastOne
IgorErin 6c4f541
refactor: use scatter in SparseVector.setPositions
IgorErin 22cc3ca
build: pass locally
IgorErin 286b78f
add: complementedMask operation, DenseVector.elementWise
IgorErin 4281f95
add: PapseVector.toDense, tests
IgorErin 04a09cc
add: Vector.elementWise
IgorErin f76e8ac
add: DenseVector.elementwise
IgorErin 0ab45fa
refactor: SparseVector.fillSubVector, elementWise
IgorErin 471cfdb
refactor: DenseVector.preparePositions
IgorErin 7b2e627
refactor: types in SparseVector.ElementWiseConstructor
IgorErin a5a3d8c
add: atLeastOneToNormalForm fun
IgorErin 929e9fe
refactor: Vector.ofList, add: complemented tests, build pass
IgorErin 50f28e7
refactor: paths
IgorErin d884d1c
merge: YaccConstructor#49 from kirillgarbar/spmv
IgorErin 6a41198
refactor: Vector.fillSubVector, .fillSubVectorComplemented
IgorErin b64bda8
merge: pull request #50 from IgorErin/duplications
IgorErin f14ab78
build: pass locally
IgorErin c611da2
refactor: Helpers, Vector
IgorErin f118659
rename: mask -> fillSubOp, add: maskOp
IgorErin a0c25a4
add: complementedMaskOp
IgorErin 251b611
refactor: Reduce.fs
IgorErin 595c187
refactor: StandartOperations
IgorErin 72a6c5a
build: pass locally
IgorErin 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 hidden or 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
This file contains hidden or 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,144 @@ | ||
| namespace GraphBLAS.FSharp.Backend.Common | ||
|
|
||
| open Brahma.FSharp | ||
| open GraphBLAS.FSharp.Backend | ||
| open Microsoft.FSharp.Control | ||
| open Microsoft.FSharp.Quotations | ||
|
|
||
| module Reduce = | ||
| let private scan<'a when 'a: struct> (clContext: ClContext) (workGroupSize: int) (opAdd: Expr<'a -> 'a -> 'a>) = | ||
|
|
||
| let scan = | ||
| <@ fun (ndRange: Range1D) length (inputArray: ClArray<'a>) (resultArray: ClArray<'a>) -> | ||
|
|
||
| let gid = ndRange.GlobalID0 | ||
| let lid = ndRange.LocalID0 | ||
|
|
||
| let localValues = localArray<'a> workGroupSize | ||
|
|
||
| if gid < length then | ||
| localValues.[lid] <- inputArray.[gid] | ||
|
|
||
| barrierLocal () | ||
|
|
||
| if gid < length then | ||
|
|
||
| (%SubReduce.run opAdd) length workGroupSize gid lid localValues | ||
|
|
||
| if lid = 0 then | ||
| resultArray.[gid / workGroupSize] <- localValues.[0] @> | ||
|
|
||
| let kernel = clContext.Compile(scan) | ||
|
|
||
| fun (processor: MailboxProcessor<_>) (valuesArray: ClArray<'a>) valuesLength (resultArray: ClArray<'a>) -> | ||
|
|
||
| let ndRange = | ||
| Range1D.CreateValid(valuesArray.Length, workGroupSize) | ||
|
|
||
| let kernel = kernel.GetKernel() | ||
|
|
||
| processor.Post( | ||
| Msg.MsgSetArguments(fun () -> kernel.KernelFunc ndRange valuesLength valuesArray resultArray) | ||
| ) | ||
|
|
||
| processor.Post(Msg.CreateRunMsg<_, _>(kernel)) | ||
|
|
||
| let private scanToCell<'a when 'a: struct> | ||
| (clContext: ClContext) | ||
| (workGroupSize: int) | ||
| (opAdd: Expr<'a -> 'a -> 'a>) | ||
| = | ||
|
|
||
| let scan = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yet another version of |
||
| <@ fun (ndRange: Range1D) length (inputArray: ClArray<'a>) (resultValue: ClCell<'a>) -> | ||
|
|
||
| let gid = ndRange.GlobalID0 | ||
| let lid = ndRange.LocalID0 | ||
|
|
||
| let localValues = localArray<'a> workGroupSize | ||
|
|
||
| if gid < length then | ||
| localValues.[lid] <- inputArray.[gid] | ||
|
|
||
| barrierLocal () | ||
|
|
||
| if gid < length then | ||
|
|
||
| (%SubReduce.run opAdd) length workGroupSize gid lid localValues | ||
|
|
||
| if lid = 0 then | ||
| resultValue.Value <- localValues.[0] @> | ||
|
|
||
| let kernel = clContext.Compile(scan) | ||
|
|
||
| fun (processor: MailboxProcessor<_>) (valuesArray: ClArray<'a>) valuesLength (resultValue: ClCell<'a>) -> | ||
|
|
||
| let ndRange = | ||
| Range1D.CreateValid(valuesArray.Length, workGroupSize) | ||
|
|
||
| let kernel = kernel.GetKernel() | ||
|
|
||
| processor.Post( | ||
| Msg.MsgSetArguments(fun () -> kernel.KernelFunc ndRange valuesLength valuesArray resultValue) | ||
| ) | ||
|
|
||
| processor.Post(Msg.CreateRunMsg<_, _>(kernel)) | ||
|
|
||
| let run<'a when 'a: struct> (clContext: ClContext) (workGroupSize: int) (opAdd: Expr<'a -> 'a -> 'a>) = | ||
|
|
||
| let scan = scan clContext workGroupSize opAdd | ||
|
|
||
| let scanToCell = scanToCell clContext workGroupSize opAdd | ||
|
|
||
| fun (processor: MailboxProcessor<_>) (inputArray: ClArray<'a>) -> | ||
|
|
||
| let scan = scan processor | ||
|
|
||
| let firstLength = | ||
| (inputArray.Length - 1) / workGroupSize + 1 | ||
|
|
||
| let firstVerticesArray = | ||
| clContext.CreateClArray( | ||
| firstLength, | ||
| hostAccessMode = HostAccessMode.NotAccessible, | ||
| deviceAccessMode = DeviceAccessMode.ReadWrite, | ||
| allocationMode = AllocationMode.Default | ||
| ) | ||
|
|
||
| let secondLength = (firstLength - 1) / workGroupSize + 1 | ||
|
|
||
| let secondVerticesArray = | ||
| clContext.CreateClArray( | ||
| secondLength, | ||
| hostAccessMode = HostAccessMode.NotAccessible, | ||
| deviceAccessMode = DeviceAccessMode.ReadWrite, | ||
| allocationMode = AllocationMode.Default | ||
| ) | ||
|
|
||
| let mutable verticesArrays = firstVerticesArray, secondVerticesArray | ||
| let swap (a, b) = (b, a) | ||
|
|
||
| scan inputArray inputArray.Length (fst verticesArrays) | ||
|
|
||
| let mutable verticesLength = firstLength | ||
|
|
||
| while verticesLength > workGroupSize do | ||
| let fstVertices = fst verticesArrays | ||
| let sndVertices = snd verticesArrays | ||
|
|
||
| scan fstVertices verticesLength sndVertices | ||
|
|
||
| verticesArrays <- swap verticesArrays | ||
| verticesLength <- (verticesLength - 1) / workGroupSize + 1 | ||
|
|
||
| let fstVertices = fst verticesArrays | ||
|
|
||
| let result = | ||
| clContext.CreateClCell Unchecked.defaultof<'a> | ||
|
|
||
| scanToCell processor fstVertices verticesLength result | ||
|
|
||
| processor.Post(Msg.CreateFreeMsg(firstVerticesArray)) | ||
| processor.Post(Msg.CreateFreeMsg(secondVerticesArray)) | ||
|
|
||
| result | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| namespace GraphBLAS.FSharp.Backend.Common | ||
|
|
||
| open FSharp.Quotations | ||
|
|
||
| type AtLeastOne<'a, 'b when 'a: struct and 'b: struct> = | ||
| | Both of 'a * 'b | ||
| | Left of 'a | ||
|
|
@@ -109,3 +111,33 @@ module StandardOperations = | |
| | None, Some right -> (%op) (Right right) | ||
| | Some left, None -> (%op) (Left left) | ||
| | None, None -> None @> | ||
|
|
||
| let fillSubToOption (op: Expr<'a option -> 'a option -> 'a option>) = | ||
| <@ fun (leftItem: 'a option) (rightItem: 'b option) (value: 'a) -> | ||
| match rightItem with | ||
| | Some _ -> (%op) leftItem (Some value) | ||
| | None -> (%op) leftItem None @> | ||
|
|
||
| let fillSubComplementedToOption (op: Expr<'a option -> 'a option -> 'a option>) = | ||
| <@ fun (leftItem: 'a option) (rightItem: 'b option) (value: 'a) -> | ||
| match rightItem with | ||
| | Some _ -> (%op) leftItem None | ||
| | None -> (%op) leftItem (Some value) @> | ||
|
|
||
| let fillSubOp<'a when 'a: struct> = | ||
| <@ fun (left: 'a option) (right: 'a option) -> | ||
| match left, right with | ||
| | _, None -> left | ||
| | _ -> right @> | ||
|
|
||
| let maskOp<'a, 'b when 'a: struct and 'b: struct> = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Complemented mask operation can also be added |
||
| <@ fun (left: 'a option) (right: 'b option) -> | ||
| match right with | ||
| | Some _ -> left | ||
| | _ -> None @> | ||
|
|
||
| let complementedMaskOp<'a, 'b when 'a: struct and 'b: struct> = | ||
| <@ fun (left: 'a option) (right: 'b option) -> | ||
| match right with | ||
| | None -> left | ||
| | _ -> None @> | ||
This file contains hidden or 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.
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.
Can this version of
scancan be reused. Can these versions of scans be generalized?