Skip to content

Commit 30ee8f0

Browse files
committed
Fixed an overflow problem in workload definition, and checks if kernel is fast enough
1 parent c770e27 commit 30ee8f0

File tree

9 files changed

+60
-45
lines changed

9 files changed

+60
-45
lines changed

.github/workflows/deploy.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ jobs:
8888
asset_name="kaspa-miner-${{ github.event.release.tag_name }}-cpu-only-osx-amd64"
8989
mkdir ${asset_name}
9090
mv ./target/x86_64-apple-darwin/release/kaspa-miner ${asset_name}/${asset_name}
91-
mv ./target/x86_64-apple-darwin/release/libkaspa*.so ${asset_name}/
9291
tar czvf ${asset_name}.tgz ${asset_name}
9392
echo "archive=${asset_name}.tgz" >> $GITHUB_ENV
9493
echo "asset_name=${asset_name}.tgz" >> $GITHUB_ENV

Cargo.lock

+8-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ num = "0.4"
4949
nix = "0.23"
5050
hex = "0.4"
5151
semver = "1.0"
52-
chrono = "0.4"
52+
time = { version = "0.3", features = ["formatting", "macros"] }
5353

5454
[features]
5555
default = ["parking_lot"]

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Build status](https://github.com/tmrlvi/kaspa-miner/workflows/ci/badge.svg)](https://github.com/tmrlvi/kaspa-miner/actions)
33
[![Latest version](https://img.shields.io/crates/v/kaspa-miner.svg)](https://crates.io/crates/kaspa-miner)
44
![License](https://img.shields.io/crates/l/kaspa-miner.svg)
5-
[![dependency status](https://deps.rs/repo/github/tmrlvi/kaspa-miner/status.svg)](https://deps.rs/repo/github/elichai/kaspa-miner)
5+
[![dependency status](https://deps.rs/repo/github/tmrlvi/kaspa-miner/status.svg)](https://deps.rs/repo/github/tmrlvi/kaspa-miner)
66

77
[![Discord](https://discordapp.com/api/guilds/599153230659846165/embed.png)](https://discord.gg/kS3SK5F36R)
88
[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)](https://t.me/Kaspaenglish)

integrations/windows/create_bat.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
echo :start > ${1}/mine.bat
1+
echo REM When mining to a local node, you can drop the -s option. > ${1}/mine.bat
2+
echo echo =========================================================== >> ${1}/mine.bat
3+
echo echo = Running Kaspa Miner With Defualt Bat. Edit to configure = >> ${1}/mine.bat
4+
echo echo =========================================================== >> ${1}/mine.bat
5+
echo :start >> ${1}/mine.bat
26
echo ${1}.exe -a kaspa:qz4jdyu04hv4hpyy00pl6trzw4gllnhnwy62xattejv2vaj5r0p5quvns058f -s n.seeder1.kaspad.net >> ${1}/mine.bat
37
echo goto start >> ${1}/mine.bat

plugins/cuda/src/worker.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use rand::{Fill, RngCore};
1111
use std::ffi::CString;
1212
use std::sync::{Arc, Weak};
1313

14+
static BPS: f32 = 1.;
15+
1416
static PTX_86: &str = include_str!("../resources/kaspa-cuda-sm86.ptx");
1517
static PTX_75: &str = include_str!("../resources/kaspa-cuda-sm75.ptx");
1618
static PTX_61: &str = include_str!("../resources/kaspa-cuda-sm61.ptx");
@@ -53,6 +55,8 @@ pub struct CudaGPUWorker<'gpu> {
5355
// NOTE: The order is important! context must be closed last
5456
heavy_hash_kernel: Kernel<'gpu>,
5557
stream: Stream,
58+
start_event: Event,
59+
stop_event: Event,
5660
_module: Arc<Module>,
5761

5862
rand_state: DeviceBuffer<u64>,
@@ -95,6 +99,7 @@ impl<'gpu> Worker for CudaGPUWorker<'gpu> {
9599
NonceGenEnum::Xoshiro => 1,
96100
};
97101

102+
self.start_event.record(stream).unwrap();
98103
unsafe {
99104
launch!(
100105
func<<<
@@ -110,11 +115,16 @@ impl<'gpu> Worker for CudaGPUWorker<'gpu> {
110115
)
111116
.unwrap(); // We see errors in sync
112117
}
118+
self.stop_event.record(stream).unwrap();
113119
}
114120

115121
#[inline(always)]
116122
fn sync(&self) -> Result<(), Error> {
117-
self.stream.synchronize()?;
123+
//self.stream.synchronize()?;
124+
self.stop_event.synchronize()?;
125+
if self.stop_event.elapsed_time_f32(&self.start_event)? > 1000. / BPS {
126+
return Err("Cuda takes longer then block rate. Please reduce your workload.".into());
127+
}
118128
Ok(())
119129
}
120130

@@ -183,32 +193,32 @@ impl<'gpu> CudaGPUWorker<'gpu> {
183193

184194
let mut heavy_hash_kernel = Kernel::new(Arc::downgrade(&_module), "heavy_hash")?;
185195

186-
let mut chosen_workload = 0usize;
196+
let mut chosen_workload = 0u32;
187197
if is_absolute {
188198
chosen_workload = 1;
189199
} else {
190200
let cur_workload = heavy_hash_kernel.get_workload();
191-
if chosen_workload == 0 || chosen_workload < cur_workload as usize {
192-
chosen_workload = cur_workload as usize;
201+
if chosen_workload == 0 || chosen_workload < cur_workload {
202+
chosen_workload = cur_workload;
193203
}
194204
}
195-
chosen_workload = (chosen_workload as f32 * workload) as usize;
205+
chosen_workload = (chosen_workload as f32 * workload) as u32;
196206
info!("GPU #{} Chosen workload: {}", device_id, chosen_workload);
197-
heavy_hash_kernel.set_workload(chosen_workload as u32);
207+
heavy_hash_kernel.set_workload(chosen_workload);
198208

199209
let final_nonce_buff = vec![0u64; 1].as_slice().as_dbuf()?;
200210

201211
let rand_state: DeviceBuffer<u64> = match random {
202212
NonceGenEnum::Xoshiro => {
203213
info!("Using xoshiro for nonce-generation");
204-
let mut buffer = DeviceBuffer::<u64>::zeroed(4 * chosen_workload).unwrap();
214+
let mut buffer = DeviceBuffer::<u64>::zeroed(4 * (chosen_workload as usize)).unwrap();
205215
info!("GPU #{} is generating initial seed. This may take some time.", device_id);
206216
let mut seed = [1u64; 4];
207217
seed.try_fill(&mut rand::thread_rng())?;
208218
buffer.copy_from(
209219
Xoshiro256StarStar::new(&seed)
210220
.iter_jump_state()
211-
.take(chosen_workload)
221+
.take(chosen_workload as usize)
212222
.flatten()
213223
.collect::<Vec<u64>>()
214224
.as_slice(),
@@ -228,7 +238,9 @@ impl<'gpu> CudaGPUWorker<'gpu> {
228238
device_id,
229239
_context,
230240
_module,
231-
workload: chosen_workload,
241+
start_event: Event::new(EventFlags::DEFAULT)?,
242+
stop_event: Event::new(EventFlags::DEFAULT)?,
243+
workload: chosen_workload as usize,
232244
stream,
233245
rand_state,
234246
final_nonce_buff,

src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ async fn main() -> Result<(), Error> {
135135
let mut opt: Opt = Opt::from_arg_matches(&matches)?;
136136
opt.process()?;
137137
env_logger::builder().filter_level(opt.log_level()).parse_default_env().init();
138+
info!("==============================");
139+
info!(" Kaspa-Miner GPU {}", env!("CARGO_PKG_VERSION"));
140+
info!("==============================");
138141
info!("Found plugins: {:?}", plugins);
139142
info!("Plugins found {} workers", worker_count);
140143
if worker_count == 0 && opt.num_threads.unwrap_or(0) == 0 {

src/miner.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,10 @@ impl MinerManager {
258258
None => continue,
259259
};
260260
state_ref.pow_gpu(gpu_work);
261-
gpu_work.sync().unwrap();
261+
if let Err(e) = gpu_work.sync() {
262+
warn!("CUDA run ignored: {}", e);
263+
continue
264+
}
262265

263266
gpu_work.copy_output_to(&mut nonces)?;
264267
if nonces[0] != 0 {
@@ -418,19 +421,29 @@ impl MinerManager {
418421
"Current hashrate is".into(),
419422
"Workers stalled or crashed. Considered reducing workload and check that your node is synced",
420423
duration,
424+
false,
421425
);
422426
for (device, rate) in &*hashes_by_worker.lock().unwrap() {
423-
Self::log_single_hashrate(rate, format!("Device {}:", device), "0 hash/s", duration);
427+
Self::log_single_hashrate(rate, format!("Device {}:", device), "0 hash/s", duration, true);
424428
}
425429
last_instant = now;
426430
}
427431
}
428432

429-
fn log_single_hashrate(counter: &Arc<AtomicU64>, prefix: String, warn_message: &str, duration: f64) {
433+
fn log_single_hashrate(
434+
counter: &Arc<AtomicU64>,
435+
prefix: String,
436+
warn_message: &str,
437+
duration: f64,
438+
keep_prefix: bool,
439+
) {
430440
let hashes = counter.swap(0, Ordering::AcqRel);
431441
let rate = (hashes as f64) / duration;
432442
if hashes == 0 {
433-
warn!("{}{}", prefix, warn_message)
443+
match keep_prefix {
444+
true => warn!("{}{}", prefix, warn_message),
445+
false => warn!("{}", warn_message),
446+
};
434447
} else if hashes != 0 {
435448
let (rate, suffix) = Self::hash_suffix(rate);
436449
info!("{} {:.2} {}", prefix, rate, suffix);

src/pow.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use chrono::{DateTime, Utc};
21
use log::info;
32
use std::sync::Arc;
43
use std::time::{Duration, UNIX_EPOCH};
4+
use time::{macros::format_description, OffsetDateTime};
55

66
pub use crate::pow::hasher::HeaderHasher;
77
use crate::{
@@ -41,13 +41,14 @@ impl BlockSeed {
4141
BlockSeed::FullBlock(block) => {
4242
let block_hash =
4343
block.block_hash().expect("We just got it from the state, we should be able to hash it");
44-
let block_time = DateTime::<Utc>::from(
44+
let format = format_description!("[year]-[month]-[day] [hour]:[minute]:[second]");
45+
let block_time = OffsetDateTime::from(
4546
UNIX_EPOCH + Duration::from_millis(block.header.as_ref().unwrap().timestamp as u64),
4647
);
4748
info!(
4849
"Found a block: {:x} (Timestamp: {})",
4950
block_hash,
50-
block_time.format("%Y-%m-%d %H:%M:%S").to_string()
51+
block_time.format(format).unwrap_or_else(|_| "unknown".to_string())
5152
);
5253
}
5354
BlockSeed::PartialBlock { .. } => info!("Found a share!"),

0 commit comments

Comments
 (0)