示例#1
0
        public static void Main()
        {
            Console.WriteLine("CUDAfy Example\nCollecting necessary resources...");

            CudafyModes.Target        = eGPUType.Cuda; // To use OpenCL, change this enum
            CudafyModes.DeviceId      = 0;
            CudafyTranslator.Language = CudafyModes.Target == eGPUType.OpenCL ? eLanguage.OpenCL : eLanguage.Cuda;

            //Check for available devices
            if (CudafyHost.GetDeviceCount(CudafyModes.Target) == 0)
            {
                throw new System.ArgumentException("No suitable devices found.", "original");
            }

            //Init device
            var gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);

            Console.WriteLine("Running example using {0}", gpu.GetDeviceProperties(false).Name);

            //Load module for GPU
            var km = CudafyTranslator.Cudafy();

            gpu.LoadModule(km);

            //Define local arrays
            var a = new int[N];
            var b = new int[N];
            var c = new int[N];

            // allocate the memory on the GPU
            var dev_c = gpu.Allocate <int>(c);

            // fill the arrays 'a' and 'b' on the CPU
            for (var i = 0; i < N; i++)
            {
                a[i] = i;
                b[i] = i * i;
            }

            // copy the arrays 'a' and 'b' to the GPU
            var dev_a = gpu.CopyToDevice(a);
            var dev_b = gpu.CopyToDevice(b);

            gpu.Launch(1, N).add(dev_a, dev_b, dev_c);

            // copy the array 'c' back from the GPU to the CPU
            gpu.CopyFromDevice(dev_c, c);

            // display the results
            for (var i = 0; i < N; i++)
            {
                Console.WriteLine("{0} + {1} = {2}", a[i], b[i], c[i]);
            }

            // free the memory allocated on the GPU
            gpu.FreeAll();

            Console.WriteLine("Done!");
            Console.ReadKey();
        }
示例#2
0
        public static bool TestGpuDoublePrecision(int DeviceId)
        {
            if (DeviceId > CudafyHost.GetDeviceCount(eGPUType.OpenCL))
            {
                return(false);
            }

            try
            {
                CudafyModes.Target        = eGPUType.OpenCL;
                CudafyTranslator.Language = eLanguage.OpenCL;
                CudafyModule km  = CudafyTranslator.Cudafy();
                GPGPU        gpu = CudafyHost.GetDevice(eGPUType.OpenCL, DeviceId);
                gpu.LoadModule(km);

                double   c;
                double[] dev_c = gpu.Allocate <double>();
                gpu.Launch().add_double(2.5d, 7.5d, dev_c);
                gpu.CopyFromDevice(dev_c, out c);
                gpu.Free(dev_c);
                return(c == 10.0d);
            }
            catch
            { return(false); }
        }
        private void PrintOutAviableDevices()
        {
            Console.WriteLine("Printing out avaiable devices...");
            Console.WriteLine("For now this code will work only with Cuda devs...");

            var numberOfCudaDevices     = CudafyHost.GetDeviceCount(eGPUType.Cuda);
            var numberOfOpenClDevices   = CudafyHost.GetDeviceCount(eGPUType.OpenCL);
            var numberOfEmulatorDevices = CudafyHost.GetDeviceCount(eGPUType.Emulator);

            Console.WriteLine("{0} devices of type Cuda found", numberOfCudaDevices);
            Console.WriteLine("{0} devices of type OpenCl found", numberOfOpenClDevices);
            Console.WriteLine("{0} devices of type Emulator found", numberOfEmulatorDevices);

            Console.WriteLine("Attempting to print out detailed info about Cuda devices..");
            var cudaDevicesProperties = CudafyHost.GetDeviceProperties(eGPUType.Cuda);

            if (cudaDevicesProperties.Count() != numberOfCudaDevices)
            {
                Console.WriteLine("Something is terribly off! Number of cuda devices differ from received properites");
            }

            foreach (var cudaDeviceProperties in cudaDevicesProperties)
            {
                Console.WriteLine(@"---");
                PrintOutObjectPublicProperties(cudaDeviceProperties);
                Console.WriteLine(@"---");
            }

            Console.WriteLine("Attempting to print out detailed info about openCl devices..");
            var openClDevicesProperties = CudafyHost.GetDeviceProperties(eGPUType.OpenCL);

            if (openClDevicesProperties.Count() != numberOfOpenClDevices)
            {
                Console.WriteLine("Something is terribly off! Number of openCl devices differ from received properites");
            }

            foreach (var openClDeviceProperties in openClDevicesProperties)
            {
                Console.WriteLine(@"---");
                PrintOutObjectPublicProperties(openClDeviceProperties);
                Console.WriteLine(@"---");
            }

            Console.WriteLine("Attempting to print out detailed info about emulator devices..");
            var emulatorDevicesProperties = CudafyHost.GetDeviceProperties(eGPUType.Emulator);

            if (emulatorDevicesProperties.Count() != numberOfEmulatorDevices)
            {
                Console.WriteLine("Something is terribly off! Number of emulator devices differ from received properites");
            }

            foreach (var emulatorDeviceProperties in emulatorDevicesProperties)
            {
                Console.WriteLine(@"---");
                PrintOutObjectPublicProperties(emulatorDeviceProperties);
                Console.WriteLine(@"---");
            }
        }
