Repository navigation
Expand file tree
/
Copy pathfld_gpu.cs
More file actions
58 lines (51 loc) · 1.65 KB
/
Copy pathfld_gpu.cs
File metadata and controls
58 lines (51 loc) · 1.65 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
using UnityEngine;
using System.Collections;
using System;
using System.IO;
using System.Linq;
public class fld_gpu : MonoBehaviour
{
public ComputeShader computeshader;
void Start ()
{
StreamReader file1 = new StreamReader ("C:\\acer.txt");
StreamReader file2 = new StreamReader ("C:\\quercus.txt");
float[,] Acer = new float[176, 64];
float[,] Quercus = new float[608,64] ;
float[] Fisher = new float[64];
for (int n = 0; n < 176; n++) //read file data
{
for (int nn = 0; nn <64; nn++)
{
Acer [n, nn] = Convert.ToSingle (file1.ReadLine());
}
}
for (int n = 0; n < 608; n++) //read file data
{
for (int nn = 0; nn < 64; nn++)
{
Quercus [n, nn] = Convert.ToSingle (file2.ReadLine ());
}
}
file1.Close (); //close file
file2.Close ();
float poczatek = Time.realtimeSinceStartup;
ComputeBuffer acer = new ComputeBuffer (176 * 64, sizeof(float));
ComputeBuffer quercus = new ComputeBuffer (608 * 64, sizeof(float));
ComputeBuffer fisher = new ComputeBuffer (64, sizeof(float));
computeshader.SetBuffer (0, "acer", acer);
computeshader.SetBuffer (0, "quercus", quercus);
computeshader.SetBuffer (0, "fisher", fisher);
acer.SetData (Acer);
quercus.SetData (Quercus);
computeshader.Dispatch (0, 1, 1, 1); //run smpd_gpu.compute
fisher.GetData (Fisher);
acer.Release ();
quercus.Release ();
fisher.Release();
float koniec = Time.realtimeSinceStartup - poczatek;
Debug.Log ("FS winner: "+Array.IndexOf (Fisher, Fisher.Max ()));
Debug.Log ("FLD value: "+Fisher.Max ());
Debug.Log ("Wykonanie skryptu trwało: "+String.Format( "{0:0.000000}",koniec)+" sekund.");
}
}