Skip to content
Merged
Show file tree
Hide file tree
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 Oct 6, 2022
cfa3920
add: zeroCreate, ofList vector funcs
IgorErin Oct 6, 2022
f7f40c8
separate: Vector opearations
IgorErin Oct 7, 2022
816b4f7
add: DenseVector.mask
IgorErin Oct 8, 2022
e996077
add: toOptionArray
IgorErin Oct 8, 2022
a00be90
add: COOVector.mask
IgorErin Oct 8, 2022
2f48101
refactor: DenseVector.getBitmap
IgorErin Oct 9, 2022
97e5cfd
refactor: Vector zeroCreate, ofList
IgorErin Oct 11, 2022
8b1a234
add: CooVector merge fun
IgorErin Oct 11, 2022
01b4bd2
refactor: CooVector merge fun
IgorErin Oct 11, 2022
7fab131
refactor: COOVector setPositions
IgorErin Oct 12, 2022
f92e158
add: CooVector.setPositions
IgorErin Oct 12, 2022
ddca856
add: CooVector.elementWiseAdd
IgorErin Oct 12, 2022
8ab5d63
add: ClCooVector.fillSubVector
IgorErin Oct 13, 2022
2b2092e
add: ClDenseVector.fillSubVector
IgorErin Oct 13, 2022
e0d47d6
add: DenseVector.fillSubVector
IgorErin Oct 13, 2022
a8bceb8
add: ClDenseVector.complemented
IgorErin Oct 13, 2022
8553bac
add: reduce module
IgorErin Oct 13, 2022
49360e0
add: ClCooVector.reduce
IgorErin Oct 15, 2022
6987dc2
add: Vector generic funcs
IgorErin Oct 15, 2022
b97162d
refactor: Vector
IgorErin Oct 16, 2022
ab59f3c
add: Reduce.run tests
IgorErin Oct 22, 2022
6c2b8f3
add: new TestCases
IgorErin Oct 22, 2022
25b068b
add: Vector.zeroCreate tests
IgorErin Oct 22, 2022
5d1482e
add: Vector.copy tests
IgorErin Oct 23, 2022
cc9f632
fix Reduce
IgorErin Oct 23, 2022
4959176
refactor: Reduce.run, add: Reduce.atomicRun
IgorErin Oct 23, 2022
462295e
add: Vector.ofList tests
IgorErin Oct 24, 2022
50bd2b6
add: Vector.copy tests
IgorErin Oct 24, 2022
0be850c
add: Vector.toCoo tests
IgorErin Oct 24, 2022
17429c0
add: Vector.elementWiseAddAtLeastOne
IgorErin Oct 24, 2022
f33ca22
add: elementWiseAddAtLeatOne with error test
IgorErin Oct 24, 2022
f1c2f04
add: eWiseTests
IgorErin Oct 28, 2022
4fc7466
add: Vector.reduce tests
IgorErin Oct 28, 2022
0217624
add: StandartOperations.mask
IgorErin Oct 29, 2022
7dd6d33
add: all tests pass localy
IgorErin Oct 30, 2022
eabf837
add: build pass localy
IgorErin Oct 30, 2022
3eb9c52
add: dot in index
IgorErin Oct 30, 2022
2e2e036
add: dots index fix
IgorErin Oct 30, 2022
f668dc1
fantomas formatting
IgorErin Oct 30, 2022
ce4a41c
fix: formatting
IgorErin Oct 30, 2022
a867ff0
fix: fantomas formatting
IgorErin Oct 30, 2022
cf235be
fix: fantomas formatting
IgorErin Oct 30, 2022
787fdbd
resolve: merge conflict
IgorErin Oct 31, 2022
126e925
build pass locally
IgorErin Oct 31, 2022
dd64f64
refactor: Utils
IgorErin Oct 31, 2022
5bb71ab
refactor: Bennchmark
IgorErin Oct 31, 2022
a9fdfee
remove: redudant ClArray functions
IgorErin Oct 31, 2022
b250012
refactor: Vector, Helpers
IgorErin Oct 31, 2022
ac31ea1
refactor: COO -> Sparse, Reduce, paths, maskAtLeasOne
IgorErin Nov 5, 2022
33bcb1f
add: getTestFromTestFixuter, refactor: Tests
IgorErin Nov 5, 2022
1f18c2a
refactor: VectorFormat in Vector.Convert test
IgorErin Nov 5, 2022
1cac128
merge: net5 -> vector
IgorErin Nov 5, 2022
1994a81
fix GraphBLAS-sharp.Test proj file
IgorErin Nov 5, 2022
210672d
fix: build
IgorErin Nov 5, 2022
4908361
fix: length in VectorDense.elementwiseAtLeastOne
IgorErin Nov 6, 2022
6c4f541
refactor: use scatter in SparseVector.setPositions
IgorErin Nov 6, 2022
22cc3ca
build: pass locally
IgorErin Nov 6, 2022
286b78f
add: complementedMask operation, DenseVector.elementWise
IgorErin Nov 10, 2022
4281f95
add: PapseVector.toDense, tests
IgorErin Nov 11, 2022
04a09cc
add: Vector.elementWise
IgorErin Nov 11, 2022
f76e8ac
add: DenseVector.elementwise
IgorErin Nov 11, 2022
0ab45fa
refactor: SparseVector.fillSubVector, elementWise
IgorErin Nov 11, 2022
471cfdb
refactor: DenseVector.preparePositions
IgorErin Nov 11, 2022
7b2e627
refactor: types in SparseVector.ElementWiseConstructor
IgorErin Nov 12, 2022
a5a3d8c
add: atLeastOneToNormalForm fun
IgorErin Nov 12, 2022
929e9fe
refactor: Vector.ofList, add: complemented tests, build pass
IgorErin Nov 13, 2022
50f28e7
refactor: paths
IgorErin Nov 13, 2022
d884d1c
merge: YaccConstructor#49 from kirillgarbar/spmv
IgorErin Nov 15, 2022
6a41198
refactor: Vector.fillSubVector, .fillSubVectorComplemented
IgorErin Nov 15, 2022
b64bda8
merge: pull request #50 from IgorErin/duplications
IgorErin Nov 15, 2022
f14ab78
build: pass locally
IgorErin Nov 15, 2022
c611da2
refactor: Helpers, Vector
IgorErin Nov 15, 2022
f118659
rename: mask -> fillSubOp, add: maskOp
IgorErin Nov 18, 2022
a0c25a4
add: complementedMaskOp
IgorErin Nov 18, 2022
251b611
refactor: Reduce.fs
IgorErin Nov 18, 2022
595c187
refactor: StandartOperations
IgorErin Nov 18, 2022
72a6c5a
build: pass locally
IgorErin Nov 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/GraphBLAS-sharp.Backend/Common/CommonQuotes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ module SubSum =

