Debian Codegraph @

rust-interface/src/amdsmi.rs

raw
1 // Copyright (C) 2024 Advanced Micro Devices. All rights reserved.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy of
4 // this software and associated documentation files (the "Software"), to deal in
5 // the Software without restriction, including without limitation the rights to
6 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 // the Software, and to permit persons to whom the Software is furnished to do so,
8 // subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in all
11 // copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20
21 use crate::amdsmi_wrapper;
22 use crate::utils::*;
23 use libc::free;
24 use std::mem::MaybeUninit;
25 use std::os::raw::c_void;
26 use std::ptr::null_mut;
27
28 /// Initializes the AMD SMI library.
29 ///
30 /// This function must be called before any other AMD SMI functions are used.
31 /// It initializes the library with the specified flags.
32 ///
33 /// # Arguments
34 ///
35 /// * `init_flags` - Use a [`ProcessorTypeT`] for initialization flags.
36 ///
37 /// # Returns
38 ///
39 /// * `AmdsmiResult<()>` - Returns `Ok(())` if the initialization is successful, or an error if it fails.
40 ///
41 /// # Example
42 ///
43 /// ```rust
44 /// # use amdsmi::*;
45 /// #
46 /// # fn main() {
47 /// match amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus) {
48 /// Ok(_) => println!("AMD SMI initialized successfully"),
49 /// Err(e) => panic!("Failed to initialize AMD SMI: {}", e),
50 /// }
51 /// //Perform various tasks by invoking additional AMD SMI functions
52 /// //...
53 ///
54 /// // Shut down the AMD SMI library
55 /// amdsmi_shut_down().expect("Failed to shut down AMD SMI");
56 /// # }
57 /// ```
58 ///
59 /// # Errors
60 ///
61 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_init` call fails.
62 pub fn amdsmi_init(init_flags: AmdsmiInitFlagsT) -> AmdsmiResult<()> {
63 call_unsafe!(amdsmi_wrapper::amdsmi_init(init_flags as u64));
64 Ok(())
65 }
66
67 /// Shuts down the AMD SMI library.
68 ///
69 /// This function should be called when the AMD SMI library is no longer needed.
70 /// It performs any necessary cleanup and releases resources allocated by the library.
71 ///
72 /// # Returns
73 ///
74 /// * `AmdsmiResult<()>` - Returns `Ok(())` if the shutdown is successful, or an error if it fails.
75 ///
76 /// # Example
77 ///
78 /// ```rust
79 /// # use amdsmi::*;
80 /// #
81 /// # fn main() {
82 /// // Initialize the AMD SMI library
83 /// amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
84 ///
85 /// // Perform operations with the AMD SMI library
86 /// // ...
87 /// #
88 /// # // Shut down the AMD SMI library
89 /// match amdsmi_shut_down() {
90 /// Ok(_) => println!("AMD SMI shut down successfully"),
91 /// Err(e) => panic!("Failed to shut down AMD SMI: {}", e),
92 /// }
93 /// # }
94 /// ```
95 ///
96 /// # Errors
97 ///
98 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_shut_down` call fails.
99 pub fn amdsmi_shut_down() -> AmdsmiResult<()> {
100 call_unsafe!(amdsmi_wrapper::amdsmi_shut_down());
101 Ok(())
102 }
103
104 /// Retrieves the socket handles for the AMD SMI library.
105 ///
106 /// This function returns a list of socket handles available in the system.
107 /// Each handle can be used to query further information about the corresponding socket.
108 ///
109 /// # Returns
110 ///
111 /// * `AmdsmiResult<Vec<AmdsmiSocketHandle>>` - Returns `Ok(Vec<AmdsmiSocketHandle>)` containing the list of [`AmdsmiSocketHandle`] if successful, or an error if it fails.
112 ///
113 /// # Example
114 ///
115 /// ```rust
116 /// # use amdsmi::*;
117 /// #
118 /// # fn main() {
119 /// # // Initialize the AMD SMI library
120 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
121 /// #
122 /// // Retrieve the socket handles
123 /// match amdsmi_get_socket_handles() {
124 /// Ok(handles) => {
125 /// for handle in handles {
126 /// // Perform operations with the AMD SMI library
127 /// // ...
128 /// }
129 /// }
130 /// Err(e) => panic!("Failed to get socket handles: {}", e),
131 /// }
132 /// #
133 /// # // Shut down the AMD SMI library
134 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
135 /// # }
136 /// ```
137 ///
138 /// # Errors
139 ///
140 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_socket_handles` call fails.
141 pub fn amdsmi_get_socket_handles() -> AmdsmiResult<Vec<AmdsmiSocketHandle>> {
142 let mut socket_count: u32 = 0;
143 call_unsafe!(amdsmi_wrapper::amdsmi_get_socket_handles(
144 &mut socket_count,
145 std::ptr::null_mut()
146 ));
147
148 let mut socket_handles = Vec::with_capacity(socket_count as usize);
149 call_unsafe!(amdsmi_wrapper::amdsmi_get_socket_handles(
150 &mut socket_count,
151 socket_handles.as_mut_ptr()
152 ));
153
154 unsafe { socket_handles.set_len(socket_count as usize) };
155 Ok(socket_handles)
156 }
157
158 /// Retrieves information about a specific socket.
159 ///
160 /// This function returns a string containing information about the specified socket handle.
161 ///
162 /// # Arguments
163 ///
164 /// * `socket_handle` - A handle to the socket for which information is being queried.
165 ///
166 /// # Returns
167 ///
168 /// * `AmdsmiResult<String>` - Returns `Ok(String)` containing the socket information if successful, or an error if it fails.
169 ///
170 /// # Example
171 ///
172 /// ```rust
173 /// # use amdsmi::*;
174 /// #
175 /// # fn main() {
176 /// # // Initialize the AMD SMI library
177 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
178 /// #
179 /// // Example socket handle, Get socket handle from amdsmi_get_socket_handles() function
180 /// let socket_handle = amdsmi_get_socket_handles().unwrap()[0];
181 ///
182 /// // Retrieve the socket information
183 /// match amdsmi_get_socket_info(socket_handle) {
184 /// Ok(info) => println!("Socket info: {}", info),
185 /// Err(e) => panic!("Failed to get socket info: {}", e),
186 /// }
187 /// #
188 /// # // Shut down the AMD SMI library
189 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
190 /// # }
191 /// ```
192 ///
193 /// # Errors
194 ///
195 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_socket_info` call fails.
196 pub fn amdsmi_get_socket_info(socket_handle: AmdsmiSocketHandle) -> AmdsmiResult<String> {
197 let (mut info, len) = define_cstr!(amdsmi_wrapper::AMDSMI_MAX_STRING_LENGTH);
198 call_unsafe!(amdsmi_wrapper::amdsmi_get_socket_info(
199 socket_handle,
200 len,
201 info.as_mut_ptr(),
202 ));
203 Ok(cstr_to_string!(info))
204 }
205
206 /// Retrieves the processor handles for a given socket.
207 ///
208 /// This function returns a list of processor handles associated with the specified socket handle.
209 /// Each handle can be used to query further information about the corresponding processor.
210 ///
211 /// # Arguments
212 ///
213 /// * `socket_handle` - A handle to the socket for which processor handles are being queried.
214 ///
215 /// # Returns
216 ///
217 /// * `AmdsmiResult<Vec<AmdsmiProcessorHandle>>` - Returns `Ok(Vec<AmdsmiProcessorHandle>)` containing the list of [`AmdsmiProcessorHandle`] if successful, or an error if it fails.
218 ///
219 /// # Example
220 ///
221 /// ```rust
222 /// # use amdsmi::*;
223 /// #
224 /// # fn main() {
225 /// # // Initialize the AMD SMI library
226 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
227 /// #
228 /// // Example socket handle, can get from amdsmi_get_socket_handles() function
229 /// let socket_handle = amdsmi_get_socket_handles().unwrap()[0];
230 ///
231 /// // Retrieve the processor handles
232 /// match amdsmi_get_processor_handles(socket_handle) {
233 /// Ok(handles) => {
234 /// for handle in handles {
235 /// // Perform operations with the AMD SMI library
236 /// // ...
237 /// }
238 /// }
239 /// Err(e) => panic!("Failed to get processor handles: {}", e),
240 /// }
241 /// #
242 /// # // Shut down the AMD SMI library
243 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
244 /// # }
245 /// ```
246 ///
247 /// # Errors
248 ///
249 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_processor_handles` call fails.
250 pub fn amdsmi_get_processor_handles(
251 socket_handle: AmdsmiSocketHandle,
252 ) -> AmdsmiResult<Vec<AmdsmiProcessorHandle>> {
253 let mut processor_count: u32 = 0;
254 call_unsafe!(amdsmi_wrapper::amdsmi_get_processor_handles(
255 socket_handle,
256 &mut processor_count,
257 std::ptr::null_mut()
258 ));
259
260 let mut processor_handles = Vec::with_capacity(processor_count as usize);
261 call_unsafe!(amdsmi_wrapper::amdsmi_get_processor_handles(
262 socket_handle,
263 &mut processor_count,
264 processor_handles.as_mut_ptr()
265 ));
266
267 unsafe {
268 processor_handles.set_len(processor_count as usize);
269 }
270 Ok(processor_handles)
271 }
272
273 /// Retrieves the type of a specific processor.
274 ///
275 /// This function returns the processor type of the specified processor handle.
276 ///
277 /// # Arguments
278 ///
279 /// * `processor_handle` - A handle to the processor for which the type is being queried.
280 ///
281 /// # Returns
282 ///
283 /// * `AmdsmiResult<ProcessorTypeT>` - Returns `Ok(ProcessorTypeT)` containing the [`ProcessorTypeT`] if successful, or an error if it fails.
284 ///
285 /// # Example
286 ///
287 /// ```rust
288 /// # use amdsmi::*;
289 /// #
290 /// # fn main() {
291 /// # // Initialize the AMD SMI library
292 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
293 /// #
294 /// // Example processor_handle, assuming the number of processors is greater than zero
295 /// let processor_handle = amdsmi_get_processor_handles!()[0];
296 ///
297 /// // Retrieve the processor type
298 /// match amdsmi_get_processor_type(processor_handle) {
299 /// Ok(processor_type) => println!("Processor type: {:?}", processor_type),
300 /// Err(e) => panic!("Failed to get processor type: {}", e),
301 /// }
302 /// #
303 /// # // Shut down the AMD SMI library
304 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
305 /// # }
306 /// ```
307 ///
308 /// # Errors
309 ///
310 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_processor_type` call fails.
311 pub fn amdsmi_get_processor_type(
312 processor_handle: AmdsmiProcessorHandle,
313 ) -> AmdsmiResult<ProcessorTypeT> {
314 let mut processor_type = ProcessorTypeT::AmdsmiProcessorTypeUnknown;
315 call_unsafe!(amdsmi_wrapper::amdsmi_get_processor_type(
316 processor_handle,
317 &mut processor_type
318 ));
319 Ok(processor_type)
320 }
321
322 ///Retrieves the processor handle for a given Bus-Device-Function (BDF) address.
323 ///
324 /// This function returns a handle to the processor associated with the specified BDF address.
325 /// The BDF address is a unique identifier for a device on the PCI bus.
326 ///
327 /// # Arguments
328 ///
329 /// * `bdf` - A [`AmdsmiBdfT`] representing the Bus-Device-Function (BDF) address.
330 ///
331 /// # Returns
332 ///
333 /// * `AmdsmiResult<AmdsmiProcessorHandle>` - Returns `Ok(AmdsmiProcessorHandle)` containing the [`AmdsmiProcessorHandle`] if successful, or an error if it fails.
334 ///
335 /// # Example
336 ///
337 /// ```rust
338 /// # use amdsmi::*;
339 /// #
340 /// # fn main() {
341 /// # // Initialize the AMD SMI library
342 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
343 /// #
344 /// // Get a processor_handle from the amdsmi_get_processor_handles() function
345 /// let processor_handle_example = amdsmi_get_processor_handles!()[0];
346 /// // Example BDF
347 /// let bdf = amdsmi_get_gpu_device_bdf(processor_handle_example).expect("Failed to get BDF");
348 ///
349 /// // Retrieve the processor handle
350 /// let processor_handle = amdsmi_get_processor_handle_from_bdf(bdf).expect("Failed to get processor handle");
351 ///
352 /// assert_eq!(processor_handle, processor_handle_example);
353 /// #
354 /// # // Shut down the AMD SMI library
355 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
356 /// # }
357 /// ```
358 ///
359 /// # Errors
360 ///
361 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_processor_handle_from_bdf` call fails.
362 pub fn amdsmi_get_processor_handle_from_bdf(
363 bdf: AmdsmiBdfT,
364 ) -> AmdsmiResult<AmdsmiProcessorHandle> {
365 let mut processor_handle = MaybeUninit::<AmdsmiProcessorHandle>::uninit();
366 call_unsafe!(amdsmi_wrapper::amdsmi_get_processor_handle_from_bdf(
367 bdf,
368 processor_handle.as_mut_ptr()
369 ));
370 Ok(unsafe { processor_handle.assume_init() })
371 }
372
373 /// Retrieves the GPU ID for a given processor handle.
374 ///
375 /// This function returns the GPU ID associated with the specified processor handle.
376 /// The GPU ID is a unique identifier for the GPU.
377 ///
378 /// # Arguments
379 ///
380 /// * `processor_handle` - A handle to the processor for which the GPU ID is being queried.
381 ///
382 /// # Returns
383 ///
384 /// * `AmdsmiResult<u32>` - Returns `Ok(u32)` containing the GPU ID if successful, or an error if it fails.
385 ///
386 /// # Example
387 ///
388 /// ```rust
389 /// # use amdsmi::*;
390 /// #
391 /// # fn main() {
392 /// # // Initialize the AMD SMI library
393 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
394 /// #
395 /// // Example processor_handle, assuming the number of processors is greater than zero
396 /// let processor_handle = amdsmi_get_processor_handles!()[0];
397 ///
398 /// // Retrieve the GPU ID
399 /// match amdsmi_get_gpu_id(processor_handle) {
400 /// Ok(gpu_id) => println!("GPU ID: {}", gpu_id),
401 /// Err(e) => panic!("Failed to get GPU ID: {}", e),
402 /// }
403 /// #
404 /// # // Shut down the AMD SMI library
405 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
406 /// # }
407 /// ```
408 ///
409 /// # Errors
410 ///
411 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_id` call fails.
412 pub fn amdsmi_get_gpu_id(processor_handle: AmdsmiProcessorHandle) -> AmdsmiResult<u16> {
413 let mut id: u16 = 0;
414 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_id(processor_handle, &mut id));
415 Ok(id)
416 }
417
418 /// Retrieves the GPU revision for a given processor handle.
419 ///
420 /// This function returns the GPU revision associated with the specified processor handle.
421 ///
422 /// # Arguments
423 ///
424 /// * `processor_handle` - A handle to the processor for which the GPU revision is being queried.
425 ///
426 /// # Returns
427 ///
428 /// * `AmdsmiResult<u32>` - Returns `Ok(u32)` containing the GPU revision if successful, or an error if it fails.
429 ///
430 /// # Example
431 ///
432 /// ```rust
433 /// # use amdsmi::*;
434 /// #
435 /// # fn main() {
436 /// # // Initialize the AMD SMI library
437 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
438 /// #
439 /// // Example processor_handle, assuming the number of processors is greater than zero
440 /// let processor_handle = amdsmi_get_processor_handles!()[0];
441 ///
442 /// // Retrieve the GPU revision
443 /// match amdsmi_get_gpu_revision(processor_handle) {
444 /// Ok(gpu_revision) => println!("GPU Revision: {}", gpu_revision),
445 /// Err(e) => panic!("Failed to get GPU revision: {}", e),
446 /// }
447 /// #
448 /// # // Shut down the AMD SMI library
449 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
450 /// # }
451 /// ```
452 ///
453 /// # Errors
454 ///
455 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_revision` call fails.
456 pub fn amdsmi_get_gpu_revision(processor_handle: AmdsmiProcessorHandle) -> AmdsmiResult<u16> {
457 let mut revision: u16 = 0;
458 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_revision(
459 processor_handle,
460 &mut revision
461 ));
462 Ok(revision)
463 }
464
465 /// Retrieves the GPU vendor name for a given processor handle.
466 ///
467 /// This function returns the GPU vendor name associated with the specified processor handle.
468 /// The vendor name provides information about the manufacturer of the GPU.
469 ///
470 /// # Arguments
471 ///
472 /// * `processor_handle` - A handle to the processor for which the GPU vendor name is being queried.
473 ///
474 /// # Returns
475 ///
476 /// * `AmdsmiResult<String>` - Returns `Ok(String)` containing the GPU vendor name if successful, or an error if it fails.
477 ///
478 /// # Example
479 ///
480 /// ```rust
481 /// # use amdsmi::*;
482 /// #
483 /// # fn main() {
484 /// # // Initialize the AMD SMI library
485 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
486 /// #
487 /// // Example processor_handle, assuming the number of processors is greater than zero
488 /// let processor_handle = amdsmi_get_processor_handles!()[0];
489 ///
490 /// // Retrieve the GPU vendor name
491 /// match amdsmi_get_gpu_vendor_name(processor_handle) {
492 /// Ok(vendor_name) => println!("GPU Vendor Name: {}", vendor_name),
493 /// Err(e) => panic!("Failed to get GPU vendor name: {}", e),
494 /// }
495 /// #
496 /// # // Shut down the AMD SMI library
497 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
498 /// # }
499 /// ```
500 ///
501 /// # Errors
502 ///
503 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_vendor_name` call fails.
504 pub fn amdsmi_get_gpu_vendor_name(processor_handle: AmdsmiProcessorHandle) -> AmdsmiResult<String> {
505 let (mut name, len) = define_cstr!(amdsmi_wrapper::AMDSMI_MAX_STRING_LENGTH);
506 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_vendor_name(
507 processor_handle,
508 name.as_mut_ptr(),
509 len
510 ));
511 Ok(cstr_to_string!(name))
512 }
513
514 /// Retrieves the GPU VRAM vendor name for a given processor handle.
515 ///
516 /// This function returns the GPU VRAM vendor name associated with the specified processor handle.
517 /// The VRAM vendor name provides information about the manufacturer of the GPU's VRAM.
518 ///
519 /// # Arguments
520 ///
521 /// * `processor_handle` - A handle to the processor for which the GPU VRAM vendor name is being queried.
522 ///
523 /// # Returns
524 ///
525 /// * `AmdsmiResult<String>` - Returns `Ok(String)` containing the GPU VRAM vendor name if successful, or an error if it fails.
526 ///
527 /// # Example
528 ///
529 /// ```rust
530 /// # use amdsmi::*;
531 /// #
532 /// # fn main() {
533 /// # // Initialize the AMD SMI library
534 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
535 /// #
536 /// // Example processor_handle, assuming the number of processors is greater than zero
537 /// let processor_handle = amdsmi_get_processor_handles!()[0];
538 ///
539 /// // Retrieve the GPU VRAM vendor name
540 /// match amdsmi_get_gpu_vram_vendor(processor_handle) {
541 /// Ok(vram_vendor_name) => println!("GPU VRAM Vendor Name: {}", vram_vendor_name),
542 /// Err(e) => panic!("Failed to get GPU VRAM vendor name: {}", e),
543 /// }
544 /// #
545 /// # // Shut down the AMD SMI library
546 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
547 /// # }
548 /// ```
549 ///
550 /// # Errors
551 ///
552 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_vram_vendor` call fails.
553 pub fn amdsmi_get_gpu_vram_vendor(processor_handle: AmdsmiProcessorHandle) -> AmdsmiResult<String> {
554 let (mut brand, len) = define_cstr!(amdsmi_wrapper::AMDSMI_MAX_STRING_LENGTH);
555 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_vram_vendor(
556 processor_handle,
557 brand.as_mut_ptr(),
558 len as u32,
559 ));
560 Ok(cstr_to_string!(brand))
561 }
562
563 /// Retrieves the GPU subsystem ID for a given processor handle.
564 ///
565 /// This function returns the GPU subsystem ID associated with the specified processor handle.
566 /// The subsystem ID provides information about the specific subsystem of the GPU.
567 ///
568 /// # Arguments
569 ///
570 /// * `processor_handle` - A handle to the processor for which the GPU subsystem ID is being queried.
571 ///
572 /// # Returns
573 ///
574 /// * `AmdsmiResult<u32>` - Returns `Ok(u32)` containing the GPU subsystem ID if successful, or an error if it fails.
575 ///
576 /// # Example
577 ///
578 /// ```rust
579 /// # use amdsmi::*;
580 /// #
581 /// # fn main() {
582 /// # // Initialize the AMD SMI library
583 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
584 /// #
585 /// // Example processor_handle, assuming the number of processors is greater than zero
586 /// let processor_handle = amdsmi_get_processor_handles!()[0];
587 ///
588 /// // Retrieve the GPU subsystem ID
589 /// match amdsmi_get_gpu_subsystem_id(processor_handle) {
590 /// Ok(subsystem_id) => println!("GPU Subsystem ID: {}", subsystem_id),
591 /// Err(e) => panic!("Failed to get GPU subsystem ID: {}", e),
592 /// }
593 /// #
594 /// # // Shut down the AMD SMI library
595 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
596 /// # }
597 /// ```
598 ///
599 /// # Errors
600 ///
601 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_subsystem_id` call fails.
602 pub fn amdsmi_get_gpu_subsystem_id(processor_handle: AmdsmiProcessorHandle) -> AmdsmiResult<u16> {
603 let mut id: u16 = 0;
604 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_subsystem_id(
605 processor_handle,
606 &mut id
607 ));
608 Ok(id)
609 }
610
611 /// Retrieves the GPU subsystem name for a given processor handle.
612 ///
613 /// This function returns the GPU subsystem name associated with the specified processor handle.
614 /// The subsystem name provides information about the specific subsystem of the GPU.
615 ///
616 /// # Arguments
617 ///
618 /// * `processor_handle` - A handle to the processor for which the GPU subsystem name is being queried.
619 ///
620 /// # Returns
621 ///
622 /// * `AmdsmiResult<String>` - Returns `Ok(String)` containing the GPU subsystem name if successful, or an error if it fails.
623 ///
624 /// # Example
625 ///
626 /// ```rust
627 /// # use amdsmi::*;
628 /// #
629 /// # fn main() {
630 /// # // Initialize the AMD SMI library
631 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
632 /// #
633 /// // Example processor_handle, assuming the number of processors is greater than zero
634 /// let processor_handle = amdsmi_get_processor_handles!()[0];
635 ///
636 /// // Retrieve the GPU subsystem name
637 /// match amdsmi_get_gpu_subsystem_name(processor_handle) {
638 /// Ok(subsystem_name) => println!("GPU Subsystem Name: {}", subsystem_name),
639 /// Err(e) => panic!("Failed to get GPU subsystem name: {}", e),
640 /// }
641 /// #
642 /// # // Shut down the AMD SMI library
643 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
644 /// # }
645 /// ```
646 ///
647 /// # Errors
648 ///
649 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_subsystem_name` call fails.
650 pub fn amdsmi_get_gpu_subsystem_name(
651 processor_handle: AmdsmiProcessorHandle,
652 ) -> AmdsmiResult<String> {
653 let (mut name, len) = define_cstr!(amdsmi_wrapper::AMDSMI_MAX_STRING_LENGTH);
654 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_subsystem_name(
655 processor_handle,
656 name.as_mut_ptr(),
657 len
658 ));
659 Ok(cstr_to_string!(name))
660 }
661
662 /// Retrieves the PCI bandwidth for a given GPU processor handle.
663 ///
664 /// This function returns the PCI bandwidth associated with the specified processor handle.
665 /// The PCI bandwidth provides information about the data transfer rate of the GPU over the PCI bus.
666 ///
667 /// # Arguments
668 ///
669 /// * `processor_handle` - A handle to the processor for which the PCI bandwidth is being queried.
670 ///
671 /// # Returns
672 ///
673 /// * `AmdsmiResult<u32>` - Returns `Ok(u32)` containing the PCI bandwidth if successful, or an error if it fails.
674 ///
675 /// # Example
676 ///
677 /// ```rust
678 /// # use amdsmi::*;
679 /// #
680 /// # fn main() {
681 /// # // Initialize the AMD SMI library
682 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
683 /// #
684 /// // Example processor_handle, assuming the number of processors is greater than zero
685 /// let processor_handle = amdsmi_get_processor_handles!()[0];
686 ///
687 /// // Retrieve the PCI bandwidth
688 /// match amdsmi_get_gpu_pci_bandwidth(processor_handle) {
689 /// Ok(pci_bandwidth) => println!("PCI Bandwidth: {:?}", pci_bandwidth),
690 /// Err(e) => panic!("Failed to get PCI bandwidth: {}", e),
691 /// }
692 /// #
693 /// # // Shut down the AMD SMI library
694 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
695 /// # }
696 /// ```
697 ///
698 /// # Errors
699 ///
700 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_pci_bandwidth` call fails.
701 pub fn amdsmi_get_gpu_pci_bandwidth(
702 processor_handle: AmdsmiProcessorHandle,
703 ) -> AmdsmiResult<AmdsmiPcieBandwidthT> {
704 let mut bandwidth = MaybeUninit::<AmdsmiPcieBandwidthT>::uninit();
705 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_pci_bandwidth(
706 processor_handle,
707 bandwidth.as_mut_ptr()
708 ));
709 let bandwidth = unsafe { bandwidth.assume_init() };
710 Ok(bandwidth)
711 }
712
713 /// Retrieves the Bus-Device-Function (BDF) ID for a given GPU processor handle.
714 ///
715 /// This function returns the BDF ID associated with the specified processor handle.
716 /// The BDF ID is a unique identifier for a device on the PCI bus, which includes the bus number, device number, and function number.
717 ///
718 /// # Arguments
719 ///
720 /// * `processor_handle` - A handle to the processor for which the BDF ID is being queried.
721 ///
722 /// # Returns
723 ///
724 /// * `AmdsmiResult<u32>` - Returns `Ok(u32)` containing the BDF ID if successful, or an error if it fails.
725 ///
726 /// # Example
727 ///
728 /// ```rust
729 /// # use amdsmi::*;
730 /// #
731 /// # fn main() {
732 /// # // Initialize the AMD SMI library
733 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
734 /// #
735 /// // Example processor_handle, assuming the number of processors is greater than zero
736 /// let processor_handle = amdsmi_get_processor_handles!()[0];
737 ///
738 /// // Retrieve the BDF ID
739 /// match amdsmi_get_gpu_bdf_id(processor_handle) {
740 /// Ok(bdf_id) => println!("BDF ID: {:#010x}", bdf_id),
741 /// Err(e) => panic!("Failed to get BDF ID: {}", e),
742 /// }
743 /// #
744 /// # // Shut down the AMD SMI library
745 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
746 /// # }
747 /// ```
748 ///
749 /// # Errors
750 ///
751 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_bdf_id` call fails.
752 pub fn amdsmi_get_gpu_bdf_id(processor_handle: AmdsmiProcessorHandle) -> AmdsmiResult<u64> {
753 let mut bdfid: u64 = 0;
754 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_bdf_id(
755 processor_handle,
756 &mut bdfid
757 ));
758 Ok(bdfid)
759 }
760
761 /// Retrieves the NUMA (Non-Uniform Memory Access) node for a given GPU processor handle.
762 ///
763 /// This function returns the NUMA node associated with the specified processor handle.
764 ///
765 /// # Arguments
766 ///
767 /// * `processor_handle` - A handle to the processor for which the NUMA node is being queried.
768 ///
769 /// # Returns
770 ///
771 /// * `AmdsmiResult<u32>` - Returns `Ok(u32)` containing the NUMA node value if successful, or an error if it fails.
772 ///
773 /// # Example
774 ///
775 /// ```rust
776 /// # use amdsmi::*;
777 /// #
778 /// # fn main() {
779 /// # // Initialize the AMD SMI library
780 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
781 /// #
782 /// // Example processor_handle, assuming the number of processors is greater than zero
783 /// let processor_handle = amdsmi_get_processor_handles!()[0];
784 ///
785 /// // Retrieve the NUMA node
786 /// match amdsmi_get_gpu_topo_numa_affinity(processor_handle) {
787 /// Ok(numa_node) => println!("NUMA Node ID: {}", numa_node),
788 /// Err(e) => panic!("Failed to get NUMA affinity: {}", e),
789 /// }
790 /// #
791 /// # // Shut down the AMD SMI library
792 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
793 /// # }
794 /// ```
795 ///
796 /// # Errors
797 ///
798 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_topo_numa_affinity` call fails.
799 pub fn amdsmi_get_gpu_topo_numa_affinity(
800 processor_handle: AmdsmiProcessorHandle,
801 ) -> AmdsmiResult<i32> {
802 let mut numa_node: i32 = 0;
803 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_topo_numa_affinity(
804 processor_handle,
805 &mut numa_node
806 ));
807 Ok(numa_node)
808 }
809
810 /// Retrieves the PCI throughput for a given GPU processor handle.
811 ///
812 /// This function returns the PCI throughput associated with the specified processor handle.
813 /// The PCI throughput provides information about the data transfer rate of the GPU over the PCI bus.
814 ///
815 /// # Arguments
816 ///
817 /// * `processor_handle` - A handle to the processor for which the PCI throughput is being queried.
818 ///
819 /// # Returns
820 ///
821 /// * `AmdsmiResult<(u64, u64, u64)>` - Returns `Ok((u64, u64, u64))` containing the PCI throughput as below:
822 /// - The first value is the number of bytes sent will be written in 1 second.
823 /// - The second value is the number of bytes received will be written.
824 /// - The third value is the maximum packet size will be written.
825 /// If successful, or an error if it fails.
826 ///
827 /// # Example
828 ///
829 /// ```rust
830 /// # use amdsmi::*;
831 /// #
832 /// # fn main() {
833 /// # // Initialize the AMD SMI library
834 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
835 /// #
836 /// // Example processor_handle, assuming the number of processors is greater than zero
837 /// let processor_handle = amdsmi_get_processor_handles!()[0];
838 ///
839 /// // Retrieve the PCI throughput
840 /// match amdsmi_get_gpu_pci_throughput(processor_handle) {
841 /// Ok((sent, received, max_pkt_sz)) => {
842 /// println!("PCI Throughput - Sent: {} B/s, Received: {} B/s, Max package size: {} B/s", sent, received, max_pkt_sz);
843 /// }
844 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_pci_throughput() not supported on this device"),
845 /// Err(e) => panic!("Failed to get PCI throughput: {}", e),
846 /// }
847 /// #
848 /// # // Shut down the AMD SMI library
849 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
850 /// # }
851 /// ```
852 ///
853 /// # Errors
854 ///
855 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_pci_throughput` call fails.
856 pub fn amdsmi_get_gpu_pci_throughput(
857 processor_handle: AmdsmiProcessorHandle,
858 ) -> AmdsmiResult<(u64, u64, u64)> {
859 let mut sent: u64 = 0;
860 let mut received: u64 = 0;
861 let mut max_pkt_sz: u64 = 0;
862 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_pci_throughput(
863 processor_handle,
864 &mut sent,
865 &mut received,
866 &mut max_pkt_sz
867 ));
868 Ok((sent, received, max_pkt_sz))
869 }
870
871 /// Retrieves the PCI replay counter for a given GPU processor handle.
872 ///
873 /// This function returns the PCI replay counter associated with the specified processor handle.
874 /// The PCI replay counter provides information about the sum of the NAK's received and generated by the GPU.
875 ///
876 /// # Arguments
877 ///
878 /// * `processor_handle` - A handle to the processor for which the PCI replay counter is being queried.
879 ///
880 /// # Returns
881 ///
882 /// * `AmdsmiResult<u64>` - Returns `Ok(u64)` containing the PCI replay counter if successful, or an error if it fails.
883 ///
884 /// # Example
885 ///
886 /// ```rust
887 /// # use amdsmi::*;
888 /// #
889 /// # fn main() {
890 /// # // Initialize the AMD SMI library
891 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
892 /// #
893 /// // Example processor_handle, assuming the number of processors is greater than zero
894 /// let processor_handle = amdsmi_get_processor_handles!()[0];
895 ///
896 /// // Retrieve the PCI replay counter
897 /// match amdsmi_get_gpu_pci_replay_counter(processor_handle) {
898 /// Ok(counter) => println!("PCI Replay Counter: {}", counter),
899 /// Err(e) => panic!("Failed to get PCI replay counter: {}", e),
900 /// }
901 /// #
902 /// # // Shut down the AMD SMI library
903 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
904 /// # }
905 /// ```
906 ///
907 /// # Errors
908 ///
909 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_pci_replay_counter` call fails.
910 pub fn amdsmi_get_gpu_pci_replay_counter(
911 processor_handle: AmdsmiProcessorHandle,
912 ) -> AmdsmiResult<u64> {
913 let mut counter: u64 = 0;
914 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_pci_replay_counter(
915 processor_handle,
916 &mut counter
917 ));
918 Ok(counter)
919 }
920
921 /// Control the set of allowed PCIe bandwidths that can be used for a given GPU processor handle.
922 ///
923 /// This function Control the set of allowed PCIe bandwidths that can be used with the specified processor handle.
924 ///
925 /// # Arguments
926 ///
927 /// * `processor_handle` - A handle to the processor for which the PCI bandwidth is being set.
928 /// * `bw_bitmask` - The allowed PCI bandwidth bitmask. A bitmask indicating the indices of the
929 /// bandwidths that are to be enabled (1) and disabled (0). Only the lowest AmdsmiFrequenciesT.num_supported bits of this mask are relevant.
930 ///
931 /// # Returns
932 ///
933 /// * `AmdsmiResult<()>` - Returns `Ok(())` if the PCI bandwidth is successfully set, or an error if it fails.
934 ///
935 /// # Example
936 ///
937 /// ```rust
938 /// # use amdsmi::*;
939 /// #
940 /// # fn main() {
941 /// # // Initialize the AMD SMI library
942 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
943 /// #
944 /// // Example processor_handle, assuming the number of processors is greater than zero
945 /// let processor_handle = amdsmi_get_processor_handles!()[0];
946 ///
947 /// // Set the PCI bandwidth
948 /// match amdsmi_set_gpu_pci_bandwidth(processor_handle, 0) {
949 /// Ok(_) => println!("PCI Bandwidth set successfully"),
950 /// Err(e) => panic!("Failed to set PCI bandwidth: {}", e),
951 /// }
952 /// #
953 /// # // Shut down the AMD SMI library
954 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
955 /// # }
956 /// ```
957 ///
958 /// # Errors
959 ///
960 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_gpu_pci_bandwidth` call fails.
961 pub fn amdsmi_set_gpu_pci_bandwidth(
962 processor_handle: AmdsmiProcessorHandle,
963 bw_bitmask: u64,
964 ) -> AmdsmiResult<()> {
965 call_unsafe!(amdsmi_wrapper::amdsmi_set_gpu_pci_bandwidth(
966 processor_handle,
967 bw_bitmask
968 ));
969 Ok(())
970 }
971
972 /// Retrieves the energy accumulator counter information for the specified processor handle.
973 ///
974 /// This function retrieves energy accumulator counter information for the specified processor handle,
975 /// returning the energy accumulator, counter resolution, and timestamp.
976 /// energy_accumulator * counter_resolution = total_energy_consumption in micro-Joules.
977 ///
978 /// # Arguments
979 ///
980 /// * `processor_handle` - A handle to the processor for which the energy count is being retrieved.
981 ///
982 /// # Returns
983 ///
984 /// * `AmdsmiResult<(u64, f32, u64)>` - Returns a tuple containing the energy accumulator, counter resolution, and timestamp if successful, or an error if it fails.
985 ///
986 /// # Example
987 ///
988 /// ```rust
989 /// # use amdsmi::*;
990 /// #
991 /// # fn main() {
992 /// # // Initialize the AMD SMI library
993 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
994 /// #
995 /// // Example processor_handle, assuming the number of processors is greater than zero
996 /// let processor_handle = amdsmi_get_processor_handles!()[0];
997 ///
998 /// // Retrieve the energy count
999 /// match amdsmi_get_energy_count(processor_handle) {
1000 /// Ok((energy_accumulator, counter_resolution, timestamp)) => {
1001 /// println!("Energy Accumulator: {}", energy_accumulator);
1002 /// println!("Counter Resolution: {}", counter_resolution);
1003 /// println!("Timestamp: {}", timestamp);
1004 /// },
1005 /// Err(e) => panic!("Failed to get energy count: {}", e),
1006 /// }
1007 /// #
1008 /// # // Shut down the AMD SMI library
1009 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1010 /// # }
1011 /// ```
1012 ///
1013 /// # Errors
1014 ///
1015 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_energy_count` call fails.
1016 pub fn amdsmi_get_energy_count(
1017 processor_handle: AmdsmiProcessorHandle,
1018 ) -> AmdsmiResult<(u64, f32, u64)> {
1019 let mut energy_accumulator: u64 = 0;
1020 let mut counter_resolution: f32 = 0.0;
1021 let mut timestamp: u64 = 0;
1022 call_unsafe!(amdsmi_wrapper::amdsmi_get_energy_count(
1023 processor_handle,
1024 &mut energy_accumulator,
1025 &mut counter_resolution,
1026 &mut timestamp
1027 ));
1028 Ok((energy_accumulator, counter_resolution, timestamp))
1029 }
1030
1031 /// Sets the power cap for a given GPU processor handle.
1032 ///
1033 /// This function sets the power cap associated with the specified processor handle.
1034 ///
1035 /// # Arguments
1036 ///
1037 /// * `processor_handle` - A handle to the processor for which the power cap is being set.
1038 /// * `power_cap` - The desired power cap in milliwatts (mW).
1039 ///
1040 /// # Returns
1041 ///
1042 /// * `AmdsmiResult<()>` - Returns `Ok(())` if the power cap is successfully set, or an error if it fails.
1043 ///
1044 /// # Example
1045 ///
1046 /// ```rust
1047 /// # use amdsmi::*;
1048 /// #
1049 /// # fn main() {
1050 /// # // Initialize the AMD SMI library
1051 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1052 /// #
1053 /// // Example processor_handle, assuming the number of processors is greater than zero
1054 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1055 /// let sensor_ind : u32 = 0;
1056 ///
1057 /// let cap_info = match amdsmi_get_power_cap_info(processor_handle, sensor_ind) {
1058 /// Ok(info) => info,
1059 /// Err(e) => panic!("Failed to get power cap information: {}", e),
1060 /// };
1061 ///
1062 /// let power_cap = (cap_info.min_power_cap + cap_info.max_power_cap) / 2;
1063 ///
1064 /// // Set the power cap
1065 /// match amdsmi_set_power_cap(processor_handle, sensor_ind, power_cap) {
1066 /// Ok(_) => println!("Power cap {} set successfully", power_cap),
1067 /// Err(e) => panic!("Failed to set power cap: {}", e),
1068 /// }
1069 /// #
1070 /// # // Shut down the AMD SMI library
1071 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1072 /// # }
1073 /// ```
1074 ///
1075 /// # Errors
1076 ///
1077 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_power_cap` call fails.
1078 pub fn amdsmi_set_power_cap(
1079 processor_handle: AmdsmiProcessorHandle,
1080 sensor_ind: u32,
1081 cap: u64,
1082 ) -> AmdsmiResult<()> {
1083 call_unsafe!(amdsmi_wrapper::amdsmi_set_power_cap(
1084 processor_handle,
1085 sensor_ind,
1086 cap
1087 ));
1088 Ok(())
1089 }
1090
1091 /// Sets the power profile for a given GPU processor handle.
1092 ///
1093 /// This function sets the power profile associated with the specified processor handle.
1094 /// The power profile determines the power consumption and performance characteristics of the GPU.
1095 ///
1096 /// # Arguments
1097 ///
1098 /// * `processor_handle` - A handle to the processor for which the power profile is being set.
1099 /// * `profile` - A [`AmdsmiPowerProfilePresetMasksT`] type that hold the mask of the desired new power profile.
1100 ///
1101 /// # Returns
1102 ///
1103 /// * `AmdsmiResult<()>` - Returns `Ok(())` if the power profile is successfully set, or an error if it fails.
1104 ///
1105 /// # Example
1106 ///
1107 /// ```rust
1108 /// # use amdsmi::*;
1109 /// #
1110 /// # fn main() {
1111 /// # // Initialize the AMD SMI library
1112 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1113 /// #
1114 /// // Example processor_handle, assuming the number of processors is greater than zero
1115 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1116 ///
1117 /// // Set the power profile
1118 /// match amdsmi_set_gpu_power_profile(processor_handle, AmdsmiPowerProfilePresetMasksT::AmdsmiPwrProfPrstCustomMask) {
1119 /// Ok(_) => println!("Power profile set successfully"),
1120 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_set_gpu_power_profile() not supported on this device"),
1121 /// Err(e) => panic!("Failed to set power profile: {}", e),
1122 /// }
1123 /// #
1124 /// # // Shut down the AMD SMI library
1125 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1126 /// # }
1127 /// ```
1128 ///
1129 /// # Errors
1130 ///
1131 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_gpu_power_profile` call fails.
1132 pub fn amdsmi_set_gpu_power_profile(
1133 processor_handle: AmdsmiProcessorHandle,
1134 profile: AmdsmiPowerProfilePresetMasksT,
1135 ) -> AmdsmiResult<()> {
1136 let reserved: u32 = 0;
1137 call_unsafe!(amdsmi_wrapper::amdsmi_set_gpu_power_profile(
1138 processor_handle,
1139 reserved,
1140 profile
1141 ));
1142 Ok(())
1143 }
1144
1145 /// Retrieves the total memory for a given GPU processor handle.
1146 ///
1147 /// This function returns the total memory associated with the specified processor handle.
1148 /// The total memory provides information about the total amount of memory that exist.
1149 ///
1150 /// # Arguments
1151 ///
1152 /// * `processor_handle` - A handle to the processor for which the total memory is being queried.
1153 ///
1154 /// # Returns
1155 ///
1156 /// * `AmdsmiResult<u64>` - Returns `Ok(u64)` containing the total memory in bytes if successful, or an error if it fails.
1157 ///
1158 /// # Example
1159 ///
1160 /// ```rust
1161 /// # use amdsmi::*;
1162 /// #
1163 /// # fn main() {
1164 /// # // Initialize the AMD SMI library
1165 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1166 /// #
1167 /// // Example processor_handle, assuming the number of processors is greater than zero
1168 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1169 ///
1170 /// // Retrieve the total memory
1171 /// match amdsmi_get_gpu_memory_total(processor_handle, AmdsmiMemoryTypeT::AmdsmiMemTypeVram) {
1172 /// Ok(total_memory) => println!("Total GPU Memory: {} bytes", total_memory),
1173 /// Err(e) => panic!("Failed to get total GPU memory: {}", e),
1174 /// }
1175 /// #
1176 /// # // Shut down the AMD SMI library
1177 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1178 /// # }
1179 /// ```
1180 ///
1181 /// # Errors
1182 ///
1183 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_memory_total` call fails.
1184 pub fn amdsmi_get_gpu_memory_total(
1185 processor_handle: AmdsmiProcessorHandle,
1186 memory_type: AmdsmiMemoryTypeT,
1187 ) -> AmdsmiResult<u64> {
1188 let mut memory_total: u64 = 0;
1189 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_memory_total(
1190 processor_handle,
1191 memory_type,
1192 &mut memory_total
1193 ));
1194 Ok(memory_total)
1195 }
1196
1197 /// Retrieves the memory usage for a given GPU processor handle.
1198 ///
1199 /// This function returns the memory usage associated with the specified processor handle.
1200 /// The memory usage provides information about the amount of memory currently being used on the GPU.
1201 ///
1202 /// # Arguments
1203 ///
1204 /// * `processor_handle` - A handle to the processor for which the memory usage is being queried.
1205 ///
1206 /// # Returns
1207 ///
1208 /// * `AmdsmiResult<u64>` - Returns `Ok(u64)` containing the memory usage in bytes if successful, or an error if it fails.
1209 ///
1210 /// # Example
1211 ///
1212 /// ```rust
1213 /// # use amdsmi::*;
1214 /// #
1215 /// # fn main() {
1216 /// # // Initialize the AMD SMI library
1217 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1218 /// #
1219 /// // Example processor_handle, assuming the number of processors is greater than zero
1220 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1221 ///
1222 /// // Retrieve the memory usage
1223 /// match amdsmi_get_gpu_memory_usage(processor_handle, AmdsmiMemoryTypeT::AmdsmiMemTypeVram) {
1224 /// Ok(memory_usage) => println!("GPU Memory Usage: {} bytes", memory_usage),
1225 /// Err(e) => panic!("Failed to get GPU memory usage: {}", e),
1226 /// }
1227 /// #
1228 /// # // Shut down the AMD SMI library
1229 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1230 /// # }
1231 /// ```
1232 ///
1233 /// # Errors
1234 ///
1235 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_memory_usage` call fails.
1236 pub fn amdsmi_get_gpu_memory_usage(
1237 processor_handle: AmdsmiProcessorHandle,
1238 memory_type: AmdsmiMemoryTypeT,
1239 ) -> AmdsmiResult<u64> {
1240 let mut memory_used: u64 = 0;
1241 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_memory_usage(
1242 processor_handle,
1243 memory_type,
1244 &mut memory_used
1245 ));
1246 Ok(memory_used)
1247 }
1248
1249 /// Retrieves the bad page information for a given GPU processor handle.
1250 ///
1251 /// This function returns the bad page information associated with the specified processor handle.
1252 ///
1253 /// # Arguments
1254 ///
1255 /// * `processor_handle` - A handle to the processor for which the bad page information is being queried.
1256 ///
1257 /// # Returns
1258 ///
1259 /// * `AmdsmiResult<Vec<AmdsmiRetiredPageRecordT>>` - Returns `Ok(Vec<AmdsmiRetiredPageRecordT>)` containing a list of [`AmdsmiRetiredPageRecordT`] structs if successful, or an error if it fails.
1260 ///
1261 /// # Example
1262 ///
1263 /// ```rust
1264 /// # use amdsmi::*;
1265 /// #
1266 /// # fn main() {
1267 /// # // Initialize the AMD SMI library
1268 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1269 /// #
1270 /// // Example processor_handle, assuming the number of processors is greater than zero
1271 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1272 ///
1273 /// // Retrieve the bad page information
1274 /// match amdsmi_get_gpu_bad_page_info(processor_handle) {
1275 /// Ok(bad_page_info) => {
1276 /// for page in bad_page_info {
1277 /// println!("Bad Page: {:?}", page);
1278 /// }
1279 /// }
1280 /// Err(e) => panic!("Failed to get bad page information: {}", e),
1281 /// }
1282 /// #
1283 /// # // Shut down the AMD SMI library
1284 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1285 /// # }
1286 /// ```
1287 ///
1288 /// # Errors
1289 ///
1290 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_bad_page_info` call fails.
1291 pub fn amdsmi_get_gpu_bad_page_info(
1292 processor_handle: AmdsmiProcessorHandle,
1293 ) -> AmdsmiResult<Vec<AmdsmiRetiredPageRecordT>> {
1294 // First call to get the number of bad pages
1295 let mut num_pages: u32 = 0;
1296 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_bad_page_info(
1297 processor_handle,
1298 &mut num_pages,
1299 std::ptr::null_mut()
1300 ));
1301
1302 // Allocate a vector with the capacity of num_pages
1303 let mut bad_pages: Vec<AmdsmiRetiredPageRecordT> = Vec::with_capacity(num_pages as usize);
1304
1305 // Second call to get the bad page information
1306 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_bad_page_info(
1307 processor_handle,
1308 &mut num_pages,
1309 bad_pages.as_mut_ptr()
1310 ));
1311
1312 // Set the length of the vector to num_pages
1313 unsafe { bad_pages.set_len(num_pages as usize) };
1314
1315 Ok(bad_pages)
1316 }
1317
1318 /// Retrieves the RAS (Reliability, Availability, and Serviceability) feature information for a given GPU handle.
1319 ///
1320 /// This function returns the RAS feature information for the specified GPU handle. The RAS feature
1321 /// information includes the RAS version and schema information.
1322 ///
1323 /// # Arguments
1324 ///
1325 /// * `processor_handle` - A handle to the processor for which the RAS feature information is being queried.
1326 ///
1327 /// # Returns
1328 ///
1329 /// * `AmdsmiResult<AmdsmiRasFeatureT>` - Returns `Ok(AmdsmiRasFeatureT)` containing the [`AmdsmiRasFeatureT`] if successful, or an error if it fails.
1330 ///
1331 /// # Example
1332 ///
1333 /// ```rust
1334 /// # use amdsmi::*;
1335 /// #
1336 /// # fn main() {
1337 /// # // Initialize the AMD SMI library
1338 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1339 /// #
1340 /// // Example processor_handle, assuming the number of processors is greater than zero
1341 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1342 ///
1343 /// // Retrieve the RAS feature information
1344 /// match amdsmi_get_gpu_ras_feature_info(processor_handle) {
1345 /// Ok(ras_info) => println!("GPU RAS Feature Info: {:?}", ras_info),
1346 /// Err(e) => panic!("Failed to get GPU RAS Feature Info: {}", e),
1347 /// }
1348 /// #
1349 /// # // Shut down the AMD SMI library
1350 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1351 /// # }
1352 /// ```
1353 ///
1354 /// # Errors
1355 ///
1356 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_ras_feature_info` call fails.
1357 pub fn amdsmi_get_gpu_ras_feature_info(
1358 processor_handle: AmdsmiProcessorHandle,
1359 ) -> AmdsmiResult<AmdsmiRasFeatureT> {
1360 let mut ras_info = MaybeUninit::<AmdsmiRasFeatureT>::uninit();
1361 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_ras_feature_info(
1362 processor_handle,
1363 ras_info.as_mut_ptr()
1364 ));
1365 let ras_info = unsafe { ras_info.assume_init() };
1366 Ok(ras_info)
1367 }
1368
1369 /// Retrieves the RAS (Reliability, Availability, and Serviceability) block status for a given GPU handle.
1370 ///
1371 /// This function returns if RAS features are enabled or disabled for given block.
1372 ///
1373 /// # Arguments
1374 ///
1375 /// * `processor_handle` - A handle to the processor for which the RAS block features are being queried.
1376 /// * `block` - The specific GPU block for which the RAS features are being queried.
1377 ///
1378 /// # Returns
1379 ///
1380 /// * `AmdsmiResult<AmdsmiRasErrStateT>` - Returns `Ok(AmdsmiRasErrStateT)` containing the [`AmdsmiRasErrStateT`] if successful, or an error if it fails.
1381 ///
1382 /// # Example
1383 ///
1384 /// ```rust
1385 /// # use amdsmi::*;
1386 /// #
1387 /// # fn main() {
1388 /// # // Initialize the AMD SMI library
1389 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1390 /// #
1391 /// // Example processor_handle, assuming the number of processors is greater than zero
1392 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1393 ///
1394 /// // Example GPU block
1395 /// let block = AmdsmiGpuBlockT::AmdsmiGpuBlockGfx;
1396 ///
1397 /// // Retrieve the enabled RAS block features
1398 /// match amdsmi_get_gpu_ras_block_features_enabled(processor_handle, block) {
1399 /// Ok(ras_features) => println!("Enabled RAS Block Features: {:?}", ras_features),
1400 /// Err(e) => panic!("Failed to get enabled RAS block features: {}", e),
1401 /// }
1402 /// #
1403 /// # // Shut down the AMD SMI library
1404 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1405 /// # }
1406 /// ```
1407 ///
1408 /// # Errors
1409 ///
1410 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_ras_block_features_enabled` call fails.
1411 pub fn amdsmi_get_gpu_ras_block_features_enabled(
1412 processor_handle: AmdsmiProcessorHandle,
1413 block: AmdsmiGpuBlockT,
1414 ) -> AmdsmiResult<AmdsmiRasErrStateT> {
1415 let mut ras_features = MaybeUninit::<AmdsmiRasErrStateT>::uninit();
1416 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_ras_block_features_enabled(
1417 processor_handle,
1418 block,
1419 ras_features.as_mut_ptr()
1420 ));
1421 let ras_features = unsafe { ras_features.assume_init() };
1422 Ok(ras_features)
1423 }
1424
1425 /// Retrieves the reserved memory pages information for a given GPU handle.
1426 ///
1427 /// This function returns the reserved memory pages information for the specified GPU handle. The reserved memory pages
1428 /// include details about the memory pages that are reserved by the GPU.
1429 ///
1430 /// # Arguments
1431 ///
1432 /// * `processor_handle` - A handle to the processor for which the reserved memory pages are being queried.
1433 ///
1434 /// # Returns
1435 ///
1436 /// * `AmdsmiResult<Vec<AmdsmiRetiredPageRecordT>>` - Returns `Ok(Vec<AmdsmiRetiredPageRecordT>)` containing the reserved memory pages if successful, or an error if it fails.
1437 ///
1438 /// # Example
1439 ///
1440 /// ```rust
1441 /// # use amdsmi::*;
1442 /// #
1443 /// # fn main() {
1444 /// # // Initialize the AMD SMI library
1445 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1446 /// #
1447 /// // Example processor_handle, assuming the number of processors is greater than zero
1448 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1449 ///
1450 /// // Retrieve the reserved memory pages
1451 /// match amdsmi_get_gpu_memory_reserved_pages(processor_handle) {
1452 /// Ok(pages) => println!("Reserved Memory Pages: {:?}", pages),
1453 /// Err(e) => panic!("Failed to get reserved memory pages: {}", e),
1454 /// }
1455 /// #
1456 /// # // Shut down the AMD SMI library
1457 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1458 /// # }
1459 /// ```
1460 ///
1461 /// # Errors
1462 ///
1463 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_memory_reserved_pages` call fails.
1464 pub fn amdsmi_get_gpu_memory_reserved_pages(
1465 processor_handle: AmdsmiProcessorHandle,
1466 ) -> AmdsmiResult<Vec<AmdsmiRetiredPageRecordT>> {
1467 let mut num_pages = 0;
1468 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_memory_reserved_pages(
1469 processor_handle,
1470 &mut num_pages,
1471 std::ptr::null_mut()
1472 ));
1473
1474 let mut pages = Vec::with_capacity(num_pages as usize);
1475 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_memory_reserved_pages(
1476 processor_handle,
1477 &mut num_pages,
1478 pages.as_mut_ptr()
1479 ));
1480
1481 unsafe {
1482 pages.set_len(num_pages as usize);
1483 }
1484
1485 Ok(pages)
1486 }
1487
1488 /// Retrieves the fan speed for a given GPU handle and sensor index.
1489 ///
1490 /// This function returns the fan speed for the specified GPU handle and sensor index. The fan speed
1491 /// provides information as a value relative to AMDSMI_MAX_FAN_SPEED.
1492 ///
1493 /// # Arguments
1494 ///
1495 /// * `processor_handle` - A handle to the processor for which the fan speed is being queried.
1496 /// * `sensor_index` - The index of the fan sensor to query.
1497 ///
1498 /// # Returns
1499 ///
1500 /// * `AmdsmiResult<i64>` - Returns `Ok(i64)` containing the fan speed relative to MAX if successful, or an error if it fails.
1501 ///
1502 /// # Example
1503 ///
1504 /// ```rust
1505 /// # use amdsmi::*;
1506 /// #
1507 /// # fn main() {
1508 /// # // Initialize the AMD SMI library
1509 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1510 /// #
1511 /// // Example processor_handle, assuming the number of processors is greater than zero
1512 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1513 ///
1514 /// // Example sensor index
1515 /// let sensor_index = 0;
1516 ///
1517 /// // Retrieve the fan speed
1518 /// match amdsmi_get_gpu_fan_speed(processor_handle, sensor_index) {
1519 /// Ok(speed) => println!("GPU Fan Speed: {}", speed),
1520 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_fan_speed() not supported on this device"),
1521 /// Err(e) => panic!("Failed to get GPU fan speed: {}", e),
1522 /// }
1523 /// #
1524 /// # // Shut down the AMD SMI library
1525 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1526 /// # }
1527 /// ```
1528 ///
1529 /// # Errors
1530 ///
1531 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_fan_speed` call fails.
1532 pub fn amdsmi_get_gpu_fan_speed(
1533 processor_handle: AmdsmiProcessorHandle,
1534 sensor_index: u32,
1535 ) -> AmdsmiResult<i64> {
1536 let mut speed = 0;
1537 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_fan_speed(
1538 processor_handle,
1539 sensor_index,
1540 &mut speed
1541 ));
1542 Ok(speed)
1543 }
1544
1545 /// Get the maximum fan speed of the device with the specified processor handle and sensor index.
1546 ///
1547 /// Given a processor handle `processor_handle` and a sensor index `sensor_ind`, this function returns
1548 /// the maximum fan speed for the specified GPU.
1549 ///
1550 /// # Arguments
1551 ///
1552 /// * `processor_handle` - A handle to the processor for which the maximum fan speed is being queried.
1553 /// * `sensor_ind` - The index of the fan sensor to query.
1554 ///
1555 /// # Returns
1556 ///
1557 /// * `AmdsmiResult<u64>` - Returns `Ok(u64)` containing the maximum fan speed if successful, or an error if it fails.
1558 ///
1559 /// # Example
1560 ///
1561 /// ```rust
1562 /// # use amdsmi::*;
1563 /// #
1564 /// # fn main() {
1565 /// # // Initialize the AMD SMI library
1566 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1567 /// #
1568 /// // Example processor_handle, assuming the number of processors is greater than zero
1569 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1570 ///
1571 /// // Example sensor index
1572 /// let sensor_ind = 0;
1573 ///
1574 /// // Retrieve the maximum fan speed
1575 /// match amdsmi_get_gpu_fan_speed_max(processor_handle, sensor_ind) {
1576 /// Ok(speed) => println!("GPU Maximum Fan Speed: {}", speed),
1577 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_fan_speed_max() not supported on this device"),
1578 /// Err(e) => panic!("Failed to get GPU maximum fan speed: {}", e),
1579 /// }
1580 /// #
1581 /// # // Shut down the AMD SMI library
1582 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1583 /// # }
1584 /// ```
1585 ///
1586 /// # Errors
1587 ///
1588 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_fan_speed_max` call fails.
1589 pub fn amdsmi_get_gpu_fan_speed_max(
1590 processor_handle: AmdsmiProcessorHandle,
1591 sensor_ind: u32,
1592 ) -> AmdsmiResult<u64> {
1593 let mut speed = 0;
1594 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_fan_speed_max(
1595 processor_handle,
1596 sensor_ind,
1597 &mut speed
1598 ));
1599 Ok(speed)
1600 }
1601
1602 /// Get the temperature metric of the device with the specified processor handle, sensor type, and metric.
1603 ///
1604 /// Given a processor handle `processor_handle`, a sensor type `sensor_type`, and a temperature metric `metric`,
1605 /// this function returns the temperature metric for the specified GPU.
1606 ///
1607 /// # Arguments
1608 ///
1609 /// * `processor_handle` - A handle to the processor for which the temperature metric is being queried.
1610 /// * `sensor_type` - The type of the temperature sensor [`AmdsmiTemperatureTypeT`] to query.
1611 /// * `metric` - The temperature metric [`AmdsmiTemperatureMetricT`] to query.
1612 ///
1613 /// # Returns
1614 ///
1615 /// * `AmdsmiResult<i64>` - Returns `Ok(i64)` containing the temperature metric value if successful, or an error if it fails.
1616 ///
1617 /// # Example
1618 ///
1619 /// ```rust
1620 /// # use amdsmi::*;
1621 /// #
1622 /// # fn main() {
1623 /// # // Initialize the AMD SMI library
1624 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1625 /// #
1626 /// // Example processor_handle, assuming the number of processors is greater than zero
1627 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1628 ///
1629 /// // Example sensor type and metric
1630 /// let sensor_type = AmdsmiTemperatureTypeT::AmdsmiTemperatureTypeEdge;
1631 /// let metric = AmdsmiTemperatureMetricT::AmdsmiTempCurrent;
1632 ///
1633 /// // Retrieve the temperature metric
1634 /// match amdsmi_get_temp_metric(processor_handle, sensor_type, metric) {
1635 /// Ok(temp_metric) => println!("GPU Temperature Metric: {}", temp_metric),
1636 /// Err(e) => panic!("Failed to get GPU temperature metric: {}", e),
1637 /// }
1638 /// #
1639 /// # // Shut down the AMD SMI library
1640 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1641 /// # }
1642 /// ```
1643 ///
1644 /// # Errors
1645 ///
1646 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_temp_metric` call fails.
1647 pub fn amdsmi_get_temp_metric(
1648 processor_handle: AmdsmiProcessorHandle,
1649 sensor_type: AmdsmiTemperatureTypeT,
1650 metric: AmdsmiTemperatureMetricT,
1651 ) -> AmdsmiResult<i64> {
1652 let mut temperature = 0;
1653 call_unsafe!(amdsmi_wrapper::amdsmi_get_temp_metric(
1654 processor_handle,
1655 sensor_type,
1656 metric,
1657 &mut temperature
1658 ));
1659 Ok(temperature)
1660 }
1661
1662 /// Get the GPU cache information of the device with the specified processor handle.
1663 ///
1664 /// Given a processor handle `processor_handle`, this function returns the GPU cache information
1665 /// for the specified processor.
1666 ///
1667 /// # Arguments
1668 ///
1669 /// * `processor_handle` - A handle to the processor for which the cache information is being queried.
1670 ///
1671 /// # Returns
1672 ///
1673 /// * `AmdsmiResult<AmdsmiGpuCacheInfoT>` - Returns `Ok(AmdsmiGpuCacheInfoT)` containing the [`AmdsmiGpuCacheInfoT`] if successful, or an error if it fails.
1674 ///
1675 /// # Example
1676 ///
1677 /// ```rust
1678 /// # use amdsmi::*;
1679 /// #
1680 /// # fn main() {
1681 /// # // Initialize the AMD SMI library
1682 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1683 /// #
1684 /// // Example processor_handle, assuming the number of processors is greater than zero
1685 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1686 ///
1687 /// // Retrieve the GPU cache information
1688 /// match amdsmi_get_gpu_cache_info(processor_handle) {
1689 /// Ok(cache_info) => println!("GPU Cache Info: {:?}", cache_info),
1690 /// Err(e) => panic!("Failed to get GPU cache info: {}", e),
1691 /// }
1692 /// #
1693 /// # // Shut down the AMD SMI library
1694 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1695 /// # }
1696 /// ```
1697 ///
1698 /// # Errors
1699 ///
1700 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_cache_info` call fails.
1701 pub fn amdsmi_get_gpu_cache_info(
1702 processor_handle: AmdsmiProcessorHandle,
1703 ) -> AmdsmiResult<AmdsmiGpuCacheInfoT> {
1704 let mut info = MaybeUninit::<AmdsmiGpuCacheInfoT>::uninit();
1705 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_cache_info(
1706 processor_handle,
1707 info.as_mut_ptr()
1708 ));
1709 let info = unsafe { info.assume_init() };
1710 Ok(info)
1711 }
1712
1713 /// Get the voltage metric of the device with the specified processor handle, sensor type, and metric.
1714 ///
1715 /// Given a processor handle `processor_handle`, a sensor type `sensor_type`, and a voltage metric type `metric`,
1716 /// this function returns the voltage metric for the specified processor.
1717 ///
1718 /// # Arguments
1719 ///
1720 /// * `processor_handle` - A handle to the processor for which the voltage metric is being queried.
1721 /// * `sensor_type` - The type of the voltage sensor [`AmdsmiVoltageTypeT`] to query.
1722 /// * `metric` - The voltage metric [`amdsmi_get_gpu_volt_metric`] to query.
1723 ///
1724 /// # Returns
1725 ///
1726 /// * `AmdsmiResult<i64>` - Returns `Ok(i64)` containing the voltage metric if successful, or an error if it fails.
1727 ///
1728 /// # Example
1729 ///
1730 /// ```rust
1731 /// # use amdsmi::*;
1732 /// #
1733 /// # fn main() {
1734 /// # // Initialize the AMD SMI library
1735 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1736 /// #
1737 /// // Example processor_handle, assuming the number of processors is greater than zero
1738 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1739 ///
1740 /// // Example sensor type and metric
1741 /// let sensor_type = AmdsmiVoltageTypeT::AmdsmiVoltTypeVddgfx;
1742 /// let metric = AmdsmiVoltageMetricT::AmdsmiVoltCurrent;
1743 ///
1744 /// // Retrieve the voltage metric
1745 /// match amdsmi_get_gpu_volt_metric(processor_handle, sensor_type, metric) {
1746 /// Ok(voltage_metric) => println!("GPU Voltage Metric: {}", voltage_metric),
1747 /// Err(e) => panic!("Failed to get GPU voltage metric: {}", e),
1748 /// }
1749 /// #
1750 /// # // Shut down the AMD SMI library
1751 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1752 /// # }
1753 /// ```
1754 ///
1755 /// # Errors
1756 ///
1757 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_volt_metric` call fails.
1758 pub fn amdsmi_get_gpu_volt_metric(
1759 processor_handle: AmdsmiProcessorHandle,
1760 sensor_type: AmdsmiVoltageTypeT,
1761 metric: AmdsmiVoltageMetricT,
1762 ) -> AmdsmiResult<i64> {
1763 let mut voltage = 0;
1764 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_volt_metric(
1765 processor_handle,
1766 sensor_type,
1767 metric,
1768 &mut voltage
1769 ));
1770 Ok(voltage)
1771 }
1772
1773 /// Reset the GPU fan of the device with the specified processor handle and sensor index.
1774 ///
1775 /// Given a processor handle `processor_handle` and a sensor index `sensor_ind`, this function resets the GPU fan
1776 /// for the specified processor.
1777 ///
1778 /// # Arguments
1779 ///
1780 /// * `processor_handle` - A handle to the processor for which the GPU fan is being reset.
1781 /// * `sensor_ind` - The 0-based sensor index of the fan sensor to reset.
1782 ///
1783 /// # Returns
1784 ///
1785 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
1786 ///
1787 /// # Example
1788 ///
1789 /// ```rust
1790 /// # use amdsmi::*;
1791 /// #
1792 /// # fn main() {
1793 /// # // Initialize the AMD SMI library
1794 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1795 /// #
1796 /// // Example processor_handle, assuming the number of processors is greater than zero
1797 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1798 ///
1799 /// // Example sensor index
1800 /// let sensor_ind = 0;
1801 ///
1802 /// // Reset the GPU fan
1803 /// match amdsmi_reset_gpu_fan(processor_handle, sensor_ind) {
1804 /// Ok(()) => println!("GPU fan reset successfully"),
1805 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_reset_gpu_fan() not supported on this device"),
1806 /// Err(e) => panic!("Failed to reset GPU fan: {}", e),
1807 /// }
1808 /// #
1809 /// # // Shut down the AMD SMI library
1810 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1811 /// # }
1812 /// ```
1813 ///
1814 /// # Errors
1815 ///
1816 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_reset_gpu_fan` call fails.
1817 pub fn amdsmi_reset_gpu_fan(
1818 processor_handle: AmdsmiProcessorHandle,
1819 sensor_ind: u32,
1820 ) -> AmdsmiResult<()> {
1821 call_unsafe!(amdsmi_wrapper::amdsmi_reset_gpu_fan(
1822 processor_handle,
1823 sensor_ind
1824 ));
1825 Ok(())
1826 }
1827
1828 /// Get the fan speed in RPM for the GPU device with the specified processor handle and sensor index.
1829 ///
1830 /// Given a processor handle `processor_handle` and a sensor index `sensor_ind`, this function retrieves the fan speed in RPM
1831 /// for the specified GPU device.
1832 ///
1833 /// # Arguments
1834 ///
1835 /// * `processor_handle` - A handle to the processor for which the fan speed is being queried.
1836 /// * `sensor_ind` - The index of the sensor for which the fan speed is being queried.
1837 ///
1838 /// # Returns
1839 ///
1840 /// * `AmdsmiResult<i64>` - Returns `Ok(i64)` containing the fan speed in RPM if successful, or an error if it fails.
1841 ///
1842 /// # Example
1843 ///
1844 /// ```rust
1845 /// # use amdsmi::*;
1846 /// #
1847 /// # fn main() {
1848 /// # // Initialize the AMD SMI library
1849 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1850 /// #
1851 /// // Example processor_handle, assuming the number of processors is greater than zero
1852 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1853 ///
1854 /// // Example sensor index
1855 /// let sensor_ind: u32 = 0;
1856 ///
1857 /// // Retrieve the fan speed in RPM
1858 /// match amdsmi_get_gpu_fan_rpms(processor_handle, sensor_ind) {
1859 /// Ok(speed) => println!("Fan speed: {} RPM", speed),
1860 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_fan_rpms() not supported on this device"),
1861 /// Err(e) => panic!("Failed to get fan speed: {}", e),
1862 /// }
1863 /// #
1864 /// # // Shut down the AMD SMI library
1865 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1866 /// # }
1867 /// ```
1868 ///
1869 /// # Errors
1870 ///
1871 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_fan_rpms` call fails.
1872 pub fn amdsmi_get_gpu_fan_rpms(
1873 processor_handle: AmdsmiProcessorHandle,
1874 sensor_ind: u32,
1875 ) -> AmdsmiResult<i64> {
1876 let mut speed: i64 = 0;
1877 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_fan_rpms(
1878 processor_handle,
1879 sensor_ind,
1880 &mut speed as *mut i64
1881 ));
1882 Ok(speed)
1883 }
1884
1885 /// Set the GPU fan speed of the device with the specified processor handle, sensor index, and speed.
1886 ///
1887 /// Given a processor handle `processor_handle`, a sensor index `sensor_ind`, and a fan speed `speed`,
1888 /// this function sets the GPU fan speed for the specified processor.
1889 ///
1890 /// # Arguments
1891 ///
1892 /// * `processor_handle` - A handle to the processor for which the GPU fan speed is being set.
1893 /// * `sensor_ind` - The index of the fan sensor to set the speed for.
1894 /// * `speed` - The speed to set the fan to, in RPM.
1895 ///
1896 /// # Returns
1897 ///
1898 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
1899 ///
1900 /// # Example
1901 ///
1902 /// ```rust
1903 /// # use amdsmi::*;
1904 /// #
1905 /// # fn main() {
1906 /// # // Initialize the AMD SMI library
1907 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1908 /// #
1909 /// // Example processor_handle, assuming the number of processors is greater than zero
1910 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1911 ///
1912 /// // Example sensor index and speed
1913 /// let sensor_ind = 0;
1914 /// let speed = 1333;
1915 ///
1916 /// // Set the GPU fan speed
1917 /// match amdsmi_set_gpu_fan_speed(processor_handle, sensor_ind, speed) {
1918 /// Ok(()) => println!("GPU fan speed set successfully"),
1919 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_set_gpu_fan_speed() not supported on this device"),
1920 /// Err(e) => panic!("Failed to set GPU fan speed: {}", e),
1921 /// }
1922 /// #
1923 /// # // Shut down the AMD SMI library
1924 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1925 /// # }
1926 /// ```
1927 ///
1928 /// # Errors
1929 ///
1930 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_gpu_fan_speed` call fails.
1931 pub fn amdsmi_set_gpu_fan_speed(
1932 processor_handle: AmdsmiProcessorHandle,
1933 sensor_ind: u32,
1934 speed: u64,
1935 ) -> AmdsmiResult<()> {
1936 call_unsafe!(amdsmi_wrapper::amdsmi_set_gpu_fan_speed(
1937 processor_handle,
1938 sensor_ind,
1939 speed
1940 ));
1941 Ok(())
1942 }
1943
1944 /// Get the GPU busy percent of the device with the specified processor handle.
1945 ///
1946 /// Given a processor handle `processor_handle`, this function returns the GPU busy percent
1947 /// for the specified processor.
1948 ///
1949 /// # Arguments
1950 ///
1951 /// * `processor_handle` - A handle to the processor which is being queried.
1952 ///
1953 /// # Returns
1954 ///
1955 /// * `AmdsmiResult<u32>` - Returns `Ok(u32)` containing the GPU busy percent if successful, or an error if it fails.
1956 ///
1957 /// # Example
1958 ///
1959 /// ```rust
1960 /// # use amdsmi::*;
1961 /// #
1962 /// # fn main() {
1963 /// # // Initialize the AMD SMI library
1964 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
1965 /// #
1966 /// // Example processor_handle, assuming the number of processors is greater than zero
1967 /// let processor_handle = amdsmi_get_processor_handles!()[0];
1968 ///
1969 /// // Retrieve the GPU busy percent
1970 /// match amdsmi_get_gpu_busy_percent(processor_handle) {
1971 /// Ok(gpu_busy_percent) => println!("GPU Busy Percent: {}", gpu_busy_percent),
1972 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_busy_percent() not supported on this device"),
1973 /// Err(e) => panic!("Failed to get GPU busy_percent level: {}", e),
1974 /// }
1975 /// #
1976 /// # // Shut down the AMD SMI library
1977 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
1978 /// # }
1979 /// ```
1980 ///
1981 /// # Errors
1982 ///
1983 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_busy_percent` call fails.
1984 pub fn amdsmi_get_gpu_busy_percent(
1985 processor_handle: AmdsmiProcessorHandle
1986 ) -> AmdsmiResult<u32> {
1987 let mut gpu_busy_percent = 0;
1988 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_busy_percent(
1989 processor_handle,
1990 &mut gpu_busy_percent
1991 ));
1992 Ok(gpu_busy_percent)
1993 }
1994
1995 ///
1996 /// Retrieves the utilization count for the specified processor handle and counter types.
1997 ///
1998 /// This function retrieves the utilization count for the specified processor handle and counter types,
1999 /// returning a list of utilization counters and a timestamp.
2000 ///
2001 /// # Arguments
2002 ///
2003 /// * `processor_handle` - A handle to the processor for which the utilization count is being retrieved.
2004 /// * `counter_types` - A list of counter types [`AmdsmiUtilizationCounterTypeT`] for which the utilization count is being retrieved.
2005 ///
2006 /// # Returns
2007 ///
2008 /// * `AmdsmiResult<(Vec<AmdsmiUtilizationCounterT>, u64)>` - Returns a tuple containing a list of [`AmdsmiUtilizationCounterT`] and a timestamp if successful, or an error if it fails.
2009 ///
2010 /// # Example
2011 ///
2012 /// ```rust
2013 /// # use amdsmi::*;
2014 /// #
2015 /// # fn main() {
2016 /// # // Initialize the AMD SMI library
2017 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2018 /// #
2019 /// // Example processor_handle, assuming the number of processors is greater than zero
2020 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2021 ///
2022 /// // Define the counter types
2023 /// let counter_types = vec![
2024 /// AmdsmiUtilizationCounterTypeT::AmdsmiFineGrainGfxActivity,
2025 /// AmdsmiUtilizationCounterTypeT::AmdsmiFineGrainMemActivity,
2026 /// ];
2027 ///
2028 /// // Get the utilization count
2029 /// match amdsmi_get_utilization_count(processor_handle, counter_types) {
2030 /// Ok((utilization_counters, timestamp)) => {
2031 /// println!("Timestamp: {}", timestamp);
2032 /// for counter in utilization_counters {
2033 /// println!("Counter Type: {:?}, Value: {}", counter.type_, counter.value);
2034 /// }
2035 /// },
2036 /// Err(e) => panic!("Failed to get utilization count: {}", e),
2037 /// }
2038 ///
2039 /// # // Shut down the AMD SMI library
2040 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2041 /// # }
2042 /// ```
2043 ///
2044 /// # Errors
2045 ///
2046 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_utilization_count` call fails.
2047 pub fn amdsmi_get_utilization_count(
2048 processor_handle: AmdsmiProcessorHandle,
2049 counter_types: Vec<AmdsmiUtilizationCounterTypeT>,
2050 ) -> AmdsmiResult<(Vec<AmdsmiUtilizationCounterT>, u64)> {
2051 let count = counter_types.len() as u32;
2052 let mut utilization_counters: Vec<AmdsmiUtilizationCounterT> =
2053 Vec::with_capacity(count as usize);
2054 let mut timestamp = 0;
2055
2056 // Initialize the utilization_counters with the appropriate types
2057 for counter_type in counter_types {
2058 let utilization_counter = AmdsmiUtilizationCounterT {
2059 type_: counter_type,
2060 value: 0,
2061 fine_value: [0; 4],
2062 fine_value_count: 0,
2063 };
2064 utilization_counters.push(utilization_counter);
2065 }
2066
2067 call_unsafe!(amdsmi_wrapper::amdsmi_get_utilization_count(
2068 processor_handle,
2069 utilization_counters.as_mut_ptr(),
2070 count,
2071 &mut timestamp
2072 ));
2073 Ok((utilization_counters, timestamp))
2074 }
2075
2076 /// Get the GPU performance level of the device with the specified processor handle.
2077 ///
2078 /// Given a processor handle `processor_handle`, this function returns the GPU performance level
2079 /// for the specified processor.
2080 ///
2081 /// # Arguments
2082 ///
2083 /// * `processor_handle` - A handle to the processor for which the GPU performance level is being queried.
2084 ///
2085 /// # Returns
2086 ///
2087 /// * `AmdsmiResult<AmdsmiDevPerfLevelT>` - Returns `Ok(AmdsmiDevPerfLevelT)` containing the [`AmdsmiDevPerfLevelT`] if successful, or an error if it fails.
2088 ///
2089 /// # Example
2090 ///
2091 /// ```rust
2092 /// # use amdsmi::*;
2093 /// #
2094 /// # fn main() {
2095 /// # // Initialize the AMD SMI library
2096 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2097 /// #
2098 /// // Example processor_handle, assuming the number of processors is greater than zero
2099 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2100 ///
2101 /// // Retrieve the GPU performance level
2102 /// match amdsmi_get_gpu_perf_level(processor_handle) {
2103 /// Ok(perf_level) => println!("GPU Performance Level: {:?}", perf_level),
2104 /// Err(e) => panic!("Failed to get GPU performance level: {}", e),
2105 /// }
2106 /// #
2107 /// # // Shut down the AMD SMI library
2108 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2109 /// # }
2110 /// ```
2111 ///
2112 /// # Errors
2113 ///
2114 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_perf_level` call fails.
2115 pub fn amdsmi_get_gpu_perf_level(
2116 processor_handle: AmdsmiProcessorHandle,
2117 ) -> AmdsmiResult<AmdsmiDevPerfLevelT> {
2118 let mut perf = MaybeUninit::<AmdsmiDevPerfLevelT>::uninit();
2119 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_perf_level(
2120 processor_handle,
2121 perf.as_mut_ptr()
2122 ));
2123 let perf = unsafe { perf.assume_init() };
2124 Ok(perf)
2125 }
2126
2127 /// Enter performance determinism mode with provided processor handle.
2128 ///
2129 /// Given a processor handle `processor_handle` and a clock value `clkvalue`, this function will enable the GPU performance
2130 /// determinism mode which enforces a GFXCLK frequency SoftMax limit per GPU for the specified processor.
2131 ///
2132 /// # Arguments
2133 ///
2134 /// * `processor_handle` - A handle to the processor for which the GPU performance determinism mode is being set.
2135 /// * `clkvalue` - The clock value to set for the performance determinism mode.
2136 ///
2137 /// # Returns
2138 ///
2139 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
2140 ///
2141 /// # Example
2142 ///
2143 /// ```rust
2144 /// # use amdsmi::*;
2145 /// #
2146 /// # fn main() {
2147 /// # // Initialize the AMD SMI library
2148 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2149 /// #
2150 /// // Example processor_handle, assuming the number of processors is greater than zero
2151 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2152 ///
2153 /// // Example clock value
2154 /// let clkvalue = 1000;
2155 ///
2156 /// // Set the GPU performance determinism mode
2157 /// match amdsmi_set_gpu_perf_determinism_mode(processor_handle, clkvalue) {
2158 /// Ok(()) => println!("GPU performance determinism mode set successfully"),
2159 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_set_gpu_perf_determinism_mode() not supported on this device"),
2160 /// Err(e) => panic!("Failed to set GPU performance determinism mode: {}", e),
2161 /// }
2162 /// #
2163 /// # // Shut down the AMD SMI library
2164 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2165 /// # }
2166 /// ```
2167 ///
2168 /// # Errors
2169 ///
2170 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_gpu_perf_determinism_mode` call fails.
2171 pub fn amdsmi_set_gpu_perf_determinism_mode(
2172 processor_handle: AmdsmiProcessorHandle,
2173 clkvalue: u64,
2174 ) -> AmdsmiResult<()> {
2175 call_unsafe!(amdsmi_wrapper::amdsmi_set_gpu_perf_determinism_mode(
2176 processor_handle,
2177 clkvalue
2178 ));
2179 Ok(())
2180 }
2181
2182 /// Get the GPU overdrive level of the device with the specified processor handle.
2183 ///
2184 /// Given a processor handle `processor_handle`, this function returns the GPU overdrive level
2185 /// for the specified processor.
2186 ///
2187 /// # Arguments
2188 ///
2189 /// * `processor_handle` - A handle to the processor for which the GPU overdrive level is being queried.
2190 ///
2191 /// # Returns
2192 ///
2193 /// * `AmdsmiResult<u32>` - Returns `Ok(u32)` containing the GPU overdrive level if successful, or an error if it fails.
2194 ///
2195 /// # Example
2196 ///
2197 /// ```rust
2198 /// # use amdsmi::*;
2199 /// #
2200 /// # fn main() {
2201 /// # // Initialize the AMD SMI library
2202 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2203 /// #
2204 /// // Example processor_handle, assuming the number of processors is greater than zero
2205 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2206 ///
2207 /// // Retrieve the GPU overdrive level
2208 /// match amdsmi_get_gpu_overdrive_level(processor_handle) {
2209 /// Ok(overdrive_level) => println!("GPU Overdrive Level: {}", overdrive_level),
2210 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_overdrive_level() not supported on this device"),
2211 /// Err(e) => panic!("Failed to get GPU overdrive level: {}", e),
2212 /// }
2213 /// #
2214 /// # // Shut down the AMD SMI library
2215 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2216 /// # }
2217 /// ```
2218 ///
2219 /// # Errors
2220 ///
2221 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_overdrive_level` call fails.
2222 pub fn amdsmi_get_gpu_overdrive_level(
2223 processor_handle: AmdsmiProcessorHandle,
2224 ) -> AmdsmiResult<u32> {
2225 let mut od = 0;
2226 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_overdrive_level(
2227 processor_handle,
2228 &mut od
2229 ));
2230 Ok(od)
2231 }
2232
2233 /// Get the memory overdrive percent for the GPU device with the specified processor handle.
2234 ///
2235 /// Given a processor handle `processor_handle`, this function retrieves the memory overdrive level
2236 /// for the specified GPU device.
2237 ///
2238 /// # Arguments
2239 ///
2240 /// * `processor_handle` - A handle to the processor for which the memory overdrive level is being queried.
2241 ///
2242 /// # Returns
2243 ///
2244 /// * `AmdsmiResult<u32>` - Returns `Ok(u32)` containing the memory overdrive level if successful, or an error if it fails.
2245 ///
2246 /// # Example
2247 ///
2248 /// ```rust
2249 /// # use amdsmi::*;
2250 /// #
2251 /// # fn main() {
2252 /// # // Initialize the AMD SMI library
2253 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2254 /// #
2255 /// // Example processor_handle, assuming the number of processors is greater than zero
2256 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2257 ///
2258 /// // Retrieve the memory overdrive level
2259 /// match amdsmi_get_gpu_mem_overdrive_level(processor_handle) {
2260 /// Ok(overdrive_level) => println!("Memory overdrive level: {}", overdrive_level),
2261 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_mem_overdrive_level() not supported on this device"),
2262 /// Err(e) => panic!("Failed to get memory overdrive level: {}", e),
2263 /// }
2264 /// #
2265 /// # // Shut down the AMD SMI library
2266 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2267 /// # }
2268 /// ```
2269 ///
2270 /// # Errors
2271 ///
2272 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_mem_overdrive_level` call fails.
2273 pub fn amdsmi_get_gpu_mem_overdrive_level(
2274 processor_handle: AmdsmiProcessorHandle,
2275 ) -> AmdsmiResult<u32> {
2276 let mut od: u32 = 0;
2277 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_mem_overdrive_level(
2278 processor_handle,
2279 &mut od as *mut u32
2280 ));
2281 Ok(od)
2282 }
2283
2284 /// Get the clock frequencies of the device with the specified processor handle and clock type.
2285 ///
2286 /// Given a processor handle `processor_handle` and a clock type `clk_type`, this function returns the clock frequencies
2287 /// for the specified processor.
2288 ///
2289 /// # Arguments
2290 ///
2291 /// * `processor_handle` - A handle to the processor for which the clock frequencies are being queried.
2292 /// * `clk_type` - The type of the clock to query.
2293 ///
2294 /// # Returns
2295 ///
2296 /// * `AmdsmiResult<AmdsmiFrequenciesT>` - Returns `Ok(AmdsmiFrequenciesT)` containing the [`AmdsmiFrequenciesT`] if successful, or an error if it fails.
2297 ///
2298 /// # Example
2299 ///
2300 /// ```rust
2301 /// # use amdsmi::*;
2302 /// #
2303 /// # fn main() {
2304 /// # // Initialize the AMD SMI library
2305 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2306 /// #
2307 /// // Example processor_handle, assuming the number of processors is greater than zero
2308 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2309 ///
2310 /// // Example clock type
2311 /// let clk_type = AmdsmiClkTypeT::AmdsmiClkTypeGfx;
2312 ///
2313 /// // Retrieve the clock frequencies
2314 /// match amdsmi_get_clk_freq(processor_handle, clk_type) {
2315 /// Ok(frequencies) => println!("Clock Frequencies: {:?}", frequencies),
2316 /// Err(e) => panic!("Failed to get clock frequencies: {}", e),
2317 /// }
2318 /// #
2319 /// # // Shut down the AMD SMI library
2320 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2321 /// # }
2322 /// ```
2323 ///
2324 /// # Errors
2325 ///
2326 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_clk_freq` call fails.
2327 pub fn amdsmi_get_clk_freq(
2328 processor_handle: AmdsmiProcessorHandle,
2329 clk_type: AmdsmiClkTypeT,
2330 ) -> AmdsmiResult<AmdsmiFrequenciesT> {
2331 let mut frequencies = MaybeUninit::<AmdsmiFrequenciesT>::uninit();
2332 call_unsafe!(amdsmi_wrapper::amdsmi_get_clk_freq(
2333 processor_handle,
2334 clk_type,
2335 frequencies.as_mut_ptr()
2336 ));
2337 let frequencies = unsafe { frequencies.assume_init() };
2338 Ok(frequencies)
2339 }
2340
2341 /// Reset the GPU of the device with the specified processor handle.
2342 ///
2343 /// Given a processor handle `processor_handle`, this function resets the GPU
2344 /// for the specified processor.
2345 ///
2346 /// # Arguments
2347 ///
2348 /// * `processor_handle` - A handle to the processor for which the GPU is being reset.
2349 ///
2350 /// # Returns
2351 ///
2352 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
2353 ///
2354 /// # Example
2355 ///
2356 /// ```rust
2357 /// # use amdsmi::*;
2358 /// #
2359 /// # fn main() {
2360 /// # // Initialize the AMD SMI library
2361 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2362 /// #
2363 /// // Example processor_handle, assuming the number of processors is greater than zero
2364 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2365 ///
2366 /// // Reset the GPU
2367 /// match amdsmi_reset_gpu(processor_handle) {
2368 /// Ok(()) => println!("GPU reset successfully"),
2369 /// Err(e) => panic!("Failed to reset GPU: {}", e),
2370 /// }
2371 /// // Wait for some time
2372 /// std::thread::sleep(std::time::Duration::from_secs(5));
2373 /// #
2374 /// # // Shut down the AMD SMI library
2375 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2376 /// # }
2377 /// ```
2378 ///
2379 /// # Errors
2380 ///
2381 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_reset_gpu` call fails.
2382 pub fn amdsmi_reset_gpu(processor_handle: AmdsmiProcessorHandle) -> AmdsmiResult<()> {
2383 call_unsafe!(amdsmi_wrapper::amdsmi_reset_gpu(processor_handle));
2384 Ok(())
2385 }
2386
2387 /// Get the GPU overdrive voltage and frequency information of the device with the specified processor handle.
2388 ///
2389 /// Given a processor handle `processor_handle`, this function returns the GPU overdrive voltage and frequency information
2390 /// for the specified processor.
2391 ///
2392 /// # Arguments
2393 ///
2394 /// * `processor_handle` - A handle to the processor for which the GPU overdrive voltage and frequency information is being queried.
2395 ///
2396 /// # Returns
2397 ///
2398 /// * `AmdsmiResult<AmdsmiOdVoltFreqDataT>` - Returns `Ok(AmdsmiOdVoltFreqDataT)` containing the [`AmdsmiOdVoltFreqDataT`] if successful, or an error if it fails.
2399 ///
2400 /// # Example
2401 ///
2402 /// ```rust
2403 /// # use amdsmi::*;
2404 /// #
2405 /// # fn main() {
2406 /// # // Initialize the AMD SMI library
2407 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2408 /// #
2409 /// // Example processor_handle, assuming the number of processors is greater than zero
2410 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2411 ///
2412 /// // Retrieve the GPU overdrive voltage and frequency information
2413 /// match amdsmi_get_gpu_od_volt_info(processor_handle) {
2414 /// Ok(od_volt_info) => println!("GPU Overdrive Voltage and Frequency Info: {:?}", od_volt_info),
2415 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_od_volt_info() not supported on this device"),
2416 /// Err(e) => panic!("Failed to get GPU overdrive voltage and frequency info: {}", e),
2417 /// }
2418 /// #
2419 /// # // Shut down the AMD SMI library
2420 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2421 /// # }
2422 /// ```
2423 ///
2424 /// # Errors
2425 ///
2426 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_od_volt_info` call fails.
2427 pub fn amdsmi_get_gpu_od_volt_info(
2428 processor_handle: AmdsmiProcessorHandle,
2429 ) -> AmdsmiResult<AmdsmiOdVoltFreqDataT> {
2430 let mut odv = MaybeUninit::<AmdsmiOdVoltFreqDataT>::uninit();
2431 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_od_volt_info(
2432 processor_handle,
2433 odv.as_mut_ptr()
2434 ));
2435 let odv = unsafe { odv.assume_init() };
2436 Ok(odv)
2437 }
2438
2439 /// Get the GPU metrics header information of the device with the specified processor handle.
2440 ///
2441 /// Given a processor handle `processor_handle`, this function returns the GPU metrics header information
2442 /// for the specified processor.
2443 ///
2444 /// # Arguments
2445 ///
2446 /// * `processor_handle` - A handle to the processor for which the GPU metrics header information is being queried.
2447 ///
2448 /// # Returns
2449 ///
2450 /// * `AmdsmiResult<AmdMetricsTableHeaderT>` - Returns `Ok(AmdMetricsTableHeaderT)` containing the [`AmdMetricsTableHeaderT`] if successful, or an error if it fails.
2451 ///
2452 /// # Example
2453 ///
2454 /// ```rust
2455 /// # use amdsmi::*;
2456 /// #
2457 /// # fn main() {
2458 /// # // Initialize the AMD SMI library
2459 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2460 /// #
2461 /// // Example processor_handle, assuming the number of processors is greater than zero
2462 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2463 ///
2464 /// // Retrieve the GPU metrics header information
2465 /// match amdsmi_get_gpu_metrics_header_info(processor_handle) {
2466 /// Ok(header_info) => println!("GPU Metrics Header Info: {:?}", header_info),
2467 /// Err(e) => panic!("Failed to get GPU metrics header info: {}", e),
2468 /// }
2469 /// #
2470 /// # // Shut down the AMD SMI library
2471 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2472 /// # }
2473 /// ```
2474 ///
2475 /// # Errors
2476 ///
2477 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_metrics_header_info` call fails.
2478 pub fn amdsmi_get_gpu_metrics_header_info(
2479 processor_handle: AmdsmiProcessorHandle,
2480 ) -> AmdsmiResult<AmdMetricsTableHeaderT> {
2481 let mut header_value = MaybeUninit::<AmdMetricsTableHeaderT>::uninit();
2482 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_metrics_header_info(
2483 processor_handle,
2484 header_value.as_mut_ptr()
2485 ));
2486 let header_value = unsafe { header_value.assume_init() };
2487 Ok(header_value)
2488 }
2489
2490 /// Get the GPU metrics information of the device with the specified processor handle.
2491 ///
2492 /// Given a processor handle `processor_handle`, this function returns the GPU metrics information
2493 /// for the specified processor.
2494 ///
2495 /// # Arguments
2496 ///
2497 /// * `processor_handle` - A handle to the processor for which the GPU metrics information is being queried.
2498 ///
2499 /// # Returns
2500 ///
2501 /// * `AmdsmiResult<AmdsmiGpuMetricsT>` - Returns `Ok(AmdsmiGpuMetricsT)` containing the [`AmdsmiGpuMetricsT`] if successful, or an error if it fails.
2502 ///
2503 /// # Example
2504 ///
2505 /// ```rust
2506 /// # use amdsmi::*;
2507 /// #
2508 /// # fn main() {
2509 /// # // Initialize the AMD SMI library
2510 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2511 /// #
2512 /// // Example processor_handle, assuming the number of processors is greater than zero
2513 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2514 ///
2515 /// // Retrieve the GPU metrics information
2516 /// match amdsmi_get_gpu_metrics_info(processor_handle) {
2517 /// Ok(gpu_metrics) => println!("GPU Metrics Info: {:?}", gpu_metrics),
2518 /// Err(e) => panic!("Failed to get GPU metrics info: {}", e),
2519 /// }
2520 /// #
2521 /// # // Shut down the AMD SMI library
2522 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2523 /// # }
2524 /// ```
2525 ///
2526 /// # Errors
2527 ///
2528 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_metrics_info` call fails.
2529 pub fn amdsmi_get_gpu_metrics_info(
2530 processor_handle: AmdsmiProcessorHandle,
2531 ) -> AmdsmiResult<AmdsmiGpuMetricsT> {
2532 let mut pgpu_metrics = MaybeUninit::<AmdsmiGpuMetricsT>::uninit();
2533 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_metrics_info(
2534 processor_handle,
2535 pgpu_metrics.as_mut_ptr()
2536 ));
2537 let pgpu_metrics = unsafe { pgpu_metrics.assume_init() };
2538 Ok(pgpu_metrics)
2539 }
2540
2541 /// Get the GPU power management metrics information of the device with the specified processor handle.
2542 ///
2543 /// Given a processor handle `processor_handle`, this function returns the GPU power management metrics information
2544 /// for the specified processor.
2545 ///
2546 /// # Arguments
2547 ///
2548 /// * `processor_handle` - A handle to the processor for which the GPU power management metrics information is being queried.
2549 ///
2550 /// # Returns
2551 ///
2552 /// * `AmdsmiResult<Vec<AmdsmiNameValueT>>` - Returns `Ok(Vec<AmdsmiNameValueT>)` containing a list of [`AmdsmiNameValueT`] if successful, or an error if it fails.
2553 ///
2554 /// # Example
2555 ///
2556 /// ```rust
2557 /// # use amdsmi::*;
2558 /// #
2559 /// # fn main() {
2560 /// # // Initialize the AMD SMI library
2561 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2562 /// #
2563 /// // Example processor_handle, assuming the number of processors is greater than zero
2564 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2565 ///
2566 /// // Retrieve the GPU power management metrics information
2567 /// match amdsmi_get_gpu_pm_metrics_info(processor_handle) {
2568 /// Ok(pm_metrics) => {
2569 /// println!("Number of Metrics: {}", pm_metrics.len());
2570 /// for metric in pm_metrics {
2571 /// println!("Metric: {:?}", metric);
2572 /// }
2573 /// },
2574 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_pm_metrics_info() not supported on this device"),
2575 /// Err(e) => panic!("Failed to get GPU power management metrics info: {}", e),
2576 /// }
2577 /// #
2578 /// # // Shut down the AMD SMI library
2579 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2580 /// # }
2581 /// ```
2582 ///
2583 /// # Errors
2584 ///
2585 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_pm_metrics_info` call fails.
2586 pub fn amdsmi_get_gpu_pm_metrics_info(
2587 processor_handle: AmdsmiProcessorHandle,
2588 ) -> AmdsmiResult<Vec<AmdsmiNameValueT>> {
2589 let mut pm_metrics_ptr: *mut AmdsmiNameValueT = null_mut();
2590 let mut num_of_metrics = 0;
2591 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_pm_metrics_info(
2592 processor_handle,
2593 &mut pm_metrics_ptr,
2594 &mut num_of_metrics
2595 ));
2596
2597 let pm_metrics_slice =
2598 unsafe { std::slice::from_raw_parts(pm_metrics_ptr, num_of_metrics as usize) };
2599 let pm_metrics = pm_metrics_slice.to_vec();
2600
2601 if !pm_metrics_ptr.is_null() {
2602 unsafe { free(pm_metrics_ptr as *mut c_void) };
2603 }
2604
2605 Ok(pm_metrics)
2606 }
2607
2608 /// Get the GPU register table information of the device with the specified processor handle and register type.
2609 ///
2610 /// Given a processor handle `processor_handle` and a register type `reg_type`, this function returns the GPU register table information
2611 /// for the specified processor.
2612 ///
2613 /// # Arguments
2614 ///
2615 /// * `processor_handle` - A handle to the processor for which the GPU register table information is being queried.
2616 /// * `reg_type` - The [`AmdsmiRegTypeT`] type of the register to query.
2617 ///
2618 /// # Returns
2619 ///
2620 /// * `AmdsmiResult<Vec<AmdsmiNameValueT>>` - Returns `Ok(Vec<AmdsmiNameValueT>)` containing a list of [`AmdsmiNameValueT`] if successful, or an error if it fails.
2621 ///
2622 /// # Example
2623 ///
2624 /// ```rust
2625 /// # use amdsmi::*;
2626 /// #
2627 /// # fn main() {
2628 /// # // Initialize the AMD SMI library
2629 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2630 /// #
2631 /// // Example processor_handle, assuming the number of processors is greater than zero
2632 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2633 ///
2634 /// // Example register type
2635 /// let reg_type = AmdsmiRegTypeT::AmdsmiRegPcie;
2636 ///
2637 /// // Retrieve the GPU register table information
2638 /// match amdsmi_get_gpu_reg_table_info(processor_handle, reg_type) {
2639 /// Ok(reg_metrics) => {
2640 /// println!("Number of Metrics: {}", reg_metrics.len());
2641 /// for metric in reg_metrics {
2642 /// println!("Metric: {:?}", metric);
2643 /// }
2644 /// },
2645 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_reg_table_info() not supported on this device"),
2646 /// Err(e) => panic!("Failed to get GPU register table info: {}", e),
2647 /// }
2648 /// #
2649 /// # // Shut down the AMD SMI library
2650 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2651 /// # }
2652 /// ```
2653 ///
2654 /// # Errors
2655 ///
2656 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_reg_table_info` call fails.
2657 pub fn amdsmi_get_gpu_reg_table_info(
2658 processor_handle: AmdsmiProcessorHandle,
2659 reg_type: AmdsmiRegTypeT,
2660 ) -> AmdsmiResult<Vec<AmdsmiNameValueT>> {
2661 let mut reg_metrics_ptr: *mut AmdsmiNameValueT = null_mut();
2662 let mut num_of_metrics = 0;
2663 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_reg_table_info(
2664 processor_handle,
2665 reg_type,
2666 &mut reg_metrics_ptr,
2667 &mut num_of_metrics
2668 ));
2669
2670 let reg_metrics_slice =
2671 unsafe { std::slice::from_raw_parts(reg_metrics_ptr, num_of_metrics as usize) };
2672 let reg_metrics = reg_metrics_slice.to_vec();
2673
2674 if !reg_metrics_ptr.is_null() {
2675 unsafe { free(reg_metrics_ptr as *mut c_void) };
2676 }
2677
2678 Ok(reg_metrics)
2679 }
2680
2681 /// Set the GPU clock range of the device with the specified processor handle, minimum clock value, maximum clock value, and clock type.
2682 ///
2683 /// Given a processor handle `processor_handle`, a minimum clock value `minclkvalue`, a maximum clock value `maxclkvalue`, and a clock type `clk_type`,
2684 /// this function sets the GPU clock range for the specified processor.
2685 ///
2686 /// # Arguments
2687 ///
2688 /// * `processor_handle` - A handle to the processor for which the GPU clock range is being set.
2689 /// * `minclkvalue` - The minimum clock value to set.
2690 /// * `maxclkvalue` - The maximum clock value to set.
2691 /// * `clk_type` - The type of the clock to set.
2692 ///
2693 /// # Returns
2694 ///
2695 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
2696 ///
2697 /// # Example
2698 ///
2699 /// ```rust
2700 /// # use amdsmi::*;
2701 /// #
2702 /// # fn main() {
2703 /// # // Initialize the AMD SMI library
2704 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2705 /// #
2706 /// // Example processor_handle, assuming the number of processors is greater than zero
2707 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2708 ///
2709 /// // Example clock values and clock type
2710 /// let minclkvalue = 500; // Set minimum clock value to 500 MHz
2711 /// let maxclkvalue = 1500; // Set maximum clock value to 1500 MHz
2712 /// let clk_type = AmdsmiClkTypeT::AmdsmiClkTypeGfx;
2713 ///
2714 /// // Set the GPU clock range
2715 /// match amdsmi_set_gpu_clk_range(processor_handle, minclkvalue, maxclkvalue, clk_type) {
2716 /// Ok(()) => println!("GPU clock range set successfully"),
2717 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_set_gpu_clk_range() not supported on this device"),
2718 /// Err(e) => panic!("Failed to set GPU clock range: {}", e),
2719 /// }
2720 /// #
2721 /// # // Shut down the AMD SMI library
2722 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2723 /// # }
2724 /// ```
2725 ///
2726 /// # Errors
2727 ///
2728 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_gpu_clk_range` call fails.
2729 pub fn amdsmi_set_gpu_clk_range(
2730 processor_handle: AmdsmiProcessorHandle,
2731 minclkvalue: u64,
2732 maxclkvalue: u64,
2733 clk_type: AmdsmiClkTypeT,
2734 ) -> AmdsmiResult<()> {
2735 call_unsafe!(amdsmi_wrapper::amdsmi_set_gpu_clk_range(
2736 processor_handle,
2737 minclkvalue,
2738 maxclkvalue,
2739 clk_type
2740 ));
2741 Ok(())
2742 }
2743
2744 /// Set the GPU clock limit of the device with the specified processor handle, clock type, limit type, and clock value.
2745 ///
2746 /// Given a processor handle `processor_handle`, a clock type `clk_type`, a limit type `limit_type`, and a clock value `clk_value`,
2747 /// this function sets the GPU clock limit for the specified processor.
2748 ///
2749 /// # Arguments
2750 ///
2751 /// * `processor_handle` - A handle to the processor for which the GPU clock limit is being set.
2752 /// * `clk_type` - The type of the clock to set.
2753 /// * `limit_type` - The type of the clock limit to set.
2754 /// * `clk_value` - The clock value to set. Frequency values are in MHz.
2755 ///
2756 /// # Returns
2757 ///
2758 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
2759 ///
2760 /// # Example
2761 ///
2762 /// ```rust
2763 /// # use amdsmi::*;
2764 /// #
2765 /// # fn main() {
2766 /// # // Initialize the AMD SMI library
2767 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2768 /// #
2769 /// // Example processor_handle, assuming the number of processors is greater than zero
2770 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2771 ///
2772 /// // Example clock type, limit type, and clock value
2773 /// let clk_type = AmdsmiClkTypeT::AmdsmiClkTypeGfx;
2774 /// let limit_type = AmdsmiClkLimitTypeT::ClkLimitMin;
2775 /// let clk_value = 1500; // Set clock value to 1500 MHz
2776 ///
2777 /// // Set the GPU clock limit
2778 /// match amdsmi_set_gpu_clk_limit(processor_handle, clk_type, limit_type, clk_value) {
2779 /// Ok(()) => println!("GPU clock limit set successfully"),
2780 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_set_gpu_clk_limit() not supported on this device"),
2781 /// Err(e) => panic!("Failed to set GPU clock limit: {}", e),
2782 /// }
2783 /// #
2784 /// # // Shut down the AMD SMI library
2785 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2786 /// # }
2787 /// ```
2788 ///
2789 /// # Errors
2790 ///
2791 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_gpu_clk_limit` call fails.
2792 pub fn amdsmi_set_gpu_clk_limit(
2793 processor_handle: AmdsmiProcessorHandle,
2794 clk_type: AmdsmiClkTypeT,
2795 limit_type: AmdsmiClkLimitTypeT,
2796 clk_value: u64,
2797 ) -> AmdsmiResult<()> {
2798 call_unsafe!(amdsmi_wrapper::amdsmi_set_gpu_clk_limit(
2799 processor_handle,
2800 clk_type,
2801 limit_type,
2802 clk_value
2803 ));
2804 Ok(())
2805 }
2806
2807 /// Set the GPU overdrive clock information of the device with the specified processor handle, level, clock value, and clock type.
2808 ///
2809 /// Given a processor handle `processor_handle`, a frequency index `level`, a clock value `clkvalue`, and a clock type `clk_type`,
2810 /// this function sets the GPU overdrive clock information for the specified processor.
2811 ///
2812 /// # Arguments
2813 ///
2814 /// * `processor_handle` - A handle to the processor for which the GPU overdrive clock information is being set.
2815 /// * `level` - The frequency index level [`AmdsmiFreqIndT`] to set.
2816 /// * `clkvalue` - The clock value to set.
2817 /// * `clk_type` - The type of the clock [`AmdsmiClkTypeT`] to set.
2818 ///
2819 /// # Returns
2820 ///
2821 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
2822 ///
2823 /// # Example
2824 ///
2825 /// ```rust
2826 /// # use amdsmi::*;
2827 /// #
2828 /// # fn main() {
2829 /// # // Initialize the AMD SMI library
2830 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2831 /// #
2832 /// // Example processor_handle, assuming the number of processors is greater than zero
2833 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2834 ///
2835 /// // Example frequency index level, clock value, and clock type
2836 /// let level = AmdsmiFreqIndT::AmdsmiFreqIndMin;
2837 /// let clkvalue = 1500; // Set clock value to 1500 MHz
2838 /// let clk_type = AmdsmiClkTypeT::AmdsmiClkTypeGfx;
2839 ///
2840 /// // Set the GPU overdrive clock information
2841 /// match amdsmi_set_gpu_od_clk_info(processor_handle, level, clkvalue, clk_type) {
2842 /// Ok(()) => println!("GPU overdrive clock information set successfully"),
2843 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_set_gpu_od_clk_info() not supported on this device"),
2844 /// Err(e) => panic!("Failed to set GPU overdrive clock information: {}", e),
2845 /// }
2846 /// #
2847 /// # // Shut down the AMD SMI library
2848 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2849 /// # }
2850 /// ```
2851 ///
2852 /// # Errors
2853 ///
2854 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_gpu_od_clk_info` call fails.
2855 pub fn amdsmi_set_gpu_od_clk_info(
2856 processor_handle: AmdsmiProcessorHandle,
2857 level: AmdsmiFreqIndT,
2858 clkvalue: u64,
2859 clk_type: AmdsmiClkTypeT,
2860 ) -> AmdsmiResult<()> {
2861 call_unsafe!(amdsmi_wrapper::amdsmi_set_gpu_od_clk_info(
2862 processor_handle,
2863 level,
2864 clkvalue,
2865 clk_type
2866 ));
2867 Ok(())
2868 }
2869
2870 /// Set the GPU overdrive voltage information of the device with the specified processor handle, voltage point, clock value, and voltage value.
2871 ///
2872 /// Given a processor handle `processor_handle`, a voltage point `vpoint`, a clock value `clkvalue`, and a voltage value `voltvalue`,
2873 /// this function sets the GPU overdrive voltage information for the specified processor.
2874 ///
2875 /// # Arguments
2876 ///
2877 /// * `processor_handle` - A handle to the processor for which the GPU overdrive voltage information is being set.
2878 /// * `vpoint` - The voltage point [0|1|2] on the voltage curve to set.
2879 /// * `clkvalue` - The clock value component of voltage curve point to set.
2880 /// * `voltvalue` - The voltage value component of voltage curve point to set.
2881 ///
2882 /// # Returns
2883 ///
2884 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
2885 ///
2886 /// # Example
2887 ///
2888 /// ```rust
2889 /// # use amdsmi::*;
2890 /// #
2891 /// # fn main() {
2892 /// # // Initialize the AMD SMI library
2893 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2894 /// #
2895 /// // Example processor_handle, assuming the number of processors is greater than zero
2896 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2897 ///
2898 /// // Example voltage point, clock value, and voltage value
2899 /// let vpoint = 1;
2900 /// let clkvalue = 1000;
2901 /// let voltvalue = 980;
2902 ///
2903 /// // Set the GPU overdrive voltage information
2904 /// match amdsmi_set_gpu_od_volt_info(processor_handle, vpoint, clkvalue, voltvalue) {
2905 /// Ok(()) => println!("GPU overdrive voltage information set successfully"),
2906 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_set_gpu_od_volt_info() not supported on this device"),
2907 /// Err(e) => panic!("Failed to set GPU overdrive voltage information: {}", e),
2908 /// }
2909 /// #
2910 /// # // Shut down the AMD SMI library
2911 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2912 /// # }
2913 /// ```
2914 ///
2915 /// # Errors
2916 ///
2917 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_gpu_od_volt_info` call fails.
2918 pub fn amdsmi_set_gpu_od_volt_info(
2919 processor_handle: AmdsmiProcessorHandle,
2920 vpoint: u32,
2921 clkvalue: u64,
2922 voltvalue: u64,
2923 ) -> AmdsmiResult<()> {
2924 call_unsafe!(amdsmi_wrapper::amdsmi_set_gpu_od_volt_info(
2925 processor_handle,
2926 vpoint,
2927 clkvalue,
2928 voltvalue
2929 ));
2930 Ok(())
2931 }
2932
2933 /// Get the GPU overdrive voltage curve regions of the device with the specified processor handle.
2934 ///
2935 /// Given a processor handle `processor_handle`, this function returns the GPU current valid overdrive voltage
2936 /// curve regions for the specified processor.
2937 ///
2938 /// # Arguments
2939 ///
2940 /// * `processor_handle` - A handle to the processor for which the GPU overdrive voltage curve regions are being queried.
2941 ///
2942 /// # Returns
2943 ///
2944 /// * `AmdsmiResult<Vec<AmdsmiFreqVoltRegionT>>` - Returns `Ok(Vec<AmdsmiFreqVoltRegionT>)` containing a list of [`AmdsmiFreqVoltRegionT`] if successful, or an error if it fails.
2945 ///
2946 /// # Example
2947 ///
2948 /// ```rust
2949 /// # use amdsmi::*;
2950 /// #
2951 /// # fn main() {
2952 /// # // Initialize the AMD SMI library
2953 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
2954 /// #
2955 /// // Example processor_handle, assuming the number of processors is greater than zero
2956 /// let processor_handle = amdsmi_get_processor_handles!()[0];
2957 ///
2958 /// // Retrieve the GPU overdrive voltage curve regions
2959 /// match amdsmi_get_gpu_od_volt_curve_regions(processor_handle) {
2960 /// Ok(regions) => {
2961 /// println!("Number of Regions: {}", regions.len());
2962 /// for region in regions {
2963 /// println!("Region: {:?}", region);
2964 /// }
2965 /// },
2966 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_od_volt_curve_regions() not supported on this device"),
2967 /// Err(e) => panic!("Failed to get GPU overdrive voltage curve regions: {}", e),
2968 /// }
2969 /// #
2970 /// # // Shut down the AMD SMI library
2971 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
2972 /// # }
2973 /// ```
2974 ///
2975 /// # Errors
2976 ///
2977 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_od_volt_curve_regions` call fails.
2978 pub fn amdsmi_get_gpu_od_volt_curve_regions(
2979 processor_handle: AmdsmiProcessorHandle,
2980 ) -> AmdsmiResult<Vec<AmdsmiFreqVoltRegionT>> {
2981 // First call to get the number of regions
2982 let mut num_regions = MaybeUninit::<u32>::uninit();
2983
2984 // First call to get the number of regions
2985 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_od_volt_curve_regions(
2986 processor_handle,
2987 num_regions.as_mut_ptr(),
2988 std::ptr::null_mut()
2989 ));
2990
2991 let num_regions = unsafe { num_regions.assume_init() };
2992
2993 // Allocate a vector with the capacity of num_regions
2994 let mut buffer: Vec<AmdsmiFreqVoltRegionT> = Vec::with_capacity(num_regions as usize);
2995
2996 // Second call to get the actual data
2997 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_od_volt_curve_regions(
2998 processor_handle,
2999 &mut (num_regions as u32),
3000 buffer.as_mut_ptr()
3001 ));
3002
3003 // Set the length of the vector to num_regions
3004 unsafe { buffer.set_len(num_regions as usize) };
3005
3006 Ok(buffer)
3007 }
3008
3009 /// Get the GPU power profile presets of the device with the specified processor handle and sensor index.
3010 ///
3011 /// Given a processor handle `processor_handle` and a sensor index `sensor_ind`, this function returns the GPU power profile presets
3012 /// for the specified processor.
3013 ///
3014 /// # Arguments
3015 ///
3016 /// * `processor_handle` - A handle to the processor for which the GPU power profile presets are being queried.
3017 /// * `sensor_ind` - The sensor index to query.
3018 ///
3019 /// # Returns
3020 ///
3021 /// * `AmdsmiResult<AmdsmiPowerProfileStatusT>` - Returns `Ok(AmdsmiPowerProfileStatusT)` containing the [`AmdsmiPowerProfileStatusT`] if successful, or an error if it fails.
3022 ///
3023 /// # Example
3024 ///
3025 /// ```rust
3026 /// # use amdsmi::*;
3027 /// #
3028 /// # fn main() {
3029 /// # // Initialize the AMD SMI library
3030 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3031 /// #
3032 /// // Example processor_handle, assuming the number of processors is greater than zero
3033 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3034 ///
3035 /// // Example sensor index
3036 /// let sensor_ind = 0; // Sensor index 0
3037 ///
3038 /// // Retrieve the GPU power profile presets
3039 /// match amdsmi_get_gpu_power_profile_presets(processor_handle, sensor_ind) {
3040 /// Ok(status) => println!("GPU Power Profile Status: {:?}", status),
3041 /// Err(e) => panic!("Failed to get GPU power profile presets: {}", e),
3042 /// }
3043 /// #
3044 /// # // Shut down the AMD SMI library
3045 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3046 /// # }
3047 /// ```
3048 ///
3049 /// # Errors
3050 ///
3051 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_power_profile_presets` call fails.
3052 pub fn amdsmi_get_gpu_power_profile_presets(
3053 processor_handle: AmdsmiProcessorHandle,
3054 sensor_ind: u32,
3055 ) -> AmdsmiResult<AmdsmiPowerProfileStatusT> {
3056 let mut status = MaybeUninit::<AmdsmiPowerProfileStatusT>::uninit();
3057 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_power_profile_presets(
3058 processor_handle,
3059 sensor_ind,
3060 status.as_mut_ptr()
3061 ));
3062 let status = unsafe { status.assume_init() };
3063 Ok(status)
3064 }
3065
3066 /// Set the GPU performance level of the device with the specified processor handle and performance level.
3067 ///
3068 /// Given a processor handle `processor_handle` and a performance level `perf_lvl`, this function sets the GPU performance level
3069 /// for the specified processor.
3070 ///
3071 /// # Arguments
3072 ///
3073 /// * `processor_handle` - A handle to the processor for which the GPU performance level is being set.
3074 /// * `perf_lvl` - The performance level [`AmdsmiDevPerfLevelT`] to set.
3075 ///
3076 /// # Returns
3077 ///
3078 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
3079 ///
3080 /// # Example
3081 ///
3082 /// ```rust
3083 /// # use amdsmi::*;
3084 /// #
3085 /// # fn main() {
3086 /// # // Initialize the AMD SMI library
3087 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3088 /// #
3089 /// // Example processor_handle, assuming the number of processors is greater than zero
3090 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3091 ///
3092 /// // Example performance level
3093 /// let perf_lvl = AmdsmiDevPerfLevelT::AmdsmiDevPerfLevelHigh;
3094 ///
3095 /// // Set the GPU performance level
3096 /// match amdsmi_set_gpu_perf_level(processor_handle, perf_lvl) {
3097 /// Ok(()) => println!("GPU performance level set successfully"),
3098 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_set_gpu_perf_level() not supported on this device"),
3099 /// Err(e) => panic!("Failed to set GPU performance level: {}", e),
3100 /// }
3101 /// #
3102 /// # // Shut down the AMD SMI library
3103 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3104 /// # }
3105 /// ```
3106 ///
3107 /// # Errors
3108 ///
3109 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_gpu_perf_level` call fails.
3110 pub fn amdsmi_set_gpu_perf_level(
3111 processor_handle: AmdsmiProcessorHandle,
3112 perf_lvl: AmdsmiDevPerfLevelT,
3113 ) -> AmdsmiResult<()> {
3114 call_unsafe!(amdsmi_wrapper::amdsmi_set_gpu_perf_level(
3115 processor_handle,
3116 perf_lvl
3117 ));
3118 Ok(())
3119 }
3120
3121 /// Set the GPU overdrive percent of the device with the specified processor handle and overdrive level.
3122 ///
3123 /// Given a processor handle `processor_handle` and an overdrive level `od`, this function sets the GPU overdrive level
3124 /// for the specified processor.
3125 ///
3126 /// # Arguments
3127 ///
3128 /// * `processor_handle` - A handle to the processor for which the GPU overdrive level is being set.
3129 /// * `od` - The overdrive level to set.
3130 ///
3131 /// # Returns
3132 ///
3133 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
3134 ///
3135 /// # Example
3136 ///
3137 /// ```rust
3138 /// # use amdsmi::*;
3139 /// #
3140 /// # fn main() {
3141 /// # // Initialize the AMD SMI library
3142 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3143 /// #
3144 /// // Example processor_handle, assuming the number of processors is greater than zero
3145 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3146 ///
3147 /// // Example overdrive level
3148 /// let od = 0; // Set overdrive level to 0
3149 ///
3150 /// // Set the GPU overdrive level
3151 /// match amdsmi_set_gpu_overdrive_level(processor_handle, od) {
3152 /// Ok(()) => println!("GPU overdrive level set successfully"),
3153 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_set_gpu_overdrive_level() not supported on this device"),
3154 /// Err(e) => panic!("Failed to set GPU overdrive level: {}", e),
3155 /// }
3156 /// #
3157 /// # // Shut down the AMD SMI library
3158 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3159 /// # }
3160 /// ```
3161 ///
3162 /// # Errors
3163 ///
3164 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_gpu_overdrive_level` call fails.
3165 pub fn amdsmi_set_gpu_overdrive_level(
3166 processor_handle: AmdsmiProcessorHandle,
3167 od: u32,
3168 ) -> AmdsmiResult<()> {
3169 call_unsafe!(amdsmi_wrapper::amdsmi_set_gpu_overdrive_level(
3170 processor_handle,
3171 od
3172 ));
3173 Ok(())
3174 }
3175
3176 /// Set the clock frequency of the device with the specified processor handle, clock type, and frequency bitmask.
3177 ///
3178 /// Given a processor handle `processor_handle`, a clock type `clk_type`, and a frequency bitmask `freq_bitmask`,
3179 /// this function sets the clock frequency for the specified processor.
3180 ///
3181 /// # Arguments
3182 ///
3183 /// * `processor_handle` - A handle to the processor for which the clock frequency is being set.
3184 /// * `clk_type` - The type of the clock to set.
3185 /// * `freq_bitmask` - The frequency bitmask to set. A bitmask indicating the indices of the frequencies
3186 /// that are to be enabled (1) and disabled (0). Only the lowest `AmdsmiFrequenciesT.num_supported`
3187 /// bits of this mask are relevant.
3188 ///
3189 /// # Returns
3190 ///
3191 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
3192 ///
3193 /// # Example
3194 ///
3195 /// ```rust
3196 /// # use amdsmi::*;
3197 /// #
3198 /// # fn main() {
3199 /// # // Initialize the AMD SMI library
3200 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3201 /// #
3202 /// // Example processor_handle, assuming the number of processors is greater than zero
3203 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3204 ///
3205 /// // Example clock type and frequency bitmask
3206 /// let clk_type = AmdsmiClkTypeT::AmdsmiClkTypeGfx;
3207 /// let freq_bitmask = 0; // Example frequency bitmask
3208 ///
3209 /// // Set the clock frequency
3210 /// match amdsmi_set_clk_freq(processor_handle, clk_type, freq_bitmask) {
3211 /// Ok(()) => println!("Clock frequency set successfully"),
3212 /// Err(e) => panic!("Failed to set clock frequency: {}", e),
3213 /// }
3214 /// #
3215 /// # // Shut down the AMD SMI library
3216 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3217 /// # }
3218 /// ```
3219 ///
3220 /// # Errors
3221 ///
3222 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_clk_freq` call fails.
3223 pub fn amdsmi_set_clk_freq(
3224 processor_handle: AmdsmiProcessorHandle,
3225 clk_type: AmdsmiClkTypeT,
3226 freq_bitmask: u64,
3227 ) -> AmdsmiResult<()> {
3228 call_unsafe!(amdsmi_wrapper::amdsmi_set_clk_freq(
3229 processor_handle,
3230 clk_type,
3231 freq_bitmask
3232 ));
3233 Ok(())
3234 }
3235
3236 /// Get the SoC P-state of the device with the specified processor handle.
3237 ///
3238 /// Given a processor handle `processor_handle`, this function returns the SoC P-state
3239 /// for the specified processor.
3240 ///
3241 /// # Arguments
3242 ///
3243 /// * `processor_handle` - A handle to the processor for which the SoC P-state is being queried.
3244 ///
3245 /// # Returns
3246 ///
3247 /// * `AmdsmiResult<AmdsmiDpmPolicyT>` - Returns `Ok(AmdsmiDpmPolicyT)` containing the [`AmdsmiDpmPolicyT`] if successful, or an error if it fails.
3248 ///
3249 /// # Example
3250 ///
3251 /// ```rust
3252 /// # use amdsmi::*;
3253 /// #
3254 /// # fn main() {
3255 /// # // Initialize the AMD SMI library
3256 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3257 /// #
3258 /// // Example processor_handle, assuming the number of processors is greater than zero
3259 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3260 ///
3261 /// // Retrieve the SoC P-state
3262 /// match amdsmi_get_soc_pstate(processor_handle) {
3263 /// Ok(policy) => println!("SoC P-state: {:?}", policy),
3264 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_soc_pstate() not supported on this device"),
3265 /// Err(e) => panic!("Failed to get SoC P-state: {}", e),
3266 /// }
3267 /// #
3268 /// # // Shut down the AMD SMI library
3269 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3270 /// # }
3271 /// ```
3272 ///
3273 /// # Errors
3274 ///
3275 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_soc_pstate` call fails.
3276 pub fn amdsmi_get_soc_pstate(
3277 processor_handle: AmdsmiProcessorHandle,
3278 ) -> AmdsmiResult<AmdsmiDpmPolicyT> {
3279 let mut policy = MaybeUninit::<AmdsmiDpmPolicyT>::uninit();
3280 call_unsafe!(amdsmi_wrapper::amdsmi_get_soc_pstate(
3281 processor_handle,
3282 policy.as_mut_ptr()
3283 ));
3284 let policy = unsafe { policy.assume_init() };
3285 Ok(policy)
3286 }
3287
3288 /// Set the SoC P-state of the device with the specified processor handle and policy ID.
3289 ///
3290 /// Given a processor handle `processor_handle` and a policy ID `policy_id`, this function sets the SoC P-state
3291 /// for the specified processor.
3292 ///
3293 /// # Arguments
3294 ///
3295 /// * `processor_handle` - A handle to the processor for which the SoC P-state is being set.
3296 /// * `policy_id` - The policy ID to set. The id is the id in [`AmdsmiDpmPolicyEntryT`], which can be obtained by calling amdsmi_get_soc_pstate().
3297 ///
3298 /// # Returns
3299 ///
3300 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
3301 ///
3302 /// # Example
3303 ///
3304 /// ```rust
3305 /// # use amdsmi::*;
3306 /// #
3307 /// # fn main() {
3308 /// # // Initialize the AMD SMI library
3309 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3310 /// #
3311 /// // Example processor_handle, assuming the number of processors is greater than zero
3312 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3313 ///
3314 /// // Example policy ID
3315 /// let policy_id = 0;
3316 ///
3317 /// // Set the SoC P-state
3318 /// match amdsmi_set_soc_pstate(processor_handle, policy_id) {
3319 /// Ok(()) => println!("SoC P-state set successfully"),
3320 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_set_soc_pstate() not supported on this device"),
3321 /// Err(e) => panic!("Failed to set SoC P-state: {}", e),
3322 /// }
3323 /// #
3324 /// # // Shut down the AMD SMI library
3325 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3326 /// # }
3327 /// ```
3328 ///
3329 /// # Errors
3330 ///
3331 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_soc_pstate` call fails.
3332 pub fn amdsmi_set_soc_pstate(
3333 processor_handle: AmdsmiProcessorHandle,
3334 policy_id: u32,
3335 ) -> AmdsmiResult<()> {
3336 call_unsafe!(amdsmi_wrapper::amdsmi_set_soc_pstate(
3337 processor_handle,
3338 policy_id
3339 ));
3340 Ok(())
3341 }
3342
3343 /// Get the XGMI per-link power down (PLPD) policy of the device with the specified processor handle.
3344 ///
3345 /// Given a processor handle `processor_handle`, this function returns the XGMI PLPD policy
3346 /// for the specified processor.
3347 ///
3348 /// # Arguments
3349 ///
3350 /// * `processor_handle` - A handle to the processor for which the XGMI PLPD policy is being queried.
3351 ///
3352 /// # Returns
3353 ///
3354 /// * `AmdsmiResult<AmdsmiDpmPolicyT>` - Returns `Ok(AmdsmiDpmPolicyT)` containing the [`AmdsmiDpmPolicyT`] if successful, or an error if it fails.
3355 ///
3356 /// # Example
3357 ///
3358 /// ```rust
3359 /// # use amdsmi::*;
3360 /// #
3361 /// # fn main() {
3362 /// # // Initialize the AMD SMI library
3363 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3364 /// #
3365 /// // Example processor_handle, assuming the number of processors is greater than zero
3366 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3367 ///
3368 /// // Retrieve the XGMI PLPD policy
3369 /// match amdsmi_get_xgmi_plpd(processor_handle) {
3370 /// Ok(xgmi_plpd) => println!("XGMI PLPD policy: {:?}", xgmi_plpd),
3371 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_xgmi_plpd() not supported on this device"),
3372 /// Err(e) => panic!("Failed to get XGMI PLPD policy: {}", e),
3373 /// }
3374 /// #
3375 /// # // Shut down the AMD SMI library
3376 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3377 /// # }
3378 /// ```
3379 ///
3380 /// # Errors
3381 ///
3382 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_xgmi_plpd` call fails.
3383 pub fn amdsmi_get_xgmi_plpd(
3384 processor_handle: AmdsmiProcessorHandle,
3385 ) -> AmdsmiResult<AmdsmiDpmPolicyT> {
3386 let mut xgmi_plpd = MaybeUninit::<AmdsmiDpmPolicyT>::uninit();
3387 call_unsafe!(amdsmi_wrapper::amdsmi_get_xgmi_plpd(
3388 processor_handle,
3389 xgmi_plpd.as_mut_ptr()
3390 ));
3391 let xgmi_plpd = unsafe { xgmi_plpd.assume_init() };
3392 Ok(xgmi_plpd)
3393 }
3394
3395 /// Set the XGMI per-link power down (PLPD) policy of the device with the specified processor handle and PLPD ID.
3396 ///
3397 /// Given a processor handle `processor_handle` and a PLPD ID `plpd_id`, this function sets the XGMI PLPD policy
3398 /// for the specified processor.
3399 ///
3400 /// # Arguments
3401 ///
3402 /// * `processor_handle` - A handle to the processor for which the XGMI PLPD policy is being set.
3403 /// * `plpd_id` - The PLPD ID to set. The id is the id in [`AmdsmiDpmPolicyEntryT`], which can be obtained by calling amdsmi_get_xgmi_plpd().
3404 ///
3405 /// # Returns
3406 ///
3407 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
3408 ///
3409 /// # Example
3410 ///
3411 /// ```rust
3412 /// # use amdsmi::*;
3413 /// #
3414 /// # fn main() {
3415 /// # // Initialize the AMD SMI library
3416 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3417 /// #
3418 /// // Example processor_handle, assuming the number of processors is greater than zero
3419 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3420 ///
3421 /// // Example PLPD ID
3422 /// let plpd_id = 0;
3423 ///
3424 /// // Set the XGMI PLPD policy
3425 /// match amdsmi_set_xgmi_plpd(processor_handle, plpd_id) {
3426 /// Ok(()) => println!("XGMI PLPD policy set successfully"),
3427 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_set_xgmi_plpd() not supported on this device"),
3428 /// Err(e) => panic!("Failed to set XGMI PLPD policy: {}", e),
3429 /// }
3430 /// #
3431 /// # // Shut down the AMD SMI library
3432 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3433 /// # }
3434 /// ```
3435 ///
3436 /// # Errors
3437 ///
3438 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_xgmi_plpd` call fails.
3439 pub fn amdsmi_set_xgmi_plpd(
3440 processor_handle: AmdsmiProcessorHandle,
3441 plpd_id: u32,
3442 ) -> AmdsmiResult<()> {
3443 call_unsafe!(amdsmi_wrapper::amdsmi_set_xgmi_plpd(
3444 processor_handle,
3445 plpd_id
3446 ));
3447 Ok(())
3448 }
3449
3450 /// Get the GPU process isolation status of the device with the specified processor handle.
3451 ///
3452 /// Given a processor handle `processor_handle`, this function returns the integer GPU process isolation status:
3453 /// 0 - disabled, 1 - enabled.
3454 ///
3455 /// # Arguments
3456 ///
3457 /// * `processor_handle` - A handle to the processor for which the GPU process isolation status is being queried.
3458 ///
3459 /// # Returns
3460 ///
3461 /// * `AmdsmiResult<u32>` - Returns `Ok(u32)` containing the GPU process isolation status if successful, or an error if it fails.
3462 ///
3463 /// # Example
3464 ///
3465 /// ```rust
3466 /// # use amdsmi::*;
3467 /// #
3468 /// # fn main() {
3469 /// # // Initialize the AMD SMI library
3470 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3471 /// #
3472 /// // Example processor_handle, assuming the number of processors is greater than zero
3473 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3474 ///
3475 /// // Retrieve the GPU process isolation status
3476 /// match amdsmi_get_gpu_process_isolation(processor_handle) {
3477 /// Ok(pisolate) => println!("GPU process isolation status: {}", pisolate),
3478 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_process_isolation() not supported on this device"),
3479 /// Err(e) => panic!("Failed to get GPU process isolation status: {}", e),
3480 /// }
3481 /// #
3482 /// # // Shut down the AMD SMI library
3483 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3484 /// # }
3485 /// ```
3486 ///
3487 /// # Errors
3488 ///
3489 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_process_isolation` call fails.
3490 pub fn amdsmi_get_gpu_process_isolation(
3491 processor_handle: AmdsmiProcessorHandle,
3492 ) -> AmdsmiResult<u32> {
3493 let mut pisolate = MaybeUninit::<u32>::uninit();
3494 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_process_isolation(
3495 processor_handle,
3496 pisolate.as_mut_ptr()
3497 ));
3498 let pisolate = unsafe { pisolate.assume_init() };
3499 Ok(pisolate)
3500 }
3501
3502 /// Enable/disable the system Process Isolation for the given device handle.
3503 ///
3504 /// Given a processor handle `processor_handle` and an isolation value `pisolate`, this function sets the GPU process isolation status
3505 /// for the specified processor.
3506 ///
3507 /// # Arguments
3508 ///
3509 /// * `processor_handle` - A handle to the processor for which the GPU process isolation status is being set.
3510 /// * `pisolate` - The isolation value to set. 0 is the process isolation disabled, and 1 is the process isolation enabled.
3511 ///
3512 /// # Returns
3513 ///
3514 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
3515 ///
3516 /// # Example
3517 ///
3518 /// ```rust
3519 /// # use amdsmi::*;
3520 /// #
3521 /// # fn main() {
3522 /// # // Initialize the AMD SMI library
3523 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3524 /// #
3525 /// // Example processor_handle, assuming the number of processors is greater than zero
3526 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3527 ///
3528 /// // Example isolation value
3529 /// let pisolate = 1; // Set isolation to enabled
3530 ///
3531 /// // Set the GPU process isolation status
3532 /// match amdsmi_set_gpu_process_isolation(processor_handle, pisolate) {
3533 /// Ok(()) => println!("GPU process isolation status set successfully"),
3534 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_set_gpu_process_isolation() not supported on this device"),
3535 /// Err(e) => panic!("Failed to set GPU process isolation status: {}", e),
3536 /// }
3537 /// #
3538 /// # // Shut down the AMD SMI library
3539 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3540 /// # }
3541 /// ```
3542 ///
3543 /// # Errors
3544 ///
3545 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_gpu_process_isolation` call fails.
3546 pub fn amdsmi_set_gpu_process_isolation(
3547 processor_handle: AmdsmiProcessorHandle,
3548 pisolate: u32,
3549 ) -> AmdsmiResult<()> {
3550 call_unsafe!(amdsmi_wrapper::amdsmi_set_gpu_process_isolation(
3551 processor_handle,
3552 pisolate
3553 ));
3554 Ok(())
3555 }
3556
3557 /// Clean the GPU local data of the device with the specified processor handle.
3558 ///
3559 /// Given a processor handle `processor_handle`, this function cleans the GPU local data
3560 /// for the specified processor.
3561 ///
3562 /// # Arguments
3563 ///
3564 /// * `processor_handle` - A handle to the processor for which the GPU local data is being cleaned.
3565 ///
3566 /// # Returns
3567 ///
3568 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
3569 ///
3570 /// # Example
3571 ///
3572 /// ```rust
3573 /// # use amdsmi::*;
3574 /// #
3575 /// # fn main() {
3576 /// # // Initialize the AMD SMI library
3577 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3578 /// #
3579 /// // Example processor_handle, assuming the number of processors is greater than zero
3580 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3581 ///
3582 /// // Clean the GPU local data
3583 /// match amdsmi_clean_gpu_local_data(processor_handle) {
3584 /// Ok(()) => println!("GPU local data cleaned successfully"),
3585 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_clean_gpu_local_data() not supported on this device"),
3586 /// Err(e) => panic!("Failed to clean GPU local data: {}", e),
3587 /// }
3588 /// #
3589 /// # // Shut down the AMD SMI library
3590 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3591 /// # }
3592 /// ```
3593 ///
3594 /// # Errors
3595 ///
3596 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_clean_gpu_local_data` call fails.
3597 pub fn amdsmi_clean_gpu_local_data(processor_handle: AmdsmiProcessorHandle) -> AmdsmiResult<()> {
3598 call_unsafe!(amdsmi_wrapper::amdsmi_clean_gpu_local_data(
3599 processor_handle
3600 ));
3601 Ok(())
3602 }
3603
3604 /// Get the GPU ECC error count for a specific block of the device with the specified processor handle.
3605 ///
3606 /// Given a processor handle `processor_handle` and a GPU block `block`, this function returns the ECC error count
3607 /// for the specified block of the processor.
3608 ///
3609 /// # Arguments
3610 ///
3611 /// * `processor_handle` - A handle to the processor for which the ECC error count is being queried.
3612 /// * `block` - The GPU block for which the ECC error count is being queried.
3613 ///
3614 /// # Returns
3615 ///
3616 /// * `AmdsmiResult<AmdsmiErrorCountT>` - Returns `Ok(AmdsmiErrorCountT)` containing the [`AmdsmiErrorCountT`] if successful, or an error if it fails.
3617 ///
3618 /// # Example
3619 ///
3620 /// ```rust
3621 /// # use amdsmi::*;
3622 /// #
3623 /// # fn main() {
3624 /// # // Initialize the AMD SMI library
3625 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3626 /// #
3627 /// // Example processor_handle, assuming the number of processors is greater than zero
3628 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3629 ///
3630 /// // Example GPU block
3631 /// let block = AmdsmiGpuBlockT::AmdsmiGpuBlockGfx;
3632 ///
3633 /// // Retrieve the GPU ECC error count
3634 /// match amdsmi_get_gpu_ecc_count(processor_handle, block) {
3635 /// Ok(ec) => println!("GPU ECC error count: {:?}", ec),
3636 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_ecc_count() not supported on this device"),
3637 /// Err(e) => panic!("Failed to get GPU ECC error count: {}", e),
3638 /// }
3639 /// #
3640 /// # // Shut down the AMD SMI library
3641 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3642 /// # }
3643 /// ```
3644 ///
3645 /// # Errors
3646 ///
3647 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_ecc_count` call fails.
3648 pub fn amdsmi_get_gpu_ecc_count(
3649 processor_handle: AmdsmiProcessorHandle,
3650 block: AmdsmiGpuBlockT,
3651 ) -> AmdsmiResult<AmdsmiErrorCountT> {
3652 let mut ec = MaybeUninit::<AmdsmiErrorCountT>::uninit();
3653 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_ecc_count(
3654 processor_handle,
3655 block,
3656 ec.as_mut_ptr()
3657 ));
3658 let ec = unsafe { ec.assume_init() };
3659 Ok(ec)
3660 }
3661
3662 /// Retrieve the enabled ECC bit-mask.
3663 ///
3664 /// Given a processor handle `processor_handle`, this function returns the ECC enabled
3665 /// ECC bit-mask for the specified processor.
3666 ///
3667 /// # Arguments
3668 ///
3669 /// * `processor_handle` - A handle to the processor for which the ECC enabled bit-mask are being queried.
3670 ///
3671 /// # Returns
3672 ///
3673 /// * `AmdsmiResult<u64>` - Returns `Ok(u64)` containing the ECC enabled bit-mask if successful, or an error if it fails.
3674 ///
3675 /// # Example
3676 ///
3677 /// ```rust
3678 /// # use amdsmi::*;
3679 /// #
3680 /// # fn main() {
3681 /// # // Initialize the AMD SMI library
3682 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3683 /// #
3684 /// // Example processor_handle, assuming the number of processors is greater than zero
3685 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3686 ///
3687 /// // Retrieve the GPU ECC enabled bit-mask
3688 /// match amdsmi_get_gpu_ecc_enabled(processor_handle) {
3689 /// Ok(enabled_mask) => println!("GPU ECC enabled: {}", enabled_mask),
3690 /// Err(e) => panic!("Failed to get GPU ECC enabled: {}", e),
3691 /// }
3692 /// #
3693 /// # // Shut down the AMD SMI library
3694 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3695 /// # }
3696 /// ```
3697 ///
3698 /// # Errors
3699 ///
3700 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_ecc_enabled` call fails.
3701 pub fn amdsmi_get_gpu_ecc_enabled(processor_handle: AmdsmiProcessorHandle) -> AmdsmiResult<u64> {
3702 let mut enabled_mask = MaybeUninit::<u64>::uninit();
3703 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_ecc_enabled(
3704 processor_handle,
3705 enabled_mask.as_mut_ptr()
3706 ));
3707 let enabled_mask = unsafe { enabled_mask.assume_init() };
3708 Ok(enabled_mask)
3709 }
3710
3711 /// Get the GPU ECC status for a specific block of the device with the specified processor handle.
3712 ///
3713 /// Given a processor handle `processor_handle` and a GPU block `block`, this function returns the ECC status
3714 /// for the specified block of the processor.
3715 ///
3716 /// # Arguments
3717 ///
3718 /// * `processor_handle` - A handle to the processor for which the ECC status is being queried.
3719 /// * `block` - The GPU block for which the ECC status is being queried.
3720 ///
3721 /// # Returns
3722 ///
3723 /// * `AmdsmiResult<AmdsmiRasErrStateT>` - Returns `Ok(AmdsmiRasErrStateT)` containing the [`AmdsmiRasErrStateT`] if successful, or an error if it fails.
3724 ///
3725 /// # Example
3726 ///
3727 /// ```rust
3728 /// # use amdsmi::*;
3729 /// #
3730 /// # fn main() {
3731 /// # // Initialize the AMD SMI library
3732 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3733 /// #
3734 /// // Example processor_handle, assuming the number of processors is greater than zero
3735 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3736 ///
3737 /// // Example GPU block
3738 /// let block = AmdsmiGpuBlockT::AmdsmiGpuBlockGfx;
3739 ///
3740 /// // Retrieve the GPU ECC status
3741 /// match amdsmi_get_gpu_ecc_status(processor_handle, block) {
3742 /// Ok(state) => println!("GPU ECC status: {:?}", state),
3743 /// Err(e) => panic!("Failed to get GPU ECC status: {}", e),
3744 /// }
3745 /// #
3746 /// # // Shut down the AMD SMI library
3747 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3748 /// # }
3749 /// ```
3750 ///
3751 /// # Errors
3752 ///
3753 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_ecc_status` call fails.
3754 pub fn amdsmi_get_gpu_ecc_status(
3755 processor_handle: AmdsmiProcessorHandle,
3756 block: AmdsmiGpuBlockT,
3757 ) -> AmdsmiResult<AmdsmiRasErrStateT> {
3758 let mut state = MaybeUninit::<AmdsmiRasErrStateT>::uninit();
3759 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_ecc_status(
3760 processor_handle,
3761 block,
3762 state.as_mut_ptr()
3763 ));
3764 let state = unsafe { state.assume_init() };
3765 Ok(state)
3766 }
3767
3768 /// Convert an AMD SMI status code to a string representation.
3769 ///
3770 /// Given a status code `status`, this function returns the string representation of the status code.
3771 ///
3772 /// # Arguments
3773 ///
3774 /// * `status` - The AMD SMI status code to convert.
3775 ///
3776 /// # Returns
3777 ///
3778 /// * `AmdsmiResult<String>` - Returns `Ok(String)` containing the string representation of the status code if successful, or an error if it fails.
3779 ///
3780 /// # Example
3781 ///
3782 /// ```rust
3783 /// # use amdsmi::*;
3784 /// #
3785 /// # fn main() {
3786 /// // Example status code
3787 /// let status = AmdsmiStatusT::AmdsmiStatusNotSupported;
3788 ///
3789 /// // Convert the status code to a string
3790 /// match amdsmi_status_code_to_string(status) {
3791 /// Ok(status_str) => println!("Status string: {}", status_str),
3792 /// Err(e) => panic!("Failed to convert status code to string: {}", e),
3793 /// }
3794 /// # }
3795 /// ```
3796 ///
3797 /// # Errors
3798 ///
3799 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_status_code_to_string` call fails.
3800 pub fn amdsmi_status_code_to_string(status: AmdsmiStatusT) -> AmdsmiResult<String> {
3801 let mut status_string: *const ::std::os::raw::c_char = null_mut();
3802 call_unsafe!(amdsmi_wrapper::amdsmi_status_code_to_string(
3803 status,
3804 &mut status_string
3805 ));
3806
3807 let c_str = unsafe { std::ffi::CStr::from_ptr(status_string) };
3808 let string = c_str.to_string_lossy().into_owned();
3809
3810 Ok(string)
3811 }
3812
3813 /// Check if a GPU counter group is supported for the device with the specified processor handle.
3814 ///
3815 /// Given a processor handle `processor_handle` and an event group `group`, this function checks if the specified GPU counter group
3816 /// is supported for the specified processor.
3817 ///
3818 /// # Arguments
3819 ///
3820 /// * `processor_handle` - A handle to the processor for which the GPU counter group support is being queried.
3821 /// * `group` - The event group to check for support.
3822 ///
3823 /// # Returns
3824 ///
3825 /// * `AmdsmiResult<bool>` - Returns `Ok(bool)` indicating whether the GPU counter group is supported if successful, or an error if it fails.
3826 ///
3827 /// # Example
3828 ///
3829 /// ```rust
3830 /// # use amdsmi::*;
3831 /// #
3832 /// # fn main() {
3833 /// # // Initialize the AMD SMI library
3834 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3835 /// #
3836 /// // Example processor_handle, assuming the number of processors is greater than zero
3837 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3838 ///
3839 /// // Example event group
3840 /// let group = AmdsmiEventGroupT::AmdsmiEvntGrpXgmi;
3841 ///
3842 /// // Check if the GPU counter group is supported
3843 /// match amdsmi_gpu_counter_group_supported(processor_handle, group) {
3844 /// Ok(supported) => println!("GPU counter group supported: {}", supported),
3845 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_gpu_counter_group_supported() not supported on this device"),
3846 /// Err(e) => panic!("Failed to check GPU counter group support: {}", e),
3847 /// }
3848 /// #
3849 /// # // Shut down the AMD SMI library
3850 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3851 /// # }
3852 /// ```
3853 ///
3854 /// # Errors
3855 ///
3856 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_gpu_counter_group_supported` call fails.
3857 pub fn amdsmi_gpu_counter_group_supported(
3858 processor_handle: AmdsmiProcessorHandle,
3859 group: AmdsmiEventGroupT,
3860 ) -> AmdsmiResult<bool> {
3861 call_unsafe!(amdsmi_wrapper::amdsmi_gpu_counter_group_supported(
3862 processor_handle,
3863 group
3864 ));
3865 // Here amdsmi_wrapper::amdsmi_gpu_counter_group_supported return successfull means supported.
3866 Ok(true)
3867 }
3868
3869 /// Creates a GPU counter for the specified event type on the device with the specified processor handle.
3870 ///
3871 /// This function creates a GPU counter for the specified event type on the specified processor handle,
3872 /// allowing the user to monitor specific GPU events.
3873 ///
3874 /// # Arguments
3875 ///
3876 /// * `processor_handle` - A handle to the processor for which the GPU counter is being created.
3877 /// * `event_type` - The type of event for which the GPU counter is being created.
3878 ///
3879 /// # Returns
3880 ///
3881 /// * `AmdsmiResult<AmdsmiEventHandleT>` - Returns `Ok(AmdsmiEventHandleT)` containing the [`AmdsmiEventHandleT`] if successful, or an error if it fails.
3882 ///
3883 /// # Example
3884 ///
3885 /// ```rust
3886 /// # use amdsmi::*;
3887 /// #
3888 /// # fn main() {
3889 /// # // Initialize the AMD SMI library
3890 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
3891 /// #
3892 /// // Example processor_handle, assuming the number of processors is greater than zero
3893 /// let processor_handle = amdsmi_get_processor_handles!()[0];
3894 ///
3895 /// // Check if the event group is supported
3896 /// let event_group = AmdsmiEventGroupT::AmdsmiEvntGrpXgmi;
3897 /// match amdsmi_gpu_counter_group_supported(processor_handle, event_group) {
3898 /// Ok(_) => println!("Event group supported."),
3899 /// Err(e) => {
3900 /// assert!( e == AmdsmiStatusT::AmdsmiStatusNotSupported, "Event group not supported: {}", e);
3901 /// }
3902 /// }
3903 ///
3904 /// // Check available GPU counters
3905 /// let available_counters = match amdsmi_get_gpu_available_counters(processor_handle, event_group) {
3906 /// Ok(available_counters) => available_counters,
3907 /// Err(e) => {
3908 /// assert!( e == AmdsmiStatusT::AmdsmiStatusNotSupported, "Failed to get available GPU counters: {}", e);
3909 /// 0
3910 /// }
3911 /// };
3912 ///
3913 /// if available_counters == 0 {
3914 /// println!("No available GPU counters or event group not supported.");
3915 /// amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3916 /// return;
3917 /// }
3918 ///
3919 /// // Example event type
3920 /// let event_type = AmdsmiEventTypeT::AmdsmiEvntXgmi0RequestTx;
3921 ///
3922 /// // Create a GPU counter
3923 /// match amdsmi_gpu_create_counter(processor_handle, event_type) {
3924 /// Ok(event_handle) => {
3925 /// println!("GPU counter created with handle: {:?}", event_handle);
3926 ///
3927 /// // Start the GPU counter
3928 /// let cmd_start = AmdsmiCounterCommandT::AmdsmiCntrCmdStart;
3929 /// amdsmi_gpu_control_counter(event_handle, cmd_start).expect("Failed to start GPU counter");
3930 ///
3931 /// // Wait for some time
3932 /// std::thread::sleep(std::time::Duration::from_secs(1));
3933 ///
3934 /// // Read the GPU counter value
3935 /// let value = amdsmi_gpu_read_counter(event_handle).expect("Failed to read GPU counter");
3936 /// println!("GPU counter value: {:?}", value);
3937 ///
3938 /// // Stop the GPU counter
3939 /// let cmd_stop = AmdsmiCounterCommandT::AmdsmiCntrCmdStop;
3940 /// amdsmi_gpu_control_counter(event_handle, cmd_stop).expect("Failed to stop GPU counter");
3941 ///
3942 /// // Destroy the GPU counter
3943 /// amdsmi_gpu_destroy_counter(event_handle).expect("Failed to destroy GPU counter");
3944 /// },
3945 /// Err(e) => eprintln!("Failed to create GPU counter: {}", e),
3946 /// }
3947 /// #
3948 /// # // Shut down the AMD SMI library
3949 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
3950 /// # }
3951 /// ```
3952 ///
3953 /// # Errors
3954 ///
3955 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_gpu_create_counter` call fails.
3956 pub fn amdsmi_gpu_create_counter(
3957 processor_handle: AmdsmiProcessorHandle,
3958 event_type: AmdsmiEventTypeT,
3959 ) -> AmdsmiResult<AmdsmiEventHandleT> {
3960 let mut evnt_handle = MaybeUninit::<AmdsmiEventHandleT>::uninit();
3961 call_unsafe!(amdsmi_wrapper::amdsmi_gpu_create_counter(
3962 processor_handle,
3963 event_type,
3964 evnt_handle.as_mut_ptr()
3965 ));
3966 let evnt_handle = unsafe { evnt_handle.assume_init() };
3967 Ok(evnt_handle)
3968 }
3969
3970 /// Destroy a GPU counter with the specified event handle.
3971 ///
3972 /// Given an event handle `evnt_handle`, this function destroys the GPU counter.
3973 ///
3974 /// # Arguments
3975 ///
3976 /// * `evnt_handle` - The event handle of the GPU counter to be destroyed.
3977 ///
3978 /// # Returns
3979 ///
3980 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
3981 ///
3982 /// # Example
3983 ///
3984 /// Refer to the example in the documentation for [`amdsmi_gpu_create_counter`].
3985 ///
3986 /// # Errors
3987 ///
3988 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_gpu_destroy_counter` call fails.
3989 pub fn amdsmi_gpu_destroy_counter(evnt_handle: AmdsmiEventHandleT) -> AmdsmiResult<()> {
3990 call_unsafe!(amdsmi_wrapper::amdsmi_gpu_destroy_counter(evnt_handle));
3991 Ok(())
3992 }
3993
3994 /// Control a GPU counter with the specified event handle and command.
3995 ///
3996 /// Given an event handle `evt_handle`, a command `cmd`, this function controls the GPU counter.
3997 ///
3998 /// # Arguments
3999 ///
4000 /// * `evt_handle` - The event handle of the GPU counter to be controlled.
4001 /// * `cmd` - The command to be executed on the GPU counter.
4002 ///
4003 /// # Returns
4004 ///
4005 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
4006 ///
4007 /// # Example
4008 ///
4009 /// Refer to the example in the documentation for [`amdsmi_gpu_create_counter`].
4010 ///
4011 /// # Errors
4012 ///
4013 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_gpu_control_counter` call fails.
4014 pub fn amdsmi_gpu_control_counter(
4015 evt_handle: AmdsmiEventHandleT,
4016 cmd: AmdsmiCounterCommandT,
4017 ) -> AmdsmiResult<()> {
4018 call_unsafe!(amdsmi_wrapper::amdsmi_gpu_control_counter(
4019 evt_handle,
4020 cmd,
4021 std::ptr::null_mut()
4022 ));
4023 Ok(())
4024 }
4025
4026 /// Read the value of a GPU counter with the specified event handle.
4027 ///
4028 /// Given an event handle `evt_handle`, this function reads the value of the GPU counter.
4029 ///
4030 /// # Arguments
4031 ///
4032 /// * `evt_handle` - The event handle of the GPU counter to be read.
4033 ///
4034 /// # Returns
4035 ///
4036 /// * `AmdsmiResult<AmdsmiCounterValueT>` - Returns `Ok(AmdsmiCounterValueT)` containing the [`AmdsmiCounterValueT`] if successful, or an error if it fails.
4037 ///
4038 /// # Example
4039 ///
4040 /// Refer to the example in the documentation for [`amdsmi_gpu_create_counter`].
4041 ///
4042 /// # Errors
4043 ///
4044 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_gpu_read_counter` call fails.
4045 pub fn amdsmi_gpu_read_counter(
4046 evt_handle: AmdsmiEventHandleT,
4047 ) -> AmdsmiResult<AmdsmiCounterValueT> {
4048 let mut value = MaybeUninit::<AmdsmiCounterValueT>::uninit();
4049 call_unsafe!(amdsmi_wrapper::amdsmi_gpu_read_counter(
4050 evt_handle,
4051 value.as_mut_ptr()
4052 ));
4053 let value = unsafe { value.assume_init() };
4054 Ok(value)
4055 }
4056
4057 /// Get the number of available GPU counters for the device with the specified processor handle and event group.
4058 ///
4059 /// Given a processor handle `processor_handle` and an event group `grp`, this function retrieves the number of available GPU counters
4060 /// for the specified processor.
4061 ///
4062 /// # Arguments
4063 ///
4064 /// * `processor_handle` - A handle to the processor for which the available GPU counters are being queried.
4065 /// * `grp` - The event group for which the available GPU counters are being queried.
4066 ///
4067 /// # Returns
4068 ///
4069 /// * `AmdsmiResult<u32>` - Returns `Ok(u32)` containing the number of available GPU counters if successful, or an error if it fails.
4070 ///
4071 /// # Example
4072 ///
4073 /// Refer to the example in the documentation for [`amdsmi_gpu_create_counter`].
4074 ///
4075 /// # Errors
4076 ///
4077 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_available_counters` call fails.
4078 pub fn amdsmi_get_gpu_available_counters(
4079 processor_handle: AmdsmiProcessorHandle,
4080 grp: AmdsmiEventGroupT,
4081 ) -> AmdsmiResult<u32> {
4082 let mut available: u32 = 0;
4083 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_available_counters(
4084 processor_handle,
4085 grp,
4086 &mut available as *mut u32
4087 ));
4088 Ok(available)
4089 }
4090
4091 /// Get the GPU compute process information.
4092 ///
4093 /// This function retrieves information about GPU compute processes.
4094 ///
4095 /// # Arguments
4096 ///
4097 /// * `procs` - A mutable pointer to an array of `AmdsmiProcessInfoT` where the process information will be stored.
4098 /// * `num_items` - A mutable pointer to a `u32` where the number of items will be stored.
4099 ///
4100 /// # Returns
4101 ///
4102 /// * `AmdsmiResult<(Vec<AmdsmiProcessInfoT>, u32)>` - Returns `Ok((Vec<AmdsmiProcessInfoT>, u32))` containing a list of [`AmdsmiProcessInfoT`] and the number of items if successful, or an error if it fails.
4103 ///
4104 /// # Example
4105 ///
4106 /// ```rust
4107 /// # use amdsmi::*;
4108 /// #
4109 /// # fn main() {
4110 /// # // Initialize the AMD SMI library
4111 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4112 /// #
4113 /// // Get the GPU compute process information
4114 /// match amdsmi_get_gpu_compute_process_info() {
4115 /// Ok((procs, num_items)) => {
4116 /// println!("Number of GPU compute processes: {}", num_items);
4117 /// for proc in procs {
4118 /// println!("{:?}", proc);
4119 /// }
4120 /// },
4121 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_compute_process_info() not supported on this device"),
4122 /// Err(e) => panic!("Failed to get GPU compute process information: {}", e),
4123 /// }
4124 /// #
4125 /// # // Shut down the AMD SMI library
4126 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4127 /// # }
4128 /// ```
4129 ///
4130 /// # Errors
4131 ///
4132 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_compute_process_info` call fails.
4133 pub fn amdsmi_get_gpu_compute_process_info() -> AmdsmiResult<(Vec<AmdsmiProcessInfoT>, u32)> {
4134 let mut num_items = MaybeUninit::<u32>::uninit();
4135
4136 // First call to get the number of items
4137 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_compute_process_info(
4138 std::ptr::null_mut(),
4139 num_items.as_mut_ptr()
4140 ));
4141
4142 let num_items = unsafe { num_items.assume_init() };
4143 let mut procs: Vec<AmdsmiProcessInfoT> = Vec::with_capacity(num_items as usize);
4144
4145 // Second call to get the actual process information
4146 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_compute_process_info(
4147 procs.as_mut_ptr(),
4148 &mut (num_items as u32)
4149 ));
4150
4151 unsafe { procs.set_len(num_items as usize) };
4152
4153 Ok((procs, num_items))
4154 }
4155
4156 /// Get the GPU compute process information by PID.
4157 ///
4158 /// This function retrieves information about a specific GPU compute process identified by its PID.
4159 ///
4160 /// # Arguments
4161 ///
4162 /// * `pid` - The process ID of the GPU compute process.
4163 /// * `proc_` - A mutable pointer to an `AmdsmiProcessInfoT` where the process information will be stored.
4164 ///
4165 /// # Returns
4166 ///
4167 /// * `AmdsmiResult<AmdsmiProcessInfoT>` - Returns `Ok(AmdsmiProcessInfoT)` containing the [`AmdsmiProcessInfoT`] if successful, or an error if it fails.
4168 ///
4169 /// # Example
4170 ///
4171 /// ```rust, should_panic
4172 /// # use amdsmi::*;
4173 /// #
4174 /// # fn main() {
4175 /// # // Initialize the AMD SMI library
4176 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4177 /// #
4178 /// // Example PID,
4179 /// let pid = 12345;
4180 ///
4181 /// // Get the process information by PID
4182 /// match amdsmi_get_gpu_compute_process_info_by_pid(pid) {
4183 /// Ok(proc_info) => println!("{:?}", proc_info),
4184 /// Err(e) => panic!("Failed to get GPU compute process information by PID: {}", e),
4185 /// }
4186 /// #
4187 /// # // Shut down the AMD SMI library
4188 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4189 /// # }
4190 /// ```
4191 ///
4192 /// # Errors
4193 ///
4194 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_compute_process_info_by_pid` call fails.
4195 pub fn amdsmi_get_gpu_compute_process_info_by_pid(pid: u32) -> AmdsmiResult<AmdsmiProcessInfoT> {
4196 let mut proc_info = MaybeUninit::<AmdsmiProcessInfoT>::uninit();
4197 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_compute_process_info_by_pid(
4198 pid,
4199 proc_info.as_mut_ptr()
4200 ));
4201 let proc_info = unsafe { proc_info.assume_init() };
4202 Ok(proc_info)
4203 }
4204
4205 /// Get the device indices currently being used by a process.
4206 ///
4207 /// This function retrieves the GPU indices for a specific GPU compute process identified by its PID.
4208 ///
4209 /// # Arguments
4210 ///
4211 /// * `pid` - The process ID of the GPU compute process.
4212 ///
4213 /// # Returns
4214 ///
4215 /// * `AmdsmiResult<Vec<u32>>` - Returns a vector containing the GPU indices if successful, or an error if it fails.
4216 ///
4217 /// # Example
4218 ///
4219 /// ```rust,should_panic
4220 /// # use amdsmi::*;
4221 /// #
4222 /// # fn main() {
4223 /// # // Initialize the AMD SMI library
4224 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4225 /// #
4226 /// // Example PID, assuming a valid PID for a GPU compute process
4227 /// let pid = 12345;
4228 ///
4229 /// // Retrieve the GPU indices for the process
4230 /// match amdsmi_get_gpu_compute_process_gpus(pid) {
4231 /// Ok(gpu_indices) => {
4232 /// for index in gpu_indices {
4233 /// println!("GPU Index: {}", index);
4234 /// }
4235 /// },
4236 /// Err(e) => panic!("Failed to get GPU compute process devices: {}", e),
4237 /// }
4238 /// #
4239 /// # // Shut down the AMD SMI library
4240 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4241 /// # }
4242 /// ```
4243 ///
4244 /// # Errors
4245 ///
4246 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_compute_process_gpus` call fails.
4247 pub fn amdsmi_get_gpu_compute_process_gpus(pid: u32) -> AmdsmiResult<Vec<u32>> {
4248 let mut num_devices: u32 = 0;
4249 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_compute_process_gpus(
4250 pid,
4251 std::ptr::null_mut(),
4252 &mut num_devices
4253 ));
4254
4255 let mut devices: Vec<u32> = Vec::with_capacity(num_devices as usize);
4256 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_compute_process_gpus(
4257 pid,
4258 devices.as_mut_ptr(),
4259 &mut num_devices
4260 ));
4261 unsafe { devices.set_len(num_devices as usize) };
4262
4263 Ok(devices)
4264 }
4265
4266 /// Get the XGMI error status of the device with the specified processor handle.
4267 ///
4268 /// Given a processor handle `processor_handle`, this function retrieves the XGMI error status
4269 /// for the specified processor.
4270 ///
4271 /// # Arguments
4272 ///
4273 /// * `processor_handle` - A handle to the processor for which the XGMI error status is being queried.
4274 ///
4275 /// # Returns
4276 ///
4277 /// * `AmdsmiResult<AmdsmiXgmiStatusT>` - Returns `Ok(AmdsmiXgmiStatusT)` containing the [`AmdsmiXgmiStatusT`] if successful, or an error if it fails.
4278 ///
4279 /// # Example
4280 ///
4281 /// ```rust
4282 /// # use amdsmi::*;
4283 /// #
4284 /// # fn main() {
4285 /// # // Initialize the AMD SMI library
4286 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4287 /// #
4288 /// // Example processor_handle, assuming the number of processors is greater than zero
4289 /// let processor_handle = amdsmi_get_processor_handles!()[0];
4290 ///
4291 /// // Retrieve the XGMI error status
4292 /// match amdsmi_gpu_xgmi_error_status(processor_handle) {
4293 /// Ok(status) => println!("XGMI error status: {:?}", status),
4294 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_gpu_xgmi_error_status() not supported on this device"),
4295 /// Err(e) => panic!("Failed to get XGMI error status: {}", e),
4296 /// }
4297 /// #
4298 /// # // Shut down the AMD SMI library
4299 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4300 /// # }
4301 /// ```
4302 ///
4303 /// # Errors
4304 ///
4305 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_gpu_xgmi_error_status` call fails.
4306 pub fn amdsmi_gpu_xgmi_error_status(
4307 processor_handle: AmdsmiProcessorHandle,
4308 ) -> AmdsmiResult<AmdsmiXgmiStatusT> {
4309 let mut status = MaybeUninit::<AmdsmiXgmiStatusT>::uninit();
4310 call_unsafe!(amdsmi_wrapper::amdsmi_gpu_xgmi_error_status(
4311 processor_handle,
4312 status.as_mut_ptr()
4313 ));
4314 let status = unsafe { status.assume_init() };
4315 Ok(status)
4316 }
4317
4318 /// Reset the XGMI error status of the device with the specified processor handle.
4319 ///
4320 /// Given a processor handle `processor_handle`, this function resets the XGMI error status
4321 /// for the specified processor.
4322 ///
4323 /// # Arguments
4324 ///
4325 /// * `processor_handle` - A handle to the processor for which the XGMI error status is being reset.
4326 ///
4327 /// # Returns
4328 ///
4329 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
4330 ///
4331 /// # Example
4332 ///
4333 /// ```rust
4334 /// # use amdsmi::*;
4335 /// #
4336 /// # fn main() {
4337 /// # // Initialize the AMD SMI library
4338 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4339 /// #
4340 /// // Example processor_handle, assuming the number of processors is greater than zero
4341 /// let processor_handle = amdsmi_get_processor_handles!()[0];
4342 ///
4343 /// // Reset the XGMI error status
4344 /// match amdsmi_reset_gpu_xgmi_error(processor_handle) {
4345 /// Ok(()) => println!("XGMI error status reset successfully"),
4346 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_reset_gpu_xgmi_error() not supported on this device"),
4347 /// Err(e) => panic!("Failed to reset XGMI error status: {}", e),
4348 /// }
4349 /// #
4350 /// # // Shut down the AMD SMI library
4351 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4352 /// # }
4353 /// ```
4354 ///
4355 /// # Errors
4356 ///
4357 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_reset_gpu_xgmi_error` call fails.
4358 pub fn amdsmi_reset_gpu_xgmi_error(processor_handle: AmdsmiProcessorHandle) -> AmdsmiResult<()> {
4359 call_unsafe!(amdsmi_wrapper::amdsmi_reset_gpu_xgmi_error(
4360 processor_handle
4361 ));
4362 Ok(())
4363 }
4364
4365 /// Get the link metrics of the device with the specified processor handle.
4366 ///
4367 /// Given a processor handle `processor_handle`, this function retrieves the link metrics
4368 /// for the specified processor.
4369 ///
4370 /// # Arguments
4371 ///
4372 /// * `processor_handle` - A handle to the processor for which the link metrics are being queried.
4373 ///
4374 /// # Returns
4375 ///
4376 /// * `AmdsmiResult<AmdsmiLinkMetricsT>` - Returns `Ok(AmdsmiLinkMetricsT)` containing the [`AmdsmiLinkMetricsT`] if successful, or an error if it fails.
4377 ///
4378 /// # Example
4379 ///
4380 /// ```rust
4381 /// # use amdsmi::*;
4382 /// #
4383 /// # fn main() {
4384 /// # // Initialize the AMD SMI library
4385 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4386 /// #
4387 /// // Example processor_handle, assuming the number of processors is greater than zero
4388 /// let processor_handle = amdsmi_get_processor_handles!()[0];
4389 ///
4390 /// // Retrieve the link metrics
4391 /// match amdsmi_get_link_metrics(processor_handle) {
4392 /// Ok(link_metrics) => println!("Link metrics number: {}", link_metrics.num_links),
4393 /// Err(e) => panic!("Failed to get link metrics: {}", e),
4394 /// }
4395 /// #
4396 /// # // Shut down the AMD SMI library
4397 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4398 /// # }
4399 /// ```
4400 ///
4401 /// # Errors
4402 ///
4403 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_link_metrics` call fails.
4404 pub fn amdsmi_get_link_metrics(
4405 processor_handle: AmdsmiProcessorHandle,
4406 ) -> AmdsmiResult<AmdsmiLinkMetricsT> {
4407 let mut link_metrics = MaybeUninit::<AmdsmiLinkMetricsT>::uninit();
4408 call_unsafe!(amdsmi_wrapper::amdsmi_get_link_metrics(
4409 processor_handle,
4410 link_metrics.as_mut_ptr()
4411 ));
4412 let link_metrics = unsafe { link_metrics.assume_init() };
4413 Ok(link_metrics)
4414 }
4415
4416 /// Get the NUMA node number of the device with the specified processor handle.
4417 ///
4418 /// Given a processor handle `processor_handle`, this function retrieves the NUMA node number
4419 /// for the specified processor.
4420 ///
4421 /// # Arguments
4422 ///
4423 /// * `processor_handle` - A handle to the processor for which the NUMA node number is being queried.
4424 ///
4425 /// # Returns
4426 ///
4427 /// * `AmdsmiResult<u32>` - Returns `Ok(u32)` containing the NUMA node number if successful, or an error if it fails.
4428 ///
4429 /// # Example
4430 ///
4431 /// ```rust
4432 /// # use amdsmi::*;
4433 /// #
4434 /// # fn main() {
4435 /// # // Initialize the AMD SMI library
4436 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4437 /// #
4438 /// // Example processor_handle, assuming the number of processors is greater than zero
4439 /// let processor_handle = amdsmi_get_processor_handles!()[0];
4440 ///
4441 /// // Retrieve the NUMA node number
4442 /// match amdsmi_topo_get_numa_node_number(processor_handle) {
4443 /// Ok(numa_node) => println!("NUMA node number: {}", numa_node),
4444 /// Err(e) => panic!("Failed to get NUMA node number: {}", e),
4445 /// }
4446 /// #
4447 /// # // Shut down the AMD SMI library
4448 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4449 /// # }
4450 /// ```
4451 ///
4452 /// # Errors
4453 ///
4454 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_topo_get_numa_node_number` call fails.
4455 pub fn amdsmi_topo_get_numa_node_number(
4456 processor_handle: AmdsmiProcessorHandle,
4457 ) -> AmdsmiResult<u32> {
4458 let mut numa_node: u32 = 0;
4459 call_unsafe!(amdsmi_wrapper::amdsmi_topo_get_numa_node_number(
4460 processor_handle,
4461 &mut numa_node
4462 ));
4463 Ok(numa_node)
4464 }
4465
4466 /// Get the link weight between two processors with the specified processor handles.
4467 ///
4468 /// Given source and destination processor handles `processor_handle_src` and `processor_handle_dst`,
4469 /// this function retrieves the link weight between the two processors.
4470 ///
4471 /// # Arguments
4472 ///
4473 /// * `processor_handle_src` - A handle to the source processor.
4474 /// * `processor_handle_dst` - A handle to the destination processor.
4475 ///
4476 /// # Returns
4477 ///
4478 /// * `AmdsmiResult<u64>` - Returns `Ok(u64)` containing the link weight if successful, or an error if it fails.
4479 ///
4480 /// # Example
4481 ///
4482 /// ```rust
4483 /// # use amdsmi::*;
4484 /// #
4485 /// # fn main() {
4486 /// # // Initialize the AMD SMI library
4487 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4488 /// #
4489 /// // Example processor handles, assuming the number of processors is greater than one
4490 /// let processor_handle_src = amdsmi_get_processor_handles!()[0];
4491 /// let processor_handle_dst = amdsmi_get_processor_handles!()[1];
4492 ///
4493 /// // Retrieve the link weight
4494 /// match amdsmi_topo_get_link_weight(processor_handle_src, processor_handle_dst) {
4495 /// Ok(weight) => println!("Link weight: {}", weight),
4496 /// Err(e) => panic!("Failed to get link weight: {}", e),
4497 /// }
4498 /// #
4499 /// # // Shut down the AMD SMI library
4500 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4501 /// # }
4502 /// ```
4503 ///
4504 /// # Errors
4505 ///
4506 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_topo_get_link_weight` call fails.
4507 pub fn amdsmi_topo_get_link_weight(
4508 processor_handle_src: AmdsmiProcessorHandle,
4509 processor_handle_dst: AmdsmiProcessorHandle,
4510 ) -> AmdsmiResult<u64> {
4511 let mut weight: u64 = 0;
4512 call_unsafe!(amdsmi_wrapper::amdsmi_topo_get_link_weight(
4513 processor_handle_src,
4514 processor_handle_dst,
4515 &mut weight
4516 ));
4517 Ok(weight)
4518 }
4519
4520 /// Get the minimum and maximum bandwidth between two processors with the specified processor handles.
4521 ///
4522 /// Given source and destination processor handles `processor_handle_src` and `processor_handle_dst`,
4523 /// this function retrieves the minimum and maximum bandwidth between the two processors.
4524 ///
4525 /// # Arguments
4526 ///
4527 /// * `processor_handle_src` - A handle to the source processor.
4528 /// * `processor_handle_dst` - A handle to the destination processor.
4529 ///
4530 /// # Returns
4531 ///
4532 /// * `AmdsmiResult<(u64, u64)>` - Returns `Ok((u64, u64))` containing the minimum and maximum bandwidth if successful, or an error if it fails.
4533 ///
4534 /// # Example
4535 ///
4536 /// ```rust
4537 /// # use amdsmi::*;
4538 /// #
4539 /// # fn main() {
4540 /// # // Initialize the AMD SMI library
4541 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4542 /// #
4543 /// // Example processor handles, assuming the number of processors is greater than one
4544 /// let processor_handle_src = amdsmi_get_processor_handles!()[0];
4545 /// let processor_handle_dst = amdsmi_get_processor_handles!()[1];
4546 ///
4547 /// // Retrieve the minimum and maximum bandwidth
4548 /// match amdsmi_get_minmax_bandwidth_between_processors(processor_handle_src, processor_handle_dst) {
4549 /// Ok((min_bandwidth, max_bandwidth)) => {
4550 /// println!("Minimum bandwidth: {}", min_bandwidth);
4551 /// println!("Maximum bandwidth: {}", max_bandwidth);
4552 /// },
4553 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_minmax_bandwidth_between_processors() not supported on this device"),
4554 /// Err(e) => panic!("Failed to get bandwidth: {}", e),
4555 /// }
4556 /// #
4557 /// # // Shut down the AMD SMI library
4558 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4559 /// # }
4560 /// ```
4561 ///
4562 /// # Errors
4563 ///
4564 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_minmax_bandwidth_between_processors` call fails.
4565 pub fn amdsmi_get_minmax_bandwidth_between_processors(
4566 processor_handle_src: AmdsmiProcessorHandle,
4567 processor_handle_dst: AmdsmiProcessorHandle,
4568 ) -> AmdsmiResult<(u64, u64)> {
4569 let mut min_bandwidth: u64 = 0;
4570 let mut max_bandwidth: u64 = 0;
4571 call_unsafe!(
4572 amdsmi_wrapper::amdsmi_get_minmax_bandwidth_between_processors(
4573 processor_handle_src,
4574 processor_handle_dst,
4575 &mut min_bandwidth,
4576 &mut max_bandwidth
4577 )
4578 );
4579 Ok((min_bandwidth, max_bandwidth))
4580 }
4581
4582 /// Check if P2P access is possible between two processors with the specified processor handles.
4583 ///
4584 /// Given source and destination processor handles `processor_handle_src` and `processor_handle_dst`,
4585 /// this function checks if P2P (peer-to-peer) access is possible between the two processors.
4586 ///
4587 /// # Arguments
4588 ///
4589 /// * `processor_handle_src` - A handle to the source processor.
4590 /// * `processor_handle_dst` - A handle to the destination processor.
4591 ///
4592 /// # Returns
4593 ///
4594 /// * `AmdsmiResult<bool>` - Returns `Ok(bool)` indicating whether P2P access is possible if successful, or an error if it fails.
4595 ///
4596 /// # Example
4597 ///
4598 /// ```rust
4599 /// # use amdsmi::*;
4600 /// #
4601 /// # fn main() {
4602 /// # // Initialize the AMD SMI library
4603 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4604 /// #
4605 /// // Example processor handles, assuming the number of processors is greater than one
4606 /// let processor_handle_src = amdsmi_get_processor_handles!()[0];
4607 /// let processor_handle_dst = amdsmi_get_processor_handles!()[1];
4608 ///
4609 /// // Check if P2P access is possible
4610 /// match amdsmi_is_p2p_accessible(processor_handle_src, processor_handle_dst) {
4611 /// Ok(accessible) => println!("P2P access is possible: {}", accessible),
4612 /// Err(e) => panic!("Failed to check P2P access: {}", e),
4613 /// }
4614 /// #
4615 /// # // Shut down the AMD SMI library
4616 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4617 /// # }
4618 /// ```
4619 ///
4620 /// # Errors
4621 ///
4622 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_is_P2P_accessible` call fails.
4623 pub fn amdsmi_is_p2p_accessible(
4624 processor_handle_src: AmdsmiProcessorHandle,
4625 processor_handle_dst: AmdsmiProcessorHandle,
4626 ) -> AmdsmiResult<bool> {
4627 let mut accessible: bool = false;
4628 call_unsafe!(amdsmi_wrapper::amdsmi_is_P2P_accessible(
4629 processor_handle_src,
4630 processor_handle_dst,
4631 &mut accessible
4632 ));
4633 Ok(accessible)
4634 }
4635
4636 /// Retrieves the link type and number of hops between two processors.
4637 ///
4638 /// This function retrieves the link type and number of hops between two processors,
4639 /// returning the results in a tuple.
4640 ///
4641 /// # Arguments
4642 ///
4643 /// * `processor_handle_src` - A handle to the source processor.
4644 /// * `processor_handle_dst` - A handle to the destination processor.
4645 ///
4646 /// # Returns
4647 ///
4648 /// * `AmdsmiResult<(u64, AmdsmiLinkTypeT)>` - Returns a tuple containing the number of hops and the link type if successful, or an error if it fails.
4649 ///
4650 /// # Example
4651 ///
4652 /// ```rust
4653 /// # use amdsmi::*;
4654 /// #
4655 /// # fn main() {
4656 /// # // Initialize the AMD SMI library
4657 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4658 /// #
4659 /// // Example processor handles, assuming the number of processors is greater than one
4660 /// let processor_handle_src = amdsmi_get_processor_handles!()[0];
4661 /// let processor_handle_dst = amdsmi_get_processor_handles!()[1];
4662 ///
4663 /// // Get the link type and number of hops
4664 /// match amdsmi_topo_get_link_type(processor_handle_src, processor_handle_dst) {
4665 /// Ok((hops, link_type)) => println!("Hops: {}, Link Type: {:?}", hops, link_type),
4666 /// Err(e) => panic!("Failed to get link type: {}", e),
4667 /// }
4668 /// #
4669 /// # // Shut down the AMD SMI library
4670 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4671 /// # }
4672 /// ```
4673 ///
4674 /// # Errors
4675 ///
4676 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_topo_get_link_type` call fails.
4677 pub fn amdsmi_topo_get_link_type(
4678 processor_handle_src: AmdsmiProcessorHandle,
4679 processor_handle_dst: AmdsmiProcessorHandle,
4680 ) -> AmdsmiResult<(u64, AmdsmiLinkTypeT)> {
4681 let mut hops: u64 = 0;
4682 let mut link_type: AmdsmiLinkTypeT = AmdsmiLinkTypeT::AmdsmiLinkTypeUnknown;
4683
4684 call_unsafe!(amdsmi_wrapper::amdsmi_topo_get_link_type(
4685 processor_handle_src,
4686 processor_handle_dst,
4687 &mut hops,
4688 &mut link_type
4689 ));
4690
4691 Ok((hops, link_type))
4692 }
4693
4694 /// Retrieves the P2P status between two processors.
4695 ///
4696 /// This function retrieves the P2P status between two processors, returning the link type and P2P capability.
4697 ///
4698 /// # Arguments
4699 ///
4700 /// * `processor_handle_src` - A handle to the source processor.
4701 /// * `processor_handle_dst` - A handle to the destination processor.
4702 ///
4703 /// # Returns
4704 ///
4705 /// * `AmdsmiResult<(AmdsmiLinkTypeT, AmdsmiP2pCapabilityT)>` - Returns a tuple containing the link type and P2P capability if successful, or an error if it fails.
4706 ///
4707 /// # Example
4708 ///
4709 /// ```rust
4710 /// # use amdsmi::*;
4711 /// #
4712 /// # fn main() {
4713 /// # // Initialize the AMD SMI library
4714 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4715 /// #
4716 /// // Example processor handles, assuming the number of processors is greater than one
4717 /// let processor_handle_src = amdsmi_get_processor_handles!()[0];
4718 /// let processor_handle_dst = amdsmi_get_processor_handles!()[1];
4719 ///
4720 /// // Get the P2P status
4721 /// match amdsmi_topo_get_p2p_status(processor_handle_src, processor_handle_dst) {
4722 /// Ok((link_type, p2p_capability)) => println!("Link Type: {:?}, P2P Capability: {:?}", link_type, p2p_capability),
4723 /// Err(e) => panic!("Failed to get P2P status: {}", e),
4724 /// }
4725 /// #
4726 /// # // Shut down the AMD SMI library
4727 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4728 /// # }
4729 /// ```
4730 ///
4731 /// # Errors
4732 ///
4733 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_topo_get_p2p_status` call fails.
4734 pub fn amdsmi_topo_get_p2p_status(
4735 processor_handle_src: AmdsmiProcessorHandle,
4736 processor_handle_dst: AmdsmiProcessorHandle,
4737 ) -> AmdsmiResult<(AmdsmiLinkTypeT, AmdsmiP2pCapabilityT)> {
4738 let mut link_type: AmdsmiLinkTypeT = AmdsmiLinkTypeT::AmdsmiLinkTypeUnknown;
4739 let mut p2p_capability = MaybeUninit::<AmdsmiP2pCapabilityT>::uninit();
4740
4741 call_unsafe!(amdsmi_wrapper::amdsmi_topo_get_p2p_status(
4742 processor_handle_src,
4743 processor_handle_dst,
4744 &mut link_type,
4745 p2p_capability.as_mut_ptr()
4746 ));
4747
4748 let p2p_capability = unsafe { p2p_capability.assume_init() };
4749
4750 Ok((link_type, p2p_capability))
4751 }
4752
4753 /// Retrieves the GPU compute partition for the device with the specified processor handle.
4754 ///
4755 /// This function retrieves the GPU compute partition for the specified processor handle,
4756 /// returning the compute partition as a string.
4757 ///
4758 /// # Arguments
4759 ///
4760 /// * `processor_handle` - A handle to the processor for which the GPU compute partition is being retrieved.
4761 ///
4762 /// # Returns
4763 ///
4764 /// * `AmdsmiResult<String>` - Returns the compute partition as a string if successful, or an error if it fails.
4765 ///
4766 /// # Example
4767 ///
4768 /// ```rust
4769 /// # use amdsmi::*;
4770 /// #
4771 /// # fn main() {
4772 /// # // Initialize the AMD SMI library
4773 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4774 /// #
4775 /// // Example processor_handle, assuming the number of processors is greater than zero
4776 /// let processor_handle = amdsmi_get_processor_handles!()[0];
4777 ///
4778 /// // Retrieve the GPU compute partition
4779 /// match amdsmi_get_gpu_compute_partition(processor_handle) {
4780 /// Ok(compute_partition) => println!("Compute Partition: {}", compute_partition),
4781 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_compute_partition() not supported on this device"),
4782 /// Err(e) => panic!("Failed to get GPU compute partition: {}", e),
4783 /// }
4784 /// #
4785 /// # // Shut down the AMD SMI library
4786 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4787 /// # }
4788 /// ```
4789 ///
4790 /// # Errors
4791 ///
4792 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_compute_partition` call fails.
4793 pub fn amdsmi_get_gpu_compute_partition(
4794 processor_handle: AmdsmiProcessorHandle,
4795 ) -> AmdsmiResult<String> {
4796 let (mut compute_partition, len) = define_cstr!(amdsmi_wrapper::AMDSMI_MAX_STRING_LENGTH);
4797 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_compute_partition(
4798 processor_handle,
4799 compute_partition.as_mut_ptr(),
4800 len as u32
4801 ));
4802
4803 Ok(cstr_to_string!(compute_partition))
4804 }
4805
4806 /// Set the GPU compute partition for the device with the specified processor handle.
4807 ///
4808 /// Given a processor handle `processor_handle` and a compute partition type `compute_partition`,
4809 /// this function sets the GPU compute partition for the specified processor.
4810 ///
4811 /// # Arguments
4812 ///
4813 /// * `processor_handle` - A handle to the processor for which the GPU compute partition is being set.
4814 /// * `compute_partition` - The compute partition type [`AmdsmiComputePartitionTypeT`] to set.
4815 ///
4816 /// # Returns
4817 ///
4818 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
4819 ///
4820 /// # Example
4821 ///
4822 /// ```rust
4823 /// # use amdsmi::*;
4824 /// #
4825 /// # fn main() {
4826 /// # // Initialize the AMD SMI library
4827 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4828 /// #
4829 /// // Example processor_handle, assuming the number of processors is greater than zero
4830 /// let processor_handle = amdsmi_get_processor_handles!()[0];
4831 ///
4832 /// // Example compute partition type
4833 /// let compute_partition = AmdsmiComputePartitionTypeT::AmdsmiComputePartitionSpx;
4834 ///
4835 /// // Set the GPU compute partition
4836 /// match amdsmi_set_gpu_compute_partition(processor_handle, compute_partition) {
4837 /// Ok(()) => println!("GPU compute partition set successfully"),
4838 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_set_gpu_compute_partition() not supported on this device"),
4839 /// Err(e) => panic!("Failed to set GPU compute partition: {}", e),
4840 /// }
4841 /// #
4842 /// # // Shut down the AMD SMI library
4843 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4844 /// # }
4845 /// ```
4846 ///
4847 /// # Errors
4848 ///
4849 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_gpu_compute_partition` call fails.
4850 pub fn amdsmi_set_gpu_compute_partition(
4851 processor_handle: AmdsmiProcessorHandle,
4852 compute_partition: AmdsmiComputePartitionTypeT,
4853 ) -> AmdsmiResult<()> {
4854 call_unsafe!(amdsmi_wrapper::amdsmi_set_gpu_compute_partition(
4855 processor_handle,
4856 compute_partition
4857 ));
4858 Ok(())
4859 }
4860
4861 /// Retrieves the GPU memory partition for the device with the specified processor handle.
4862 ///
4863 /// This function retrieves the GPU memory partition for the specified processor handle,
4864 /// returning the memory partition as a string.
4865 ///
4866 /// # Arguments
4867 ///
4868 /// * `processor_handle` - A handle to the processor for which the GPU memory partition is being retrieved.
4869 ///
4870 /// # Returns
4871 ///
4872 /// * `AmdsmiResult<String>` - Returns the memory partition as a string if successful, or an error if it fails.
4873 ///
4874 /// # Example
4875 ///
4876 /// ```rust
4877 /// # use amdsmi::*;
4878 /// #
4879 /// # fn main() {
4880 /// # // Initialize the AMD SMI library
4881 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4882 /// #
4883 /// // Example processor_handle, assuming the number of processors is greater than zero
4884 /// let processor_handle = amdsmi_get_processor_handles!()[0];
4885 ///
4886 /// // Retrieve the GPU memory partition
4887 /// match amdsmi_get_gpu_memory_partition(processor_handle) {
4888 /// Ok(memory_partition) => println!("Memory Partition: {}", memory_partition),
4889 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_gpu_memory_partition() not supported on this device"),
4890 /// Err(e) => panic!("Failed to get GPU memory partition: {}", e),
4891 /// }
4892 /// #
4893 /// # // Shut down the AMD SMI library
4894 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4895 /// # }
4896 /// ```
4897 ///
4898 /// # Errors
4899 ///
4900 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_memory_partition` call fails.
4901 pub fn amdsmi_get_gpu_memory_partition(
4902 processor_handle: AmdsmiProcessorHandle,
4903 ) -> AmdsmiResult<String> {
4904 let (mut memory_partition, len) = define_cstr!(amdsmi_wrapper::AMDSMI_MAX_STRING_LENGTH);
4905 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_memory_partition(
4906 processor_handle,
4907 memory_partition.as_mut_ptr(),
4908 len as u32
4909 ));
4910
4911 Ok(cstr_to_string!(memory_partition))
4912 }
4913
4914 /// Set the GPU memory partition for the device with the specified processor handle.
4915 ///
4916 /// Given a processor handle `processor_handle` and a memory partition type `memory_partition`,
4917 /// this function sets the GPU memory partition for the specified processor.
4918 ///
4919 /// # Arguments
4920 ///
4921 /// * `processor_handle` - A handle to the processor for which the GPU memory partition is being set.
4922 /// * `memory_partition` - The memory partition type [`AmdsmiMemoryPartitionTypeT`] to set.
4923 ///
4924 /// # Returns
4925 ///
4926 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
4927 ///
4928 /// # Example
4929 ///
4930 /// ```rust
4931 /// # use amdsmi::*;
4932 /// #
4933 /// # fn main() {
4934 /// # // Initialize the AMD SMI library
4935 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4936 /// #
4937 /// // Example processor_handle, assuming the number of processors is greater than zero
4938 /// let processor_handle = amdsmi_get_processor_handles!()[0];
4939 ///
4940 /// // Example memory partition type
4941 /// let memory_partition = AmdsmiMemoryPartitionTypeT::AmdsmiMemoryPartitionNps1;
4942 ///
4943 /// // Set the GPU memory partition
4944 /// match amdsmi_set_gpu_memory_partition(processor_handle, memory_partition) {
4945 /// Ok(()) => println!("GPU memory partition set successfully"),
4946 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_set_gpu_memory_partition() not supported on this device"),
4947 /// Err(e) => panic!("Failed to set GPU memory partition: {}", e),
4948 /// }
4949 /// #
4950 /// # // Shut down the AMD SMI library
4951 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
4952 /// # }
4953 /// ```
4954 ///
4955 /// # Errors
4956 ///
4957 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_gpu_memory_partition` call fails.
4958 pub fn amdsmi_set_gpu_memory_partition(
4959 processor_handle: AmdsmiProcessorHandle,
4960 memory_partition: AmdsmiMemoryPartitionTypeT,
4961 ) -> AmdsmiResult<()> {
4962 call_unsafe!(amdsmi_wrapper::amdsmi_set_gpu_memory_partition(
4963 processor_handle,
4964 memory_partition
4965 ));
4966 Ok(())
4967 }
4968
4969 /// Initialize GPU event notification for the device with the specified processor handle.
4970 ///
4971 /// Given a processor handle `processor_handle`, this function initializes GPU event notification
4972 /// for the specified processor.
4973 ///
4974 /// # Arguments
4975 ///
4976 /// * `processor_handle` - A handle to the processor for which the GPU event notification is being initialized.
4977 ///
4978 /// # Returns
4979 ///
4980 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
4981 ///
4982 /// # Example
4983 ///
4984 /// ```rust
4985 /// # use amdsmi::*;
4986 /// #
4987 /// # fn main() {
4988 /// # // Initialize the AMD SMI library
4989 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
4990 /// #
4991 /// // Example processor_handle, assuming the number of processors is greater than zero
4992 /// let processor_handle = amdsmi_get_processor_handles!()[0];
4993 ///
4994 /// // Initialize GPU event notification
4995 /// match amdsmi_init_gpu_event_notification(processor_handle) {
4996 /// Ok(_) => println!("GPU event notification initialized successfully."),
4997 /// Err(e) => {
4998 /// panic!("Failed to initialize GPU event notification: {}", e);
4999 /// }
5000 /// }
5001 ///
5002 /// // Set GPU event notification mask
5003 /// let event_mask: u64 = 0x0000000000000003; // AmdsmiEvtNotifVmfault | AmdsmiEvtNotifThermalThrottle
5004 /// match amdsmi_set_gpu_event_notification_mask(processor_handle, event_mask) {
5005 /// Ok(_) => println!("GPU event notification mask set successfully."),
5006 /// Err(e) => {
5007 /// panic!("Failed to set GPU event notification mask: {}", e);
5008 /// }
5009 /// }
5010 ///
5011 /// // Example timeout in milliseconds
5012 /// let timeout_ms: i32 = 10000;
5013 /// let mut num_elem : u32 = 10;
5014 ///
5015 /// // Get the GPU event notification data
5016 /// match amdsmi_get_gpu_event_notification(timeout_ms, num_elem) {
5017 /// Ok(data) => {
5018 /// for event in data {
5019 /// println!("Event: {:?}", event);
5020 /// }
5021 /// },
5022 /// Err(e) => assert!(e == AmdsmiStatusT::AmdsmiStatusNoData, "Failed to get GPU event notification data: {}", e),
5023 /// }
5024 ///
5025 /// // Stop GPU event notification
5026 /// match amdsmi_stop_gpu_event_notification(processor_handle) {
5027 /// Ok(_) => println!("GPU event notification stopped successfully."),
5028 /// Err(e) => {
5029 /// panic!("Failed to stop GPU event notification: {}", e);
5030 /// }
5031 /// }
5032 ///
5033 /// # // Shut down the AMD SMI library
5034 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5035 /// # }
5036 /// ```
5037 ///
5038 /// # Errors
5039 ///
5040 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_socket_handles` call fails.
5041 pub fn amdsmi_init_gpu_event_notification(
5042 processor_handle: AmdsmiProcessorHandle,
5043 ) -> AmdsmiResult<()> {
5044 call_unsafe!(amdsmi_wrapper::amdsmi_init_gpu_event_notification(
5045 processor_handle
5046 ));
5047 Ok(())
5048 }
5049
5050 /// Set the GPU event notification mask for the device with the specified processor handle.
5051 ///
5052 /// Given a processor handle `processor_handle` and a mask `mask`, this function sets the GPU event notification mask
5053 /// for the specified processor.
5054 ///
5055 /// # Arguments
5056 ///
5057 /// * `processor_handle` - A handle to the processor for which the GPU event notification mask is being set.
5058 /// * `mask` - The event notification mask to set. Bitmask generated by OR'ing 1 or more elements of
5059 /// [`AmdsmiEvtNotificationTypeT`] indicating which event types to listen for.
5060 ///
5061 /// # Returns
5062 ///
5063 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
5064 ///
5065 /// # Example
5066 ///
5067 /// Refer to the example in the documentation for [`amdsmi_init_gpu_event_notification`].
5068 ///
5069 /// # Errors
5070 ///
5071 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_set_gpu_event_notification_mask` call fails.
5072 pub fn amdsmi_set_gpu_event_notification_mask(
5073 processor_handle: AmdsmiProcessorHandle,
5074 mask: u64,
5075 ) -> AmdsmiResult<()> {
5076 call_unsafe!(amdsmi_wrapper::amdsmi_set_gpu_event_notification_mask(
5077 processor_handle,
5078 mask
5079 ));
5080 Ok(())
5081 }
5082
5083 /// Get the GPU event notification data.
5084 ///
5085 /// Given a timeout in milliseconds `timeout_ms`, this function retrieves the GPU event notification data.
5086 ///
5087 /// # Arguments
5088 ///
5089 /// * `timeout_ms` - The timeout in milliseconds to wait for the event notification.
5090 /// * `num_elem` - The number of elements to retrieve.
5091 ///
5092 /// # Returns
5093 ///
5094 /// * `AmdsmiResult<Vec<AmdsmiEvtNotificationDataT>>` - Returns `Ok(Vec<AmdsmiEvtNotificationDataT>)` containing the [`Vec<AmdsmiEvtNotificationDataT>`] if successful, or an error if it fails.
5095 ///
5096 /// # Example
5097 ///
5098 /// Refer to the example in the documentation for [`amdsmi_init_gpu_event_notification`].
5099 ///
5100 /// # Errors
5101 ///
5102 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_event_notification` call fails.
5103 pub fn amdsmi_get_gpu_event_notification(
5104 timeout_ms: i32,
5105 mut num_elem: u32,
5106 ) -> AmdsmiResult<Vec<AmdsmiEvtNotificationDataT>> {
5107 let mut data: Vec<AmdsmiEvtNotificationDataT> = Vec::with_capacity(num_elem as usize);
5108
5109 // Call to get the actual event notification data
5110 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_event_notification(
5111 timeout_ms,
5112 &mut num_elem,
5113 data.as_mut_ptr()
5114 ));
5115
5116 unsafe { data.set_len(num_elem as usize) };
5117
5118 Ok(data)
5119 }
5120
5121 /// Stop GPU event notification for the device with the specified processor handle.
5122 ///
5123 /// Given a processor handle `processor_handle`, this function stops GPU event notification
5124 /// for the specified processor.
5125 ///
5126 /// # Arguments
5127 ///
5128 /// * `processor_handle` - A handle to the processor for which the GPU event notification is being stopped.
5129 ///
5130 /// # Returns
5131 ///
5132 /// * `AmdsmiResult<()>` - Returns `Ok(())` if successful, or an error if it fails.
5133 ///
5134 /// # Example
5135 ///
5136 /// Refer to the example in the documentation for [`amdsmi_init_gpu_event_notification`].
5137 ///
5138 /// # Errors
5139 ///
5140 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_stop_gpu_event_notification` call fails.
5141 pub fn amdsmi_stop_gpu_event_notification(
5142 processor_handle: AmdsmiProcessorHandle,
5143 ) -> AmdsmiResult<()> {
5144 call_unsafe!(amdsmi_wrapper::amdsmi_stop_gpu_event_notification(
5145 processor_handle
5146 ));
5147 Ok(())
5148 }
5149
5150 /// Get the BDF (Bus-Device-Function) information for the GPU device with the specified processor handle.
5151 ///
5152 /// Given a processor handle `processor_handle`, this function retrieves the BDF information
5153 /// for the specified GPU device.
5154 ///
5155 /// # Arguments
5156 ///
5157 /// * `processor_handle` - A handle to the processor for which the BDF information is being queried.
5158 ///
5159 /// # Returns
5160 ///
5161 /// * `AmdsmiResult<AmdsmiBdfT>` - Returns `Ok(AmdsmiBdfT)` containing the [`AmdsmiBdfT`] if successful, or an error if it fails.
5162 ///
5163 /// # Example
5164 ///
5165 /// ```rust
5166 /// # use amdsmi::*;
5167 /// #
5168 /// # fn main() {
5169 /// # // Initialize the AMD SMI library
5170 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5171 /// #
5172 /// // Example processor_handle, assuming the number of processors is greater than zero
5173 /// let processor_handle = amdsmi_get_processor_handles!()[0];
5174 ///
5175 /// // Retrieve the BDF information
5176 /// match amdsmi_get_gpu_device_bdf(processor_handle) {
5177 /// Ok(bdf) => println!("BDF information: {}", bdf),
5178 /// Err(e) => panic!("Failed to get BDF information: {}", e),
5179 /// }
5180 /// #
5181 /// # // Shut down the AMD SMI library
5182 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5183 /// # }
5184 /// ```
5185 ///
5186 /// # Errors
5187 ///
5188 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_device_bdf` call fails.
5189 pub fn amdsmi_get_gpu_device_bdf(
5190 processor_handle: AmdsmiProcessorHandle,
5191 ) -> AmdsmiResult<AmdsmiBdfT> {
5192 let mut bdf = MaybeUninit::<AmdsmiBdfT>::uninit();
5193 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_device_bdf(
5194 processor_handle,
5195 bdf.as_mut_ptr()
5196 ));
5197 let bdf = unsafe { bdf.assume_init() };
5198 Ok(bdf)
5199 }
5200
5201 /// Get the UUID of the GPU device with the specified processor handle.
5202 ///
5203 /// Given a processor handle `processor_handle`, this function retrieves the UUID of the specified GPU device.
5204 ///
5205 /// # Arguments
5206 ///
5207 /// * `processor_handle` - A handle to the processor for which the UUID is being queried.
5208 ///
5209 /// # Returns
5210 ///
5211 /// * `AmdsmiResult<String>` - Returns `Ok(String)` containing the UUID if successful, or an error if it fails.
5212 ///
5213 /// # Example
5214 ///
5215 /// ```rust
5216 /// # use amdsmi::*;
5217 /// #
5218 /// # fn main() {
5219 /// # // Initialize the AMD SMI library
5220 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5221 /// #
5222 /// // Example processor_handle, assuming the number of processors is greater than zero
5223 /// let processor_handle = amdsmi_get_processor_handles!()[0];
5224 ///
5225 /// // Retrieve the UUID
5226 /// match amdsmi_get_gpu_device_uuid(processor_handle) {
5227 /// Ok(uuid) => println!("GPU device UUID: {}", uuid),
5228 /// Err(e) => panic!("Failed to get GPU device UUID: {}", e),
5229 /// }
5230 /// #
5231 /// # // Shut down the AMD SMI library
5232 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5233 /// # }
5234 /// ```
5235 ///
5236 /// # Errors
5237 ///
5238 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_device_uuid` call fails.
5239 pub fn amdsmi_get_gpu_device_uuid(processor_handle: AmdsmiProcessorHandle) -> AmdsmiResult<String> {
5240 let (mut uuid, uuid_len) = define_cstr!(amdsmi_wrapper::AMDSMI_GPU_UUID_SIZE);
5241 let mut uuid_len = uuid_len as std::os::raw::c_uint;
5242
5243 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_device_uuid(
5244 processor_handle,
5245 &mut uuid_len,
5246 uuid.as_mut_ptr()
5247 ));
5248
5249 Ok(cstr_to_string!(uuid))
5250 }
5251
5252 /// Get the GPU driver information for the device with the specified processor handle.
5253 ///
5254 /// Given a processor handle `processor_handle`, this function retrieves the GPU driver information
5255 /// for the specified processor.
5256 ///
5257 /// # Arguments
5258 ///
5259 /// * `processor_handle` - A handle to the processor for which the GPU driver information is being queried.
5260 ///
5261 /// # Returns
5262 ///
5263 /// * `AmdsmiResult<AmdsmiDriverInfoT>` - Returns `Ok(AmdsmiDriverInfoT)` containing the [`AmdsmiDriverInfoT`] if successful, or an error if it fails.
5264 ///
5265 /// # Example
5266 ///
5267 /// ```rust
5268 /// # use amdsmi::*;
5269 /// #
5270 /// # fn main() {
5271 /// # // Initialize the AMD SMI library
5272 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5273 /// #
5274 /// // Example processor_handle, assuming the number of processors is greater than zero
5275 /// let processor_handle = amdsmi_get_processor_handles!()[0];
5276 ///
5277 /// // Retrieve the GPU driver information
5278 /// match amdsmi_get_gpu_driver_info(processor_handle) {
5279 /// Ok(info) => println!("GPU driver information: {:?}", info),
5280 /// Err(e) => panic!("Failed to get GPU driver information: {}", e),
5281 /// }
5282 /// #
5283 /// # // Shut down the AMD SMI library
5284 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5285 /// # }
5286 /// ```
5287 ///
5288 /// # Errors
5289 ///
5290 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_driver_info` call fails.
5291 pub fn amdsmi_get_gpu_driver_info(
5292 processor_handle: AmdsmiProcessorHandle,
5293 ) -> AmdsmiResult<AmdsmiDriverInfoT> {
5294 let mut info = MaybeUninit::<AmdsmiDriverInfoT>::uninit();
5295 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_driver_info(
5296 processor_handle,
5297 info.as_mut_ptr()
5298 ));
5299 let info = unsafe { info.assume_init() };
5300 Ok(info)
5301 }
5302
5303 /// Get the GPU ASIC information for the device with the specified processor handle.
5304 ///
5305 /// Given a processor handle `processor_handle`, this function retrieves the GPU ASIC information
5306 /// for the specified processor.
5307 ///
5308 /// # Arguments
5309 ///
5310 /// * `processor_handle` - A handle to the processor for which the GPU ASIC information is being queried.
5311 ///
5312 /// # Returns
5313 ///
5314 /// * `AmdsmiResult<AmdsmiAsicInfoT>` - Returns `Ok(AmdsmiAsicInfoT)` containing the [`AmdsmiAsicInfoT`] if successful, or an error if it fails.
5315 ///
5316 /// # Example
5317 ///
5318 /// ```rust
5319 /// # use amdsmi::*;
5320 /// #
5321 /// # fn main() {
5322 /// # // Initialize the AMD SMI library
5323 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5324 /// #
5325 /// // Example processor_handle, assuming the number of processors is greater than zero
5326 /// let processor_handle = amdsmi_get_processor_handles!()[0];
5327 ///
5328 /// // Retrieve the GPU ASIC information
5329 /// match amdsmi_get_gpu_asic_info(processor_handle) {
5330 /// Ok(info) => println!("GPU ASIC information: {:?}", info),
5331 /// Err(e) => panic!("Failed to get GPU ASIC information: {}", e),
5332 /// }
5333 /// #
5334 /// # // Shut down the AMD SMI library
5335 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5336 /// # }
5337 /// ```
5338 ///
5339 /// # Errors
5340 ///
5341 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_asic_info` call fails.
5342 pub fn amdsmi_get_gpu_asic_info(
5343 processor_handle: AmdsmiProcessorHandle,
5344 ) -> AmdsmiResult<AmdsmiAsicInfoT> {
5345 let mut info = MaybeUninit::<AmdsmiAsicInfoT>::uninit();
5346 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_asic_info(
5347 processor_handle,
5348 info.as_mut_ptr()
5349 ));
5350 let info = unsafe { info.assume_init() };
5351 Ok(info)
5352 }
5353
5354 /// Get the GPU VRAM information for the device with the specified processor handle.
5355 ///
5356 /// Given a processor handle `processor_handle`, this function retrieves the GPU VRAM information
5357 /// for the specified processor.
5358 ///
5359 /// # Arguments
5360 ///
5361 /// * `processor_handle` - A handle to the processor for which the GPU VRAM information is being queried.
5362 ///
5363 /// # Returns
5364 ///
5365 /// * `AmdsmiResult<AmdsmiVramInfoT>` - Returns `Ok(AmdsmiVramInfoT)` containing the [`AmdsmiVramInfoT`] if successful, or an error if it fails.
5366 ///
5367 /// # Example
5368 ///
5369 /// ```rust
5370 /// # use amdsmi::*;
5371 /// #
5372 /// # fn main() {
5373 /// # // Initialize the AMD SMI library
5374 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5375 /// #
5376 /// // Example processor_handle, assuming the number of processors is greater than zero
5377 /// let processor_handle = amdsmi_get_processor_handles!()[0];
5378 ///
5379 /// // Retrieve the GPU VRAM information
5380 /// match amdsmi_get_gpu_vram_info(processor_handle) {
5381 /// Ok(info) => println!("GPU VRAM information: {:?}", info),
5382 /// Err(e) => panic!("Failed to get GPU VRAM information: {}", e),
5383 /// }
5384 /// #
5385 /// # // Shut down the AMD SMI library
5386 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5387 /// # }
5388 /// ```
5389 ///
5390 /// # Errors
5391 ///
5392 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_vram_info` call fails.
5393 pub fn amdsmi_get_gpu_vram_info(
5394 processor_handle: AmdsmiProcessorHandle,
5395 ) -> AmdsmiResult<AmdsmiVramInfoT> {
5396 let mut info = MaybeUninit::<AmdsmiVramInfoT>::uninit();
5397 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_vram_info(
5398 processor_handle,
5399 info.as_mut_ptr()
5400 ));
5401 let info = unsafe { info.assume_init() };
5402 Ok(info)
5403 }
5404
5405 /// Get the GPU board information for the device with the specified processor handle.
5406 ///
5407 /// Given a processor handle `processor_handle`, this function retrieves the GPU board information
5408 /// for the specified processor.
5409 ///
5410 /// # Arguments
5411 ///
5412 /// * `processor_handle` - A handle to the processor for which the GPU board information is being queried.
5413 ///
5414 /// # Returns
5415 ///
5416 /// * `AmdsmiResult<AmdsmiBoardInfoT>` - Returns `Ok(AmdsmiBoardInfoT)` containing the [`AmdsmiBoardInfoT`] if successful, or an error if it fails.
5417 ///
5418 /// # Example
5419 ///
5420 /// ```rust
5421 /// # use amdsmi::*;
5422 /// #
5423 /// # fn main() {
5424 /// # // Initialize the AMD SMI library
5425 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5426 /// #
5427 /// // Example processor_handle, assuming the number of processors is greater than zero
5428 /// let processor_handle = amdsmi_get_processor_handles!()[0];
5429 ///
5430 /// // Retrieve the GPU board information
5431 /// match amdsmi_get_gpu_board_info(processor_handle) {
5432 /// Ok(info) => println!("GPU board information: {:?}", info),
5433 /// Err(e) => panic!("Failed to get GPU board information: {}", e),
5434 /// }
5435 /// #
5436 /// # // Shut down the AMD SMI library
5437 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5438 /// # }
5439 /// ```
5440 ///
5441 /// # Errors
5442 ///
5443 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_board_info` call fails.
5444 pub fn amdsmi_get_gpu_board_info(
5445 processor_handle: AmdsmiProcessorHandle,
5446 ) -> AmdsmiResult<AmdsmiBoardInfoT> {
5447 let mut info = MaybeUninit::<AmdsmiBoardInfoT>::uninit();
5448 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_board_info(
5449 processor_handle,
5450 info.as_mut_ptr()
5451 ));
5452 let info = unsafe { info.assume_init() };
5453 Ok(info)
5454 }
5455
5456 /// Get the power cap information for the device with the specified processor handle and sensor index.
5457 ///
5458 /// Given a processor handle `processor_handle` and a sensor index `sensor_ind`, this function retrieves the power cap information
5459 /// for the specified processor.
5460 ///
5461 /// # Arguments
5462 ///
5463 /// * `processor_handle` - A handle to the processor for which the power cap information is being queried.
5464 /// * `sensor_ind` - The index of the sensor for which the power cap information is being queried.
5465 ///
5466 /// # Returns
5467 ///
5468 /// * `AmdsmiResult<AmdsmiPowerCapInfoT>` - Returns `Ok(AmdsmiPowerCapInfoT)` containing the [`AmdsmiPowerCapInfoT`] if successful, or an error if it fails.
5469 ///
5470 /// # Example
5471 ///
5472 /// ```rust
5473 /// # use amdsmi::*;
5474 /// #
5475 /// # fn main() {
5476 /// # // Initialize the AMD SMI library
5477 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5478 /// #
5479 /// // Example processor_handle, assuming the number of processors is greater than zero
5480 /// let processor_handle = amdsmi_get_processor_handles!()[0];
5481 ///
5482 /// // Example sensor index
5483 /// let sensor_ind: u32 = 0;
5484 ///
5485 /// // Retrieve the power cap information
5486 /// match amdsmi_get_power_cap_info(processor_handle, sensor_ind) {
5487 /// Ok(info) => println!("Power cap information: {:?}", info),
5488 /// Err(e) => panic!("Failed to get power cap information: {}", e),
5489 /// }
5490 /// #
5491 /// # // Shut down the AMD SMI library
5492 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5493 /// # }
5494 /// ```
5495 ///
5496 /// # Errors
5497 ///
5498 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_power_cap_info` call fails.
5499 pub fn amdsmi_get_power_cap_info(
5500 processor_handle: AmdsmiProcessorHandle,
5501 sensor_ind: u32,
5502 ) -> AmdsmiResult<AmdsmiPowerCapInfoT> {
5503 let mut info = MaybeUninit::<AmdsmiPowerCapInfoT>::uninit();
5504 call_unsafe!(amdsmi_wrapper::amdsmi_get_power_cap_info(
5505 processor_handle,
5506 sensor_ind,
5507 info.as_mut_ptr()
5508 ));
5509 let info = unsafe { info.assume_init() };
5510 Ok(info)
5511 }
5512
5513 /// Get the PCIe information for the device with the specified processor handle.
5514 ///
5515 /// Given a processor handle `processor_handle`, this function retrieves the PCIe information
5516 /// for the specified processor.
5517 ///
5518 /// # Arguments
5519 ///
5520 /// * `processor_handle` - A handle to the processor for which the PCIe information is being queried.
5521 ///
5522 /// # Returns
5523 ///
5524 /// * `AmdsmiResult<AmdsmiPcieInfoT>` - Returns `Ok(AmdsmiPcieInfoT)` containing the [`AmdsmiPcieInfoT`] if successful, or an error if it fails.
5525 ///
5526 /// # Example
5527 ///
5528 /// ```rust
5529 /// # use amdsmi::*;
5530 /// #
5531 /// # fn main() {
5532 /// # // Initialize the AMD SMI library
5533 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5534 /// #
5535 /// // Example processor_handle, assuming the number of processors is greater than zero
5536 /// let processor_handle = amdsmi_get_processor_handles!()[0];
5537 ///
5538 /// // Retrieve the PCIe information
5539 /// match amdsmi_get_pcie_info(processor_handle) {
5540 /// Ok(info) => println!("PCIe information: {:?}", info),
5541 /// Err(e) => panic!("Failed to get PCIe information: {}", e),
5542 /// }
5543 /// #
5544 /// # // Shut down the AMD SMI library
5545 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5546 /// # }
5547 /// ```
5548 ///
5549 /// # Errors
5550 ///
5551 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_pcie_info` call fails.
5552 pub fn amdsmi_get_pcie_info(
5553 processor_handle: AmdsmiProcessorHandle,
5554 ) -> AmdsmiResult<AmdsmiPcieInfoT> {
5555 let mut info = MaybeUninit::<AmdsmiPcieInfoT>::uninit();
5556 call_unsafe!(amdsmi_wrapper::amdsmi_get_pcie_info(
5557 processor_handle,
5558 info.as_mut_ptr()
5559 ));
5560 let info = unsafe { info.assume_init() };
5561 Ok(info)
5562 }
5563
5564 /// Get the XGMI information for the device with the specified processor handle.
5565 ///
5566 /// Given a processor handle `processor_handle`, this function retrieves the XGMI information
5567 /// for the specified processor.
5568 ///
5569 /// # Arguments
5570 ///
5571 /// * `processor_handle` - A handle to the processor for which the XGMI information is being queried.
5572 ///
5573 /// # Returns
5574 ///
5575 /// * `AmdsmiResult<AmdsmiXgmiInfoT>` - Returns `Ok(AmdsmiXgmiInfoT)` containing the [`AmdsmiXgmiInfoT`] if successful, or an error if it fails.
5576 ///
5577 /// # Example
5578 ///
5579 /// ```rust
5580 /// # use amdsmi::*;
5581 /// #
5582 /// # fn main() {
5583 /// # // Initialize the AMD SMI library
5584 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5585 /// #
5586 /// // Example processor_handle, assuming the number of processors is greater than zero
5587 /// let processor_handle = amdsmi_get_processor_handles!()[0];
5588 ///
5589 /// // Retrieve the XGMI information
5590 /// match amdsmi_get_xgmi_info(processor_handle) {
5591 /// Ok(info) => println!("XGMI information: {:?}", info),
5592 /// Err(e) => panic!("Failed to get XGMI information: {}", e),
5593 /// }
5594 /// #
5595 /// # // Shut down the AMD SMI library
5596 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5597 /// # }
5598 /// ```
5599 ///
5600 /// # Errors
5601 ///
5602 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_xgmi_info` call fails.
5603 pub fn amdsmi_get_xgmi_info(
5604 processor_handle: AmdsmiProcessorHandle,
5605 ) -> AmdsmiResult<AmdsmiXgmiInfoT> {
5606 let mut info = MaybeUninit::<AmdsmiXgmiInfoT>::uninit();
5607 call_unsafe!(amdsmi_wrapper::amdsmi_get_xgmi_info(
5608 processor_handle,
5609 info.as_mut_ptr()
5610 ));
5611 let info = unsafe { info.assume_init() };
5612 Ok(info)
5613 }
5614
5615 /// Get the firmware information for the device with the specified processor handle.
5616 ///
5617 /// Given a processor handle `processor_handle`, this function retrieves the firmware information
5618 /// for the specified processor.
5619 ///
5620 /// # Arguments
5621 ///
5622 /// * `processor_handle` - A handle to the processor for which the firmware information is being queried.
5623 ///
5624 /// # Returns
5625 ///
5626 /// * `AmdsmiResult<AmdsmiFwInfoT>` - Returns `Ok(AmdsmiFwInfoT)` containing the [`AmdsmiFwInfoT`] if successful, or an error if it fails.
5627 ///
5628 /// # Example
5629 ///
5630 /// ```rust
5631 /// # use amdsmi::*;
5632 /// #
5633 /// # fn main() {
5634 /// # // Initialize the AMD SMI library
5635 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5636 /// #
5637 /// // Example processor_handle, assuming the number of processors is greater than zero
5638 /// let processor_handle = amdsmi_get_processor_handles!()[0];
5639 ///
5640 /// // Retrieve the firmware information
5641 /// let info = amdsmi_get_fw_info(processor_handle).expect("Failed to get firmware info");
5642 ///
5643 /// assert!(0 < info.num_fw_info &&
5644 /// info.num_fw_info < AmdsmiFwBlockT::AmdsmiFwIdMax as u8);
5645 ///
5646 /// #
5647 /// # // Shut down the AMD SMI library
5648 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5649 /// # }
5650 /// ```
5651 ///
5652 /// # Errors
5653 ///
5654 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_fw_info` call fails.
5655 pub fn amdsmi_get_fw_info(processor_handle: AmdsmiProcessorHandle) -> AmdsmiResult<AmdsmiFwInfoT> {
5656 let mut info = MaybeUninit::<AmdsmiFwInfoT>::uninit();
5657 call_unsafe!(amdsmi_wrapper::amdsmi_get_fw_info(
5658 processor_handle,
5659 info.as_mut_ptr()
5660 ));
5661 let info = unsafe { info.assume_init() };
5662 Ok(info)
5663 }
5664
5665 /// Get the VBIOS information for the GPU device with the specified processor handle.
5666 ///
5667 /// Given a processor handle `processor_handle`, this function retrieves the VBIOS information
5668 /// for the specified GPU device.
5669 ///
5670 /// # Arguments
5671 ///
5672 /// * `processor_handle` - A handle to the processor for which the VBIOS information is being queried.
5673 ///
5674 /// # Returns
5675 ///
5676 /// * `AmdsmiResult<AmdsmiVbiosInfoT>` - Returns `Ok(AmdsmiVbiosInfoT)` containing the [`AmdsmiVbiosInfoT`] if successful, or an error if it fails.
5677 ///
5678 /// # Example
5679 ///
5680 /// ```rust
5681 /// # use amdsmi::*;
5682 /// #
5683 /// # fn main() {
5684 /// # // Initialize the AMD SMI library
5685 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5686 /// #
5687 /// // Example processor_handle, assuming the number of processors is greater than zero
5688 /// let processor_handle = amdsmi_get_processor_handles!()[0];
5689 ///
5690 /// // Retrieve the VBIOS information
5691 /// match amdsmi_get_gpu_vbios_info(processor_handle) {
5692 /// Ok(info) => println!("VBIOS information: {:?}", info),
5693 /// Err(e) => panic!("Failed to get VBIOS information: {}", e),
5694 /// }
5695 /// #
5696 /// # // Shut down the AMD SMI library
5697 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5698 /// # }
5699 /// ```
5700 ///
5701 /// # Errors
5702 ///
5703 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_vbios_info` call fails.
5704 pub fn amdsmi_get_gpu_vbios_info(
5705 processor_handle: AmdsmiProcessorHandle,
5706 ) -> AmdsmiResult<AmdsmiVbiosInfoT> {
5707 let mut info = MaybeUninit::<AmdsmiVbiosInfoT>::uninit();
5708 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_vbios_info(
5709 processor_handle,
5710 info.as_mut_ptr()
5711 ));
5712 let info = unsafe { info.assume_init() };
5713 Ok(info)
5714 }
5715
5716 /// Get the GPU activity information for the device with the specified processor handle.
5717 ///
5718 /// Given a processor handle `processor_handle`, this function retrieves the GPU activity information
5719 /// for the specified processor.
5720 ///
5721 /// # Arguments
5722 ///
5723 /// * `processor_handle` - A handle to the processor for which the GPU activity information is being queried.
5724 ///
5725 /// # Returns
5726 ///
5727 /// * `AmdsmiResult<AmdsmiEngineUsageT>` - Returns `Ok(AmdsmiEngineUsageT)` containing the [`AmdsmiEngineUsageT`] if successful, or an error if it fails.
5728 ///
5729 /// # Example
5730 ///
5731 /// ```rust
5732 /// # use amdsmi::*;
5733 /// #
5734 /// # fn main() {
5735 /// # // Initialize the AMD SMI library
5736 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5737 /// #
5738 /// // Example processor_handle, assuming the number of processors is greater than zero
5739 /// let processor_handle = amdsmi_get_processor_handles!().first().expect("No processor handles found").clone();
5740 ///
5741 /// // Retrieve the GPU activity information
5742 /// match amdsmi_get_gpu_activity(processor_handle) {
5743 /// Ok(info) => println!("GPU activity information: {:?}", info),
5744 /// Err(e) => panic!("Failed to get GPU activity information: {}", e),
5745 /// }
5746 /// #
5747 /// # // Shut down the AMD SMI library
5748 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5749 /// # }
5750 /// ```
5751 ///
5752 /// # Errors
5753 ///
5754 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_activity` call fails.
5755 pub fn amdsmi_get_gpu_activity(
5756 processor_handle: AmdsmiProcessorHandle,
5757 ) -> AmdsmiResult<AmdsmiEngineUsageT> {
5758 let mut info = MaybeUninit::<AmdsmiEngineUsageT>::uninit();
5759 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_activity(
5760 processor_handle,
5761 info.as_mut_ptr()
5762 ));
5763 let info = unsafe { info.assume_init() };
5764 Ok(info)
5765 }
5766
5767 /// Get the power information for the device with the specified processor handle.
5768 ///
5769 /// Given a processor handle `processor_handle`, this function retrieves the power information
5770 /// for the specified processor.
5771 ///
5772 /// # Arguments
5773 ///
5774 /// * `processor_handle` - A handle to the processor for which the power information is being queried.
5775 ///
5776 /// # Returns
5777 ///
5778 /// * `AmdsmiResult<AmdsmiPowerInfoT>` - Returns `Ok(AmdsmiPowerInfoT)` containing the [`AmdsmiPowerInfoT`] if successful, or an error if it fails.
5779 ///
5780 /// # Example
5781 ///
5782 /// ```rust
5783 /// # use amdsmi::*;
5784 /// #
5785 /// # fn main() {
5786 /// # // Initialize the AMD SMI library
5787 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5788 /// #
5789 /// // Example processor_handle, assuming the number of processors is greater than zero
5790 /// let processor_handle = amdsmi_get_processor_handles!()[0];
5791 ///
5792 /// // Retrieve the power information
5793 /// match amdsmi_get_power_info(processor_handle) {
5794 /// Ok(info) => println!("Power information: {:?}", info),
5795 /// Err(e) => panic!("Failed to get power information: {}", e),
5796 /// }
5797 /// #
5798 /// # // Shut down the AMD SMI library
5799 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5800 /// # }
5801 /// ```
5802 ///
5803 /// # Errors
5804 ///
5805 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_power_info` call fails.
5806 pub fn amdsmi_get_power_info(
5807 processor_handle: AmdsmiProcessorHandle,
5808 ) -> AmdsmiResult<AmdsmiPowerInfoT> {
5809 let mut info = MaybeUninit::<AmdsmiPowerInfoT>::uninit();
5810 call_unsafe!(amdsmi_wrapper::amdsmi_get_power_info(
5811 processor_handle,
5812 info.as_mut_ptr()
5813 ));
5814 let info = unsafe { info.assume_init() };
5815 Ok(info)
5816 }
5817
5818 /// Check if GPU power management is enabled for the device with the specified processor handle.
5819 ///
5820 /// Given a processor handle `processor_handle`, this function checks if GPU power management is enabled
5821 /// for the specified processor.
5822 ///
5823 /// # Arguments
5824 ///
5825 /// * `processor_handle` - A handle to the processor for which the power management status is being queried.
5826 ///
5827 /// # Returns
5828 ///
5829 /// * `AmdsmiResult<bool>` - Returns `Ok(bool)` indicating whether power management is enabled if successful, or an error if it fails.
5830 ///
5831 /// # Example
5832 ///
5833 /// ```rust
5834 /// # use amdsmi::*;
5835 /// #
5836 /// # fn main() {
5837 /// # // Initialize the AMD SMI library
5838 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5839 /// #
5840 /// // Example processor_handle, assuming the number of processors is greater than zero
5841 /// let processor_handle = amdsmi_get_processor_handles!()[0];
5842 ///
5843 /// // Check if GPU power management is enabled
5844 /// match amdsmi_is_gpu_power_management_enabled(processor_handle) {
5845 /// Ok(enabled) => println!("GPU power management enabled: {}", enabled),
5846 /// Err(e) => panic!("Failed to check GPU power management status: {}", e),
5847 /// }
5848 /// #
5849 /// # // Shut down the AMD SMI library
5850 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5851 /// # }
5852 /// ```
5853 ///
5854 /// # Errors
5855 ///
5856 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_is_gpu_power_management_enabled` call fails.
5857 pub fn amdsmi_is_gpu_power_management_enabled(
5858 processor_handle: AmdsmiProcessorHandle,
5859 ) -> AmdsmiResult<bool> {
5860 let mut enabled: bool = false;
5861 call_unsafe!(amdsmi_wrapper::amdsmi_is_gpu_power_management_enabled(
5862 processor_handle,
5863 &mut enabled as *mut bool
5864 ));
5865 Ok(enabled)
5866 }
5867
5868 /// Get the clock information for the device with the specified processor handle and clock type.
5869 ///
5870 /// Given a processor handle `processor_handle` and a clock type `clk_type`, this function retrieves the clock information
5871 /// for the specified processor.
5872 ///
5873 /// # Arguments
5874 ///
5875 /// * `processor_handle` - A handle to the processor for which the clock information is being queried.
5876 /// * `clk_type` - The type of clock for which the information is being queried.
5877 ///
5878 /// # Returns
5879 ///
5880 /// * `AmdsmiResult<AmdsmiClkInfoT>` - Returns `Ok(AmdsmiClkInfoT)` containing the [`AmdsmiClkInfoT`] if successful, or an error if it fails.
5881 ///
5882 /// # Example
5883 ///
5884 /// ```rust
5885 /// # use amdsmi::*;
5886 /// #
5887 /// # fn main() {
5888 /// # // Initialize the AMD SMI library
5889 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5890 /// #
5891 /// // Example processor_handle, assuming the number of processors is greater than zero
5892 /// let processor_handle = amdsmi_get_processor_handles!()[0];
5893 ///
5894 /// // Example clock type
5895 /// let clk_type = AmdsmiClkTypeT::AmdsmiClkTypeSys;
5896 ///
5897 /// // Retrieve the clock information
5898 /// match amdsmi_get_clock_info(processor_handle, clk_type) {
5899 /// Ok(info) => println!("Clock information: {:?}", info),
5900 /// Err(e) => panic!("Failed to get clock information: {}", e),
5901 /// }
5902 /// #
5903 /// # // Shut down the AMD SMI library
5904 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5905 /// # }
5906 /// ```
5907 ///
5908 /// # Errors
5909 ///
5910 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_clock_info` call fails.
5911 pub fn amdsmi_get_clock_info(
5912 processor_handle: AmdsmiProcessorHandle,
5913 clk_type: AmdsmiClkTypeT,
5914 ) -> AmdsmiResult<AmdsmiClkInfoT> {
5915 let mut info = MaybeUninit::<AmdsmiClkInfoT>::uninit();
5916 call_unsafe!(amdsmi_wrapper::amdsmi_get_clock_info(
5917 processor_handle,
5918 clk_type,
5919 info.as_mut_ptr()
5920 ));
5921 let info = unsafe { info.assume_init() };
5922 Ok(info)
5923 }
5924
5925 /// Get the VRAM usage information for the device with the specified processor handle.
5926 ///
5927 /// Given a processor handle `processor_handle`, this function retrieves the VRAM usage information
5928 /// for the specified processor.
5929 ///
5930 /// # Arguments
5931 ///
5932 /// * `processor_handle` - A handle to the processor for which the VRAM usage information is being queried.
5933 ///
5934 /// # Returns
5935 ///
5936 /// * `AmdsmiResult<AmdsmiVramUsageT>` - Returns `Ok(AmdsmiVramUsageT)` containing the [`AmdsmiVramUsageT`] if successful, or an error if it fails.
5937 ///
5938 /// # Example
5939 ///
5940 /// ```rust
5941 /// # use amdsmi::*;
5942 /// #
5943 /// # fn main() {
5944 /// # // Initialize the AMD SMI library
5945 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5946 /// #
5947 /// // Example processor_handle, assuming the number of processors is greater than zero
5948 /// let processor_handle = amdsmi_get_processor_handles!()[0];
5949 ///
5950 /// // Retrieve the VRAM usage information
5951 /// match amdsmi_get_gpu_vram_usage(processor_handle) {
5952 /// Ok(info) => println!("VRAM usage information: {:?}", info),
5953 /// Err(e) => panic!("Failed to get VRAM usage information: {}", e),
5954 /// }
5955 /// #
5956 /// # // Shut down the AMD SMI library
5957 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
5958 /// # }
5959 /// ```
5960 ///
5961 /// # Errors
5962 ///
5963 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_vram_usage` call fails.
5964 pub fn amdsmi_get_gpu_vram_usage(
5965 processor_handle: AmdsmiProcessorHandle,
5966 ) -> AmdsmiResult<AmdsmiVramUsageT> {
5967 let mut info = MaybeUninit::<AmdsmiVramUsageT>::uninit();
5968 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_vram_usage(
5969 processor_handle,
5970 info.as_mut_ptr()
5971 ));
5972 let info = unsafe { info.assume_init() };
5973 Ok(info)
5974 }
5975
5976 /// Get the total ECC error count for the GPU device with the specified processor handle.
5977 ///
5978 /// Given a processor handle `processor_handle`, this function retrieves the total ECC error count
5979 /// for the specified GPU device.
5980 ///
5981 /// # Arguments
5982 ///
5983 /// * `processor_handle` - A handle to the processor for which the ECC error count is being queried.
5984 ///
5985 /// # Returns
5986 ///
5987 /// * `AmdsmiResult<AmdsmiErrorCountT>` - Returns `Ok(AmdsmiErrorCountT)` containing the [`AmdsmiErrorCountT`] if successful, or an error if it fails.
5988 ///
5989 /// # Example
5990 ///
5991 /// ```rust
5992 /// # use amdsmi::*;
5993 /// #
5994 /// # fn main() {
5995 /// # // Initialize the AMD SMI library
5996 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
5997 /// #
5998 /// // Example processor_handle, assuming the number of processors is greater than zero
5999 /// let processor_handle = amdsmi_get_processor_handles!()[0];
6000 ///
6001 /// // Retrieve the total ECC error count
6002 /// match amdsmi_get_gpu_total_ecc_count(processor_handle) {
6003 /// Ok(error_count) => println!("Total ECC error count: {:?}", error_count),
6004 /// Err(e) => panic!("Failed to get total ECC error count: {}", e),
6005 /// }
6006 /// #
6007 /// # // Shut down the AMD SMI library
6008 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
6009 /// # }
6010 /// ```
6011 ///
6012 /// # Errors
6013 ///
6014 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_total_ecc_count` call fails.
6015 pub fn amdsmi_get_gpu_total_ecc_count(
6016 processor_handle: AmdsmiProcessorHandle,
6017 ) -> AmdsmiResult<AmdsmiErrorCountT> {
6018 let mut ec = MaybeUninit::<AmdsmiErrorCountT>::uninit();
6019 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_total_ecc_count(
6020 processor_handle,
6021 ec.as_mut_ptr()
6022 ));
6023 let ec = unsafe { ec.assume_init() };
6024 Ok(ec)
6025 }
6026
6027 /// Retrieves the list of GPU processes for the specified processor handle.
6028 ///
6029 /// Given a processor handle `processor_handle`, this function retrieves the list of GPU processes
6030 /// for the specified processor.
6031 ///
6032 /// # Arguments
6033 ///
6034 /// * `processor_handle` - A handle to the processor for which the GPU process list is being retrieved.
6035 ///
6036 /// # Returns
6037 ///
6038 /// * `AmdsmiResult<Vec<AmdsmiProcInfoT>>` - Returns a vector containing the [`AmdsmiProcInfoT`] if successful, or an error if it fails.
6039 ///
6040 /// # Example
6041 ///
6042 /// ```rust
6043 /// # use amdsmi::*;
6044 /// #
6045 /// # fn main() {
6046 /// # // Initialize the AMD SMI library
6047 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
6048 /// #
6049 /// // Example processor_handle, assuming the number of processors is greater than zero
6050 /// let processor_handle = amdsmi_get_processor_handles!()[0];
6051 ///
6052 /// // Retrieve the list of GPU processes
6053 /// match amdsmi_get_gpu_process_list(processor_handle) {
6054 /// Ok(process_list) => {
6055 /// for process in process_list {
6056 /// println!("Process Info: {:?}", process);
6057 /// }
6058 /// },
6059 /// Err(e) => panic!("Failed to get GPU process list: {}", e),
6060 /// }
6061 /// #
6062 /// # // Shut down the AMD SMI library
6063 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
6064 /// # }
6065 /// ```
6066 ///
6067 /// # Errors
6068 ///
6069 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_process_list` call fails.
6070 pub fn amdsmi_get_gpu_process_list(
6071 processor_handle: AmdsmiProcessorHandle,
6072 ) -> AmdsmiResult<Vec<AmdsmiProcInfoT>> {
6073 let mut num_processes: u32 = 0;
6074 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_process_list(
6075 processor_handle,
6076 &mut num_processes,
6077 std::ptr::null_mut()
6078 ));
6079
6080 let mut processes: Vec<AmdsmiProcInfoT> = Vec::with_capacity(num_processes as usize);
6081 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_process_list(
6082 processor_handle,
6083 &mut num_processes,
6084 processes.as_mut_ptr()
6085 ));
6086 unsafe { processes.set_len(num_processes as usize) };
6087
6088 Ok(processes)
6089 }
6090
6091 /// Get the library version information.
6092 ///
6093 /// This function retrieves the version information of the AMD SMI library.
6094 ///
6095 /// # Arguments
6096 ///
6097 /// * `version` - A mutable pointer to an `AmdsmiVersionT` structure where the version information will be stored.
6098 ///
6099 /// # Returns
6100 ///
6101 /// * `AmdsmiResult<AmdsmiVersionT>` - Returns `Ok(AmdsmiVersionT)` containing the [`AmdsmiVersionT`] if successful, or an error if it fails.
6102 ///
6103 /// # Example
6104 ///
6105 /// ```rust
6106 /// # use amdsmi::*;
6107 /// #
6108 /// # fn main() {
6109 /// # // Initialize the AMD SMI library
6110 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
6111 /// #
6112 /// // Retrieve the library version information
6113 /// match amdsmi_get_lib_version() {
6114 /// Ok(version) => println!("Library version: {:?}", version),
6115 /// Err(e) => panic!("Failed to get library version: {}", e),
6116 /// }
6117 /// #
6118 /// # // Shut down the AMD SMI library
6119 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
6120 /// # }
6121 /// ```
6122 ///
6123 /// # Errors
6124 ///
6125 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_lib_version` call fails.
6126 pub fn amdsmi_get_lib_version() -> AmdsmiResult<AmdsmiVersionT> {
6127 let mut version = MaybeUninit::<AmdsmiVersionT>::uninit();
6128 call_unsafe!(amdsmi_wrapper::amdsmi_get_lib_version(version.as_mut_ptr()));
6129 let version = unsafe { version.assume_init() };
6130 Ok(version)
6131 }
6132
6133 /// Retrieve the GPU accelerator partition profile.
6134 ///
6135 /// This function retrieves the GPU accelerator partition profile for a given processor handle.
6136 ///
6137 /// # Arguments
6138 ///
6139 /// * `processor_handle` - A handle to the processor for which the GPU accelerator partition profile is being retrieved.
6140 ///
6141 /// # Returns
6142 ///
6143 /// * `AmdsmiResult<(AmdsmiAcceleratorPartitionProfileT, u32)>` - Returns `Ok((AmdsmiAcceleratorPartitionProfileT, u32))` containing the [`AmdsmiAcceleratorPartitionProfileT`] and partition ID if successful, or an error if it fails.
6144 ///
6145 /// # Example
6146 ///
6147 /// ```rust
6148 /// # use amdsmi::*;
6149 /// #
6150 /// # fn main() {
6151 /// # // Initialize the AMD SMI library
6152 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
6153 /// #
6154 /// // Example processor_handle, assuming the number of processors is greater than zero
6155 /// let processor_handle = amdsmi_get_processor_handles!()[0];
6156 ///
6157 /// match amdsmi_get_gpu_accelerator_partition_profile(processor_handle) {
6158 /// Ok((profile, partition_id)) => {
6159 /// println!("Profile: {:?}", profile.profile_type);
6160 /// println!("Partition ID: {}", partition_id);
6161 /// },
6162 /// Err(e) => println!("Failed to retrieve GPU accelerator partition profile: {}", e),
6163 /// }
6164 /// #
6165 /// # // Shut down the AMD SMI library
6166 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
6167 /// # }
6168 /// ```
6169 ///
6170 /// # Errors
6171 ///
6172 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_accelerator_partition_profile` call fails.
6173 pub fn amdsmi_get_gpu_accelerator_partition_profile(
6174 processor_handle: AmdsmiProcessorHandle,
6175 ) -> AmdsmiResult<(AmdsmiAcceleratorPartitionProfileT, u32)> {
6176 let mut profile = MaybeUninit::<AmdsmiAcceleratorPartitionProfileT>::uninit();
6177 let mut partition_id = MaybeUninit::<u32>::uninit();
6178 call_unsafe!(
6179 amdsmi_wrapper::amdsmi_get_gpu_accelerator_partition_profile(
6180 processor_handle,
6181 profile.as_mut_ptr(),
6182 partition_id.as_mut_ptr()
6183 )
6184 );
6185 let profile = unsafe { profile.assume_init() };
6186 let partition_id = unsafe { partition_id.assume_init() };
6187 Ok((profile, partition_id))
6188 }
6189
6190 /// Retrieve the GPU KFD information.
6191 ///
6192 /// This function retrieves the GPU KFD information for a given processor handle.
6193 ///
6194 /// # Arguments
6195 ///
6196 /// * `processor_handle` - A handle to the processor for which the GPU KFD information is being retrieved.
6197 ///
6198 /// # Returns
6199 ///
6200 /// * `AmdsmiResult<AmdsmiKfdInfoT>` - Returns `Ok(AmdsmiKfdInfoT)` containing the [`AmdsmiKfdInfoT`] if successful, or an error if it fails.
6201 ///
6202 /// # Example
6203 ///
6204 /// ```rust
6205 /// # use amdsmi::*;
6206 /// #
6207 /// # fn main() {
6208 /// # // Initialize the AMD SMI library
6209 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
6210 /// #
6211 /// // Example processor_handle, assuming the number of processors is greater than zero
6212 /// let processor_handle = amdsmi_get_processor_handles!()[0];
6213 ///
6214 /// match amdsmi_get_gpu_kfd_info(processor_handle) {
6215 /// Ok(info) => {
6216 /// println!("KFD Info: {:?}", info);
6217 /// },
6218 /// Err(e) => println!("Failed to retrieve GPU KFD information: {}", e),
6219 /// }
6220 /// #
6221 /// # // Shut down the AMD SMI library
6222 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
6223 /// # }
6224 /// ```
6225 ///
6226 /// # Errors
6227 ///
6228 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_gpu_kfd_info` call fails.
6229 pub fn amdsmi_get_gpu_kfd_info(
6230 processor_handle: AmdsmiProcessorHandle,
6231 ) -> AmdsmiResult<AmdsmiKfdInfoT> {
6232 let mut info = MaybeUninit::<AmdsmiKfdInfoT>::uninit();
6233 call_unsafe!(amdsmi_wrapper::amdsmi_get_gpu_kfd_info(
6234 processor_handle,
6235 info.as_mut_ptr()
6236 ));
6237 let info = unsafe { info.assume_init() };
6238 Ok(info)
6239 }
6240
6241 /// Retrieve the GPU violation status.
6242 ///
6243 /// This function retrieves the violation status for a given processor handle.
6244 ///
6245 /// # Arguments
6246 ///
6247 /// * `processor_handle` - A handle to the processor for which the violation status is being retrieved.
6248 ///
6249 /// # Returns
6250 ///
6251 /// * `AmdsmiResult<AmdsmiViolationStatusT>` - Returns `Ok(AmdsmiViolationStatusT)` containing the [`AmdsmiViolationStatusT`] if successful, or an error if it fails.
6252 ///
6253 /// # Example
6254 ///
6255 /// ```rust
6256 /// # use amdsmi::*;
6257 /// #
6258 /// # fn main() {
6259 /// # // Initialize the AMD SMI library
6260 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
6261 /// #
6262 /// // Example processor_handle, assuming the number of processors is greater than zero
6263 /// let processor_handle = amdsmi_get_processor_handles!()[0];
6264 ///
6265 /// match amdsmi_get_violation_status(processor_handle) {
6266 /// Ok(info) => {
6267 /// println!("Violation Status: {:?}", info);
6268 /// },
6269 /// Err(AmdsmiStatusT::AmdsmiStatusNotSupported) => println!("amdsmi_get_violation_status() not supported on this device"),
6270 /// Err(e) => println!("Failed to retrieve violation status: {}", e),
6271 /// }
6272 /// #
6273 /// # // Shut down the AMD SMI library
6274 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
6275 /// # }
6276 /// ```
6277 ///
6278 /// # Errors
6279 ///
6280 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_violation_status` call fails.
6281 pub fn amdsmi_get_violation_status(
6282 processor_handle: AmdsmiProcessorHandle,
6283 ) -> AmdsmiResult<AmdsmiViolationStatusT> {
6284 let mut info = MaybeUninit::<AmdsmiViolationStatusT>::uninit();
6285 call_unsafe!(amdsmi_wrapper::amdsmi_get_violation_status(
6286 processor_handle,
6287 info.as_mut_ptr()
6288 ));
6289 let info = unsafe { info.assume_init() };
6290 Ok(info)
6291 }
6292
6293 /// Retrieve the nearest link topology information.
6294 ///
6295 /// This function retrieves the nearest link topology information for a given processor handle and link type.
6296 ///
6297 /// # Arguments
6298 ///
6299 /// * `processor_handle` - A handle to the processor for which the link topology information is being retrieved.
6300 /// * `link_type` - The type of [`AmdsmiLinkTypeT`] for which the topology information is being retrieved.
6301 ///
6302 /// # Returns
6303 ///
6304 /// * `AmdsmiResult<AmdsmiTopologyNearestT>` - Returns `Ok(AmdsmiTopologyNearestT)` containing the [`AmdsmiTopologyNearestT`] if successful, or an error if it fails.
6305 ///
6306 /// # Example
6307 ///
6308 /// ```rust
6309 /// # use amdsmi::*;
6310 /// #
6311 /// # fn main() {
6312 /// # // Initialize the AMD SMI library
6313 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
6314 /// #
6315 /// // Example processor_handle, assuming the number of processors is greater than zero
6316 /// let processor_handle = amdsmi_get_processor_handles!()[0];
6317 /// let link_type = AmdsmiLinkTypeT::AmdsmiLinkTypePcie;
6318 ///
6319 /// match amdsmi_get_link_topology_nearest(processor_handle, link_type) {
6320 /// Ok(info) => {
6321 /// println!("Topology Nearest Info: {:?}", info);
6322 /// },
6323 /// Err(e) => println!("Failed to retrieve link topology nearest information: {}", e),
6324 /// }
6325 /// #
6326 /// # // Shut down the AMD SMI library
6327 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
6328 /// # }
6329 /// ```
6330 ///
6331 /// # Errors
6332 ///
6333 /// This function will return the error in [`AmdsmiStatusT`] if the underlying `amdsmi_wrapper::amdsmi_get_link_topology_nearest` call fails.
6334 pub fn amdsmi_get_link_topology_nearest(
6335 processor_handle: AmdsmiProcessorHandle,
6336 link_type: AmdsmiLinkTypeT,
6337 ) -> AmdsmiResult<AmdsmiTopologyNearestT> {
6338 let mut topology_nearest_info = MaybeUninit::<AmdsmiTopologyNearestT>::uninit();
6339 call_unsafe!(amdsmi_wrapper::amdsmi_get_link_topology_nearest(
6340 processor_handle,
6341 link_type,
6342 topology_nearest_info.as_mut_ptr()
6343 ));
6344 let topology_nearest_info = unsafe { topology_nearest_info.assume_init() };
6345 Ok(topology_nearest_info)
6346 }
6347
6348 /// A macro to get all the GPU processor handles directly.
6349 ///
6350 /// This macro retrieves all the GPU processor handles by first getting the socket handles
6351 /// and then getting the processor handles for each socket.
6352 ///
6353 /// # Example
6354 ///
6355 /// ```rust
6356 /// # use amdsmi::*;
6357 ///
6358 /// # fn main() {
6359 /// # // Initialize the AMD SMI library
6360 /// # amdsmi_init(AmdsmiInitFlagsT::AmdsmiInitAmdGpus).expect("Failed to initialize AMD SMI");
6361 /// #
6362 /// let processor_handles = amdsmi_get_processor_handles!();
6363 /// for handle in processor_handles {
6364 /// // Perform operations with each processor handle
6365 /// // ...
6366 /// }
6367 /// #
6368 /// # // Shut down the AMD SMI library
6369 /// # amdsmi_shut_down().expect("Failed to shut down AMD SMI");
6370 /// # }
6371 /// ```
6372 #[macro_export]
6373 macro_rules! amdsmi_get_processor_handles {
6374 () => {{
6375 // Get the socket handles
6376 let socket_handles = amdsmi_get_socket_handles().expect("Failed to get socket handles");
6377
6378 let mut processor_handles = Vec::new();
6379
6380 // Iterate over each socket handle to get the processor handles
6381 for socket_handle in socket_handles {
6382 // Call the amdsmi_get_processor_handles function directly
6383 let mut processors = amdsmi_get_processor_handles(socket_handle)
6384 .expect("Failed to get processor handles for socket");
6385
6386 // Append the processor handles to the main vector
6387 processor_handles.append(&mut processors);
6388 }
6389
6390 processor_handles
6391 }};
6392 }