示例#4
0
        public void Test_GetEmulatedDeviceCount()
        {
            if (CudafyModes.Target != eGPUType.Emulator)
            {
                Console.WriteLine("Only tests Emulator devices, so skip.");
                return;
            }
            int cnt = CudafyHost.GetDeviceCount(eGPUType.Emulator);

            Console.WriteLine("Emulated device count = {0}", cnt);
            Assert.True(cnt > 0);
        }
示例#5
0
        public void Test_GetCudaDeviceCount()
        {
            if (CudafyModes.Target != eGPUType.Cuda)
            {
                Console.WriteLine("Only tests CUDA devices, so skip.");
                return;
            }
            int cnt = CudafyHost.GetDeviceCount(eGPUType.Cuda);

            Console.WriteLine("Cuda device count = {0}", cnt);
            Assert.True(cnt > 0);
        }
示例#6
0
        static void Main(string[] args)
        {
            try
            {
                CudafyModes.DeviceId     = 0;
                CudafyModes.Architecture = CudafyHost.GetDevice(eGPUType.Cuda, CudafyModes.DeviceId).GetArchitecture();  //eArchitecture.sm_35; // *** Change this to the architecture of your target board ***
                CudafyModes.Target       = CompilerHelper.GetGPUType(CudafyModes.Architecture);

                if (CudafyModes.Target != eGPUType.OpenCL)
                {
                    CURANDTests.Basics();
                }

                StringTests st = new StringTests();
                CudafyUnitTest.PerformAllTests(st);

                BasicFunctionTests bft = new BasicFunctionTests();
                CudafyUnitTest.PerformAllTests(bft);

                GMathUnitTests gmu = new GMathUnitTests();
                CudafyUnitTest.PerformAllTests(gmu);

                MultithreadedTests mtt = new MultithreadedTests();
                CudafyUnitTest.PerformAllTests(mtt);

                CopyTests1D ct1d = new CopyTests1D();
                CudafyUnitTest.PerformAllTests(ct1d);

                GPGPUTests gput = new GPGPUTests();
                CudafyUnitTest.PerformAllTests(gput);

                if (CudafyHost.GetDeviceCount(CudafyModes.Target) > 1)
                {
                    MultiGPUTests mgt = new MultiGPUTests();
                    CudafyUnitTest.PerformAllTests(mgt);
                }

                if (CudafyModes.Architecture == eArchitecture.sm_35)
                {
                    Compute35Features c35f = new Compute35Features();
                    CudafyUnitTest.PerformAllTests(c35f);
                }

                Console.WriteLine("Done");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
            }
        }
示例#7
0
        public void Test_CreateOpenCLDevice()
        {
            if (CudafyModes.Target != eGPUType.OpenCL)
            {
                Console.WriteLine("Only tests OpenCL devices, so skip.");
                return;
            }
            int cnt = CudafyHost.GetDeviceCount(eGPUType.OpenCL);

            if (cnt > 0)
            {
                GPGPU gpu = CudafyHost.GetDevice(eGPUType.OpenCL, 0);
                Assert.IsTrue(gpu is OpenCLDevice);
                gpu = null;
            }
        }
