Ejemplo n.º 1
0
        public static void GetSols()
        {
            while (solutions.Count > 0)
            {
                var so = solutions.Dequeue();
                if (so.nonces.Count == 42)
                {
                    ActiveSolution = so;

                    tstate = TrimmerState.Solving;

                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(string.Format("Recovering solution: nonce:{0:X} k0:{1:X} k1:{2:X} k2:{3:X} k3:{4:X}", so.nonce, so.k0, so.k1, so.k2, so.k3));
                    Console.ResetColor();

                    cuda.StandardInput.Write(string.Format("#s {0} {1} {2} {3} {4}", so.k0, so.k1, so.k2, so.k3, 0));
                    foreach (var n in so.nonces)
                    {
                        cuda.StandardInput.Write(" " + ((UInt64)n.Item1 | ((UInt64)n.Item2 << 32)).ToString());
                    }
                    cuda.StandardInput.WriteLine();

                    int max = 2000;
                    Task.Delay(50);
                    while (tstate != TrimmerState.Ready)
                    {
                        if (--max < 0)
                        {
                            break;
                        }
                        Task.Delay(1).Wait();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void Listen()
        {
            while (bridge.Connected)
            {
                try
                {
                    string message = reader.ReadLine();

                    if (message.StartsWith("#"))
                    {
                        switch (message[1])
                        {
                        case 'N':
                            Status        = TrimmerState.Starting;
                            StatusMessage = "TRM NET OK";
                            break;

                        case 'A':
                            Status        = TrimmerState.Trimming;
                            StatusMessage = "TRIMMING";
                            break;

                        case 'D':
                        {
                            string[] data = message.Split(';');
                            if (data.Length == 3)
                            {
                                gpu.DeviceName   = data[1];
                                gpu.DeviceMemory = long.Parse(data[2]);
                                Logger.Log(LogType.Info, "Detected " + gpu.DeviceName + " ID:" + gpu.DeviceID);
                            }
                        }
                        break;

                        case 'R':
                            Status        = TrimmerState.Ready;
                            StatusMessage = "TRM READY";
                            break;

                        case 'E':
                            Status        = TrimmerState.SendingEdges;
                            StatusMessage = "TRM EDGES OUT";
                            break;
                        }
                    }
                    else
                    {
                        Logger.Log(LogType.Error, "Unknown message from trimmer " + gpu.GPUID + ": " + message);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(LogType.Error, "Trimmer message read fail " + gpu.GPUID, ex);
                    Task.Delay(500);
                }
            }
        }
Ejemplo n.º 3
0
        private static void Cuda_ErrorDataReceived(object sender, DataReceivedEventArgs e)
        {
            try
            {
                if (e.Data != null && !SupressCudaConsole)
                {
                    CppInitText += e.Data;
                }

                if (e.Data != null && e.Data != "" && e.Data.Trim()[0] == '#')
                {
                    // valid command line
                    switch (e.Data.Trim()[1])
                    {
                    case 'a':
                        tstate = TrimmerState.Trimming;
                        break;

                    case 'r':
                        tstate = TrimmerState.Ready;
                        break;

                    case 'e':
                        tstate = TrimmerState.SendingEdges;

                        lock (edges)
                        {
                            edges.Clear();

                            try
                            {
                                using (var mmf = MemoryMappedFile.OpenExisting("CDS" + device.ToString()))
                                {
                                    using (var mmfs = mmf.CreateViewStream(0, 8000000, MemoryMappedFileAccess.Read))
                                    {
                                        using (var br = new BinaryReader(mmfs))
                                        {
                                            var count = br.ReadUInt32();

                                            for (int i = 0; i < count; i++)
                                            {
                                                var a = br.ReadUInt32();
                                                var b = br.ReadUInt32();
                                                edges.Add(new Tuple <uint, uint>(a, b));
                                            }
                                        }
                                    }
                                }
                            }
                            catch
                            {
                                // error in shared data stuff, lets try secondary solution
                                try
                                {
                                    //edges\\data.bin
                                    if (File.Exists("edges/data.bin"))
                                    {
                                        byte[] data = File.ReadAllBytes("edges/data.bin");
                                        File.Delete("edges/data.bin");
                                        using (MemoryStream ms = new MemoryStream(data))
                                            using (BinaryReader br = new BinaryReader(ms))
                                            {
                                                var count = br.ReadUInt32();

                                                for (int i = 0; i < count; i++)
                                                {
                                                    var a = br.ReadUInt32();
                                                    var b = br.ReadUInt32();
                                                    edges.Add(new Tuple <uint, uint>(a, b));
                                                }
                                            }
                                    }
                                }
                                catch
                                {
                                    Console.WriteLine("Unable to get edges from trimmer!");
                                }
                            }
                        }

                        break;

                    case 'x':
                        tstate = TrimmerState.Terminated;
                        break;

                    case 's':
                        try
                        {
                            var nonces = e.Data.Split(' ');
                            var sols   = nonces.Skip(1).Select(n => uint.Parse(n)).OrderBy(n => n).ToList();

                            var diffOk = CheckAdditionalDifficulty(sols, ActiveSolution.difficulty, out ulong diff);
                            if (diffOk && (ulong)gc.CurrentJob.job_id == ActiveSolution.jobId)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("Solution difficulty: " + diff.ToString() + " | " + ActiveSolution.difficulty);
                                Console.ResetColor();

                                Task.Run(() => { gc.SendSolution(ActiveSolution, sols); });
                            }
                            else if ((ulong)gc.CurrentJob.job_id == ActiveSolution.jobId)
                            {
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine("Solution difficulty: " + diff.ToString() + " | " + ActiveSolution.difficulty);
                                Console.ResetColor();
                            }

                            statistics.solutions++;
                        }
                        catch
                        {
                            Console.WriteLine("Solution return failed.");
                        }
                        break;
                    }
                }
                else if (e.Data != null)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine(e.Data);
                    Console.ResetColor();
                }
            }
            catch (Exception ex)
            {
                if (!SupressCudaConsole)
                {
                    Console.WriteLine("Unknown problem parsing c++ output: " + e.Data + ", " + ex.Message);
                }
            }
        }
Ejemplo n.º 4
0
        public TrimDriver(GPU gpu)
        {
            this.gpu      = gpu;
            StatusMessage = "Idle";

            ocl = Process.Start(new ProcessStartInfo()
            {
                FileName               = "OCLacka.exe",  // platform devID mode(0) port(13430)
                Arguments              = string.Format("{0} {1} {2} {3}", gpu.Type == GPUtype.CUDA ? "NVIDIA" : "AMD", gpu.DeviceID, 0, gpu.GPUID + 13430),
                CreateNoWindow         = true,
                RedirectStandardError  = true,
                RedirectStandardInput  = true,
                RedirectStandardOutput = true,
                StandardErrorEncoding  = Encoding.ASCII,
                StandardOutputEncoding = Encoding.ASCII,
                UseShellExecute        = false
            });

            ocl.ErrorDataReceived  += (sender, e) => { LogError(e.Data, gpu); };
            ocl.OutputDataReceived += (sender, e) => { LogStd(e.Data, gpu); };
            ocl.BeginOutputReadLine();
            ocl.BeginErrorReadLine();

            Task.Delay(3000).Wait();

            if (ocl.HasExited)
            {
                Status        = TrimmerState.Error;
                StatusMessage = "Instacrash";
                return;
            }

            try
            {
                bridge   = new TcpClient("127.0.0.1", gpu.GPUID + 13430);
                stream   = bridge.GetStream();
                reader   = new StreamReader(stream);
                listener = Task.Factory.StartNew(() => { Listen(); });
            }
            catch
            {
                Status        = TrimmerState.Error;
                StatusMessage = "TCP Con Failed";
                return;
            }

            Task.Delay(1000).Wait();

            if (bridge != null && bridge.Connected)
            {
                if (Status == TrimmerState.Ready && !ocl.HasExited)
                {
                    Task.Factory.StartNew(() => { TrimmingLoop(); }, TaskCreationOptions.LongRunning);
                }
                else
                {
                    Status        = TrimmerState.Error;
                    StatusMessage = ocl.HasExited ?  "Trimmer Exit" : "Trimmer !Ready";
                }
            }
            else
            {
                Status        = TrimmerState.Error;
                StatusMessage = "TCP Con Discn";
            }
        }