コード例 #1
0
        public void DeviceMismatchException()
        {
            ReadWriteBuffer <int> buffer = Gpu.Default.AllocateReadWriteBuffer <int>(1);

            GraphicsDevice device = Gpu.EnumerateDevices().First();

            Action <ThreadIds> action = id => buffer[0] = 1;

            Assert.ThrowsException <GraphicsDeviceMismatchException>(() => device.For(1, action));
        }
コード例 #2
0
        public void DeviceMismatchException()
        {
            ReadWriteBuffer <int> buffer = Gpu.Default.AllocateReadWriteBuffer <int>(1);

            GraphicsDevice device = Gpu.EnumerateDevices().First();

            var shader = new DeviceMismatchException_Shader {
                B = buffer
            };

            device.For(1, shader);
        }
コード例 #3
0
        public void RunShaderOnAllDevices()
        {
            foreach (GraphicsDevice gpu in Gpu.EnumerateDevices())
            {
                using (ReadWriteBuffer <float> buffer = gpu.AllocateReadWriteBuffer <float>(100))
                {
                    Action <ThreadIds> action = id => buffer[id.X] = id.X;

                    gpu.For(100, action);

                    float[] array    = buffer.GetData();
                    float[] expected = Enumerable.Range(0, 100).Select(i => (float)i).ToArray();

                    Assert.IsTrue(array.AsSpan().ContentEquals(expected));
                }

                gpu.Dispose();
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: JohnMasen/VirusSimulator
        public void Run(string[] args)
        {
            if (args.Length >= 1)
            {
                int.TryParse(args[0], out items);
            }
            if (args.Length >= 2 && int.TryParse(args[1], out int loopDuationInSeconds))
            {
                loopDuration = TimeSpan.FromSeconds(loopDuationInSeconds);
            }

            if (args.Length >= 3)
            {
                bool.TryParse(args[2], out copyBack);
            }
            try
            {
                Console.WriteLine($"Test with {items} items, duration ={loopDuration},copy back ={copyBack}");
                Console.Write("Testing with CPU ");
                Console.WriteLine($"{runCpuTest(items, loopDuration)}");
                foreach (var item in Gpu.EnumerateDevices())
                {
                    Console.Write($"Testing with ComputeSharp [{item.Name}] ");
                    Console.WriteLine($"{runComputeSharpTest(items, loopDuration, item, copyBack)}");
                }
                using (Context c = new Context())
                {
                    c.EnableAlgorithms();
                    foreach (var item in Accelerator.Accelerators)
                    {
                        using (var acc = Accelerator.Create(c, item))
                        {
                            Console.Write($"Testing with ILGPU [{acc.Name}-{item.AcceleratorType}] ");
                            Console.WriteLine($"{runILGPUTest(items, loopDuration, acc, copyBack)}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }