Esempio n. 1
0
        protected override void PushTarget(Device.DeviceBase device)
        {
            var errorMessage = new StringBuilder(1024);

            Helper.CUDA.Solver.PushTarget(UnmanagedInstance, device.CommonPointers.Target, errorMessage);

            if (errorMessage.Length > 0)
            {
                PrintMessage(device.Type, device.Platform, device.DeviceID, "Error", errorMessage.ToString());
            }
        }
Esempio n. 2
0
        public ulong GetHashRateByDevice(Device.DeviceBase device)
        {
            var hashRate = 0ul;

            if (!IsPause)
            {
                hashRate = (ulong)(device.HashCount / (DateTime.Now - device.HashStartTime).TotalSeconds);
            }

            return(hashRate);
        }
Esempio n. 3
0
        protected override void PushMessage(Device.DeviceBase device)
        {
            var errorMessage = new StringBuilder(1024);

            Helper.OpenCL.Solver.PushMessage(UnmanagedInstance, ((Device.OpenCL)device).DeviceCL_Struct, device.CommonPointers.Message, errorMessage);

            if (errorMessage.Length > 0)
            {
                PrintMessage(device.Type, device.Platform, device.DeviceID, "Error", errorMessage.ToString());
            }
        }
Esempio n. 4
0
        protected override void StartFinding(Device.DeviceBase device, bool isKingMaking)
        {
            var deviceCPU = (Device.CPU)device;

            if (!deviceCPU.IsInitialized)
            {
                return;
            }

            while (!deviceCPU.HasNewTarget || !deviceCPU.HasNewChallenge)
            {
                Task.Delay(500).Wait();
            }

            PrintMessage(device.Type, device.Platform, deviceCPU.DeviceID, "Info", "Start mining...");

            foreach (var processor in deviceCPU.Processor_Structs)
            {
                Task.Factory.StartNew(() => StartThreadFinding(deviceCPU, processor, isKingMaking));
            }
        }
Esempio n. 5
0
        protected void CheckInputs(Device.DeviceBase device, bool isKingMaking, ref byte[] currentChallenge)
        {
            if (device.HasNewTarget || device.HasNewChallenge)
            {
                if (device.HasNewTarget)
                {
                    if (isKingMaking)
                    {
                        PushTarget(device);
                    }
                    else
                    {
                        PushHigh64Target(device);
                    }

                    device.HasNewTarget = false;
                }

                if (device.HasNewChallenge)
                {
                    if (isKingMaking)
                    {
                        PushMessage(device);
                    }
                    else
                    {
                        PushMidState(device);
                    }

                    Array.Copy(device.Challenge, currentChallenge, UINT256_LENGTH);
                    device.HasNewChallenge = false;
                }

                device.HashStartTime = DateTime.Now;
                device.HashCount     = 0;
            }
        }
Esempio n. 6
0
 protected abstract void StartFinding(Device.DeviceBase device, bool isKingMaking);
Esempio n. 7
0
 protected abstract void PushMessage(Device.DeviceBase device);
Esempio n. 8
0
 protected abstract void PushMidState(Device.DeviceBase device);
Esempio n. 9
0
 protected abstract void PushTarget(Device.DeviceBase device);
Esempio n. 10
0
        protected override void StartFinding(Device.DeviceBase device, bool isKingMaking)
        {
            var deviceCL = ((Device.OpenCL)device).DeviceCL_Struct;

            try
            {
                if (!device.IsInitialized)
                {
                    return;
                }

                while (!device.HasNewTarget || !device.HasNewChallenge)
                {
                    Task.Delay(500).Wait();
                }

                PrintMessage(device.Type, device.Platform, device.DeviceID, "Info", "Start mining...");

                PrintMessage(device.Type, device.Platform, device.DeviceID, "Debug",
                             string.Format("Threads: {0} Local work size: {1} Block size: {2}",
                                           deviceCL.GlobalWorkSize, deviceCL.LocalWorkSize, deviceCL.GlobalWorkSize / deviceCL.LocalWorkSize));

                var errorMessage     = new StringBuilder(1024);
                var currentChallenge = (byte[])Array.CreateInstance(typeof(byte), UINT256_LENGTH);

                device.HashStartTime   = DateTime.Now;
                device.HashCount       = 0;
                device.IsMining        = true;
                deviceCL.SolutionCount = 0;

                do
                {
                    while (device.IsPause)
                    {
                        Task.Delay(500).Wait();
                        device.HashStartTime = DateTime.Now;
                        device.HashCount     = 0;
                    }

                    CheckInputs(device, isKingMaking, ref currentChallenge);

                    Work.IncrementPosition(ref deviceCL.WorkPosition, deviceCL.GlobalWorkSize);
                    device.HashCount += deviceCL.GlobalWorkSize;

                    Helper.OpenCL.Solver.Hash(UnmanagedInstance,
                                              ref deviceCL,
                                              errorMessage);
                    if (errorMessage.Length > 0)
                    {
                        PrintMessage(device.Type, device.Platform, device.DeviceID, "Error", errorMessage.ToString());
                        device.IsMining = false;
                    }

                    if (deviceCL.SolutionCount > 0)
                    {
                        lock (((Device.OpenCL)device).Solutions)
                            if (deviceCL.SolutionCount > 0)
                            {
                                var tempSolutionCount = deviceCL.SolutionCount;
                                var tempSolutions     = ((Device.OpenCL)device).Solutions.Where(s => s != 0).ToArray();

                                SubmitSolutions(tempSolutions, currentChallenge,
                                                device.Type, device.Platform, device.DeviceID,
                                                tempSolutionCount, isKingMaking);

                                deviceCL.SolutionCount = 0;
                            }
                    }
                } while (device.IsMining);

                PrintMessage(device.Type, device.Platform, device.DeviceID, "Info", "Stop mining...");

                device.HashCount = 0;

                Helper.OpenCL.Solver.ReleaseDeviceObjects(UnmanagedInstance, ref deviceCL, errorMessage);
                if (errorMessage.Length > 0)
                {
                    PrintMessage(device.Type, device.Platform, device.DeviceID, "Error", errorMessage.ToString());
                    errorMessage.Clear();
                }

                device.IsStopped     = true;
                device.IsInitialized = false;
            }
            catch (Exception ex)
            {
                PrintMessage(device.Type, device.Platform, -1, "Error", ex.Message);
            }
            PrintMessage(device.Type, device.Platform, device.DeviceID, "Info", "Mining stopped.");
        }
