Skip to content

Commit 62fdfde

Browse files
committed
stats
1 parent f5f0a4b commit 62fdfde

6 files changed

Lines changed: 97 additions & 31 deletions

File tree

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7-
cust = { git = "https://github.com/Rust-GPU/Rust-CUDA.git" }
7+
cust = { git = "https://github.com/LegNeato/Rust-CUDA.git", rev = "6a3b08bfaa3c3441f7e3d8a522ad444d794e35b5" }
88
hex = "0.4.3"
99
rand = "0.8"
1010

1111
[build-dependencies]
12-
#cuda_builder = { git = "https://github.com/LegNeato/Rust-CUDA.git", rev = "5bfda9ad027bfe1829c5c7263908ec0ed124c528" }
13-
cuda_builder = { git = "https://github.com/Rust-GPU/Rust-CUDA.git" }
12+
cuda_builder = { git = "https://github.com/LegNeato/Rust-CUDA.git", rev = "6a3b08bfaa3c3441f7e3d8a522ad444d794e35b5" }
13+
#cuda_builder = { git = "https://github.com/Rust-GPU/Rust-CUDA.git" }

kernel/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ edition = "2024"
77
crate-type = ["cdylib", "rlib"]
88

99
[dependencies]
10-
#cuda_std = { git = "https://github.com/LegNeato/Rust-CUDA.git", rev = "5bfda9ad027bfe1829c5c7263908ec0ed124c528" }
11-
#curve25519-dalek = { version = "4.1.3", default-features = false, features = ["alloc", "precomputed-tables"] }
10+
cuda_std = { git = "https://github.com/LegNeato/Rust-CUDA.git", rev = "6a3b08bfaa3c3441f7e3d8a522ad444d794e35b5" }
11+
curve25519-dalek = { version = "4.1.3", default-features = false, features = ["alloc", "precomputed-tables"] }
1212

13-
cuda_std = { git = "https://github.com/Rust-GPU/Rust-CUDA.git" }
14-
curve25519-dalek = { git = "https://github.com/brandonros/curve25519-dalek.git", rev = "5c453288e39eed68697c3a689f7adf14a3a93ef3", default-features = false, features = ["alloc", "precomputed-tables", "cuda"] }
13+
#cuda_std = { git = "https://github.com/Rust-GPU/Rust-CUDA.git" }
14+
#curve25519-dalek = { git = "https://github.com/brandonros/curve25519-dalek.git", rev = "5c453288e39eed68697c3a689f7adf14a3a93ef3", default-features = false, features = ["alloc", "precomputed-tables", "cuda"] }

rust-toolchain.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
[toolchain]
22
channel = "nightly-2025-03-02"
3-
components = ["clippy", "llvm-tools-preview", "rust-src", "rustc-dev", "rustfmt", "rust-analyzer"]
3+
components = [
4+
"clippy",
5+
"llvm-tools-preview",
6+
"rust-src",
7+
"rustc-dev",
8+
"rustfmt",
9+
"rust-analyzer"
10+
]

