@@ -49,81 +49,82 @@ impl Plugin for CudaPlugin {
49
49
}
50
50
51
51
//noinspection RsTypeCheck
52
- fn process_option ( & mut self , matches : & ArgMatches ) -> Result < ( ) , kaspa_miner:: Error > {
52
+ fn process_option ( & mut self , matches : & ArgMatches ) -> Result < usize , kaspa_miner:: Error > {
53
53
let opts: CudaOpt = CudaOpt :: from_arg_matches ( matches) ?;
54
54
55
55
self . _enabled = !opts. cuda_disable ;
56
+ if self . _enabled {
57
+ let gpus: Vec < u16 > = match & opts. cuda_device {
58
+ Some ( devices) => devices. clone ( ) ,
59
+ None => {
60
+ let gpu_count = Device :: num_devices ( ) . unwrap ( ) as u16 ;
61
+ ( 0 ..gpu_count) . collect ( )
62
+ }
63
+ } ;
64
+
65
+ // if any of cuda_lock_core_clocks / cuda_lock_mem_clocks / cuda_power_limit is valid, init nvml and try to apply
66
+ if opts. cuda_lock_core_clocks . is_some ( )
67
+ || opts. cuda_lock_mem_clocks . is_some ( )
68
+ || opts. cuda_power_limits . is_some ( )
69
+ {
70
+ for i in 0 ..gpus. len ( ) {
71
+ let lock_mem_clock: Option < u32 > = match & opts. cuda_lock_mem_clocks {
72
+ Some ( mem_clocks) if i < mem_clocks. len ( ) => Some ( mem_clocks[ i] ) ,
73
+ Some ( mem_clocks) if !mem_clocks. is_empty ( ) => Some ( * mem_clocks. last ( ) . unwrap ( ) ) ,
74
+ _ => None ,
75
+ } ;
56
76
57
- let gpus: Vec < u16 > = match & opts. cuda_device {
58
- Some ( devices) => devices. clone ( ) ,
59
- None => {
60
- let gpu_count = Device :: num_devices ( ) . unwrap ( ) as u16 ;
61
- ( 0 ..gpu_count) . collect ( )
62
- }
63
- } ;
64
-
65
- // if any of cuda_lock_core_clocks / cuda_lock_mem_clocks / cuda_power_limit is valid, init nvml and try to apply
66
- if opts. cuda_lock_core_clocks . is_some ( )
67
- || opts. cuda_lock_mem_clocks . is_some ( )
68
- || opts. cuda_power_limits . is_some ( )
69
- {
70
- for i in 0 ..gpus. len ( ) {
71
- let lock_mem_clock: Option < u32 > = match & opts. cuda_lock_mem_clocks {
72
- Some ( mem_clocks) if i < mem_clocks. len ( ) => Some ( mem_clocks[ i] ) ,
73
- Some ( mem_clocks) if !mem_clocks. is_empty ( ) => Some ( * mem_clocks. last ( ) . unwrap ( ) ) ,
74
- _ => None ,
75
- } ;
76
-
77
- let lock_core_clock: Option < u32 > = match & opts. cuda_lock_core_clocks {
78
- Some ( core_clocks) if i < core_clocks. len ( ) => Some ( core_clocks[ i] ) ,
79
- Some ( core_clocks) if !core_clocks. is_empty ( ) => Some ( * core_clocks. last ( ) . unwrap ( ) ) ,
80
- _ => None ,
81
- } ;
82
-
83
- let power_limit: Option < u32 > = match & opts. cuda_power_limits {
84
- Some ( power_limits) if i < power_limits. len ( ) => Some ( power_limits[ i] ) ,
85
- Some ( power_limits) if !power_limits. is_empty ( ) => Some ( * power_limits. last ( ) . unwrap ( ) ) ,
86
- _ => None ,
87
- } ;
88
-
89
- let mut nvml_device: NvmlDevice = self . nvml_instance . device_by_index ( gpus[ i] as u32 ) ?;
90
-
91
- if let Some ( lmc) = lock_mem_clock {
92
- match nvml_device. set_mem_locked_clocks ( lmc, lmc) {
93
- Err ( e) => error ! ( "set mem locked clocks {:?}" , e) ,
94
- _ => info ! ( "GPU #{} #{} lock mem clock at {} Mhz" , i, & nvml_device. name( ) ?, & lmc) ,
77
+ let lock_core_clock: Option < u32 > = match & opts. cuda_lock_core_clocks {
78
+ Some ( core_clocks) if i < core_clocks. len ( ) => Some ( core_clocks[ i] ) ,
79
+ Some ( core_clocks) if !core_clocks. is_empty ( ) => Some ( * core_clocks. last ( ) . unwrap ( ) ) ,
80
+ _ => None ,
95
81
} ;
96
- }
97
82
98
- if let Some ( lcc ) = lock_core_clock {
99
- match nvml_device . set_gpu_locked_clocks ( lcc , lcc ) {
100
- Err ( e ) => error ! ( "set gpu locked clocks {:?}" , e ) ,
101
- _ => info ! ( "GPU #{} #{} lock core clock at {} Mhz" , i , & nvml_device . name ( ) ? , & lcc ) ,
83
+ let power_limit : Option < u32 > = match & opts . cuda_power_limits {
84
+ Some ( power_limits ) if i < power_limits . len ( ) => Some ( power_limits [ i ] ) ,
85
+ Some ( power_limits ) if !power_limits . is_empty ( ) => Some ( * power_limits . last ( ) . unwrap ( ) ) ,
86
+ _ => None ,
102
87
} ;
103
- } ;
104
88
105
- if let Some ( pl) = power_limit {
106
- match nvml_device. set_power_management_limit ( pl * 1000 ) {
107
- Err ( e) => error ! ( "set power limit {:?}" , e) ,
108
- _ => info ! ( "GPU #{} #{} power limit at {} W" , i, & nvml_device. name( ) ?, & pl) ,
89
+ let mut nvml_device: NvmlDevice = self . nvml_instance . device_by_index ( gpus[ i] as u32 ) ?;
90
+
91
+ if let Some ( lmc) = lock_mem_clock {
92
+ match nvml_device. set_mem_locked_clocks ( lmc, lmc) {
93
+ Err ( e) => error ! ( "set mem locked clocks {:?}" , e) ,
94
+ _ => info ! ( "GPU #{} #{} lock mem clock at {} Mhz" , i, & nvml_device. name( ) ?, & lmc) ,
95
+ } ;
96
+ }
97
+
98
+ if let Some ( lcc) = lock_core_clock {
99
+ match nvml_device. set_gpu_locked_clocks ( lcc, lcc) {
100
+ Err ( e) => error ! ( "set gpu locked clocks {:?}" , e) ,
101
+ _ => info ! ( "GPU #{} #{} lock core clock at {} Mhz" , i, & nvml_device. name( ) ?, & lcc) ,
102
+ } ;
109
103
} ;
110
- } ;
104
+
105
+ if let Some ( pl) = power_limit {
106
+ match nvml_device. set_power_management_limit ( pl * 1000 ) {
107
+ Err ( e) => error ! ( "set power limit {:?}" , e) ,
108
+ _ => info ! ( "GPU #{} #{} power limit at {} W" , i, & nvml_device. name( ) ?, & pl) ,
109
+ } ;
110
+ } ;
111
+ }
111
112
}
112
- }
113
113
114
- self . specs = ( 0 ..gpus. len ( ) )
115
- . map ( |i| CudaWorkerSpec {
116
- device_id : gpus[ i] as u32 ,
117
- workload : match & opts. cuda_workload {
118
- Some ( workload) if i < workload. len ( ) => workload[ i] ,
119
- Some ( workload) if !workload. is_empty ( ) => * workload. last ( ) . unwrap ( ) ,
120
- _ => DEFAULT_WORKLOAD_SCALE ,
121
- } ,
122
- is_absolute : opts. cuda_workload_absolute ,
123
- blocking_sync : !opts. cuda_no_blocking_sync ,
124
- } )
125
- . collect ( ) ;
126
- Ok ( ( ) )
114
+ self . specs = ( 0 ..gpus. len ( ) )
115
+ . map ( |i| CudaWorkerSpec {
116
+ device_id : gpus[ i] as u32 ,
117
+ workload : match & opts. cuda_workload {
118
+ Some ( workload) if i < workload. len ( ) => workload[ i] ,
119
+ Some ( workload) if !workload. is_empty ( ) => * workload. last ( ) . unwrap ( ) ,
120
+ _ => DEFAULT_WORKLOAD_SCALE ,
121
+ } ,
122
+ is_absolute : opts. cuda_workload_absolute ,
123
+ blocking_sync : !opts. cuda_no_blocking_sync ,
124
+ } )
125
+ . collect ( ) ;
126
+ }
127
+ Ok ( self . specs . len ( ) )
127
128
}
128
129
}
129
130
0 commit comments