public static void Run() { Console.WriteLine("*** Raw data:"); Console.WriteLine("*** "); PrintArray(data); // Console.WriteLine("*** manifest resource:"); // Console.WriteLine("*** "); // var assembly = Assembly.GetExecutingAssembly(); // var resourceName = "OpenCl.Samples.Kernels.bitonicsort.cl"; // var source = (String)null; // using (Stream stream = assembly.GetManifestResourceStream(resourceName)) // using (StreamReader reader = new StreamReader(stream)) // { // source = reader.ReadToEnd(); // } // RunNative(source, true); Console.WriteLine("*** IL translation:"); // Console.WriteLine("*** "); // Console.WriteLine(Compiler.EmitKernel("opencl-samples.exe", "OpenCl.Samples.BitonicSortSample", "BitonicSort")); Console.WriteLine("*** "); RunNative(ClCompiler.EmitKernel("opencl-samples.exe", "OpenCl.Samples.BitonicSortSample", "BitonicSort"), true); Console.WriteLine("*** Cl.RunKernel:"); Console.WriteLine("*** "); RunManaged(true); }
public void TestIfCl() { var a = new int[] { 7, 14, 6, 10 }; var b = new int[] { 5, 10, 6, 14 }; var r = new int[4]; // compile Cl kernel var source = ClCompiler.EmitKernel("opencl-tests", "OpenCl.Tests.TestIf", "test_if"); // test Cl kernel var platform = Platform.GetPlatformIDs().First(); var device = Device.GetDeviceIDs(platform, DeviceType.All).First(); using (var context = Context.CreateContext(platform, device, null, null)) using (var queue = CommandQueue.CreateCommandQueue(context, device)) using (var program = Program.CreateProgramWithSource(context, device, source)) using (var kernel = Kernel.CreateKernel(program, "test_if")) using (var ma = Mem <int> .CreateBuffer(context, MemFlags.ReadOnly | MemFlags.CopyHostPtr, a)) using (var mb = Mem <int> .CreateBuffer(context, MemFlags.ReadOnly | MemFlags.CopyHostPtr, b)) using (var mr = Mem <int> .CreateBuffer(context, MemFlags.ReadWrite, 4 * Marshal.SizeOf <int>())) { kernel.SetKernelArg(0, (HandleObject)ma); kernel.SetKernelArg(1, (HandleObject)mb); kernel.SetKernelArg(2, (HandleObject)mr); queue.EnqueueNDRangeKernel(kernel, null, new int[] { 4 }, null, null); queue.Finish(); queue.EnqueueReadBuffer(mr, true, r); } Assert.AreEqual(2, r[0]); Assert.AreEqual(4, r[1]); Assert.AreEqual(0, r[2]); Assert.AreEqual(4, r[3]); }
public static void Run() { Console.WriteLine("*** IL translation:"); // Console.WriteLine("*** "); // Console.WriteLine(Compiler.EmitKernel("opencl-samples.exe", "OpenCl.Samples.GemmSample", "GemmNN")); Console.WriteLine("*** "); RunNative(ClCompiler.EmitKernel("opencl-samples.exe", "OpenCl.Samples.GemmSample", "GemmNN")); Console.WriteLine("*** Cl.RunKernel:"); Console.WriteLine("*** "); RunManaged(); }
public static void Run() { Console.WriteLine("*** IL translation:"); Console.WriteLine("*** "); RunConvolution(ClCompiler.EmitKernel("opencl-samples.exe", "OpenCl.Samples.ConvolveSample", "Conv")); Console.WriteLine("*** Cl.RunKernel:"); Console.WriteLine("*** "); Cl.RunKernel( new int[] { (int)outputSignalWidth, (int)outputSignalHeight }, new int[] { 1, 1 }, (Action <uint[], uint[], uint[], int, int>)Conv, inputSignal, mask, outputSignal, (int)inputSignalWidth, (int)maskWidth ); PrintOutputSignal(); }
public void TestComponentAccessors1() { int nr = 2; int nw = 2; float[] r = new float[nr]; float2[] w = new float2[nw]; // test managed Array.Clear(r, 0, nr); Array.Clear(w, 0, nw); Cl.RunKernel( new int[] { 1 }, new int[] { 1 }, (Action <float[], float2[]>)test_components1, r, w ); Assert.AreEqual((float)1, r[0]); Assert.AreEqual((float)1, w[0].s0); Assert.AreEqual((float)0, w[0].s1); Assert.AreEqual((float)2, r[1]); Assert.AreEqual((float)1, w[1].s1); Assert.AreEqual((float)0, w[1].s0); // compile kernel var source = ClCompiler.EmitKernel("opencl-tests.dll", "OpenCl.Tests.TestFloat2", "test_components1"); // test native Platform platform = Platform.GetPlatformIDs()[0]; Device[] devices = Device.GetDeviceIDs(platform, DeviceType.Cpu); using (var context = Context.CreateContext(platform, devices, null, null)) using (var queue = CommandQueue.CreateCommandQueue(context, devices[0])) { var program = null as Program; var kernel = null as Kernel; var mr = null as Mem <float>; var mw = null as Mem <float2>; try { program = Program.CreateProgramWithSource(context, new String[] { source }); try { program.BuildProgram(devices, null, null, null); } catch (OpenClException ex) { Console.WriteLine(source); throw ex; } kernel = Kernel.CreateKernel(program, "test_components1"); mr = Mem <float> .CreateBuffer(context, MemFlags.WriteOnly, nr *Marshal.SizeOf <float>()); mw = Mem <float2> .CreateBuffer(context, MemFlags.WriteOnly, nw *Marshal.SizeOf <float2>()); kernel.SetKernelArg(0, (HandleObject)mr); kernel.SetKernelArg(1, (HandleObject)mw); queue.EnqueueNDRangeKernel(kernel, null, new int[] { 1 }, null, null); queue.Finish(); Array.Clear(r, 0, nr); queue.EnqueueReadBuffer(mr, false, r); Array.Clear(w, 0, nw); queue.EnqueueReadBuffer(mw, false, w); queue.Finish(); } finally { if (mr != null) { mr.Dispose(); } if (mw != null) { mw.Dispose(); } if (kernel != null) { kernel.Dispose(); } if (program != null) { program.Dispose(); } } } Assert.AreEqual((float)1, r[0]); Assert.AreEqual((float)1, w[0].s0); Assert.AreEqual((float)0, w[0].s1); Assert.AreEqual((float)2, r[1]); Assert.AreEqual((float)1, w[1].s1); Assert.AreEqual((float)0, w[1].s0); }
public void TestGe() { float2[] a = new float2[] { new float2((float)2, (float)1), new float2((float)0, (float)1) }; float2[] b = new float2[] { new float2((float)0, (float)1), new float2((float)2, (float)1) }; int2[] r = new int2[2]; // test managed Array.Clear(r, 0, 2); Cl.RunKernel( new int[] { 2 }, new int[] { 1 }, (Action <float2[], float2[], int2[]>)test_float2_ge, a, b, r ); Assert.AreEqual(-1, r[0].s0); Assert.AreEqual(-1, r[0].s1); Assert.AreEqual(0, r[1].s0); Assert.AreEqual(-1, r[1].s1); // compile kernel var source = ClCompiler.EmitKernel("opencl-tests.dll", "OpenCl.Tests.TestFloat2", "test_float2_ge"); // test native Platform platform = Platform.GetPlatformIDs()[0]; Device[] devices = Device.GetDeviceIDs(platform, DeviceType.Cpu); using (var context = Context.CreateContext(platform, devices, null, null)) using (var queue = CommandQueue.CreateCommandQueue(context, devices[0])) { var program = null as Program; var kernel = null as Kernel; var ma = null as Mem <float2>; var mb = null as Mem <float2>; var mr = null as Mem <int2>; try { program = Program.CreateProgramWithSource(context, new String[] { source }); try { program.BuildProgram(devices, null, null, null); } catch (OpenClException ex) { Console.WriteLine(source); throw ex; } kernel = Kernel.CreateKernel(program, "test_float2_ge"); ma = Mem <float2> .CreateBuffer(context, MemFlags.ReadOnly | MemFlags.CopyHostPtr, a); mb = Mem <float2> .CreateBuffer(context, MemFlags.ReadOnly | MemFlags.CopyHostPtr, b); mr = Mem <int2> .CreateBuffer(context, MemFlags.WriteOnly, 2 *Marshal.SizeOf <int2>()); kernel.SetKernelArg(0, (HandleObject)ma); kernel.SetKernelArg(1, (HandleObject)mb); kernel.SetKernelArg(2, (HandleObject)mr); queue.EnqueueNDRangeKernel(kernel, null, new int[] { 2 }, null, null); queue.Finish(); Array.Clear(r, 0, 2); queue.EnqueueReadBuffer(mr, true, r); } finally { if (mr != null) { mr.Dispose(); } if (mb != null) { mb.Dispose(); } if (ma != null) { ma.Dispose(); } if (kernel != null) { kernel.Dispose(); } if (program != null) { program.Dispose(); } } } Assert.AreEqual(-1, r[0].s0); Assert.AreEqual(-1, r[0].s1); Assert.AreEqual(0, r[1].s0); Assert.AreEqual(-1, r[1].s1); }