src/main.rs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
mod stats;
2+
13
use cust::device::Device;
24
use cust::module::{Module, ModuleJitOption};
35
use cust::prelude::Context;
@@ -13,7 +15,8 @@ fn device_main(
1315
ordinal: usize,
1416
vanity_prefix: String,
1517
blocks_per_grid: usize,
16-
threads_per_block: usize
18+
threads_per_block: usize,
19+
global_stats: Arc<GlobalStats>
1720
) -> Result<(), Box<dyn Error + Send + Sync>> {
1821
// check if the vanity prefix contains any of the forbidden characters
1922
assert!(vanity_prefix.contains("l") == false); // lowercase L
@@ -51,7 +54,6 @@ fn device_main(
5154
launches += 1;
5255
total_operations += operations_per_launch;
5356
let rng_seed: u64 = rng.r#gen::<u64>();
54-
//let rng_seed: u64 = 3314977520786701659;
5557

5658
let mut found_flag_slice = [0.0f32; 1];
5759
let mut found_private_key = [0u8; 32];
@@ -85,6 +87,9 @@ fn device_main(
8587

8688
stream.synchronize()?;
8789

90+
// increment stats
91+
global_stats.add_launch(operations_per_launch);
92+
8893
// Check if we found a match
8994
found_flag_slice_dev.copy_to(&mut found_flag_slice)?;
9095

@@ -95,20 +100,22 @@ fn device_main(
95100
found_bs58_encoded_public_key_dev.copy_to(&mut found_bs58_encoded_public_key)?;
96101
found_thread_idx_slice_dev.copy_to(&mut found_thread_idx_slice)?;
97102

98-
// print
103+
global_stats.add_matches(found_flag_slice[0] as usize);
104+
105+
// Format results
99106
let found_thread_idx = found_thread_idx_slice[0];
100107
let wallet_formatted_result = hex::encode([found_private_key, found_public_key].concat());
101108
let public_key_string = String::from_utf8(found_bs58_encoded_public_key.to_vec()).unwrap();
102-
println!("[{ordinal}] Found match: {rng_seed} {found_thread_idx} {public_key_string} {wallet_formatted_result}");
103-
104-
// increment stats
105-
matches_found += found_flag_slice[0] as usize;
106-
let elapsed = start_time.elapsed();
107-
let elapsed_seconds = elapsed.as_secs_f64();
108-
let launches_per_second = launches as f64 / elapsed_seconds;
109-
let operations_per_second = total_operations as f64 / elapsed_seconds / 1_000_000.00;
110-
let matches_per_second = matches_found as f64 / elapsed_seconds;
111-
println!("[{ordinal}] Found {matches_found} matches in {elapsed_seconds:.2}s ({matches_per_second:.6} matches/sec, {launches_per_second:.2} launches/sec, {operations_per_second:.2}M ops/sec) with {launches} launches {total_operations} operations {operations_per_launch} ops/launch {blocks_per_grid} blocks/grid {threads_per_block} threads/block");
109+
110+
// Print stats using global counters
111+
global_stats.print_stats(
112+
ordinal,
113+
found_flag_slice[0],
114+
&public_key_string,
115+
&wallet_formatted_result,
116+
rng_seed,
117+
found_thread_idx
118+
);
112119
}
113120
}
114121
}
@@ -121,16 +128,26 @@ fn main() -> Result<(), Box<dyn Error>> {
121128
let threads_per_block = args[3].parse::<usize>().unwrap();
122129

123130
// Initialize CUDA context and get default stream
124-
125131
cust::init(CudaFlags::empty())?;
126132
let num_devices = Device::num_devices()?;
127133
println!("Found {} CUDA devices", num_devices);
128134

135+
// Initialize global stats
136+
let global_stats = Arc::new(GlobalStats::new());
137+
138+
// start threads
129139
let mut handles = Vec::new();
130140
for i in 0..num_devices as usize {
131141
println!("Starting device {}", i);
132142
let vanity_prefix_clone = vanity_prefix.clone();
133-
let handle = std::thread::spawn(move || device_main(i, vanity_prefix_clone, blocks_per_grid, threads_per_block));
143+
let stats_clone = Arc::clone(&global_stats);
144+
let handle = std::thread::spawn(move || device_main(
145+
i,
146+
vanity_prefix_clone,
147+
blocks_per_grid,
148+
threads_per_block,
149+
stats_clone
150+
));
134151
handles.push(handle);
135152
}
136153
for handle in handles {

src/stats.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
pub struct GlobalStats {
2+
launches: AtomicUsize,
3+
matches_found: AtomicUsize,
4+
total_operations: AtomicU64,
5+
start_time: Instant,
6+
}
7+
8+
impl GlobalStats {
9+
pub fn new() -> Self {
10+
Self {
11+
launches: AtomicUsize::new(0),
12+
matches_found: AtomicUsize::new(0),
13+
total_operations: AtomicU64::new(0),
14+
start_time: Instant::now(),
15+
}
16+
}
17+
18+
fn add_launch(&self, operations: usize) {
19+
self.launches.fetch_add(1, Ordering::Relaxed);
20+
self.total_operations.fetch_add(operations as u64, Ordering::Relaxed);
21+
}
22+
23+
fn add_matches(&self, matches: usize) {
24+
self.matches_found.fetch_add(matches, Ordering::Relaxed);
25+
}
26+
27+
fn print_stats(&self, device_id: usize, matches_this_launch: f32, public_key: &str, wallet: &str, seed: u64, thread_idx: u32) {
28+
let launches = self.launches.load(Ordering::Relaxed);
29+
let matches = self.matches_found.load(Ordering::Relaxed);
30+
let operations = self.total_operations.load(Ordering::Relaxed);
31+
32+
let elapsed = self.start_time.elapsed();
33+
let elapsed_seconds = elapsed.as_secs_f64();
34+
let launches_per_second = launches as f64 / elapsed_seconds;
35+
let operations_per_second = operations as f64 / elapsed_seconds / 1_000_000.0;
36+
let matches_per_second = matches as f64 / elapsed_seconds;
37+
38+
println!("[{device_id}] Found {matches_this_launch} matches this launch");
39+
println!("[{device_id}] First match: seed = {seed} thread_idx = {thread_idx} public_key = {public_key} wallet = {wallet}");
40+
println!("[{device_id}] GLOBAL STATS: Found {matches} matches in {elapsed_seconds:.2}s ({matches_per_second:.6} matches/sec, {launches_per_second:.2} launches/sec, {operations_per_second:.2}M ops/sec) with {launches} total launches, {operations} total operations");
41+
}
42+
}

0 commit comments

Comments
 (0)