mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-07 16:10:44 +00:00
Merged VectorAdd fixes from trunk.
This commit is contained in:
commit
e790b327ee
|
@ -17,7 +17,7 @@ namespace Examples
|
||||||
{
|
{
|
||||||
public static void Main()
|
public static void Main()
|
||||||
{
|
{
|
||||||
const int cnBlockSize = 512;
|
const int cnBlockSize = 4;
|
||||||
const int cnBlocks = 3;
|
const int cnBlocks = 3;
|
||||||
IntPtr cnDimension = new IntPtr(cnBlocks * cnBlockSize);
|
IntPtr cnDimension = new IntPtr(cnBlocks * cnBlockSize);
|
||||||
string sProgramSource = @"
|
string sProgramSource = @"
|
||||||
|
@ -66,8 +66,12 @@ vectorAdd(__global const float * a,
|
||||||
float[] B = new float[cnDimension.ToInt32()];
|
float[] B = new float[cnDimension.ToInt32()];
|
||||||
float[] C = new float[cnDimension.ToInt32()];
|
float[] C = new float[cnDimension.ToInt32()];
|
||||||
// initialize host memory
|
// initialize host memory
|
||||||
// randomInit(pA, cnDimension);
|
Random rand = new Random();
|
||||||
//randomInit(pB, cnDimension);
|
for (int i = 0; i < A.Length; i++)
|
||||||
|
{
|
||||||
|
A[i] = rand.Next() % 256;
|
||||||
|
B[i] = rand.Next() % 256;
|
||||||
|
}
|
||||||
|
|
||||||
// allocate device memory
|
// allocate device memory
|
||||||
unsafe
|
unsafe
|
||||||
|
@ -107,11 +111,19 @@ vectorAdd(__global const float * a,
|
||||||
new IntPtr(pB), 0, null, (IntPtr[])null);
|
new IntPtr(pB), 0, null, (IntPtr[])null);
|
||||||
|
|
||||||
// execute kernel
|
// execute kernel
|
||||||
CL.EnqueueNDRangeKernel(hCmdQueue, hKernel, 1, null, &cnDimension, null, 0, null, null);
|
error = (ErrorCode)CL.EnqueueNDRangeKernel(hCmdQueue, hKernel, 1, null, &cnDimension, null, 0, null, null);
|
||||||
|
if (error != ErrorCode.Success)
|
||||||
|
throw new Exception(error.ToString());
|
||||||
|
|
||||||
// copy results from device back to host
|
// copy results from device back to host
|
||||||
CL.EnqueueReadBuffer(hCmdQueue, hDeviceMemC, true, IntPtr.Zero,
|
IntPtr event_handle = IntPtr.Zero;
|
||||||
|
error = (ErrorCode)CL.EnqueueReadBuffer(hCmdQueue, hDeviceMemC, true, IntPtr.Zero,
|
||||||
new IntPtr(cnDimension.ToInt32() * sizeof(float)),
|
new IntPtr(cnDimension.ToInt32() * sizeof(float)),
|
||||||
new IntPtr(pC), 0, null, (IntPtr[])null);
|
new IntPtr(pC), 0, null, (IntPtr[])null);
|
||||||
|
if (error != ErrorCode.Success)
|
||||||
|
throw new Exception(error.ToString());
|
||||||
|
|
||||||
|
CL.Finish(hCmdQueue);
|
||||||
|
|
||||||
CL.ReleaseMemObject(hDeviceMemA);
|
CL.ReleaseMemObject(hDeviceMemA);
|
||||||
CL.ReleaseMemObject(hDeviceMemB);
|
CL.ReleaseMemObject(hDeviceMemB);
|
||||||
|
|
Loading…
Reference in a new issue