let treeSum<'a> opAdd = sumGeneral<'a> <| treeAccess<'a> opAdd

module SubReduce =
let run opAdd =
<@ fun length wgSize gid lid (localValues: 'a []) ->
let mutable step = 2

while step <= wgSize do
if (gid + wgSize / step) < length
&& lid < wgSize / step then
let firstValue = localValues.[lid]
let secondValue = localValues.[lid + wgSize / step]

localValues.[lid] <- (%opAdd) firstValue secondValue

step <- step <<< 1

barrierLocal () @>

module PreparePositions =
let both<'c> =
<@ fun index (result: 'c option) (rawPositionsBuffer: ClArray<int>) (allValuesBuffer: ClArray<'c>) ->
Expand Down
144 changes: 144 additions & 0 deletions src/GraphBLAS-sharp.Backend/Common/Reduce.fs
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 =
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 this version of scan can be reused. Can these versions of scans be generalized?

<@ 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 =
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.

Yet another version of scan. Can we create, for example, a scan builder helper function?

<@ 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
32 changes: 32 additions & 0 deletions src/GraphBLAS-sharp.Backend/Common/StandardOperations.fs
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
Expand Down Expand Up @@ -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> =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 @>
5 changes: 5 additions & 0 deletions src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<Compile Include="Common/BitonicSort.fs" />
<Compile Include="Common/Scatter.fs" />
<Compile Include="Common/StandardOperations.fs" />
<Compile Include="Common/Reduce.fs" />
<Compile Include="Predefined/PrefixSum.fs" />
<!--Compile Include="Matrices.fs" /-->
<Compile Include="Masks.fs" />
Expand All @@ -32,6 +33,10 @@
<Compile Include="Matrix/CSRMatrix/CSRMatrix.fs" />
<Compile Include="Matrix/CSRMatrix/CSRMatrix.fs" />
<Compile Include="Matrix/Matrix.fs" />
<Compile Include="Vector/SparseVector/SparseElementwise.fs" />
<Compile Include="Vector/SparseVector/SparseVector.fs" />
<Compile Include="Vector/DenseVector/DenseVector.fs" />
<Compile Include="Vector/Vector.fs" />
<Compile Include="Vector/SpMV.fs" />
<!--Compile Include="Backend/CSRMatrix/GetTuples.fs" /-->
<!--Compile Include="Backend/CSRMatrix/SpMSpV.fs" /-->
Expand Down
Loading