Beispiel #1
0
        public CPU(NetworkInterface.INetworkInterface networkInterface, Device[] devices, bool isSubmitStale, int pauseOnFailedScans)
        {
            try
            {
                Devices             = devices;
                NetworkInterface    = networkInterface;
                m_pauseOnFailedScan = pauseOnFailedScans;
                m_failedScanCount   = 0;

                var devicesStr = string.Empty;
                foreach (var device in Devices)
                {
                    if (!device.AllowDevice)
                    {
                        continue;
                    }

                    if (!string.IsNullOrEmpty(devicesStr))
                    {
                        devicesStr += ',';
                    }
                    devicesStr += device.DeviceID.ToString("X64");
                }

                NetworkInterface.OnGetTotalHashrate += NetworkInterface_OnGetTotalHashrate;

                m_instance = Solver.GetInstance(new StringBuilder(devicesStr));
                unsafe
                {
                    m_GetSolutionTemplateCallback = Solver.SetOnGetSolutionTemplateHandler(m_instance, Work.GetSolutionTemplate);
                    m_GetKingAddressCallback      = Solver.SetOnGetKingAddressHandler(m_instance, Work.GetKingAddress);
                }
                m_GetWorkPositionCallback       = Solver.SetOnGetWorkPositionHandler(m_instance, Work.GetPosition);
                m_ResetWorkPositionCallback     = Solver.SetOnResetWorkPositionHandler(m_instance, Work.ResetPosition);
                m_IncrementWorkPositionCallback = Solver.SetOnIncrementWorkPositionHandler(m_instance, Work.IncrementPosition);
                m_MessageCallback  = Solver.SetOnMessageHandler(m_instance, m_instance_OnMessage);
                m_SolutionCallback = Solver.SetOnSolutionHandler(m_instance, m_instance_OnSolution);

                NetworkInterface.OnGetMiningParameterStatus += NetworkInterface_OnGetMiningParameterStatus;
                NetworkInterface.OnNewMessagePrefix         += NetworkInterface_OnNewMessagePrefix;
                NetworkInterface.OnNewTarget += NetworkInterface_OnNewTarget;
                networkInterface.OnStopSolvingCurrentChallenge += NetworkInterface_OnStopSolvingCurrentChallenge;

                Solver.SetSubmitStale(m_instance, isSubmitStale);

                if (string.IsNullOrWhiteSpace(devicesStr))
                {
                    Program.Print("[INFO] No CPU assigned.");
                    return;
                }
            }
            catch (Exception ex)
            {
                Program.Print(string.Format("[ERROR] {0}", ex.Message));
            }
        }
        public void Dispose()
        {
            try
            {
                if (m_instance != null && m_instance.ToInt64() != 0)
                {
                    Solver.DisposeInstance(m_instance);
                }

                m_GetSolutionTemplateCallback   = null;
                m_GetKingAddressCallback        = null;
                m_GetWorkPositionCallback       = null;
                m_ResetWorkPositionCallback     = null;
                m_IncrementWorkPositionCallback = null;
                m_MessageCallback  = null;
                m_SolutionCallback = null;
            }
            catch (Exception ex)
            {
                Program.Print(string.Format("OpenCL [ERROR] {0}", ex.Message));
            }
        }
        public OpenCL(NetworkInterface.INetworkInterface networkInterface,
                      Device[] intelDevices, Device[] amdDevices, bool isSubmitStale, int pauseOnFailedScans)
        {
            try
            {
                NetworkInterface    = networkInterface;
                m_pauseOnFailedScan = pauseOnFailedScans;
                m_failedScanCount   = 0;

                var hasADL_API = false;
                Solver.FoundADL_API(ref hasADL_API);
                if (!hasADL_API)
                {
                    Program.Print("OpenCL [WARN] ADL library not found.");
                }

                if (!hasADL_API && RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    UseLinuxQuery = API.AmdLinuxQuery.QuerySuccess();
                }

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && !UseLinuxQuery)
                {
                    Program.Print("OpenCL [WARN] Unable to find AMD devices in Linux kernel.");
                }

                HasMonitoringAPI = hasADL_API || UseLinuxQuery;

                NetworkInterface.OnGetTotalHashrate += NetworkInterface_OnGetTotalHashrate;

                if (!HasMonitoringAPI)
                {
                    Program.Print("OpenCL [WARN] GPU monitoring not available.");
                }

                m_instance = Solver.GetInstance();
                unsafe
                {
                    m_GetSolutionTemplateCallback = Solver.SetOnGetSolutionTemplateHandler(m_instance, Work.GetSolutionTemplate);
                    m_GetKingAddressCallback      = Solver.SetOnGetKingAddressHandler(m_instance, Work.GetKingAddress);
                }
                m_GetWorkPositionCallback       = Solver.SetOnGetWorkPositionHandler(m_instance, Work.GetPosition);
                m_ResetWorkPositionCallback     = Solver.SetOnResetWorkPositionHandler(m_instance, Work.ResetPosition);
                m_IncrementWorkPositionCallback = Solver.SetOnIncrementWorkPositionHandler(m_instance, Work.IncrementPosition);
                m_MessageCallback  = Solver.SetOnMessageHandler(m_instance, m_instance_OnMessage);
                m_SolutionCallback = Solver.SetOnSolutionHandler(m_instance, m_instance_OnSolution);

                NetworkInterface.OnGetMiningParameterStatusEvent += NetworkInterface_OnGetMiningParameterStatusEvent;
                NetworkInterface.OnNewMessagePrefixEvent         += NetworkInterface_OnNewMessagePrefixEvent;
                NetworkInterface.OnNewTargetEvent += NetworkInterface_OnNewTargetEvent;

                Solver.SetSubmitStale(m_instance, isSubmitStale);

                if ((!Program.AllowIntel && !Program.AllowAMD) || (intelDevices.All(d => !d.AllowDevice) && amdDevices.All(d => !d.AllowDevice)))
                {
                    Program.Print("OpenCL [INFO] Device not set.");
                    return;
                }

                var deviceName     = new StringBuilder(256);
                var deviceNameSize = 0ul;

                if (Program.AllowIntel)
                {
                    for (int i = 0; i < intelDevices.Length; i++)
                    {
                        if (intelDevices[i].AllowDevice)
                        {
                            Solver.AssignDevice(m_instance, new StringBuilder(intelDevices[i].Platform), intelDevices[i].DeviceID,
                                                ref intelDevices[i].Intensity, ref intelDevices[i].PciBusID, deviceName, ref deviceNameSize);
                        }
                    }
                }

                if (Program.AllowAMD)
                {
                    for (int i = 0; i < amdDevices.Length; i++)
                    {
                        if (amdDevices[i].AllowDevice)
                        {
                            deviceName.Clear();
                            Solver.AssignDevice(m_instance, new StringBuilder(amdDevices[i].Platform), amdDevices[i].DeviceID,
                                                ref amdDevices[i].Intensity, ref amdDevices[i].PciBusID, deviceName, ref deviceNameSize);
                            if (!UseLinuxQuery)
                            {
                                amdDevices[i].Name = deviceName.ToString();
                            }
                            else
                            {
                                amdDevices[i].Name = API.AmdLinuxQuery.GetDeviceRealName(amdDevices[i].PciBusID, deviceName.ToString());
                                Program.Print(string.Format("{0} (OpenCL) ID: {1} [INFO] Assigned OpenCL device ({2})",
                                                            amdDevices[i].Platform, amdDevices[i].DeviceID, amdDevices[i].Name));
                            }
                        }
                    }
                }

                if (Program.AllowIntel && Program.AllowAMD)
                {
                    Devices = intelDevices.Union(amdDevices).ToArray();
                }
                else if (Program.AllowIntel)
                {
                    Devices = intelDevices;
                }
                else if (Program.AllowAMD)
                {
                    Devices = amdDevices;
                }
            }
            catch (Exception ex)
            {
                Program.Print(string.Format("OpenCL [ERROR] {0}", ex.Message));
            }
        }
        public CUDA(NetworkInterface.INetworkInterface networkInterface, Device[] cudaDevices, bool isSubmitStale, int pauseOnFailedScans)
        {
            try
            {
                Devices             = cudaDevices;
                NetworkInterface    = networkInterface;
                m_pauseOnFailedScan = pauseOnFailedScans;
                m_failedScanCount   = 0;

                var hasNvAPI64 = false;
                Solver.FoundNvAPI64(ref hasNvAPI64);

                if (!hasNvAPI64)
                {
                    Program.Print("CUDA [WARN] NvAPI64 library not found.");
                }

                var foundNvSMI = API.NvSMI.FoundNvSMI();

                if (!foundNvSMI)
                {
                    Program.Print("CUDA [WARN] NvSMI not found.");
                }

                UseNvSMI = !hasNvAPI64 && foundNvSMI;

                HasMonitoringAPI = hasNvAPI64 | UseNvSMI;

                if (!HasMonitoringAPI)
                {
                    Program.Print("CUDA [WARN] GPU monitoring not available.");
                }

                NetworkInterface.OnGetTotalHashrate += NetworkInterface_OnGetTotalHashrate;

                m_instance = Solver.GetInstance();
                unsafe
                {
                    m_GetSolutionTemplateCallback = Solver.SetOnGetSolutionTemplateHandler(m_instance, Work.GetSolutionTemplate);
                    m_GetKingAddressCallback      = Solver.SetOnGetKingAddressHandler(m_instance, Work.GetKingAddress);
                }
                m_GetWorkPositionCallback       = Solver.SetOnGetWorkPositionHandler(m_instance, Work.GetPosition);
                m_ResetWorkPositionCallback     = Solver.SetOnResetWorkPositionHandler(m_instance, Work.ResetPosition);
                m_IncrementWorkPositionCallback = Solver.SetOnIncrementWorkPositionHandler(m_instance, Work.IncrementPosition);
                m_MessageCallback  = Solver.SetOnMessageHandler(m_instance, m_instance_OnMessage);
                m_SolutionCallback = Solver.SetOnSolutionHandler(m_instance, m_instance_OnSolution);

                NetworkInterface.OnGetMiningParameterStatusEvent += NetworkInterface_OnGetMiningParameterStatusEvent;
                NetworkInterface.OnNewMessagePrefixEvent         += NetworkInterface_OnNewMessagePrefixEvent;
                NetworkInterface.OnNewTargetEvent += NetworkInterface_OnNewTargetEvent;

                Solver.SetSubmitStale(m_instance, isSubmitStale);

                if (!Program.AllowCUDA || cudaDevices.All(d => !d.AllowDevice))
                {
                    Program.Print("[INFO] CUDA device not set.");
                    return;
                }

                for (int i = 0; i < Devices.Length; i++)
                {
                    if (Devices[i].AllowDevice)
                    {
                        Solver.AssignDevice(m_instance, Devices[i].DeviceID, ref Devices[i].PciBusID, ref Devices[i].Intensity);
                    }
                }
            }
            catch (Exception ex)
            {
                Program.Print(string.Format("[ERROR] {0}", ex.Message));
            }
        }