示例#1
0
        public static void Execute()
        {
            int i = 0;

            foreach (GPGPUProperties prop in CudafyHost.GetDeviceProperties(CudafyModes.Target, false))
            {
                Console.WriteLine("   --- General Information for device {0} ---", i);
                Console.WriteLine("Name:  {0}", prop.Name);
                Console.WriteLine("Platform Name:  {0}", prop.PlatformName);
                Console.WriteLine("Device Id:  {0}", prop.DeviceId);
                Console.WriteLine("Compute capability:  {0}.{1}", prop.Capability.Major, prop.Capability.Minor);
                Console.WriteLine("Clock rate: {0}", prop.ClockRate);
                Console.WriteLine("Simulated: {0}", prop.IsSimulated);
                Console.WriteLine();

                Console.WriteLine("   --- Memory Information for device {0} ---", i);
                Console.WriteLine("Total global mem:  {0}", prop.TotalMemory);
                Console.WriteLine("Total constant Mem:  {0}", prop.TotalConstantMemory);
                Console.WriteLine("Max mem pitch:  {0}", prop.MemoryPitch);
                Console.WriteLine("Texture Alignment:  {0}", prop.TextureAlignment);
                Console.WriteLine();

                Console.WriteLine("   --- MP Information for device {0} ---", i);
                Console.WriteLine("Shared mem per mp: {0}", prop.SharedMemoryPerBlock);
                Console.WriteLine("Registers per mp:  {0}", prop.RegistersPerBlock);
                Console.WriteLine("Threads in warp:  {0}", prop.WarpSize);
                Console.WriteLine("Max threads per block:  {0}", prop.MaxThreadsPerBlock);
                Console.WriteLine("Max thread dimensions:  ({0}, {1}, {2})", prop.MaxThreadsSize.x, prop.MaxThreadsSize.y, prop.MaxThreadsSize.z);
                Console.WriteLine("Max grid dimensions:  ({0}, {1}, {2})", prop.MaxGridSize.x, prop.MaxGridSize.y, prop.MaxGridSize.z);

                Console.WriteLine();

                i++;
            }
        }
        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(@"---");
            }
        }
示例#3
0
 public static GPGPUProperties getProperties()
 {
     foreach (GPGPUProperties prop in CudafyHost.GetDeviceProperties(CudafyModes.Target))
     {
         gpgpuProperties = prop;
         return(prop);
     }
     return(null);
 }
示例#4
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);
        }
        public static int GetMaxThreadsPerBlock()
        {
            var cudaDevicesProperties = CudafyHost.GetDeviceProperties(eGPUType.Cuda);
            var usedDeviceProperties  = cudaDevicesProperties.ElementAt(ChosenDeviceId);
            var cubeRoot = Convert.ToInt32(System.Math.Pow(usedDeviceProperties.MaxThreadsPerBlock, (1.0d / 3.0d)));

            int i = 2;

            for (i = 2; i <= usedDeviceProperties.WarpSize && i < cubeRoot; i = i * 2)
            {
                if (cubeRoot <= i)
                {
                    return(i);
                }
            }

            return(i / 2);
        }
示例#6
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);
        }
示例#7
0
        private static bool Init()
        {
            if (s_Gpu != null)
            {
                return(true);
            }

            try
            {
                var devices = CudafyHost.GetDeviceProperties(eGPUType.OpenCL).ToArray();
                var device  = devices.FirstOrDefault(d => d.Integrated && d.PlatformName.Contains("Intel(R)")); // use Intel iGPU if possible
                if (device == null || IsInUseForVideoRendering(device))
                {
                    // Fallback to CPU (prefer AMD Accelerated Parallel Processing first as it is faster)
                    const string cpuId = " CPU ";
                    device = devices.FirstOrDefault(d => d.Name.Contains(cpuId) && d.PlatformName.Contains("AMD"));
                    if (device == null)
                    {
                        // Settle for any CPU OpenCL device (most likely Intel OpenCL) as the last resort
                        device = devices.FirstOrDefault(d => d.Name.Contains(cpuId));
                        if (device == null)
                        {
                            throw new OpenClException("Error: CPU OpenCL drivers not installed");
                        }
                    }
                }
                var gpu = CudafyHost.GetDevice(eGPUType.OpenCL, device.DeviceId);
                gpu.LoadAudioKernel(typeof(AudioKernels));

                Player.Closed += PlayerOnClosed;

                s_Gpu = gpu;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
                return(false);
            }

            return(true);
        }
