0
내 문제는Cudafy C# GPU 계산에서 값을 반환하는 방법은 무엇입니까?
이봐, 내가 (내 시스템을위한 벤치 마크로 사용으로) 0에서 100도 사이의 죄의 합을 찾으려면이 간단한 계산을 만들고있어, 계산은 아니다
코드
public const int N = 33 * 1024;
public const int threadsPerBlock = 256;
public const int blocksPerGrid = 32;
public static void Main()
{
Stopwatch watch = new Stopwatch();
watch.Start();
string Text = "";
int iterations = 1000000;
CudafyModule km = CudafyTranslator.Cudafy();
GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
gpu.LoadModule(km);
double[] dev_Value = gpu.Allocate<double>();
gpu.Launch(blocksPerGrid, threadsPerBlock).SumOfSines(iterations,dev_Value);
double Value;
gpu.CopyFromDevice(dev_Value, out Value);
watch.Stop();
Text = watch.Elapsed.TotalSeconds.ToString();
Console.WriteLine("The process took a total of: " + Text + " Seconds");
Console.WriteLine(Value);
Console.Read();
gpu.FreeAll();
}
[Cudafy]
public static void SumOfSines(GThread thread,int iterations,double [] Value)
{
double total = new double();
double degAsRad = Math.PI/180.0;
for (int i = 0; i < iterations; i++)
{
total = 0.0;
for (int z = 1; z < 101; z++)
{
double angle = (double)z * degAsRad;
total += Math.Sin(angle);
}
}
Value[0] = total;
}
: 문제는 내 문제는 내가 Cudafy에 새로운 오전과 내가 제대로에서 통과하고 여기에 떨어져 인쇄 할 수 있도록 값을 반환 할 수 있겠군요임을 것은 내 코드입니다 내가하려고하는 가치 CUDAfy 부분의 xtract는 합계이며 벤치마킹 시간을 인쇄하여 인쇄합니다. 누구든지 조언을 게시 할 수 있다면 매우 감사 할 것입니다. (쓸모없는 줄이나 불충분 한 부분을 없애기위한 제안도 좋습니다).
을 그리고 그것은'dev_Value [0]'에 있지? – Andrew