private void CheckErr(Cl.ErrorCode err, string name) { if (err != Cl.ErrorCode.Success) { Console.WriteLine("ERROR: " + name + " (" + err.ToString() + ")"); MessageBox.Show("ERROR: " + name + " (" + err.ToString() + ")"); } }
public static void CheckErr(CL.ErrorCode err, string name) { //Console.WriteLine($"{name}..."); if (err != CL.ErrorCode.Success) { Console.WriteLine("ERROR: " + name + " (" + err.ToString() + ")"); } }
public override Brahma.CommandQueue Finish() { ClNet.ErrorCode error = Cl.Finish(_queue); if (error != ClNet.ErrorCode.Success) { throw new Cl.Exception(error); } return(this); }
/* private void Setup() { OpenCL.Net.ErrorCode error; var platforms = Cl.GetPlatformIDs(out error); List<Device> devicesList = new List<Device>(); CheckErr(error, "Cl.GetPlatformIDs"); foreach (Platform platform in platforms) { string platformName = Cl.GetPlatformInfo(platform, PlatformInfo.Name, out error).ToString(); Console.WriteLine("Platform: " + platformName); CheckErr(error, "Cl.GetPlatformInfo"); //We will be looking only for GPU devices foreach (Device device in Cl.GetDeviceIDs(platform, DeviceType.Gpu, out error)) { CheckErr(error, "Cl.GetDeviceIDs"); var vendor = Cl.GetDeviceInfo(device, DeviceInfo.Vendor, out error); var name = Cl.GetDeviceInfo(device, DeviceInfo.Name, out error); var worksize = Cl.GetDeviceInfo(device, DeviceInfo.LocalMemSize, out error); Console.WriteLine("Vendor: " + vendor + " , " + name); Console.WriteLine("Device: " + device.GetType()); Console.WriteLine("localMemsizr: " + worksize.CastTo<long>()); devicesList.Add(device); } } if (devicesList.Count <= 0) { Console.WriteLine("No devices found."); return; } _device = devicesList[0]; if (Cl.GetDeviceInfo(_device, DeviceInfo.ImageSupport, out error).CastTo<Bool>() == Bool.False) { Console.WriteLine("No image support."); return; } cxGPUContext = Cl.CreateContext(null, 1, new[] {_device}, ContextNotify, IntPtr.Zero, out error); //Second parameter is amount of devices CheckErr(error, "Cl.CreateContext"); cqCommandQueue = Cl.CreateCommandQueue(cxGPUContext, _device, (CommandQueueProperties) 0, out error); CheckErr(error, "Cl.CreateCommandQueue"); } */ private void CheckErr(ErrorCode err, string name) { if (err != ErrorCode.Success) { Console.WriteLine("error: " + name + " (" + err.ToString() + ")"); Console.WriteLine("error: " + name + " (" + err + ")"); using (StreamWriter sw = File.AppendText(@"D:\Projects\gpu\GPGPUCollisionDetection\GPGPUCollisionDetection\OpenCLDebugLog.txt")) { sw.WriteLine("error: " + name + " (" + err + ")"); } } }
static void Main(string[] args) { initOpenCL(); // Simple sortTest List <int> numOfSortValues = new List <int>(); for (int i = 0; i < 2; i++) { numOfSortValues.Add(20); } foreach (var numElements in numOfSortValues) { uint[] testKeys = new uint[numElements]; ulong[] testValues = new ulong[numElements]; uint[] testKeysOutput = new uint[numElements]; // ulong[] testValuesOutput = new ulong[numElements]; Random rnd = new Random(); Console.WriteLine("\n New Sort test with {0} random values", numElements); Console.WriteLine("Init:"); for (uint i = 0; i < numElements; i++) { uint tmp = (uint)rnd.Next(10000); testKeys[i] = tmp; testValues[i] = tmp; // Console.WriteLine("Key: {0} value: {1}", testKeys[i], testValues[i]); } var before = DateTime.Now; // create buffers Console.WriteLine("Start creating Buffers for {0} values", numElements); // Create Buffers IMem cl_KeyMem = Cl.CreateBuffer (cxGPUContext, MemFlags.ReadWrite, (IntPtr)(testKeys.Length * 4), testKeys, out error); CheckErr(error, "Createbuffer"); IMem cl_ValueMem = Cl.CreateBuffer (cxGPUContext, MemFlags.ReadWrite, (IntPtr)(testKeys.Length * 8), testValues, out error); CheckErr(error, "Createbuffer"); IMem cl_KeyOutput = Cl.CreateBuffer (cxGPUContext, MemFlags.ReadWrite, (IntPtr)(testKeys.Length * 4), testKeys, out error); CheckErr(error, "Createbuffer"); IMem cl_ValueOutput; Event eve; error = Cl.EnqueueWriteBuffer (cqCommandQueue, cl_KeyMem, Bool.True, IntPtr.Zero, (IntPtr)(testKeys.Length * 4), testKeys, 0, null, out eve); CheckErr(error, "EnqBuffer"); error = Cl.EnqueueWriteBuffer (cqCommandQueue, cl_ValueMem, Bool.True, IntPtr.Zero, (IntPtr)(testKeys.Length * 8), testValues, 0, null, out eve); CheckErr(error, "EnqBuffer"); error = Cl.Finish(cqCommandQueue); CheckErr(error, "Cl.Finish"); Console.WriteLine ("finished creating Buffers for {0} values after {1} ms -> Started sorting", numElements, (DateTime.Now - before).TotalMilliseconds); // sort.sortKeysValue(cl_KeyMem, cl_ValueMem, testKeys.Length); sort.sortKeysOnly(cl_KeyMem, cl_KeyOutput, testKeys.Length); Console.WriteLine("finished sort for {0} values after {1} ms", numElements, (DateTime.Now - before).TotalMilliseconds); error = Cl.EnqueueReadBuffer (cqCommandQueue, cl_KeyMem, Bool.True, IntPtr.Zero, (IntPtr)(testKeys.Length * 4), testKeysOutput, 0, null, out eve); CheckErr(error, "Cl.EnqueueReadBuffer"); Console.WriteLine("Total sort time {0} ms", (DateTime.Now - before).TotalMilliseconds); // error = Cl.EnqueueReadBuffer(cqCommandQueue, cl_ValueMem, Bool.True, IntPtr.Zero, (IntPtr)(testKeys.Length * 8), // testValuesOutput, 0, null, out eve); // CheckErr(error, "Cl.EnqueueReadBuffer"); Array.Sort(testKeys); Console.WriteLine("Sort finished"); for (uint i = 0; i < testKeys.Length; i++) { if (testKeysOutput[i] != testKeys[i]) { Console.WriteLine("radixoutput{0} = {1} false", testKeysOutput[i], testKeys[i]); } else { Console.WriteLine("radixoutput{0} = {1} true", testKeysOutput[i], testKeys[i]); } ; // Assert.True(testValuesOutput[i] == (uint)testKeys[i], "values not sorted"); } // Assert.False(testKeys == testValues, "did not work"); Cl.ReleaseMemObject(cl_KeyMem); Cl.ReleaseMemObject(cl_ValueMem); Console.WriteLine("Run with {0} random numbers finished without errors", numElements); Cl.ReleaseMemObject(cl_KeyOutput); // Cl.ReleaseMemObject(cl_ValueOutput); } }