示例#8
0
        public void Test_CreateCudaGPU()
        {
            if (CudafyModes.Target != eGPUType.Cuda)
            {
                Console.WriteLine("Only tests CUDA devices, so skip.");
                return;
            }
            int cnt = CudafyHost.GetDeviceCount(eGPUType.Cuda);

            if (cnt > 0)
            {
                GPGPU gpu = CudafyHost.GetDevice(eGPUType.Cuda, 0);
                Assert.IsTrue(gpu is CudaGPU);
                gpu = null;
            }
        }
示例#9
0
        public void Test_GetEmulatedDeviceProps()
        {
            if (CudafyModes.Target != eGPUType.Emulator)
            {
                Console.WriteLine("Only tests Emulator devices, so skip.");
                return;
            }
            List <GPGPUProperties> props = CudafyHost.GetDeviceProperties(eGPUType.Emulator, false).ToList();
            int cnt = CudafyHost.GetDeviceCount(eGPUType.Emulator);

            Assert.AreEqual(cnt, props.Count);
            Assert.AreEqual(0, props[0].DeviceId);
            Assert.AreEqual(true, props[0].IsSimulated);
            Assert.AreEqual(false, props[0].Integrated);
            Assert.AreEqual(false, props[0].UseAdvanced);
            Assert.IsTrue(props[0].MultiProcessorCount == 0);
        }
示例#10
0
        public void Test_GetCudaDeviceProps()
        {
            if (CudafyModes.Target != eGPUType.Cuda)
            {
                Console.WriteLine("Only testing CUDA devices, so skip.");
                return;
            }
            List <GPGPUProperties> props = CudafyHost.GetDeviceProperties(eGPUType.Cuda, false).ToList();
            int cnt = CudafyHost.GetDeviceCount(eGPUType.Cuda);

            Assert.AreEqual(cnt, props.Count);
            Assert.AreEqual(0, props[0].DeviceId);
            Assert.AreEqual(false, props[0].IsSimulated);
            Assert.AreEqual(false, props[0].Integrated);
            Assert.AreEqual(false, props[0].UseAdvanced);
            Assert.IsTrue(props[0].MultiProcessorCount == 0);
            Assert.GreaterOrEqual(props[0].AsynchEngineCount, 1);
        }
