Skip to content

Commit 286b78f

Browse files
committed
add: complementedMask operation, DenseVector.elementWise
1 parent 22cc3ca commit 286b78f

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,10 @@ module StandardOperations =
107107
match value with
108108
| Left left -> Some left
109109
| _ -> Some res @>
110+
111+
let complementedMask<'a, 'b when 'a: struct and 'b: struct> res =
112+
<@ fun (left: 'a option) (right: 'b option) ->
113+
match left, right with
114+
| Some left, Some _-> Some left
115+
| None, Some _ -> None
116+
| _ -> Some res @>

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,46 @@ open GraphBLAS.FSharp.Backend.Common
66
open Microsoft.FSharp.Quotations
77

88
module DenseVector =
9+
let elementWise<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct>
10+
(clContext: ClContext)
11+
(opAdd: Expr<'a option -> 'b option -> 'c option>)
12+
(workGroupSize: int)
13+
=
14+
15+
let eWiseAdd =
16+
<@ fun (ndRange: Range1D) resultLength (leftVector: ClArray<'a option>) (rightVector: ClArray<'b option>) (resultVector: ClArray<'c option>) ->
17+
18+
let gid = ndRange.GlobalID0
19+
20+
if gid < resultLength then
21+
resultVector.[gid] <- (%opAdd) leftVector.[gid] rightVector.[gid] @>
22+
23+
let kernel = clContext.Compile(eWiseAdd)
24+
25+
fun (processor: MailboxProcessor<_>) (leftVector: ClArray<'a option>) (rightVector: ClArray<'b option>) ->
26+
27+
let resultVector =
28+
clContext.CreateClArray(
29+
leftVector.Length,
30+
hostAccessMode = HostAccessMode.NotAccessible,
31+
deviceAccessMode = DeviceAccessMode.ReadWrite,
32+
allocationMode = AllocationMode.Default
33+
)
34+
35+
let ndRange =
36+
Range1D.CreateValid(leftVector.Length, workGroupSize)
37+
38+
let kernel = kernel.GetKernel()
39+
40+
processor.Post(
41+
Msg.MsgSetArguments
42+
(fun () -> kernel.KernelFunc ndRange leftVector.Length leftVector rightVector resultVector)
43+
)
44+
45+
processor.Post(Msg.CreateRunMsg<_, _>(kernel))
46+
47+
resultVector
48+
949
let elementWiseAtLeastOne<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct>
1050
(clContext: ClContext)
1151
(opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>)

0 commit comments

Comments
 (0)