Skip to content

Commit 929e9fe

Browse files
committed
refactor: Vector.ofList, add: complemented tests, build pass
1 parent a5a3d8c commit 929e9fe

13 files changed

Lines changed: 400 additions & 439 deletions

File tree

src/GraphBLAS-sharp.Backend/Common/StandardOperations.fs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,21 @@ module StandardOperations =
117117
let complementedMask<'a, 'b when 'a: struct and 'b: struct> =
118118
<@ fun (left: 'a option) (right: 'b option) value ->
119119
match left, right with
120-
| _, Some _-> left
120+
| _, Some _ -> left
121121
| _ -> Some value @>
122+
123+
let atLeastOneToNormalForm op =
124+
<@ fun (leftItem: 'a option) (rightItem: 'b option) ->
125+
match leftItem, rightItem with
126+
| Some left, Some right -> (%op) (Both(left, right))
127+
| None, Some right -> (%op) (Right right)
128+
| Some left, None -> (%op) (Left left)
129+
| None, None -> None @>
130+
131+
let fillSubVectorAtLeastOneToNormalForm op =
132+
<@ fun (leftItem: 'a option) (rightItem: 'b option) (value: 'a) ->
133+
match leftItem, rightItem with
134+
| Some left, Some right -> (%op) (Both(left, right)) value
135+
| None, Some right -> (%op) (Right right) value
136+
| Some left, None -> (%op) (Left left) value
137+
| None, None -> None @>

src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@
3333
<Compile Include="Matrix/CSRMatrix/CSRMatrix.fs" />
3434
<Compile Include="Matrix/CSRMatrix/SpMV.fs" />
3535
<Compile Include="Matrix/Matrix.fs" />
36-
<Compile Include="Vector\SparseVector\ElementwiseConstructor.fs" />
36+
<Compile Include="Vector\SparseVector\SparseElementwise.fs" />
3737
<Compile Include="Vector/SparseVector/SparseVector.fs" />
38-
<Compile Include="Vector\DenseVector\ElementwiseConstructor.fs" />
3938
<Compile Include="Vector/DenseVector/DenseVector.fs" />
4039
<Compile Include="Vector/Vector.fs" />
4140
<!--Compile Include="Backend/CSRMatrix/GetTuples.fs" /-->

src/GraphBLAS-sharp.Backend/Vector/DenseVector/DenseVector.fs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ module DenseVector =
1212
(workGroupSize: int)
1313
=
1414

15-
let kernel = clContext.Compile(ElementwiseConstructor.kernel opAdd)
15+
let elementWise =
16+
<@ fun (ndRange: Range1D) resultLength (leftVector: ClArray<'a option>) (rightVector: ClArray<'b option>) (resultVector: ClArray<'c option>) ->
1617

17-
fun (processor: MailboxProcessor<_>) (leftVector: ClArray<'a option>) (rightVector: ClArray<'b option>) ->
18+
let gid = ndRange.GlobalID0
19+
20+
if gid < resultLength then
21+
resultVector.[gid] <- (%opAdd) leftVector.[gid] rightVector.[gid] @>
1822

23+
let kernel = clContext.Compile(elementWise)
24+
25+
fun (processor: MailboxProcessor<_>) (leftVector: ClArray<'a option>) (rightVector: ClArray<'b option>) ->
1926
let resultVector =
2027
clContext.CreateClArray(
2128
leftVector.Length,
@@ -39,18 +46,27 @@ module DenseVector =
3946
resultVector
4047

4148
let elementWiseAtLeastOne clContext op workGroupSize =
42-
elementWise clContext (ElementwiseConstructor.atLeastOneToNormalForm op) workGroupSize
49+
elementWise clContext (StandardOperations.atLeastOneToNormalForm op) workGroupSize
4350

4451
let fillSubVector<'a, 'b when 'a: struct and 'b: struct>
4552
(clContext: ClContext)
4653
(maskOp: Expr<'a option -> 'b option -> 'a -> 'a option>)
47-
(workGroupSize: int) =
54+
(workGroupSize: int)
55+
=
56+
57+
let fillSubVectorKernel =
58+
<@ fun (ndRange: Range1D) resultLength (leftVector: ClArray<'a option>) (maskVector: ClArray<'b option>) (value: ClCell<'a>) (resultVector: ClArray<'a option>) ->
59+
60+
let gid = ndRange.GlobalID0
61+
62+
if gid < resultLength then
63+
resultVector.[gid] <- (%maskOp) leftVector.[gid] maskVector.[gid] value.Value @>
4864

49-
let kernel = clContext.Compile(ElementwiseConstructor.fillSubVectorKernel maskOp)
65+
let kernel = clContext.Compile(fillSubVectorKernel)
5066

5167
fun (processor: MailboxProcessor<_>) (leftVector: ClArray<'a option>) (maskVector: ClArray<'b option>) (value: ClCell<'a>) ->
52-
let resultArray =
53-
clContext.CreateClArray(
68+
let resultVector =
69+
clContext.CreateClArray<'a option>(
5470
leftVector.Length,
5571
hostAccessMode = HostAccessMode.NotAccessible,
5672
deviceAccessMode = DeviceAccessMode.ReadWrite,
@@ -63,14 +79,16 @@ module DenseVector =
6379
let kernel = kernel.GetKernel()
6480

6581
processor.Post(
66-
Msg.MsgSetArguments(fun () ->
67-
kernel.KernelFunc ndRange leftVector.Length leftVector maskVector value resultArray)
82+
Msg.MsgSetArguments
83+
(fun () -> kernel.KernelFunc ndRange leftVector.Length leftVector maskVector value resultVector)
6884
)
6985

70-
resultArray
86+
processor.Post(Msg.CreateRunMsg<_, _>(kernel))
87+
88+
resultVector
7189

7290
let fillSubVectorAtLeasOne clContext opAdd workGroupSize =
73-
fillSubVector clContext (ElementwiseConstructor.fillSubVectorAtLeastOneToNormalForm opAdd) workGroupSize
91+
fillSubVector clContext (StandardOperations.fillSubVectorAtLeastOneToNormalForm opAdd) workGroupSize
7492

7593
let private getBitmap<'a when 'a: struct> (clContext: ClContext) (workGroupSize: int) =
7694

@@ -87,7 +105,6 @@ module DenseVector =
87105
let kernel = clContext.Compile(getPositions)
88106

89107
fun (processor: MailboxProcessor<_>) (vector: ClArray<'a option>) ->
90-
91108
let positions =
92109
clContext.CreateClArray(
93110
vector.Length,

src/GraphBLAS-sharp.Backend/Vector/DenseVector/ElementwiseConstructor.fs

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)