示例#11
0
        static void Main(string[] args)
        {
            String komen;

            CudafyModes.Target        = eGPUType.OpenCL;
            CudafyModes.DeviceId      = 0;
            CudafyTranslator.Language = CudafyModes.Target == eGPUType.OpenCL ? eLanguage.OpenCL : eLanguage.Cuda;
            try
            {
                int deviceCount = CudafyHost.GetDeviceCount(CudafyModes.Target);
                if (deviceCount == 0)
                {
                    Console.WriteLine("Tidak ada device ditemukan {0}", CudafyModes.Target);
                }
                else
                {
                    Console.WriteLine("--------------Program Processing VGA ------------");
                    Console.WriteLine("-------------- C h r o n o M E Dev ------------");
                    GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
                    Console.WriteLine("Radeon RX 570/580 Series");
                    Console.WriteLine("Code name: " + gpu.GetDeviceProperties(false).Name);
                    Console.WriteLine("Memori VGA: " + gpu.GetDeviceProperties(false).TotalMemory);
                    Console.WriteLine("Jumlah Pipeline " + gpu.GetDeviceProperties(false).MultiProcessorCount);

                    do
                    {
                        gpu_calculation.primaGPU();
                        //gpu_calculation.eksekusi();
                        //cpu_tes.eksekusi();
                        cpu_tes.prima();
                        Console.WriteLine("Done!");

                        Console.Write("Press q to quit > ");
                        komen = Console.ReadLine().ToString();
                    } while (komen != "q");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
示例#12
0
        public static bool InitGPU(PictureBox passedViewport)
        {
            viewport = passedViewport;

            CudafyModes.Target        = eGPUType.OpenCL; // To use OpenCL, change this enum
            CudafyModes.DeviceId      = 0;
            CudafyTranslator.Language = CudafyModes.Target == eGPUType.OpenCL ? eLanguage.OpenCL : eLanguage.Cuda;

            CudafyModule km = null;

            try
            {
                int deviceCount = CudafyHost.GetDeviceCount(CudafyModes.Target);
                if (deviceCount == 0)
                {
                    Console.WriteLine("No suitable {0} devices found.", CudafyModes.Target);
                    return(false);
                }

                gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
                Console.WriteLine("Device Name: {0}", gpu.GetDeviceProperties(false).Name);

                var result = gpu.GetDeviceProperties(true); // diagnostic data

                km = CudafyTranslator.Cudafy();
                gpu.LoadModule(km);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.WriteLine(km.SourceCode);
                Debugger.Break();
                return(false);
            }

            InitDevicePointers();

            return(true);
        }
        public int Init()
        {
            this.m_km = CudafyTranslator.Cudafy();

            CudafyModes.Target = eGPUType.Cuda;
            var tgCount = CudafyHost.GetDeviceCount(CudafyModes.Target);


            if (tgCount <= 0)
            {
                CudafyModes.Target = eGPUType.OpenCL;
                tgCount            = CudafyHost.GetDeviceCount(CudafyModes.Target);
            }

            if (tgCount <= 0)
            {
                CudafyModes.Target = eGPUType.Emulator;
                tgCount            = CudafyHost.GetDeviceCount(CudafyModes.Target);
            }


            if (tgCount <= 0)
            {
                throw new CtkCudafyCannotUseException("無法使用Cudafy");
            }

            for (int idx = 0; idx < tgCount; idx++)
            {
                try
                {
                    this.m_gpu = CudafyHost.GetDevice(CudafyModes.Target, idx);
                    this.m_gpu.LoadModule(Km);
                    return(0);
                }
                catch (Cudafy.CudafyCompileException) { }
            }

            throw new Exception("Cudafy buidling fail.");
        }
示例#14
0
        static void Main(string[] args)
        {
            // CudafyModes.Target = eGPUType.Cuda; // Jak chcesz obliczac na CUDA
            CudafyModes.Target = eGPUType.OpenCL; // Jak chcesz obliczac na OpenCL

            CudafyModes.DeviceId      = 0;
            CudafyTranslator.Language = CudafyModes.Target == eGPUType.OpenCL ? eLanguage.OpenCL : eLanguage.Cuda;
            try
            {
                int deviceCount = CudafyHost.GetDeviceCount(CudafyModes.Target);
                if (deviceCount == 0)
                {
                    Console.WriteLine("No suitable {0} devices found.", CudafyModes.Target);
                    throw new Exception("No suitable devices found.");
                }
                GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
                Console.WriteLine("Running examples using {0}", gpu.GetDeviceProperties(false).Name);
                int waitTime;
                if (Int32.TryParse(args[0], out waitTime))
                {
                    SQL.Execute(waitTime);    // glowna funkcja
                }
                else
                {
                    Console.WriteLine("Nie podano liczby całkowitej, program zostanie wyłączony...");
                }
                //SQL.Test();         // testowa funkcja
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.WriteLine("Done!");
            Console.ReadKey();
        }
        private void InitializeGPUs()
        {
            eGPUType[]  gpuTypes  = new eGPUType[] { eGPUType.Cuda, eGPUType.OpenCL, eGPUType.Emulator };
            eLanguage[] languages = new eLanguage[] { eLanguage.Cuda, eLanguage.OpenCL };

            foreach (eGPUType gpuType in gpuTypes)
            {
                try
                {
                    int numberOfAvailableDevices = CudafyHost.GetDeviceCount(gpuType);

                    for (int deviceNumber = 0; deviceNumber < numberOfAvailableDevices; deviceNumber++)
                    {
                        GPGPU           gpgpu           = CudafyHost.GetDevice(gpuType, deviceNumber);
                        GPGPUProperties gpgpuProperties = gpgpu.GetDeviceProperties(true);
                        CudafyModes.Target = gpuType;

                        foreach (eLanguage language in languages)
                        {
                            string cudaRandomFilename = Path.GetRandomFileName();

                            try
                            {
                                CudafyTranslator.Language = language;

                                CompileProperties compileProperties = CompilerHelper.Create(ePlatform.Auto, eArchitecture.Unknown, eCudafyCompileMode.Default, CudafyTranslator.WorkingDirectory, CudafyTranslator.GenerateDebug);

                                // Use a random filename to prevent conflict on default temp file when multithreading (unit tests)
                                compileProperties.InputFile = cudaRandomFilename;

                                // If this line fails with NCrunch/Unit tests, there probably is a new version of Cudafy.NET
                                // and it needs to be registered in the GAC like this: gacutil -i Cudafy.NET.dll
                                CudafyModule cudafyModule = CudafyTranslator.Cudafy(compileProperties, typeof(Primitives));

                                if (!gpgpu.IsModuleLoaded(cudafyModule.Name))
                                {
                                    gpgpu.LoadModule(cudafyModule);
                                }

                                gpgpu.EnableMultithreading();

                                string gpuName = gpgpuProperties.Name.Trim() + " - " + gpuType.ToString() + " - " + language.ToString();

                                ////this.gpgpus.Add(gpuName, gpgpu);
                                ////this.gpgpuProperties.Add(gpuName, gpgpuProperties);
                                ////this.gpuTypes.Add(gpuName, gpuType);
                            }
                            catch (CudafyCompileException)
                            {
                                // Language not supported
                            }
                            finally
                            {
                                File.Delete(cudaRandomFilename);

                                // ncrunch: no coverage start
                            }
                        }
                    }
                }
                catch (DllNotFoundException)
                {
                }
                catch (InvalidOperationException)
                {
                    // Language not supported
                }
                catch (Cloo.ComputeException)
                {
                    // Language not supported
                } // ncrunch: no coverage end
            }
        }
示例#16
0
        private void PopulateGPGPUComboBox()
        {
            gpus.Clear();

            if (rdoCPU.Checked == true)     // If CPU is Selected, disable GPGPU combo box and set TestType to CPU
            {
                cbGPGPU.Text    = "Disabled";
                cbGPGPU.Enabled = false;
                TestType        = "CPU";
            }
            if (rdoGPU.Checked == true)  // If OpenCL is Selected:
            {
                cbGPGPU.Items.Clear();   // Clear GPGPU Selection box
                multiGPU = false;

                try
                {
                    if (CudafyHost.GetDeviceCount(CudafyModes.Target = eGPUType.OpenCL) >= 1)
                    {
                        int gpuCount = 0;
                        foreach (GPGPUProperties prop in CudafyHost.GetDeviceProperties(CudafyModes.Target = eGPUType.OpenCL))
                        {
                            if (!prop.Name.Contains("CPU") && !prop.Name.Contains("Processor"))
                            {
                                gpuCount++;
                            }
                        }

                        if (gpuCount > 1)
                        {
                            cbGPGPU.Items.Add("Multi-GPU");
                            multiGPU = true;
                            cbGPGPU.SelectedIndex   = 0;
                            lblPlatformDefault.Text = "Recommended Default Settings (Multi-GPU)";
                        }

                        foreach (GPGPUProperties prop in CudafyHost.GetDeviceProperties(CudafyModes.Target = eGPUType.OpenCL))
                        {
                            // Add all GPGPUs to combo box belonging to OpenCL
                            cbGPGPU.Items.Add(prop.Name.Trim() + "   ||   OpenCL platform: " + prop.PlatformName.Trim());
                            if (multiGPU == false && (!prop.Name.Contains("CPU") && !prop.Name.Contains("Processor")))
                            {
                                cbGPGPU.SelectedIndex   = cbGPGPU.Items.Count - 1;
                                lblPlatformDefault.Text = "Recommended Default Settings (" + prop.Name.Trim() + ")";
                            }
                            if (multiGPU == true && (!prop.Name.Contains("CPU") && !prop.Name.Contains("Processor")))
                            {
                                gpus.Add(prop.DeviceId);
                            }

                            gpuMem.Add(prop.TotalGlobalMem);

                            if (!prop.Name.Contains("CPU") && !prop.Name.Contains("Processor"))
                            {
                                if (maxGPUMem == 0 || prop.TotalGlobalMem < maxGPUMem)
                                {
                                    maxGPUMem = prop.TotalGlobalMem;
                                }
                            }
                            //MessageBox.Show(maxGPUMem.ToString());
                        }
                        cbGPGPU.Enabled = true;     // Enable combo box
                    }
                    else
                    {
                        cbGPGPU.Items.Add("No GPU detected on system");
                        cbGPGPU.SelectedIndex   = cbGPGPU.Items.Count - 1;
                        lblPlatformDefault.Text = "Recommended Default Settings (CPU)";
                        cbGPGPU.Enabled         = false;
                        rdoGPU.Enabled          = false;
                        rdoCPU.Checked          = true;
                    }
                }
                catch
                {
                    cbGPGPU.Items.Add("Error populating GPUs on system");
                    cbGPGPU.SelectedIndex   = cbGPGPU.Items.Count - 1;
                    lblPlatformDefault.Text = "Recommended Default Settings (CPU)";
                    cbGPGPU.Enabled         = false;
                    rdoGPU.Enabled          = false;
                    rdoCPU.Checked          = true;
                }
            }
        }
示例#17
0
        static void Main(string[] args)
        {
            CudafyModes.Target        = eGPUType.Cuda; // To use OpenCL, change this enum
            CudafyModes.DeviceId      = 0;
            CudafyTranslator.Language = CudafyModes.Target == eGPUType.OpenCL ? eLanguage.OpenCL : eLanguage.Cuda;

            Console.WriteLine("===================================\n          Cudafy.Demo\n        Hybrid DSP Systems\nCopyright © Hybrid DSP Systems 2011\n===================================");
            Console.WriteLine("\n* Modern adaptation by dev.lepo.co\n");

            try
            {
                int deviceCount = CudafyHost.GetDeviceCount(CudafyModes.Target);
                if (deviceCount == 0)
                {
                    Console.WriteLine("No suitable {0} devices found.", CudafyModes.Target);
                    goto theEnd;
                }
                GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
                Console.WriteLine("Running examples using {0}", gpu.GetDeviceProperties(false).Name);

                // Chapter 3
                Console.WriteLine("\r\nChapter 3");
                Console.WriteLine("\r\nhello_world");
                hello_world.Execute();
                Console.WriteLine("\r\nsimple_kernel");
                simple_kernel.Execute();
                Console.WriteLine("\r\nsimple_kernel_params");
                simple_kernel_params.Execute();
                Console.WriteLine("\r\nenum_gpu");
                enum_gpu.Execute();

                // Chapter 4
                Console.WriteLine("\r\nChapter 4");
                Console.WriteLine("\r\nadd_loop_cpu");
                add_loop_cpu.Execute();
                Console.WriteLine("\r\nadd_loop_gpu");
                add_loop_gpu.Execute();
                Console.WriteLine("\r\nadd_loop_gpu_alt");
                add_loop_gpu_alt.Execute();
                Console.WriteLine("\r\nadd_loop_long");
                add_loop_long.Execute();
                Console.WriteLine("\r\njulia (cpu)");
                new julia_gui(false).ShowDialog();
                Console.WriteLine("\r\njulia (gpu)");
                new julia_gui(true).ShowDialog();

                // Chapter 5
                Console.WriteLine("\r\nChapter 5");
                Console.WriteLine("\r\nadd_loop_blocks");
                add_loop_blocks.Execute();
                Console.WriteLine("\r\nadd_loop_long_blocks");
                add_loop_long_blocks.Execute();
                Console.WriteLine("\r\nripple");
                ripple r = new ripple();
                r.Execute();
                Console.WriteLine("\r\ndot");
                dot.Execute();

                // Chapter 6
                Console.WriteLine("\r\nChapter 6");
                Console.WriteLine("\r\nray (no constant memory) (OpenCL compatible as well as CUDA)");
                new ray_gui(ray_gui.eRayVersion.OpenCL).ShowDialog();
                Console.WriteLine("\r\nray (constant memory) (OpenCL compatible as well as CUDA)");
                new ray_gui(ray_gui.eRayVersion.OpenCL_const).ShowDialog();
                if (CudafyTranslator.Language == eLanguage.Cuda) // CUDA only
                {
                    Console.WriteLine("\r\nray (no constant memory)");
                    new ray_gui(ray_gui.eRayVersion.CUDA).ShowDialog();       // no const
                    Console.WriteLine("\r\nray (constant memory)");
                    new ray_gui(ray_gui.eRayVersion.CUDA_const).ShowDialog(); // const
                }

                // Chapter 9
                Console.WriteLine("\r\nChapter 9");
                Console.WriteLine("\r\nhist_gpu_shmem_atomics");
                hist_gpu_shmem_atomics.Execute();

                // Chapter 10
                Console.WriteLine("\r\nChapter 10");
                Console.WriteLine("\r\nbasic_double_stream_correct");
                basic_double_stream_correct.Execute();
                Console.WriteLine("\r\ncopy_timed");
                new copy_timed().Execute();

                Console.WriteLine("Done!");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
theEnd:
            Console.ReadKey();
        }
示例#18
0
        static void Main(string[] args)
        {
            try
            {
                CudafyModes.DeviceId = 0;
                GPGPU gpu = CudafyHost.GetDevice(eGPUType.Cuda, CudafyModes.DeviceId);
                CudafyModes.Architecture = gpu.GetArchitecture(); //eArchitecture.sm_35; // *** Change this to the architecture of your target board ***
                CudafyModes.Target       = CompilerHelper.GetGPUType(CudafyModes.Architecture);
                Console.WriteLine("{0}: Arch: {1}, Type: {2}, ID: {3}", gpu.GetDeviceProperties(false).Name, CudafyModes.Architecture, CudafyModes.Target, CudafyModes.DeviceId);

                if (CudafyModes.Target == eGPUType.Cuda)
                {
                    CURANDTests.Basics();
                }

                SIMDFunctionTests sft = new SIMDFunctionTests();
                CudafyUnitTest.PerformAllTests(sft);

                StringTests st = new StringTests();
                CudafyUnitTest.PerformAllTests(st);

                BasicFunctionTests bft = new BasicFunctionTests();
                CudafyUnitTest.PerformAllTests(bft);

                GMathUnitTests gmu = new GMathUnitTests();
                CudafyUnitTest.PerformAllTests(gmu);

                MultithreadedTests mtt = new MultithreadedTests();
                CudafyUnitTest.PerformAllTests(mtt);

                CopyTests1D ct1d = new CopyTests1D();
                CudafyUnitTest.PerformAllTests(ct1d);

                GPGPUTests gput = new GPGPUTests();
                CudafyUnitTest.PerformAllTests(gput);

                if (CudafyHost.GetDeviceCount(CudafyModes.Target) > 1)
                {
                    MultiGPUTests mgt = new MultiGPUTests();
                    CudafyUnitTest.PerformAllTests(mgt);
                }

                if (CudafyModes.Architecture >= eArchitecture.sm_30 && CudafyModes.Target == eGPUType.Cuda)
                {
                    WarpShuffleTests wst = new WarpShuffleTests();
                    CudafyUnitTest.PerformAllTests(wst);
                }

                if (CudafyModes.Architecture >= eArchitecture.sm_35 && CudafyModes.Target == eGPUType.Cuda)
                {
                    Compute35Features c35f = new Compute35Features();
                    CudafyUnitTest.PerformAllTests(c35f);
                }

                Console.WriteLine("Done");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
            }
        }
示例#19
0
        public static IEnumerable <string> TestCUDASDK()
        {
            StringBuilder sb = new StringBuilder();

            NvccCompilerOptions nvcc = null;

            if (IntPtr.Size == 8)
            {
                nvcc = NvccCompilerOptions.Createx64();
            }
            else
            {
                nvcc = NvccCompilerOptions.Createx86();
            }
            yield return(string.Format("Platform={0}", nvcc.Platform));

            yield return("Checking for CUDA SDK at " + nvcc.CompilerPath);

            if (!nvcc.TryTest())
            {
                yield return("Could not locate CUDA Include directory.");
            }
            else
            {
                yield return(string.Format("CUDA SDK Version={0}", nvcc.Version));

                yield return("Attempting to cudafy a kernel function.");

                var mod = CudafyTranslator.Cudafy(nvcc.Platform, eArchitecture.sm_11, nvcc.Version, false, typeof(CUDACheck));
                yield return("Successfully translated to CUDA C.");

                yield return("Attempting to compile CUDA C code.");

                string s = mod.Compile(eGPUCompiler.CudaNvcc, true);
                yield return("Successfully compiled CUDA C into a module.");

                if (CudafyHost.GetDeviceCount(eGPUType.Cuda) > 0)
                {
                    yield return("Attempting to instantiate CUDA device object (GPGPU).");

                    var gpu = CudafyHost.GetDevice(eGPUType.Cuda, 0);
                    yield return("Successfully got CUDA device 0.");

                    yield return("Attempting to load module.");

                    gpu.LoadModule(mod);
                    yield return("Successfully loaded module.");

                    yield return("Attempting to transfer data to GPU.");

                    int[]  a    = new int[1024];
                    int[]  b    = new int[1024];
                    int[]  c    = new int[1024];
                    Random rand = new Random();
                    for (int i = 0; i < 1024; i++)
                    {
                        a[i] = rand.Next(16384);
                        b[i] = rand.Next(16384);
                    }
                    int[] dev_a = gpu.CopyToDevice(a);
                    int[] dev_b = gpu.CopyToDevice(b);
                    int[] dev_c = gpu.Allocate(c);
                    yield return("Successfully transferred data to GPU.");

                    yield return("Attempting to launch function on GPU.");

                    gpu.Launch(1, 1024).TestKernelFunction(dev_a, dev_b, dev_c);
                    yield return("Successfully launched function on GPU.");

                    yield return("Attempting to transfer results back from GPU.");

                    gpu.CopyFromDevice(dev_c, c);
                    yield return("Successfully transferred results from GPU.");

                    yield return("Testing results.");

                    int errors = 0;
                    for (int i = 0; i < 1024; i++)
                    {
                        if (a[i] + b[i] != c[i])
                        {
                            errors++;
                        }
                    }
                    if (errors == 0)
                    {
                        yield return("Successfully tested results.");
                    }
                    else
                    {
                        yield return("Test failed - results not as expected.");
                    }

                    yield return("Checking for math libraries (FFT, BLAS, SPARSE, RAND).");

                    var fft     = GPGPUFFT.Create(gpu);
                    int version = fft.GetVersion();
                    if (version > 0)
                    {
                        yield return("Successfully detected.");
                    }
                }
            }
        }
示例#20
0
        public static IEnumerable <string> TestOpenCL()
        {
            yield return("Attempting to cudafy a kernel function.");

            //CudafyTranslator.Language = eLanguage.OpenCL;
            var mod = CudafyTranslator.Cudafy(ePlatform.x64, eArchitecture.OpenCL, null, false, typeof(CUDACheck));

            yield return("Successfully translated to OpenCL C.");

            for (int id = 0; id < CudafyHost.GetDeviceCount(eGPUType.OpenCL); id++)
            {
                yield return("Attempting to instantiate OpenCL device object (GPGPU).");

                var gpu = CudafyHost.GetDevice(eGPUType.OpenCL, id);
                yield return(string.Format("Successfully got OpenCL device {0}.", id));

                yield return("Name: " + gpu.GetDeviceProperties(false).Name);

                yield return("Attempting to load module.");

                gpu.LoadModule(mod);
                yield return("Successfully loaded module.");

                yield return("Attempting to transfer data to device.");

                int[]  a    = new int[1024];
                int[]  b    = new int[1024];
                int[]  c    = new int[1024];
                Random rand = new Random();
                for (int i = 0; i < 1024; i++)
                {
                    a[i] = rand.Next(16384);
                    b[i] = rand.Next(16384);
                }
                int[] dev_a = gpu.CopyToDevice(a);
                int[] dev_b = gpu.CopyToDevice(b);
                int[] dev_c = gpu.Allocate(c);
                yield return("Successfully transferred data to device.");

                yield return("Attempting to launch function on device.");

                gpu.Launch(4, 256).TestKernelFunction(dev_a, dev_b, dev_c);
                yield return("Successfully launched function on device.");

                yield return("Attempting to transfer results back from device.");

                gpu.CopyFromDevice(dev_c, c);
                yield return("Successfully transferred results from device.");

                yield return("Testing results.");

                int errors = 0;
                for (int i = 0; i < 1024; i++)
                {
                    if (a[i] + b[i] != c[i])
                    {
                        errors++;
                    }
                }
                if (errors == 0)
                {
                    yield return("Successfully tested results.\r\n\r\n");
                }
                else
                {
                    yield return("Test failed - results not as expected.\r\n\r\n");
                }
            }
        }