public void Start(int aLbryIntensity = 256, int aLbryLocalWorkSize = 256) { mLbryGlobalWorkSizeArray[0] = aLbryIntensity * OpenCLDevice.GetMaxComputeUnits() * aLbryLocalWorkSize; mLbryLocalWorkSizeArray[0] = aLbryLocalWorkSize; base.Start(); }
public void Submit(OpenCLDevice device, Job job, UInt32 output, String result) { if (Stopped) { return; } try { mMutex.WaitOne(5000); } catch (Exception) { } RegisterDeviceWithShare(device); try { String stringNonce = String.Format("{0:x2}{1:x2}{2:x2}{3:x2}", ((output >> 0) & 0xff), ((output >> 8) & 0xff), ((output >> 16) & 0xff), ((output >> 24) & 0xff)); String message = JsonConvert.SerializeObject(new Dictionary <string, Object> { { "method", "submit" }, { "params", new Dictionary <String, String> { { "id", mUserID }, { "job_id", job.ID }, { "nonce", stringNonce }, { "result", result } } }, { "id", 4 } }); WriteLine(message); MainForm.Logger("Device #" + device.DeviceIndex + " submitted a share."); } catch (Exception ex) { MainForm.Logger("Failed to submit share: " + ex.Message); try { mMutex.ReleaseMutex(); } catch (Exception) { } Reconnect(); } try { mMutex.ReleaseMutex(); } catch (Exception) { } }
public OpenCLDummyLbryMiner(OpenCLDevice aGatelessGateDevice) : base(aGatelessGateDevice, "Lbry") { mLbryInputBuffer = new ComputeBuffer <byte>(Context, ComputeMemoryFlags.ReadOnly, 112); mLbryOutputBuffer = new ComputeBuffer <UInt32>(Context, ComputeMemoryFlags.ReadWrite, lbryOutputSize); mIterations = (aGatelessGateDevice.GetVendor() == "NVIDIA") ? 8 : 1; }
private void BuildEthashProgram() { ComputeDevice computeDevice = OpenCLDevice.GetComputeDevice(); try { mProgramArrayMutex.WaitOne(5000); } catch (Exception) { } if (mEthashProgramArray.ContainsKey(new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] })) { mEthashProgram = mEthashProgramArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }]; mEthashDAGKernel = mEthashDAGKernelArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }]; mEthashSearchKernel = mEthashSearchKernelArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }]; } else { try { if (mEthashLocalWorkSizeArray[0] != 192) { throw new Exception("No suitable binary file was found."); } string fileName = @"BinaryKernels\" + computeDevice.Name + "_ethash.bin"; byte[] binary = System.IO.File.ReadAllBytes(fileName); mEthashProgram = new ComputeProgram(Context, new List <byte[]>() { binary }, new List <ComputeDevice>() { computeDevice }); MainForm.Logger("Loaded " + fileName + " for Device #" + DeviceIndex + "."); } catch (Exception) { //MainForm.Logger("ex.message: " + ex.Message); String source = System.IO.File.ReadAllText(@"Kernels\ethash.cl"); mEthashProgram = new ComputeProgram(Context, source); MainForm.Logger(@"Loaded Kernels\ethash.cl for Device #" + DeviceIndex + "."); } String buildOptions = (OpenCLDevice.GetVendor() == "AMD" ? "-O1 " : OpenCLDevice.GetVendor() == "NVIDIA" ? "" : // "-cl-nv-opt-level=1 -cl-nv-maxrregcount=256 " : "") + " -IKernels -DWORKSIZE=" + mEthashLocalWorkSizeArray[0]; try { mEthashProgram.Build(OpenCLDevice.DeviceList, buildOptions, null, IntPtr.Zero); } catch (Exception) { MainForm.Logger(mEthashProgram.GetBuildLog(computeDevice)); throw; } MainForm.Logger("Built Ethash program for Device #" + DeviceIndex + "."); MainForm.Logger("Build options: " + buildOptions); mEthashProgramArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }] = mEthashProgram; mEthashDAGKernelArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }] = mEthashDAGKernel = mEthashProgram.CreateKernel("GenerateDAG"); mEthashSearchKernelArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }] = mEthashSearchKernel = mEthashProgram.CreateKernel("search"); } try { mProgramArrayMutex.ReleaseMutex(); } catch (Exception) { } }
public void Submit(OpenCLDevice aDevice, NeoScryptStratum.Work work, UInt32 aNonce) { if (Stopped) { return; } try { mMutex.WaitOne(5000); } catch (Exception) { } ReportSubmittedShare(aDevice); try { String stringNonce = (String.Format("{3:x2}{2:x2}{1:x2}{0:x2}", ((aNonce >> 0) & 0xff), ((aNonce >> 8) & 0xff), ((aNonce >> 16) & 0xff), ((aNonce >> 24) & 0xff))); String message = JsonConvert.SerializeObject(new Dictionary <string, Object> { { "id", mJsonRPCMessageID }, { "method", "mining.submit" }, { "params", new List <string> { Username, work.Job.ID, work.LocalExtranonceString, work.Job.NTime, stringNonce } } }); WriteLine(message); ++mJsonRPCMessageID; } catch (Exception ex) { MainForm.Logger("Failed to submit share: " + ex.Message + "\nReconnecting to the server..."); Reconnect(); } try { mMutex.ReleaseMutex(); } catch (Exception) { } }
override public void Submit(OpenCLDevice aDevice, EthashStratum.Job job, UInt64 output) { if (Stopped) { return; } try { mMutex.WaitOne(5000); } catch (Exception) { } ReportSubmittedShare(aDevice); try { String stringNonce = ((PoolExtranonce.Length == 0) ? (String.Format("{7:x2}{6:x2}{5:x2}{4:x2}{3:x2}{2:x2}{1:x2}{0:x2}", ((output >> 0) & 0xff), ((output >> 8) & 0xff), ((output >> 16) & 0xff), ((output >> 24) & 0xff), ((output >> 32) & 0xff), ((output >> 40) & 0xff), ((output >> 48) & 0xff), ((output >> 56) & 0xff))) : (PoolExtranonce.Length == 2) ? (String.Format("{6:x2}{5:x2}{4:x2}{3:x2}{2:x2}{1:x2}{0:x2}", ((output >> 0) & 0xff), ((output >> 8) & 0xff), ((output >> 16) & 0xff), ((output >> 24) & 0xff), ((output >> 32) & 0xff), ((output >> 40) & 0xff), ((output >> 48) & 0xff))) : (PoolExtranonce.Length == 4) ? (String.Format("{5:x2}{4:x2}{3:x2}{2:x2}{1:x2}{0:x2}", ((output >> 0) & 0xff), ((output >> 8) & 0xff), ((output >> 16) & 0xff), ((output >> 24) & 0xff), ((output >> 32) & 0xff), ((output >> 40) & 0xff))) : (String.Format("{4:x2}{3:x2}{2:x2}{1:x2}{0:x2}", ((output >> 0) & 0xff), ((output >> 8) & 0xff), ((output >> 16) & 0xff), ((output >> 24) & 0xff), ((output >> 32) & 0xff)))); String message = JsonConvert.SerializeObject(new Dictionary <string, Object> { { "id", mJsonRPCMessageID }, { "method", "mining.submit" }, { "params", new List <string> { Username, job.ID, stringNonce } } }); WriteLine(message); ++mJsonRPCMessageID; } catch (Exception ex) { MainForm.Logger("Failed to submit share: " + ex.Message + "\nReconnecting to the server..."); Reconnect(); } try { mMutex.ReleaseMutex(); } catch (Exception) { } }
protected void ReportRejectedShare(string reason = null) { int shareID = -1; OpenCLDevice device = null; try { mMutex.WaitOne(5000); } catch (Exception) { } if (mDevicesWithShare.Count > 0) { device = mDevicesWithShare[0]; mDevicesWithShare.RemoveAt(0); shareID = mShareIDs[0]; mShareIDs.RemoveAt(0); } try { mMutex.ReleaseMutex(); } catch (Exception) { } if (!MainForm.DevFeeMode) { device.IncrementRejectedShares(); MainForm.Instance.ReportRejectedShare(); } if (shareID >= 0 && !MainForm.DevFeeMode) { MainForm.Logger("Share #" + shareID + " rejected."); } else { MainForm.Logger("Share rejected."); } }
public void BuildNeoScryptProgram() { ComputeDevice computeDevice = OpenCLDevice.GetComputeDevice(); try { mProgramArrayMutex.WaitOne(5000); } catch (Exception) { } if (mNeoScryptProgramArray.ContainsKey(new ProgramArrayIndex(DeviceIndex, mNeoScryptLocalWorkSizeArray[0]))) { mNeoScryptProgram = mNeoScryptProgramArray[new ProgramArrayIndex(DeviceIndex, mNeoScryptLocalWorkSizeArray[0])]; mNeoScryptSearchKernel = mNeoScryptSearchKernelArray[new ProgramArrayIndex(DeviceIndex, mNeoScryptLocalWorkSizeArray[0])]; } else { String source = System.IO.File.ReadAllText(@"Kernels\neoscrypt.cl"); mNeoScryptProgram = new ComputeProgram(Context, source); MainForm.Logger(@"Loaded Kernels\neoscrypt.cl for Device #" + DeviceIndex + "."); String buildOptions = (OpenCLDevice.GetVendor() == "AMD" ? "-O5 -legacy" : // "-legacy" : OpenCLDevice.GetVendor() == "NVIDIA" ? "" : //"-cl-nv-opt-level=1 -cl-nv-maxrregcount=256 " : "") + " -IKernels -DWORKSIZE=" + mNeoScryptLocalWorkSizeArray[0]; try { mNeoScryptProgram.Build(OpenCLDevice.DeviceList, buildOptions, null, IntPtr.Zero); } catch (Exception) { MainForm.Logger(mNeoScryptProgram.GetBuildLog(computeDevice)); throw; } MainForm.Logger("Built NeoScrypt program for Device #" + DeviceIndex + "."); MainForm.Logger("Build options: " + buildOptions); mNeoScryptProgramArray[new ProgramArrayIndex(DeviceIndex, mNeoScryptLocalWorkSizeArray[0])] = mNeoScryptProgram; mNeoScryptSearchKernelArray[new ProgramArrayIndex(DeviceIndex, mNeoScryptLocalWorkSizeArray[0])] = mNeoScryptSearchKernel = mNeoScryptProgram.CreateKernel("search"); } try { mProgramArrayMutex.ReleaseMutex(); } catch (Exception) { } }
protected ComputeProgram BuildProgram(string programName, long localWorkSize, string optionsAMD, string optionsNVIDIA, string optionsOthers) { ComputeProgram program; string defultBinaryFilePath = @"BinaryKernels\" + ComputeDevice.Name + "_" + programName + "_" + localWorkSize + ".bin"; string savedBinaryFilePath = (MainForm.SavedOpenCLBinaryKernelPathBase + @"\") + ComputeDevice.Name + "_" + programName + "_" + localWorkSize + ".bin"; string sourceFilePath = @"Kernels\" + programName + ".cl"; String buildOptions = (OpenCLDevice.GetVendor() == "AMD" ? optionsAMD : OpenCLDevice.GetVendor() == "NVIDIA" ? optionsNVIDIA : optionsOthers) + " -IKernels -DWORKSIZE=" + localWorkSize; try { if (!MainForm.UseDefaultOpenCLBinariesChecked) { throw new Exception(); } byte[] binary = System.IO.File.ReadAllBytes(defultBinaryFilePath); program = new ComputeProgram(Context, new List <byte[]>() { binary }, new List <ComputeDevice>() { ComputeDevice }); MainForm.Logger("Loaded " + defultBinaryFilePath + " for Device #" + DeviceIndex + "."); } catch (Exception) { try { if (!MainForm.ReuseCompiledBinariesChecked) { throw new Exception(); } byte[] binary = System.IO.File.ReadAllBytes(savedBinaryFilePath); program = new ComputeProgram(Context, new List <byte[]>() { binary }, new List <ComputeDevice>() { ComputeDevice }); MainForm.Logger("Loaded " + savedBinaryFilePath + " for Device #" + DeviceIndex + "."); } catch (Exception) { String source = System.IO.File.ReadAllText(sourceFilePath); program = new ComputeProgram(Context, source); MainForm.Logger(@"Loaded " + sourceFilePath + " for Device #" + DeviceIndex + "."); } } try { program.Build(OpenCLDevice.DeviceList, buildOptions, null, IntPtr.Zero); if (MainForm.ReuseCompiledBinariesChecked) { System.IO.File.WriteAllBytes(savedBinaryFilePath, program.Binaries[0]); } } catch (Exception) { MainForm.Logger(program.GetBuildLog(ComputeDevice)); program.Dispose(); throw; } MainForm.Logger("Built " + programName + " program for Device #" + DeviceIndex + "."); MainForm.Logger("Build options: " + buildOptions); return(program); }
public void Start(PascalStratum aPascalStratum, int aPascalIntensity, int aPascalLocalWorkSize) { Stratum = aPascalStratum; mPascalGlobalWorkSizeArray[0] = aPascalIntensity * OpenCLDevice.GetMaxComputeUnits() * aPascalLocalWorkSize; mPascalLocalWorkSizeArray[0] = aPascalLocalWorkSize; base.Start(); }
public void Start(LbryStratum aLbryStratum, int aLbryIntensity, int aLbryLocalWorkSize) { Stratum = aLbryStratum; mLbryGlobalWorkSizeArray[0] = aLbryIntensity * OpenCLDevice.GetMaxComputeUnits() * aLbryLocalWorkSize; mLbryLocalWorkSizeArray[0] = aLbryLocalWorkSize; base.Start(); }
public void Start(NeoScryptStratum aNeoScryptStratum, int aNeoScryptIntensity, int aNeoScryptLocalWorkSize) { mNeoScryptStratum = aNeoScryptStratum; mNeoScryptGlobalWorkSizeArray[0] = aNeoScryptIntensity * OpenCLDevice.GetMaxComputeUnits() * aNeoScryptLocalWorkSize; mNeoScryptLocalWorkSizeArray[0] = aNeoScryptLocalWorkSize; base.Start(); }
public void BuildLbryProgram() { ComputeDevice computeDevice = OpenCLDevice.GetComputeDevice(); try { mProgramArrayMutex.WaitOne(5000); } catch (Exception) { } if (mLbryProgramArray.ContainsKey(new ProgramArrayIndex(DeviceIndex, mLbryLocalWorkSizeArray[0]))) { mLbryProgram = mLbryProgramArray[new ProgramArrayIndex(DeviceIndex, mLbryLocalWorkSizeArray[0])]; mLbrySearchKernel = mLbrySearchKernelArray[new ProgramArrayIndex(DeviceIndex, mLbryLocalWorkSizeArray[0])]; } else { try { if (mLbryLocalWorkSizeArray[0] != 256) { throw new Exception("No suitable binary file was found."); } string fileName = @"BinaryKernels\" + computeDevice.Name + "_lbry.bin"; byte[] binary = System.IO.File.ReadAllBytes(fileName); mLbryProgram = new ComputeProgram(Context, new List <byte[]>() { binary }, new List <ComputeDevice>() { computeDevice }); //MainForm.Logger("Loaded " + fileName + " for Device #" + DeviceIndex + "."); } catch (Exception) { String source = System.IO.File.ReadAllText(@"Kernels\lbry.cl"); mLbryProgram = new ComputeProgram(Context, source); //MainForm.Logger(@"Loaded Kernels\lbry.cl for Device #" + DeviceIndex + "."); } String buildOptions = (OpenCLDevice.GetVendor() == "AMD" ? "-O1 " : //"-O1 " : OpenCLDevice.GetVendor() == "NVIDIA" ? "" : //"-cl-nv-opt-level=1 -cl-nv-maxrregcount=256 " : "") + " -IKernels -DWORKSIZE=" + mLbryLocalWorkSizeArray[0] + " -DITERATIONS=" + mIterations; try { mLbryProgram.Build(OpenCLDevice.DeviceList, buildOptions, null, IntPtr.Zero); } catch (Exception) { MainForm.Logger(mLbryProgram.GetBuildLog(computeDevice)); throw; } //MainForm.Logger("Built Lbry program for Device #" + DeviceIndex + "."); //MainForm.Logger("Build options: " + buildOptions); mLbryProgramArray[new ProgramArrayIndex(DeviceIndex, mLbryLocalWorkSizeArray[0])] = mLbryProgram; mLbrySearchKernelArray[new ProgramArrayIndex(DeviceIndex, mLbryLocalWorkSizeArray[0])] = mLbrySearchKernel = mLbryProgram.CreateKernel("search_combined"); } try { mProgramArrayMutex.ReleaseMutex(); } catch (Exception) { } }
protected Miner(OpenCLDevice aDevice, String aAlgorithmName, String aFirstAlgorithmName = "", String aSecondAlgorithmName = "") { mDevice = aDevice; mAlgorithmName = aAlgorithmName; mFirstAlgorithmName = (aFirstAlgorithmName == "") ? aAlgorithmName : aFirstAlgorithmName; mSecondAlgorithmName = aSecondAlgorithmName; Speed = 0; SecondSpeed = 0; }
public OpenCLEthashMiner(OpenCLDevice aGatelessGateDevice) : base(aGatelessGateDevice, "Ethash") { try { mEthashOutputBuffer = new ComputeBuffer <UInt32>(Context, ComputeMemoryFlags.ReadWrite, 256); mEthashHeaderBuffer = new ComputeBuffer <byte>(Context, ComputeMemoryFlags.ReadOnly, 32); } catch (Exception ex) { throw new UnrecoverableException(ex, GatelessGateDevice); } }
public OpenCLNeoScryptMiner(OpenCLDevice aGatelessGateDevice) : base(aGatelessGateDevice, "NeoScrypt") { try { mNeoScryptInputBuffer = new ComputeBuffer <byte>(Context, ComputeMemoryFlags.ReadOnly, sNeoScryptInputSize); mNeoScryptOutputBuffer = new ComputeBuffer <UInt32>(Context, ComputeMemoryFlags.ReadWrite, sNeoScryptOutputSize); } catch (Exception ex) { throw new UnrecoverableException(ex, GatelessGateDevice); } }
public OpenCLCryptoNightMiner(OpenCLDevice aGatelessGateDevice) : base(aGatelessGateDevice, "CryptoNight") { try { inputBuffer = new ComputeBuffer <byte>(Context, ComputeMemoryFlags.ReadOnly, 76); outputBuffer = new ComputeBuffer <UInt32>(Context, ComputeMemoryFlags.ReadWrite, outputSize); terminateBuffer = new ComputeBuffer <Int32>(Context, ComputeMemoryFlags.ReadWrite, 1); } catch (Exception ex) { throw new UnrecoverableException(ex, GatelessGateDevice); } }
public OpenCLPascalMiner(OpenCLDevice aGatelessGateDevice) : base(aGatelessGateDevice, "Pascal") { try { mPascalInputBuffer = new ComputeBuffer <byte>(Context, ComputeMemoryFlags.ReadOnly, sPascalInputSize); mPascalOutputBuffer = new ComputeBuffer <UInt32>(Context, ComputeMemoryFlags.ReadWrite, sPascalOutputSize); mPascalMidstateBuffer = new ComputeBuffer <byte>(Context, ComputeMemoryFlags.ReadOnly, sPascalMidstateSize); } catch (Exception ex) { throw new UnrecoverableException(ex, GatelessGateDevice); } }
public OpenCLLbryMiner(OpenCLDevice aGatelessGateDevice) : base(aGatelessGateDevice, "Lbry") { try { mLbryInputBuffer = new ComputeBuffer <byte>(Context, ComputeMemoryFlags.ReadOnly, 112); mLbryOutputBuffer = new ComputeBuffer <UInt32>(Context, ComputeMemoryFlags.ReadWrite, lbryOutputSize); } catch (Exception ex) { throw new UnrecoverableException(ex, GatelessGateDevice); } mIterations = (aGatelessGateDevice.GetVendor() == "NVIDIA") ? 8 : 1; }
public OpenCLDualEthashLbryMiner(OpenCLDevice aGatelessGateDevice) : base(aGatelessGateDevice, "ethash_lbry", "ethash", "lbry") { try { mEthashOutputBuffer = new ComputeBuffer <UInt32>(Context, ComputeMemoryFlags.ReadWrite, 256); mEthashHeaderBuffer = new ComputeBuffer <byte>(Context, ComputeMemoryFlags.ReadOnly, 32); mLbryInputBuffer = new ComputeBuffer <byte>(Context, ComputeMemoryFlags.ReadOnly, 112); mLbryOutputBuffer = new ComputeBuffer <UInt32>(Context, ComputeMemoryFlags.ReadWrite, lbryOutputSize); } catch (Exception ex) { throw new UnrecoverableException(ex, Device); } }
protected void ReportShareRejection() { if (MainForm.DevFeeMode) { return; } try { mMutex.WaitOne(5000); } catch (Exception) { } if (mDevicesWithShare.Count > 0) { OpenCLDevice device = mDevicesWithShare[0]; mDevicesWithShare.RemoveAt(0); device.IncrementRejectedShares(); } try { mMutex.ReleaseMutex(); } catch (Exception) { } }
public static OpenCLDevice[] GetAllOpenCLDevices() { var computeDeviceArrayList = new ArrayList(); bool doneWithAMD = false; foreach (var platform in ComputePlatform.Platforms) { if (platform.Name == "AMD Accelerated Parallel Processing" && doneWithAMD) { continue; } IList <ComputeDevice> openclDevices = platform.Devices; var properties = new ComputeContextPropertyList(platform); using (var context = new ComputeContext(openclDevices, properties, null, IntPtr.Zero)) { foreach (var openclDevice in context.Devices) { if (IsOpenCLDeviceIgnored(openclDevice)) { continue; } computeDeviceArrayList.Add(openclDevice); } } if (platform.Name == "AMD Accelerated Parallel Processing") { doneWithAMD = true; } } var computeDevices = Array.ConvertAll(computeDeviceArrayList.ToArray(), item => (ComputeDevice)item); OpenCLDevice[] devices = new OpenCLDevice[computeDevices.Length]; var deviceIndex = 0; foreach (var computeDevice in computeDevices) { devices[deviceIndex] = new OpenCLDevice(deviceIndex, computeDevice); deviceIndex++; } return(devices); }
public void Submit(OpenCLDevice aDevice, LbryStratum.Work work, UInt32 aNonce, string result) { if (Stopped) { return; } if (!VerifyShare(work, aNonce, result)) { MainForm.Logger("Error in computation has been detected (Lbry)."); return; // TODO } try { mMutex.WaitOne(5000); } catch (Exception) { } RegisterDeviceWithShare(aDevice); try { String stringNonce = (String.Format("{3:x2}{2:x2}{1:x2}{0:x2}", ((aNonce >> 0) & 0xff), ((aNonce >> 8) & 0xff), ((aNonce >> 16) & 0xff), ((aNonce >> 24) & 0xff))); String message = JsonConvert.SerializeObject(new Dictionary <string, Object> { { "id", mJsonRPCMessageID++ }, { "method", "mining.submit" }, { "params", new List <string> { Username, work.Job.ID, work.LocalExtranonceString, work.Job.NTime, stringNonce } } }); WriteLine(message); MainForm.Logger("Device #" + aDevice.DeviceIndex + " submitted a share."); //MainForm.Logger("message: " + message); } catch (Exception ex) { MainForm.Logger("Failed to submit share: " + ex.Message); try { mMutex.ReleaseMutex(); } catch (Exception) { } Reconnect(); } try { mMutex.ReleaseMutex(); } catch (Exception) { } }
protected void ReportSubmittedShare(OpenCLDevice aDevice) { int shareID = -1; try { mMutex.WaitOne(5000); } catch (Exception) { } mDevicesWithShare.Add(aDevice); shareID = mShareCounter; mShareIDs.Add(mShareCounter++); try { mMutex.ReleaseMutex(); } catch (Exception) { } if (shareID >= 0 && !MainForm.DevFeeMode) { MainForm.Logger("Device #" + aDevice.DeviceIndex + " submitted Share #" + shareID + " to " + ServerAddress + " as " + (Utilities.IsDevFeeAddress(Username) ? "a DEVFEE" : Username) + "."); } else { MainForm.Logger("Device #" + aDevice.DeviceIndex + " submitted a share to " + ServerAddress + " as " + (Utilities.IsDevFeeAddress(Username) ? "a DEVFEE" : Username) + "."); } }
override public void Submit(OpenCLDevice aDevice, EthashStratum.Job job, UInt64 output) { if (Stopped) { return; } try { mMutex.WaitOne(5000); } catch (Exception) { } RegisterDeviceWithShare(aDevice); try { String stringNonce = String.Format("{7:x2}{6:x2}{5:x2}{4:x2}{3:x2}{2:x2}{1:x2}{0:x2}", ((output >> 0) & 0xff), ((output >> 8) & 0xff), ((output >> 16) & 0xff), ((output >> 24) & 0xff), ((output >> 32) & 0xff), ((output >> 40) & 0xff), ((output >> 48) & 0xff), ((output >> 56) & 0xff)); mShareIDs.Add(mJsonRPCMessageID.ToString()); String message = JsonConvert.SerializeObject(new Dictionary <string, Object> { { "id", mJsonRPCMessageID++ }, { "jsonrpc", "2.0" }, { "method", "eth_submitWork" }, { "params", new List <string> { "0x" + stringNonce, "0x" + job.Headerhash, // The header's pow-hash (256 bits) "0x" + job.GetMixHash(output) // mix digest } } }); WriteLine(message); MainForm.Logger("Device #" + aDevice.DeviceIndex + " submitted a share."); } catch (Exception ex) { MainForm.Logger("Failed to submit share: " + ex.Message + ex.StackTrace); try { mMutex.ReleaseMutex(); } catch (Exception) { } Reconnect(); } try { mMutex.ReleaseMutex(); } catch (Exception) { } }
private void BuildEthashProgram() { ComputeDevice computeDevice = OpenCLDevice.GetComputeDevice(); try { mProgramArrayMutex.WaitOne(5000); } catch (Exception) { } if (mEthashProgramArray.ContainsKey(new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] })) { mEthashProgram = mEthashProgramArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }]; mEthashDAGKernel = mEthashDAGKernelArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }]; mEthashSearchKernel = mEthashSearchKernelArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }]; } else { String source = System.IO.File.ReadAllText(@"Kernels\ethash_lbry.cl"); mEthashProgram = new ComputeProgram(Context, source); MainForm.Logger(@"Loaded Kernels\ethash_lbry.cl for Device #" + DeviceIndex + "."); String buildOptions = (OpenCLDevice.GetVendor() == "AMD" ? "-O1 " : OpenCLDevice.GetVendor() == "NVIDIA" ? "" : // "-cl-nv-opt-level=1 -cl-nv-maxrregcount=256 " : "") + " -IKernels -DWORKSIZE=" + mEthashLocalWorkSizeArray[0]; try { mEthashProgram.Build(OpenCLDevice.DeviceList, buildOptions, null, IntPtr.Zero); } catch (Exception) { MainForm.Logger(mEthashProgram.GetBuildLog(computeDevice)); throw; } MainForm.Logger("Built Ethash program for Device #" + DeviceIndex + "."); MainForm.Logger("Build options: " + buildOptions); mEthashProgramArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }] = mEthashProgram; mEthashDAGKernelArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }] = mEthashDAGKernel = mEthashProgram.CreateKernel("GenerateDAG"); mEthashSearchKernelArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }] = mEthashSearchKernel = mEthashProgram.CreateKernel("search"); } try { mProgramArrayMutex.ReleaseMutex(); } catch (Exception) { } }
private void BuildEthashProgram() { ComputeDevice computeDevice = OpenCLDevice.GetComputeDevice(); try { mProgramArrayMutex.WaitOne(5000); } catch (Exception) { } if (mEthashProgramArray.ContainsKey(new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] })) { mEthashProgram = mEthashProgramArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }]; mEthashDAGKernel = mEthashDAGKernelArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }]; mEthashSearchKernel = mEthashSearchKernelArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }]; } else { mEthashProgram = BuildProgram("ethash_lbry", mEthashLocalWorkSizeArray[0], "-O1", "", ""); mEthashProgramArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }] = mEthashProgram; mEthashDAGKernelArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }] = mEthashDAGKernel = mEthashProgram.CreateKernel("GenerateDAG"); mEthashSearchKernelArray[new long[] { DeviceIndex, mEthashLocalWorkSizeArray[0] }] = mEthashSearchKernel = mEthashProgram.CreateKernel("search"); } try { mProgramArrayMutex.ReleaseMutex(); } catch (Exception) { } }
override unsafe protected void MinerThread() { ComputeProgram program = null; ComputeBuffer <byte> statesBuffer = null; ComputeBuffer <byte> scratchpadsBuffer = null; try { Random r = new Random(); var openCLName = OpenCLDevice.GetComputeDevice().Name; var GCN1 = openCLName == "Capeverde" || openCLName == "Hainan" || openCLName == "Oland" || openCLName == "Pitcairn" || openCLName == "Tahiti"; MarkAsAlive(); MainForm.Logger("Miner thread for Device #" + DeviceIndex + " started."); MainForm.Logger("NiceHash mode is " + (NiceHashMode ? "on" : "off") + "."); program = BuildProgram("cryptonight", localWorkSizeA[0], "-O5" + (GCN1 ? " -legacy" : ""), "", ""); statesBuffer = OpenCLDevice.RequestComputeByteBuffer(ComputeMemoryFlags.ReadWrite, 200 * globalWorkSizeA[0]); scratchpadsBuffer = OpenCLDevice.RequestComputeByteBuffer(ComputeMemoryFlags.ReadWrite, ((long)1 << 21) * globalWorkSizeA[0]); using (var searchKernel0 = program.CreateKernel("search")) using (var searchKernel1 = program.CreateKernel("search1")) using (var searchKernel2 = program.CreateKernel("search2")) using (var searchKernel3 = program.CreateKernel("search3")) using (var inputBuffer = new ComputeBuffer <byte>(Context, ComputeMemoryFlags.ReadOnly, 76)) using (var outputBuffer = new ComputeBuffer <UInt32>(Context, ComputeMemoryFlags.ReadWrite, outputSize)) using (var terminateBuffer = new ComputeBuffer <Int32>(Context, ComputeMemoryFlags.ReadWrite, 1)) fixed(Int32 *terminatePtr = terminate) fixed(byte *inputPtr = input) fixed(UInt32 * outputPtr = output) while (!Stopped) { MarkAsAlive(); MemoryUsage = 200 * globalWorkSizeA[0] + ((long)1 << 21) * globalWorkSizeA[0] + 76 + outputSize + 1; try { searchKernel0.SetMemoryArgument(0, inputBuffer); searchKernel0.SetMemoryArgument(1, scratchpadsBuffer); searchKernel0.SetMemoryArgument(2, statesBuffer); searchKernel1.SetMemoryArgument(0, scratchpadsBuffer); searchKernel1.SetMemoryArgument(1, statesBuffer); searchKernel1.SetMemoryArgument(2, terminateBuffer); searchKernel2.SetMemoryArgument(0, scratchpadsBuffer); searchKernel2.SetMemoryArgument(1, statesBuffer); searchKernel3.SetMemoryArgument(0, statesBuffer); searchKernel3.SetMemoryArgument(1, outputBuffer); // Wait for the first job to arrive. int elapsedTime = 0; while ((Stratum == null || Stratum.GetJob() == null) && elapsedTime < Parameters.TimeoutForFirstJobInMilliseconds && !Stopped) { Thread.Sleep(100); elapsedTime += 100; } if (Stratum == null || Stratum.GetJob() == null) { throw new TimeoutException("Stratum server failed to send a new job."); } System.Diagnostics.Stopwatch consoleUpdateStopwatch = new System.Diagnostics.Stopwatch(); CryptoNightStratum.Work work; CryptoNightStratum.Job job; while (!Stopped && (work = Stratum.GetWork()) != null && (job = work.GetJob()) != null) { MarkAsAlive(); Array.Copy(Utilities.StringToByteArray(job.Blob), input, 76); byte localExtranonce = (byte)work.LocalExtranonce; byte[] targetByteArray = Utilities.StringToByteArray(job.Target); UInt32 startNonce; if (NiceHashMode) { startNonce = ((UInt32)input[42] << (8 * 3)) | ((UInt32)localExtranonce << (8 * 2)) | (UInt32)(r.Next(0, int.MaxValue) & (0x0000ffffu)); } else { startNonce = ((UInt32)localExtranonce << (8 * 3)) | (UInt32)(r.Next(0, int.MaxValue) & (0x00ffffffu)); } UInt32 target = ((UInt32)targetByteArray[0] << 0) | ((UInt32)targetByteArray[1] << 8) | ((UInt32)targetByteArray[2] << 16) | ((UInt32)targetByteArray[3] << 24); searchKernel3.SetValueArgument <UInt32>(2, target); Queue.Write <byte>(inputBuffer, true, 0, 76, (IntPtr)inputPtr, null); consoleUpdateStopwatch.Start(); while (!Stopped && Stratum.GetJob() != null && Stratum.GetJob().Equals(job)) { MarkAsAlive(); globalWorkOffsetA[0] = globalWorkOffsetB[0] = startNonce; // Get a new local extranonce if necessary. if (NiceHashMode) { if ((startNonce & 0xffff) + (UInt32)globalWorkSizeA[0] >= 0x10000) { break; } } else { if ((startNonce & 0xffffff) + (UInt32)globalWorkSizeA[0] >= 0x1000000) { break; } } System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); output[255] = 0; // output[255] is used as an atomic counter. Queue.Write <UInt32>(outputBuffer, true, 0, outputSize, (IntPtr)outputPtr, null); terminate[0] = 0; Queue.Write <Int32>(terminateBuffer, true, 0, 1, (IntPtr)terminatePtr, null); Queue.Execute(searchKernel0, globalWorkOffsetA, globalWorkSizeA, localWorkSizeA, null); Queue.Finish(); if (Stopped) { break; } Queue.Execute(searchKernel1, globalWorkOffsetB, globalWorkSizeB, localWorkSizeB, null); Queue.Finish(); if (Stopped) { break; } Queue.Execute(searchKernel2, globalWorkOffsetA, globalWorkSizeA, localWorkSizeA, null); Queue.Finish(); if (Stopped) { break; } Queue.Execute(searchKernel3, globalWorkOffsetB, globalWorkSizeB, localWorkSizeB, null); Queue.Finish(); // Run the above statement before leaving the current local scope. if (Stopped) { break; } Queue.Read <UInt32>(outputBuffer, true, 0, outputSize, (IntPtr)outputPtr, null); if (Stratum.GetJob() != null && Stratum.GetJob().Equals(job)) { for (int i = 0; i < output[255]; ++i) { String result = ""; for (int j = 0; j < 8; ++j) { UInt32 word = output[256 + i * 8 + j]; result += String.Format("{0:x2}{1:x2}{2:x2}{3:x2}", ((word >> 0) & 0xff), ((word >> 8) & 0xff), ((word >> 16) & 0xff), ((word >> 24) & 0xff)); } Stratum.Submit(Device, job, output[i], result); } } startNonce += (UInt32)globalWorkSizeA[0]; sw.Stop(); Speed = ((double)globalWorkSizeA[0]) / sw.Elapsed.TotalSeconds; Device.TotalHashesPrimaryAlgorithm += (double)globalWorkSizeA[0]; if (consoleUpdateStopwatch.ElapsedMilliseconds >= 10 * 1000) { MainForm.Logger("Device #" + DeviceIndex + " (CryptoNight): " + String.Format("{0:N2} h/s", Speed)); consoleUpdateStopwatch.Restart(); } } } } catch (Exception ex) { if (statesBuffer != null) { OpenCLDevice.ReleaseComputeByteBuffer(statesBuffer); statesBuffer = null; } if (scratchpadsBuffer != null) { OpenCLDevice.ReleaseComputeByteBuffer(scratchpadsBuffer); scratchpadsBuffer = null; } MainForm.Logger("Exception in miner thread: " + ex.Message + ex.StackTrace); if (UnrecoverableException.IsUnrecoverableException(ex)) { this.UnrecoverableException = new UnrecoverableException(ex, Device); Stop(); } } Speed = 0; if (!Stopped) { MainForm.Logger("Restarting miner thread..."); System.Threading.Thread.Sleep(Parameters.WaitTimeForRestartingMinerThreadInMilliseconds); } } } catch (UnrecoverableException ex) { this.UnrecoverableException = ex; } catch (Exception ex) { this.UnrecoverableException = new UnrecoverableException(ex, Device); } finally { MarkAsDone(); MemoryUsage = 0; if (program != null) { program.Dispose(); program = null; } if (statesBuffer != null) { OpenCLDevice.ReleaseComputeByteBuffer(statesBuffer); statesBuffer = null; } if (scratchpadsBuffer != null) { OpenCLDevice.ReleaseComputeByteBuffer(scratchpadsBuffer); scratchpadsBuffer = null; } } }
public OpenCLCryptoNightMiner(OpenCLDevice aGatelessGateDevice) : base(aGatelessGateDevice, "cryptonight") { }
public void Start(EthashStratum aEthashStratum, PascalStratum aPascalStratum, int aEthashIntensity, int aPascalIterations) { mEthashStratum = aEthashStratum; mEthashLocalWorkSizeArray[0] = 256; mEthashGlobalWorkSizeArray[0] = aEthashIntensity * mEthashLocalWorkSizeArray[0] * OpenCLDevice.GetComputeDevice().MaxComputeUnits; mPascalStratum = aPascalStratum; mPascalRatio = (UInt32)aPascalIterations; base.Start(); }