1
- use ash:: vk;
2
- use ash:: Entry ;
3
1
use serde:: { Deserialize , Serialize } ;
4
2
use nvml_wrapper:: Nvml ;
5
3
use nvml_wrapper:: error:: NvmlError ;
6
4
use std:: error:: Error ;
7
- use std:: ffi:: CStr ;
8
5
use std:: fs:: { read_dir, read_to_string} ;
9
6
use std:: path:: PathBuf ;
7
+ use ash:: vk;
8
+ use ash:: Entry ;
9
+ use std:: ffi:: CStr ;
10
10
use std:: ptr;
11
11
12
12
#[ derive( Serialize , Deserialize , Debug ) ]
@@ -114,10 +114,10 @@ fn read_hwmon_info(
114
114
115
115
if let Ok ( power_input) = read_to_string ( hwmon_path. join ( "power1_average" ) ) {
116
116
let power_mw = power_input. trim ( ) . parse :: < u64 > ( ) . unwrap_or ( 0 ) ;
117
- wattage = Some ( format ! ( "{:.3} W" , power_mw as f64 / 1000 .0) ) ; // Divide by 1000 to convert mW to W
117
+ wattage = Some ( format ! ( "{:.3} W" , power_mw as f64 / 1000000 .0) ) ;
118
118
} else if let Ok ( power_input) = read_to_string ( hwmon_path. join ( "power1_input" ) ) {
119
119
let power_mw = power_input. trim ( ) . parse :: < u64 > ( ) . unwrap_or ( 0 ) ;
120
- wattage = Some ( format ! ( "{:.3} W" , power_mw as f64 / 1000 .0) ) ; // Divide by 1000 to convert mW to W
120
+ wattage = Some ( format ! ( "{:.3} W" , power_mw as f64 / 1000000 .0) ) ;
121
121
}
122
122
}
123
123
}
@@ -126,6 +126,71 @@ fn read_hwmon_info(
126
126
( fan_speed, temperature, clock_speed, wattage)
127
127
}
128
128
129
+ fn get_amd_gpu_name ( ) -> String {
130
+ // Initialize Vulkan entry point
131
+ let entry = unsafe { Entry :: load ( ) . expect ( "Failed to create Vulkan entry" ) } ;
132
+
133
+ // Create a Vulkan instance
134
+ let app_name = CStr :: from_bytes_with_nul ( b"AMD GPU Detector\0 " ) . unwrap ( ) ;
135
+ let engine_name = CStr :: from_bytes_with_nul ( b"No Engine\0 " ) . unwrap ( ) ;
136
+
137
+ let app_info = vk:: ApplicationInfo {
138
+ s_type : vk:: StructureType :: APPLICATION_INFO ,
139
+ p_next : ptr:: null ( ) ,
140
+ p_application_name : app_name. as_ptr ( ) ,
141
+ p_engine_name : engine_name. as_ptr ( ) ,
142
+ application_version : vk:: make_api_version ( 0 , 1 , 0 , 0 ) ,
143
+ engine_version : vk:: make_api_version ( 0 , 1 , 0 , 0 ) ,
144
+ api_version : vk:: make_api_version ( 0 , 1 , 0 , 0 ) ,
145
+ } ;
146
+
147
+ let create_info = vk:: InstanceCreateInfo {
148
+ s_type : vk:: StructureType :: INSTANCE_CREATE_INFO ,
149
+ p_next : ptr:: null ( ) ,
150
+ flags : vk:: InstanceCreateFlags :: empty ( ) ,
151
+ p_application_info : & app_info,
152
+ enabled_layer_count : 0 ,
153
+ pp_enabled_layer_names : ptr:: null ( ) ,
154
+ enabled_extension_count : 0 ,
155
+ pp_enabled_extension_names : ptr:: null ( ) ,
156
+ } ;
157
+
158
+ let instance = unsafe {
159
+ entry
160
+ . create_instance ( & create_info, None )
161
+ . expect ( "Failed to create Vulkan instance" )
162
+ } ;
163
+
164
+ // Enumerate physical devices (GPUs)
165
+ let physical_devices = unsafe {
166
+ instance
167
+ . enumerate_physical_devices ( )
168
+ . expect ( "Failed to enumerate physical devices" )
169
+ } ;
170
+
171
+ // Get the name of the first GPU
172
+ let device_name = if let Some ( & device) = physical_devices. first ( ) {
173
+ // Get device properties
174
+ let properties = unsafe { instance. get_physical_device_properties ( device) } ;
175
+
176
+ // Convert the device name to a Rust String
177
+ unsafe {
178
+ CStr :: from_ptr ( properties. device_name . as_ptr ( ) )
179
+ . to_string_lossy ( )
180
+ . into_owned ( )
181
+ }
182
+ } else {
183
+ String :: from ( "No GPU found" )
184
+ } ;
185
+
186
+ // Clean up Vulkan instance
187
+ unsafe {
188
+ instance. destroy_instance ( None ) ;
189
+ }
190
+
191
+ device_name
192
+ }
193
+
129
194
fn get_amd_gpu_info ( ) -> Result < GpuInformations , Box < dyn Error > > {
130
195
let drm_path = PathBuf :: from ( "/sys/class/drm/" ) ;
131
196
let mut amd_gpu_path = None ;
@@ -184,7 +249,7 @@ fn get_amd_gpu_info() -> Result<GpuInformations, Box<dyn Error>> {
184
249
let utilization = read_gpu_busy_percent ( & device_path) ;
185
250
186
251
Ok ( GpuInformations {
187
- name : Some ( "AMD GPU" . to_string ( ) ) ,
252
+ name : Some ( get_amd_gpu_name ( ) ) ,
188
253
driver_version : None ,
189
254
memory_total,
190
255
memory_used,
0 commit comments