1+ mod stats;
2+
13use cust:: device:: Device ;
24use cust:: module:: { Module , ModuleJitOption } ;
35use 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 {
0 commit comments