1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
|
let TriMat (mat: array<float>) rows columns =
let localWorkSize0 = 2
let localWorkSize1 = 2
let mutable size = rows
let platformName = "NVIDIA*"
let deviceType = DeviceType.Default
if rows <> columns
then failwith "Can not compute triangle matrix"
for i in 0 .. rows - 1 do
if mat.[i * rows + i] = 0.0
then failwith "Can not compute triangle matrix"
let provider =
try ComputeProvider.Create(platformName, deviceType)
with
| ex -> failwith ex.Message
let commandQueue = new CommandQueue(provider, provider.Devices |> Seq.head)
let command =
<@
fun (rng:_2D) (a: array<_>) ->
for y in 0 .. size - 2 do
for x in y + 1 .. size - 1 do
let k = a.[x * size + y] / a.[y * size + y]
for i in 0 .. size - 1 do
a.[x * size + i] <- a.[x * size + i] - a.[y * size + i] * k
@>
let a = mat
let kernel, kernelPrepare, kernelRun = provider.Compile command
let d =(new _2D(rows, columns, localWorkSize0, localWorkSize1))
kernelPrepare d a
let _ = commandQueue.Add(kernelRun())
let _ = commandQueue.Add(a.ToHost provider).Finish()
commandQueue.Dispose()
provider.Dispose()
provider.CloseAllBuffers()
a
|