@@ -9,40 +9,21 @@ open Microsoft.FSharp.Reflection
99open Brahma.FSharp .OpenCL .WorkflowBuilder .Evaluation
1010open GraphBLAS.FSharp .Predefined
1111
12- open GraphBLAS.FSharp
12+ open OpenCL.Net
13+ open GraphBLAS.FSharp .Backend .Common
14+ open Brahma.FSharp .OpenCL .Core
1315
1416[<EntryPoint>]
1517let main argv =
1618
17- // let mutable oclContext = OpenCLEvaluationContext(platform_name = "*")
18-
19- // let xs = [|6|]
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-
4119 let workGroupSize = 256
4220 let workSize n =
4321 let m = n - 1
4422 m - m % workGroupSize + workGroupSize
4523
24+ let mutable oclContext = OpenCLEvaluationContext( " Intel*" , DeviceType.Gpu)
25+ // let mutable oclContext = OpenCLEvaluationContext("NVIDIA*")
26+
4627 let leftMatrix = COOMatrix( 100 , 100 , [| 0 ; 1 ; 2 ; 3 ; 4 ; 7 |], [| 1 ; 7 ; 5 ; 6 ; 0 ; 1 |], [| 1. ; 2. ;- 4. ; 4. ; 5. ; 6. |])
4728 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. |])
4829 // let leftMatrix = COOMatrix(100, 100, [||], [||], [||])
@@ -59,8 +40,164 @@ let main argv =
5940 // let resultMatrix : COOMatrix<float> = downcast oclContext.RunSync workflow
6041 // printfn "%O" resultMatrix
6142 let res = oclContext.RunSync workflow
43+
6244 printfn " %A " res.RowIndices
6345 printfn " %A " res.ColumnIndices
6446 printfn " %A " res.Values
6547
48+
49+
50+
51+ // let len = 257
52+ // let xs = Array.create len 1
53+ // let command =
54+ // <@
55+ // fun (ndRange: _1D)
56+ // (xs: int[]) ->
57+
58+ // if ndRange.GlobalID0 < len then
59+ // barrier ()
60+ // xs.[ndRange.GlobalID0] <- 42
61+ // @>
62+ // let wf =
63+ // opencl {
64+ // do! RunCommand command <| fun kernelP ->
65+ // let ndRange = _1D(workSize xs.Length, workGroupSize)
66+ // kernelP
67+ // ndRange
68+ // xs
69+ // return! ToHost xs
70+ // }
71+
72+ // let res = oclContext.RunSync wf
73+ // printfn "%A" res.[len - 1]
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+ // let longSide = 7
84+ // let shortSide = 6
85+ // let sumOfSides = longSide + shortSide
86+ // let merge =
87+ // <@
88+ // fun (ndRange: _1D)
89+ // (firstRowsBuffer: int[])
90+ // (firstColumnsBuffer: int[])
91+ // (firstValuesBuffer: float[])
92+ // (secondRowsBuffer: int[])
93+ // (secondColumnsBuffer: int[])
94+ // (secondValuesBuffer: float[])
95+ // (allRowsBuffer: int[])
96+ // (allColumnsBuffer: int[])
97+ // (allValuesBuffer: float[]) ->
98+
99+ // let i = ndRange.GlobalID0
100+
101+ // if i < sumOfSides then
102+ // let mutable beginIdxLocal = local ()
103+ // let mutable endIdxLocal = local ()
104+ // let localID = ndRange.LocalID0
105+ // if localID < 2 then
106+ // let mutable x = localID * (workGroupSize - 1) + i - 1
107+ // if x >= sumOfSides then x <- sumOfSides - 1
108+ // let diagonalNumber = x
109+
110+ // let mutable leftEdge = diagonalNumber + 1 - shortSide
111+ // if leftEdge < 0 then leftEdge <- 0
112+
113+ // let mutable rightEdge = longSide - 1
114+ // if rightEdge > diagonalNumber then rightEdge <- diagonalNumber
115+
116+ // while leftEdge <= rightEdge do
117+ // let middleIdx = (leftEdge + rightEdge) / 2
118+ // let firstIndex: uint64 = ((uint64 firstRowsBuffer.[middleIdx]) <<< 32) ||| (uint64 firstColumnsBuffer.[middleIdx])
119+ // let secondIndex: uint64 = ((uint64 secondRowsBuffer.[diagonalNumber - middleIdx]) <<< 32) ||| (uint64 secondColumnsBuffer.[diagonalNumber - middleIdx])
120+ // if firstIndex < secondIndex then leftEdge <- middleIdx + 1 else rightEdge <- middleIdx - 1
121+
122+ // // Here localID equals either 0 or 1
123+ // if localID = 0 then beginIdxLocal <- leftEdge else endIdxLocal <- leftEdge
124+ // barrier ()
125+
126+ // let beginIdx = beginIdxLocal
127+ // let endIdx = endIdxLocal
128+ // let firstLocalLength = endIdx - beginIdx
129+ // let mutable x = workGroupSize - firstLocalLength
130+ // if endIdx = longSide then x <- shortSide - i + localID + beginIdx
131+ // let secondLocalLength = x
132+
133+ // //First indices are from 0 to firstLocalLength - 1 inclusive
134+ // //Second indices are from firstLocalLength to firstLocalLength + secondLocalLength - 1 inclusive
135+ // let localIndices = localArray<uint64> workGroupSize
136+
137+ // if localID < firstLocalLength then
138+ // localIndices.[localID] <- ((uint64 firstRowsBuffer.[beginIdx + localID]) <<< 32) ||| (uint64 firstColumnsBuffer.[beginIdx + localID])
139+ // if localID < secondLocalLength then
140+ // localIndices.[firstLocalLength + localID] <- ((uint64 secondRowsBuffer.[i - beginIdx]) <<< 32) ||| (uint64 secondColumnsBuffer.[i - beginIdx])
141+ // barrier ()
142+
143+ // let mutable leftEdge = localID + 1 - secondLocalLength
144+ // if leftEdge < 0 then leftEdge <- 0
145+
146+ // let mutable rightEdge = firstLocalLength - 1
147+ // if rightEdge > localID then rightEdge <- localID
148+
149+ // while leftEdge <= rightEdge do
150+ // let middleIdx = (leftEdge + rightEdge) / 2
151+ // let firstIndex = localIndices.[middleIdx]
152+ // let secondIndex = localIndices.[firstLocalLength + localID - middleIdx]
153+ // if firstIndex < secondIndex then leftEdge <- middleIdx + 1 else rightEdge <- middleIdx - 1
154+
155+ // let boundaryX = rightEdge
156+ // let boundaryY = localID - leftEdge
157+
158+ // // boundaryX and boundaryY can't be off the right edge of array (only off the left edge)
159+ // let isValidX = boundaryX >= 0
160+ // let isValidY = boundaryY >= 0
161+
162+ // let mutable fstIdx = uint64 0
163+ // if isValidX then fstIdx <- localIndices.[boundaryX]
164+
165+ // let mutable sndIdx = uint64 0
166+ // if isValidY then sndIdx <- localIndices.[firstLocalLength + boundaryY]
167+
168+ // if not isValidX || isValidY && fstIdx < sndIdx then
169+ // allRowsBuffer.[i] <- int (sndIdx >>> 32)
170+ // allColumnsBuffer.[i] <- int sndIdx
171+ // allValuesBuffer.[i] <- secondValuesBuffer.[i - localID - beginIdx + boundaryY]
172+ // else
173+ // allRowsBuffer.[i] <- int (fstIdx >>> 32)
174+ // allColumnsBuffer.[i] <- int fstIdx
175+ // allValuesBuffer.[i] <- firstValuesBuffer.[beginIdx + boundaryX]
176+ // @>
177+
178+ // let len = 257
179+ // let command =
180+ // <@
181+ // fun (ndRange: _1D)
182+ // (xs: int[]) ->
183+
184+ // if ndRange.GlobalID0 < len then
185+ // barrier ()
186+ // xs.[ndRange.GlobalID0] <- 42
187+ // @>
188+
189+ // //'_1D -> int[] -> int[] -> float[] -> int[] -> int[] -> float[] -> int[] -> int[] -> float[] -> unit
190+ // let translate2opencl (provider: ComputeProvider) (command: Quotations.Expr<('_1D -> int[] -> unit)>) : string =
191+ // let options = ComputeProvider.DefaultOptions_p
192+ // let tOptions = []
193+ // provider.SetCompileOptions options
194+
195+ // let kernel = System.Activator.CreateInstance<Kernel<'_1D>>()
196+ // CLCodeGenerator.GenerateKernel(command, provider, kernel, tOptions) |> ignore
197+ // let code = (kernel :> ICLKernel).Source.ToString()
198+ // code
199+
200+ // let code = translate2opencl oclContext.Provider command
201+ // printfn "%s" code
202+
66203 0
0 commit comments