示例#8
0
        public GpuRenderer()
        {
            var availableOpenCLDevices = CudafyHost.GetDeviceProperties(eGPUType.OpenCL);

            if (availableOpenCLDevices.Any() == false)
            {
                throw new Exception("No OpenCL devices found...");
            }
            var device = availableOpenCLDevices.First();

            Module = CudafyTranslator.Cudafy(eArchitecture.OpenCL12);
            var blockSide =
                Enumerable
                .Range(1, 15)
                .Reverse()
                .First(count => count * count <= device.MaxThreadsPerBlock);

            BlockSize = new dim3(blockSide, blockSide);

            // Initialize gpu and load the module (avoids reloading every time)
            gpu = CudafyHost.GetDevice(eGPUType.OpenCL);
            gpu.LoadModule(Module);
        }
示例#9
0
        public Form GetForm()
        {
            string prefix = this.GetLocalizationPrefix();

            var tab1 = DWSIM.UI.Shared.Common.GetDefaultContainer();

            tab1.Tag = "Interface";

            if (Application.Instance.Platform.IsMac)
            {
                tab1.CreateAndAddLabelRow("TouchBar");

                tab1.CreateAndAddCheckBoxRow("Enable Custom TouchBar Buttons", Settings.EnableCustomTouchBar, (CheckBox sender, EventArgs obj) => { Settings.EnableCustomTouchBar = sender.Checked.Value; });
                tab1.CreateAndAddDescriptionRow("Enables/disables custom TouchBar buttons on supported MacBook Pro models + macOS versions.");
            }

            tab1.CreateAndAddLabelRow("Renderer");

            int currentrenderer = 0;
            var renderers       = new List <String>();

            switch (GlobalSettings.Settings.RunningPlatform())
            {
            case Settings.Platform.Windows:
                renderers.AddRange(Enum.GetNames(typeof(Settings.WindowsPlatformRenderer)));
                currentrenderer = (int)Settings.WindowsRenderer;
                break;

            case Settings.Platform.Linux:
                renderers.AddRange(Enum.GetNames(typeof(Settings.LinuxPlatformRenderer)));
                currentrenderer = (int)Settings.LinuxRenderer;
                break;

            case Settings.Platform.Mac:
                renderers.AddRange(Enum.GetNames(typeof(Settings.MacOSPlatformRenderer)));
                currentrenderer = (int)Settings.MacOSRenderer;
                break;
            }

            //tab1.CreateAndAddDropDownRow("Platform Renderer", renderers, currentrenderer, (sender, e) =>
            //{
            //    switch (GlobalSettings.Settings.RunningPlatform())
            //    {
            //        case Settings.Platform.Windows:
            //            Settings.WindowsRenderer = (Settings.WindowsPlatformRenderer)sender.SelectedIndex;
            //            break;
            //        case Settings.Platform.Linux:
            //            Settings.LinuxRenderer = (Settings.LinuxPlatformRenderer)sender.SelectedIndex;
            //            break;
            //        case Settings.Platform.Mac:
            //            Settings.MacOSRenderer = (Settings.MacOSPlatformRenderer)sender.SelectedIndex;
            //            break;
            //    }
            //});

            //tab1.CreateAndAddDescriptionRow("This sets the GUI Renderer for the current platform. Recommended renderers for each platform are:\nWindows: WPF (Windows Presentation Foundation)\nLinux: GTK 2\nmacOS: MonoMac");
            //tab1.CreateAndAddDescriptionRow("Changes to this setting will have effect upon application restart.");

            //if (Settings.RunningPlatform() == Settings.Platform.Mac)
            //{
            //    var check1 = tab1.CreateAndAddCheckBoxRow("Enable Dark Mode (macOS Mojave only)", Settings.DarkMode, (CheckBox sender, EventArgs obj) => { Settings.DarkMode = sender.Checked.Value; });
            //    check1.Enabled = false;
            //}

            tab1.CreateAndAddNumericEditorRow("Scaling Factor", Settings.UIScalingFactor, 0.2, 3.0, 2, (sender, e) => Settings.UIScalingFactor = sender.Value);
            tab1.CreateAndAddDescriptionRow("Sets the Scaling Factor for controls (windows, panels, buttons, lists, etc). Useful on Linux when used in conjunction with Font Scaling on High DPI displays.");

            tab1.CreateAndAddLabelRow("Flowsheet Designer");

            tab1.CreateAndAddDropDownRow("Flowsheet Renderer", new List <string>()
            {
                "Software (CPU)", "Hardware (OpenGL)"
            }, (int)Settings.FlowsheetRenderer, (sender, e) =>
            {
                Settings.FlowsheetRenderer = (Settings.SkiaCanvasRenderer)sender.SelectedIndex;
            });

            tab1.CreateAndAddCheckBoxRow("EnableAntiAliasing".Localize(prefix), Settings.DrawingAntiAlias, (CheckBox sender, EventArgs obj) => { Settings.DrawingAntiAlias = sender.Checked.Value; });
            tab1.CreateAndAddDescriptionRow("Sets anti-aliasing (edge smoothing) for the Flowsheet Designer.");

            tab1.CreateAndAddLabelRow("Editors");

            var sizes = new[] { "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16" };

            if (Settings.EditorFontSize == -1)
            {
                Settings.EditorFontSize = (int)(new Eto.Drawing.Font(Eto.Drawing.SystemFont.Label).Size);
            }

            tab1.CreateAndAddDropDownRow("Font Size (Editor Labels/Descriptions)", sizes.ToList(), sizes.ToList().IndexOf(Settings.EditorFontSize.ToString()), (DropDown sender, EventArgs obj) => { Settings.EditorFontSize = int.Parse(sender.SelectedValue.ToString()); });
            tab1.CreateAndAddDescriptionRow("Sets the Font Size for Editor labels and descriptions.");

            tab1.CreateAndAddDropDownRow("Font Size (Text Reports)", sizes.ToList(), sizes.ToList().IndexOf(Settings.ResultsReportFontSize.ToString()), (DropDown sender, EventArgs obj) => { Settings.ResultsReportFontSize = int.Parse(sender.SelectedValue.ToString()); });
            tab1.CreateAndAddDescriptionRow("Sets the Font Size for text reports.");

            tab1.CreateAndAddCheckBoxRow("Fix Size of Input Controls", Settings.EditorTextBoxFixedSize, (CheckBox sender, EventArgs obj) => { Settings.EditorTextBoxFixedSize = sender.Checked.Value; });
            tab1.CreateAndAddDescriptionRow("Fix the size of input textboxes and checkboxes on editors.");

            tab1.CreateAndAddCheckBoxRow("View/Open Object Editor After Selection", Settings.EditOnSelect, (CheckBox sender, EventArgs obj) => { Settings.EditOnSelect = sender.Checked.Value; });
            tab1.CreateAndAddDescriptionRow("Opens the object editor after selection on the flowsheet.");

            tab1.CreateAndAddCheckBoxRow("Call Solver on Editor Property Update", Settings.CallSolverOnEditorPropertyChanged, (CheckBox sender, EventArgs obj) => { Settings.CallSolverOnEditorPropertyChanged = sender.Checked.Value; });
            tab1.CreateAndAddDescriptionRow("Requests a flowsheet calculation after an object property is changed/updated on the editor.");

            CheckBox chkInsp = null, chkCPUP = null;

            var tab2a = DWSIM.UI.Shared.Common.GetDefaultContainer();

            tab2a.Tag = "Inspector";

            chkInsp = tab2a.CreateAndAddCheckBoxRow("Enable Inspector Reports", Settings.InspectorEnabled, (CheckBox sender, EventArgs obj) => {
                Settings.InspectorEnabled         = sender.Checked.GetValueOrDefault();
                Settings.EnableParallelProcessing = !Settings.InspectorEnabled;
                chkCPUP.Checked = !sender.Checked.GetValueOrDefault();
            });
            tab2a.CreateAndAddDescriptionRow("Enabling Inspector Reports will create model description and performance reports on-the-fly as the calculations are requested by the Flowsheet Solver. Use the Solution Inspector tool to view these reports.");
            tab2a.CreateAndAddDescriptionRow("When the Inspector Reports feature is enabled and the Flowsheet Solver is called, the Parallel CPU Processing is automatically disabled. You must re-enable it manually and disable the Inspector to increase the calculation speed again.");
            tab2a.CreateAndAddCheckBoxRow("Clear Previous Reports on new Flowsheet Calculation Request", Settings.ClearInspectorHistoryOnNewCalculationRequest, (CheckBox sender, EventArgs obj) => { Settings.ClearInspectorHistoryOnNewCalculationRequest = sender.Checked.GetValueOrDefault(); });
            tab2a.CreateAndAddDescriptionRow("This will erase all previously stored reports when a new flowsheet calculation request is made by the user.");

            var tab2 = DWSIM.UI.Shared.Common.GetDefaultContainer();

            tab2.Tag = "Solver".Localize(prefix);

            tab2.CreateAndAddTextBoxRow("N0", "Solver Timeout (s)", GlobalSettings.Settings.SolverTimeoutSeconds, (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    GlobalSettings.Settings.SolverTimeoutSeconds = Convert.ToInt32(sender.Text);
                }
            });
            tab2.CreateAndAddDescriptionRow("Set the solver's maximum calculation (waiting) time.");

            chkCPUP = tab2.CreateAndAddCheckBoxRow("EnableCPUParallelProcessing".Localize(prefix), Settings.EnableParallelProcessing, (CheckBox sender, EventArgs obj) => {
                Settings.EnableParallelProcessing = sender.Checked.GetValueOrDefault();
                Settings.InspectorEnabled         = !Settings.EnableParallelProcessing;
                chkInsp.Checked = !sender.Checked.GetValueOrDefault();
            });
            tab2.CreateAndAddDescriptionRow("Enables utilization of all CPU cores during flowsheet calculations.");
            tab2.CreateAndAddCheckBoxRow("EnableCPUSIMDAccel".Localize(prefix), Settings.UseSIMDExtensions, (CheckBox sender, EventArgs obj) => { Settings.UseSIMDExtensions = sender.Checked.GetValueOrDefault(); });
            tab2.CreateAndAddDescriptionRow("Enables utilization of special CPU instructions for accelerated math calculations.");

            tab2.CreateAndAddCheckBoxRow("BreakOnException".Localize(prefix), Settings.SolverBreakOnException, (CheckBox sender, EventArgs obj) => { Settings.SolverBreakOnException = sender.Checked.GetValueOrDefault(); });
            tab2.CreateAndAddDescriptionRow("If activated, the solver won't calculate the rest of the flowsheet if an error occurs during the calculation of an intermediate block/object.");
            tab2.CreateAndAddCheckBoxRow("EnableGPUAccel".Localize(prefix), Settings.EnableGPUProcessing, (CheckBox sender, EventArgs obj) => { Settings.EnableGPUProcessing = sender.Checked.Value; });
            TextArea tbgpucaps = null;
            var      cbgpu     = tab2.CreateAndAddDropDownRow("Computing Device", new List <string>(), 0, (sender, e) =>
            {
                if (!(sender.SelectedValue == null))
                {
                    if (sender.SelectedValue.ToString().Contains("Emulator"))
                    {
                        Settings.CudafyTarget = (int)eGPUType.Emulator;
                    }
                    else if (sender.SelectedValue.ToString().Contains("CUDA"))
                    {
                        Settings.CudafyTarget = (int)eGPUType.Cuda;
                    }
                    else
                    {
                        Settings.CudafyTarget = (int)eGPUType.OpenCL;
                    }

                    Settings.CudafyTarget = Settings.CudafyTarget;
                    try
                    {
                        foreach (GPGPUProperties prop in CudafyHost.GetDeviceProperties((eGPUType)Settings.CudafyTarget, false))
                        {
                            if (sender.SelectedValue.ToString().Split('|')[1].Contains(prop.Name))
                            {
                                Settings.SelectedGPU    = sender.SelectedValue.ToString();
                                Settings.CudafyDeviceID = prop.DeviceId;
                                Application.Instance.Invoke(() => GetCUDACaps(prop, tbgpucaps));
                                break;
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                    if (loaded)
                    {
                        if (Settings.gpu != null)
                        {
                            Settings.gpu.Dispose();
                        }
                        Settings.gpu = null;
                        try
                        {
                            //set CUDA params
                            CudafyModes.Compiler = eGPUCompiler.All;
                            CudafyModes.Target   = (eGPUType)Settings.CudafyTarget;
                            Cudafy.Translator.CudafyTranslator.GenerateDebug = false;
                            DWSIM.Thermodynamics.Calculator.InitComputeDevice();
                            Console.WriteLine("GPU initialized successfully: " + Settings.SelectedGPU + "(" + CudafyModes.Target.ToString() + ")");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("GPU initialization failed: " + ex.ToString());
                            var ex1 = ex;
                            while (ex1.InnerException != null)
                            {
                                Console.WriteLine("GPU initialization failed (IEX): " + ex1.InnerException.ToString());
                                if (ex1.InnerException is ReflectionTypeLoadException)
                                {
                                    foreach (var tlex in ((ReflectionTypeLoadException)(ex1.InnerException)).LoaderExceptions)
                                    {
                                        Console.WriteLine("GPU initialization failed (TLEX): " + tlex.Message);
                                    }
                                }
                                ex1 = ex1.InnerException;
                            }
                        }
                    }
                }
            });

            tbgpucaps = tab2.CreateAndAddMultilineMonoSpaceTextBoxRow("", 200, true, null);

            Task.Factory.StartNew(() =>
            {
                List <string> list = new List <string>();
                try
                {
                    CudafyModes.Target = eGPUType.Cuda;
                    foreach (GPGPUProperties prop in CudafyHost.GetDeviceProperties(CudafyModes.Target, false))
                    {
                        list.Add("CUDA | " + prop.Name + " (" + prop.DeviceId + ")");
                    }
                }
                catch (Exception)
                {
                }
                try
                {
                    CudafyModes.Target = eGPUType.OpenCL;
                    foreach (GPGPUProperties prop in CudafyHost.GetDeviceProperties(CudafyModes.Target, false))
                    {
                        list.Add("OpenCL | " + prop.Name + " (" + prop.DeviceId + ")");
                    }
                }
                catch (Exception)
                {
                }
                return(list);
            }).ContinueWith(t =>
            {
                foreach (var item in t.Result)
                {
                    cbgpu.Items.Add(item);
                }
                CudafyModes.Target = (eGPUType)Settings.CudafyTarget;
                if (Settings.SelectedGPU != "")
                {
                    foreach (var s in cbgpu.Items)
                    {
                        if (s.Text == Settings.SelectedGPU)
                        {
                            cbgpu.SelectedValue = s;
                            break;
                        }
                    }
                }
                else
                {
                }
                loaded = true;
            }, TaskScheduler.FromCurrentSynchronizationContext());

            var tab3 = DWSIM.UI.Shared.Common.GetDefaultContainer();

            tab3.Tag = "UserComps".Localize(prefix);

            tab3.CreateAndAddLabelRow("User-Defined Compound Datasets");
            var list1 = tab3.CreateAndAddListBoxRow(200, GlobalSettings.Settings.UserDatabases.ToArray(), null);

            tab3.CreateAndAddButtonRow("Add Dataset", null, (sender, e) =>
            {
                var dialog   = new OpenFileDialog();
                dialog.Title = "Select File".Localize();
                dialog.Filters.Add(new FileFilter("Compound dataset files", new[] { ".xml", ".json" }));
                dialog.MultiSelect        = false;
                dialog.CurrentFilterIndex = 0;
                if (dialog.ShowDialog(null) == DialogResult.Ok)
                {
                    if (!GlobalSettings.Settings.UserDatabases.Contains(dialog.FileName))
                    {
                        GlobalSettings.Settings.UserDatabases.Add(dialog.FileName);
                        list1.Items.Add(dialog.FileName);
                    }
                }
            });
            tab3.CreateAndAddButtonRow("Remove selected", null, (sender, e) =>
            {
                GlobalSettings.Settings.UserDatabases.Remove(list1.SelectedValue.ToString());
                list1.Items.RemoveAt(list1.SelectedIndex);
            });

            tab3.CreateAndAddLabelRow("User-Defined Interaction Parameter Datasets");
            var list2 = tab3.CreateAndAddListBoxRow(200, GlobalSettings.Settings.UserInteractionsDatabases.ToArray(), null);

            tab3.CreateAndAddButtonRow("Add Dataset", null, (sender, e) =>
            {
                var dialog   = new OpenFileDialog();
                dialog.Title = "Select File".Localize();
                dialog.Filters.Add(new FileFilter("Interaction Parameter dataset files", new[] { ".xml" }));
                dialog.MultiSelect        = false;
                dialog.CurrentFilterIndex = 0;
                if (dialog.ShowDialog(null) == DialogResult.Ok)
                {
                    if (!GlobalSettings.Settings.UserInteractionsDatabases.Contains(dialog.FileName))
                    {
                        GlobalSettings.Settings.UserInteractionsDatabases.Add(dialog.FileName);
                        list2.Items.Add(dialog.FileName);
                    }
                }
            });
            tab3.CreateAndAddButtonRow("Remove selected", null, (sender, e) =>
            {
                GlobalSettings.Settings.UserInteractionsDatabases.Remove(list2.SelectedValue.ToString());
                list2.Items.RemoveAt(list2.SelectedIndex);
            });

            var tab4 = DWSIM.UI.Shared.Common.GetDefaultContainer();

            tab4.Tag = "Backup".Localize(prefix);

            tab4.CreateAndAddLabelRow("BackupCopies".Localize(prefix));
            tab4.CreateAndAddCheckBoxRow("EnableBackupCopies".Localize(prefix), Settings.EnableBackupCopies, (CheckBox sender, EventArgs obj) => { Settings.EnableBackupCopies = sender.Checked.Value; });
            tab4.CreateAndAddEmptySpace();
            tab4.CreateAndAddTextBoxRow("N0", "BackupInterval".Localize(prefix), Settings.BackupInterval, (TextBox sender, EventArgs obj) => { Settings.BackupInterval = sender.Text.IsValidDouble() ? (int)sender.Text.ToDouble() : Settings.BackupInterval; });
            tab4.CreateAndAddEmptySpace();
            tab4.CreateAndAddButtonRow("PurgeBackupFolder".Localize(prefix), null, (sender, e) =>
            {
                string backupdir = "";
                if (GlobalSettings.Settings.RunningPlatform() == GlobalSettings.Settings.Platform.Mac)
                {
                    backupdir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Documents", "DWSIM Application Data", "Backup") + Path.DirectorySeparatorChar;
                }
                else
                {
                    backupdir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "DWSIM Application Data", "Backup") + Path.DirectorySeparatorChar;
                }
                var files = Directory.GetFiles(backupdir);
                foreach (var file in files)
                {
                    try
                    {
                        File.Delete(file);
                    }
                    catch { }
                }
            });
            tab4.CreateAndAddEmptySpace();

            var tab5 = DWSIM.UI.Shared.Common.GetDefaultContainer();

            tab5.Tag = "Misc".Localize(prefix);

            tab5.CreateAndAddLabelRow("Octave Settings");
            tab5.CreateAndAddDescriptionRow("Setup the path for Octave binaries to enable integration with DWSIM.");
            TextBox tbox = null;

            tbox = tab5.CreateAndAddLabelAndTextBoxAndButtonRow("Binaries Path", GlobalSettings.Settings.OctavePath, "Search", null,
                                                                (sender, e) => GlobalSettings.Settings.OctavePath = sender.Text,
                                                                (sender, e) =>
            {
                var searchdialog = new SelectFolderDialog()
                {
                    Title = "Search"
                };
                if (searchdialog.ShowDialog(tab5) == DialogResult.Ok)
                {
                    tbox.Text = searchdialog.Directory;
                }
            });
            tab5.CreateAndAddTextBoxRow("N0", "Calling Timeout (minutes)", GlobalSettings.Settings.OctaveTimeoutInMinutes, (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    GlobalSettings.Settings.OctaveTimeoutInMinutes = sender.Text.ToDouble();
                }
            });

            tab5.CreateAndAddLabelRow("Python Settings");
            tab5.CreateAndAddDescriptionRow("Setup the path for Python binaries to enable integration with DWSIM.");
            TextBox tbox2 = null;

            tbox2 = tab5.CreateAndAddLabelAndTextBoxAndButtonRow("Binaries Path", GlobalSettings.Settings.PythonPath, "Search", null,
                                                                 (sender, e) => GlobalSettings.Settings.PythonPath = sender.Text,
                                                                 (sender, e) =>
            {
                var searchdialog = new SelectFolderDialog()
                {
                    Title = "Search"
                };
                if (searchdialog.ShowDialog(tab5) == DialogResult.Ok)
                {
                    tbox2.Text = searchdialog.Directory;
                }
            });
            tab5.CreateAndAddTextBoxRow("N0", "Calling Timeout (minutes)", GlobalSettings.Settings.PythonTimeoutInMinutes, (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    GlobalSettings.Settings.PythonTimeoutInMinutes = sender.Text.ToDouble();
                }
            });

            var form = DWSIM.UI.Shared.Common.GetDefaultTabbedForm("Title".Localize(prefix), 700, 550, new[] { tab1, tab2, tab2a, tab3, tab4, tab5 });

            form.Closed += (s, e) => {
                try
                {
                    DWSIM.GlobalSettings.Settings.SaveSettings("dwsim_newui.ini");
                }
                catch
                {
                }
            };

            return(form);
        }
