Skip to content

Commit e7b41eb

Browse files
committed
Fixed bug with zero matrices, improved addition for matrices (removed tails, optimized algorithm)
1 parent 47b76e8 commit e7b41eb

11 files changed

Lines changed: 663 additions & 600 deletions

File tree

GraphBLAS-sharp.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "GraphBLAS-sharp.Benchmarks"
1717
EndProject
1818
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "docsTool", "docsTool\docsTool.fsproj", "{8855EC73-F6A1-43D3-AFBC-04A3E09F9BD9}"
1919
EndProject
20+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "App", "src\App\App.fsproj", "{595F68BC-ED74-40FB-9F58-0B0A0F55FCD2}"
21+
EndProject
2022
Global
2123
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2224
Debug|Any CPU = Debug|Any CPU
@@ -78,10 +80,23 @@ Global
7880
{4C6EB3D0-B6BF-4FF5-BC77-CC7CB3F307E6}.Release|x64.Build.0 = Release|Any CPU
7981
{4C6EB3D0-B6BF-4FF5-BC77-CC7CB3F307E6}.Release|x86.ActiveCfg = Release|Any CPU
8082
{4C6EB3D0-B6BF-4FF5-BC77-CC7CB3F307E6}.Release|x86.Build.0 = Release|Any CPU
83+
{595F68BC-ED74-40FB-9F58-0B0A0F55FCD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
84+
{595F68BC-ED74-40FB-9F58-0B0A0F55FCD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
85+
{595F68BC-ED74-40FB-9F58-0B0A0F55FCD2}.Debug|x64.ActiveCfg = Debug|Any CPU
86+
{595F68BC-ED74-40FB-9F58-0B0A0F55FCD2}.Debug|x64.Build.0 = Debug|Any CPU
87+
{595F68BC-ED74-40FB-9F58-0B0A0F55FCD2}.Debug|x86.ActiveCfg = Debug|Any CPU
88+
{595F68BC-ED74-40FB-9F58-0B0A0F55FCD2}.Debug|x86.Build.0 = Debug|Any CPU
89+
{595F68BC-ED74-40FB-9F58-0B0A0F55FCD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
90+
{595F68BC-ED74-40FB-9F58-0B0A0F55FCD2}.Release|Any CPU.Build.0 = Release|Any CPU
91+
{595F68BC-ED74-40FB-9F58-0B0A0F55FCD2}.Release|x64.ActiveCfg = Release|Any CPU
92+
{595F68BC-ED74-40FB-9F58-0B0A0F55FCD2}.Release|x64.Build.0 = Release|Any CPU
93+
{595F68BC-ED74-40FB-9F58-0B0A0F55FCD2}.Release|x86.ActiveCfg = Release|Any CPU
94+
{595F68BC-ED74-40FB-9F58-0B0A0F55FCD2}.Release|x86.Build.0 = Release|Any CPU
8195
EndGlobalSection
8296
GlobalSection(NestedProjects) = preSolution
8397
{5D30E174-2538-47AC-8443-318C8C5DC2C9} = {C397A34C-84F1-49E7-AEBC-2F9F2B196216}
8498
{1CA2E092-2320-451D-A4F0-9ED7C7C528CA} = {ACBEE43C-7A88-4FB1-9B06-DB064D22B29F}
8599
{4C6EB3D0-B6BF-4FF5-BC77-CC7CB3F307E6} = {DEF656DE-BCED-4C49-B5ED-950D4A29B78B}
100+
{595F68BC-ED74-40FB-9F58-0B0A0F55FCD2} = {C397A34C-84F1-49E7-AEBC-2F9F2B196216}
86101
EndGlobalSection
87102
EndGlobal

src/App/App.fsproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Include="Program.fs" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\GraphBLAS-sharp\GraphBLAS-sharp.fsproj" />
14+
</ItemGroup>
15+
16+
</Project>

src/App/Program.fs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
open System
2+
3+
open Brahma.OpenCL
4+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
5+
6+
open System
7+
open GraphBLAS.FSharp
8+
open Microsoft.FSharp.Reflection
9+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
10+
open GraphBLAS.FSharp.Predefined
11+
12+
open GraphBLAS.FSharp
13+
14+
[<EntryPoint>]
15+
let main argv =
16+
17+
// let mutable oclContext = OpenCLEvaluationContext()
18+
19+
// let xs = [||]
20+
// let command =
21+
// <@
22+
// fun (ndRange: _1D)
23+
// (xs: int[]) ->
24+
25+
// xs.[ndRange.GlobalID0] <- 42
26+
// @>
27+
// let wf =
28+
// opencl {
29+
// let binder k =
30+
// let ndRange = _1D(xs.Length)
31+
// k ndRange xs
32+
// do! RunCommand command binder
33+
// return! ToHost xs
34+
// }
35+
36+
// let res = oclContext.RunSync wf
37+
// printfn "%A" res
38+
39+
let mutable oclContext = OpenCLEvaluationContext()
40+
41+
let workGroupSize = 256
42+
let workSize n =
43+
let m = n - 1
44+
m - m % workGroupSize + workGroupSize
45+
46+
//let leftMatrix = COOMatrix(100, 100, [|0;1;2;3;4;7|], [|1;7;5;6;0;1|], [|1.;2.;-4.;4.;5.;6.|])
47+
//let rightMatrix = COOMatrix(100, 100, [|0;0;1;2;3;4;7|], [|1;5;4;5;7;0;1|], [|1.;2.;-4.;4.;5.;6.;7.|])
48+
let leftMatrix = COOMatrix(100, 100, [||], [||], [||])
49+
let rightMatrix = COOMatrix(100, 100, [||], [||], [||])
50+
51+
let workflow =
52+
opencl {
53+
let! resultMatrix = leftMatrix.EWiseAdd rightMatrix None FloatSemiring.addMult
54+
let! tuples = resultMatrix.GetTuples()
55+
return! tuples.ToHost()
56+
//return! resultMatrix.ToHost()
57+
}
58+
59+
// let resultMatrix : COOMatrix<float> = downcast oclContext.RunSync workflow
60+
// printfn "%O" resultMatrix
61+
let res = oclContext.RunSync workflow
62+
printfn "%A" res.RowIndices
63+
printfn "%A" res.ColumnIndices
64+
printfn "%A" res.Values
65+
66+
0

src/GraphBLAS-sharp/Abstracts.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ type MatrixTuples<'a when 'a : struct and 'a : equality> = {
1010
}
1111
with
1212
member this.ToHost() = opencl {
13-
let! rows = ToHost this.RowIndices
14-
let! cols = ToHost this.ColumnIndices
15-
let! vals = ToHost this.Values
13+
let! rows = if this.RowIndices.Length = 0 then opencl { return [||] } else ToHost this.RowIndices
14+
let! cols = if this.ColumnIndices.Length = 0 then opencl { return [||] } else ToHost this.ColumnIndices
15+
let! vals = if this.Values.Length = 0 then opencl { return [||] } else ToHost this.Values
1616

1717
return {
1818
RowIndices = rows
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace GraphBLAS.FSharp.Backend.Common
2+
3+
open Brahma.OpenCL
4+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
5+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
6+
open Utils
7+
8+
module internal Copy =
9+
let runNotEmpty (inputArray: 'a[]) =
10+
let outputArray = Array.zeroCreate inputArray.Length
11+
let inputArrayLength = inputArray.Length
12+
let copy =
13+
<@
14+
fun (ndRange: _1D)
15+
(inputArrayBuffer: 'a[])
16+
(outputArrayBuffer: 'a[]) ->
17+
18+
let i = ndRange.GlobalID0
19+
if i < inputArrayLength then
20+
outputArrayBuffer.[i] <- inputArrayBuffer.[i]
21+
@>
22+
let binder kernelP =
23+
let ndRange = _1D(workSize inputArray.Length, workGroupSize)
24+
kernelP ndRange inputArray outputArray
25+
opencl {
26+
do! RunCommand copy binder
27+
return outputArray
28+
}
29+
30+
let run (inputArray: 'a[]) = if inputArray.Length = 0 then opencl { return [||] } else runNotEmpty inputArray

0 commit comments

Comments
 (0)