Esempio n. 11
0
 protected override void PushMessage(Device.DeviceBase device)
 {
     // Do nothing
 }
Esempio n. 12
0
 protected override void PushMidState(Device.DeviceBase device)
 {
     // Do nothing
 }
Esempio n. 13
0
 protected override void PushTarget(Device.DeviceBase device)
 {
     // Do nothing
 }
Esempio n. 14
0
        protected override void StartFinding(Device.DeviceBase device, bool isKingMaking)
        {
            var deviceCUDA = (Device.CUDA)device;

            try
            {
                if (!deviceCUDA.IsInitialized)
                {
                    return;
                }

                while (!deviceCUDA.HasNewTarget || !deviceCUDA.HasNewChallenge)
                {
                    Task.Delay(500).Wait();
                }

                PrintMessage(device.Type, device.Platform, deviceCUDA.DeviceID, "Info", "Start mining...");

                PrintMessage(device.Type, device.Platform, deviceCUDA.DeviceID, "Debug",
                             string.Format("Threads: {0} Grid size: {1} Block size: {2}",
                                           deviceCUDA.Threads, deviceCUDA.Grid.X, deviceCUDA.Block.X));

                var errorMessage     = new StringBuilder(1024);
                var currentChallenge = (byte[])Array.CreateInstance(typeof(byte), UINT256_LENGTH);

                Helper.CUDA.Solver.SetDevice(UnmanagedInstance, deviceCUDA.DeviceID, errorMessage);
                if (errorMessage.Length > 0)
                {
                    PrintMessage(device.Type, device.Platform, deviceCUDA.DeviceID, "Error", errorMessage.ToString());
                    return;
                }

                deviceCUDA.HashStartTime = DateTime.Now;
                deviceCUDA.HashCount     = 0;
                deviceCUDA.IsMining      = true;

                unsafe
                {
                    ulong *solutions     = (ulong *)deviceCUDA.DeviceCUDA_Struct.Solutions.ToPointer();
                    uint * solutionCount = (uint *)deviceCUDA.DeviceCUDA_Struct.SolutionCount.ToPointer();
                    *      solutionCount = 0;
                    do
                    {
                        while (deviceCUDA.IsPause)
                        {
                            Task.Delay(500).Wait();
                            deviceCUDA.HashStartTime = DateTime.Now;
                            deviceCUDA.HashCount     = 0;
                        }

                        CheckInputs(deviceCUDA, isKingMaking, ref currentChallenge);

                        Work.IncrementPosition(ref deviceCUDA.DeviceCUDA_Struct.WorkPosition, deviceCUDA.Threads);
                        deviceCUDA.HashCount += deviceCUDA.Threads;

                        if (isKingMaking)
                        {
                            Helper.CUDA.Solver.HashMessage(UnmanagedInstance, ref deviceCUDA.DeviceCUDA_Struct, errorMessage);
                        }
                        else
                        {
                            Helper.CUDA.Solver.HashMidState(UnmanagedInstance, ref deviceCUDA.DeviceCUDA_Struct, errorMessage);
                        }

                        if (errorMessage.Length > 0)
                        {
                            PrintMessage(device.Type, device.Platform, deviceCUDA.DeviceID, "Error", errorMessage.ToString());
                            deviceCUDA.IsMining = false;
                        }

                        if (*solutionCount > 0)
                        {
                            var solutionArray = (ulong[])Array.CreateInstance(typeof(ulong), *solutionCount);

                            for (var i = 0; i < *solutionCount; i++)
                            {
                                solutionArray[i] = solutions[i];
                            }

                            SubmitSolutions(solutionArray, currentChallenge, device.Type, device.Platform, deviceCUDA.DeviceID, *solutionCount, isKingMaking);

                            *solutionCount = 0;
                        }
                    } while (deviceCUDA.IsMining);
                }

                PrintMessage(device.Type, device.Platform, deviceCUDA.DeviceID, "Info", "Stop mining...");

                deviceCUDA.HashCount = 0;

                Helper.CUDA.Solver.ReleaseDeviceObjects(UnmanagedInstance, ref deviceCUDA.DeviceCUDA_Struct, errorMessage);
                if (errorMessage.Length > 0)
                {
                    PrintMessage(device.Type, device.Platform, deviceCUDA.DeviceID, "Error", errorMessage.ToString());
                    errorMessage.Clear();
                }

                Helper.CUDA.Solver.ResetDevice(UnmanagedInstance, deviceCUDA.DeviceID, errorMessage);
                if (errorMessage.Length > 0)
                {
                    PrintMessage(device.Type, device.Platform, deviceCUDA.DeviceID, "Error", errorMessage.ToString());
                    errorMessage.Clear();
                }

                deviceCUDA.IsStopped     = true;
                deviceCUDA.IsInitialized = false;
            }
            catch (Exception ex)
            {
                PrintMessage(device.Type, device.Platform, -1, "Error", ex.Message);
            }
            PrintMessage(device.Type, device.Platform, deviceCUDA.DeviceID, "Info", "Mining stopped.");
        }