示例#10
0
        public static IEnumerable <string> EnumerateDevices(bool openCL = false)//out string info, out bool driverInstalled)
        {
            int    count   = 0;
            string message = string.Empty;
            string info    = string.Empty;

            IsDriverInstalled = true;
            List <string>          sb          = new List <string>();
            List <GPGPUProperties> deviceProps = new List <GPGPUProperties>();
            bool failed = true;

            try
            {
                count       = openCL ? OpenCLDevice.GetDeviceCount() : CudaGPU.GetDeviceCount();
                deviceProps = CudafyHost.GetDeviceProperties(openCL ? eGPUType.OpenCL : eGPUType.Cuda).ToList();
                failed      = false;
            }
            catch (DllNotFoundException dnfe)
            {
                sb.Add("Suitable driver not installed. " + dnfe.Message);
                IsDriverInstalled = false;
            }
            catch (GASS.CUDA.CUDAException ex)
            {
                if (ex.Message == "ErrorNotInitialized")
                {
                    sb.Add("Found 0 CUDA devices.");
                }
                else
                {
                    sb.Add("CUDAException: " + ex.Message);
                }
            }
            catch (Exception ex)
            {
                sb.Add("Error: " + ex.Message);
            }

            if (failed)
            {
                foreach (var s in sb)
                {
                    yield return(s);
                }
            }
            else
            {
                yield return(string.Format("Found {0} devices.\r\n", count));

                foreach (var prop in deviceProps)
                {
                    yield return("Name: " + prop.Name);

                    if (openCL)
                    {
                        yield return("OpenCL Version: " + prop.Capability.ToString());
                    }
                    else
                    {
                        yield return("Compute capability: " + prop.Capability.ToString());
                    }
                    if (!openCL && prop.Capability < new Version(1, 4))
                    {
                        yield return("Note: This device will not support default calls to Cudafy(). Use overloads to give specific value.");
                    }
                    yield return(string.Empty);
                }
            }
        }
示例#11
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;
                }
            }
        }