コード例 #1
0
        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));
            }
        }
コード例 #2
0
ファイル: OpenCL.cs プロジェクト: usscsmith/SoliditySHA3Miner
        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.OnGetMiningParameterStatus += NetworkInterface_OnGetMiningParameterStatus;
                NetworkInterface.OnNewMessagePrefix         += NetworkInterface_OnNewMessagePrefix;
                NetworkInterface.OnNewTarget += NetworkInterface_OnNewTarget;
                networkInterface.OnStopSolvingCurrentChallenge += NetworkInterface_OnStopSolvingCurrentChallenge;

                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));
            }
        }