@@ -7,14 +7,17 @@ pub(crate) struct Env {
7
7
git_sha : & ' static str ,
8
8
docker_label : & ' static str ,
9
9
nvidia_env : String ,
10
+ xpu_env : String ,
10
11
}
11
12
12
13
impl Env {
13
14
pub fn new ( ) -> Self {
14
15
let nvidia_env = nvidia_smi ( ) ;
16
+ let xpu_env = xpu_smi ( ) ;
15
17
16
18
Self {
17
19
nvidia_env : nvidia_env. unwrap_or ( "N/A" . to_string ( ) ) ,
20
+ xpu_env : xpu_env. unwrap_or ( "N/A" . to_string ( ) ) ,
18
21
cargo_target : env ! ( "VERGEN_CARGO_TARGET_TRIPLE" ) ,
19
22
cargo_version : env ! ( "VERGEN_RUSTC_SEMVER" ) ,
20
23
git_sha : option_env ! ( "VERGEN_GIT_SHA" ) . unwrap_or ( "N/A" ) ,
@@ -31,7 +34,8 @@ impl fmt::Display for Env {
31
34
writeln ! ( f, "Cargo version: {}" , self . cargo_version) ?;
32
35
writeln ! ( f, "Commit sha: {}" , self . git_sha) ?;
33
36
writeln ! ( f, "Docker label: {}" , self . docker_label) ?;
34
- write ! ( f, "nvidia-smi:\n {}" , self . nvidia_env) ?;
37
+ writeln ! ( f, "nvidia-smi:\n {}" , self . nvidia_env) ?;
38
+ write ! ( f, "xpu-smi:\n {}" , self . xpu_env) ?;
35
39
36
40
Ok ( ( ) )
37
41
}
@@ -43,3 +47,10 @@ fn nvidia_smi() -> Option<String> {
43
47
let output = nvidia_smi. replace ( '\n' , "\n " ) ;
44
48
Some ( output. trim ( ) . to_string ( ) )
45
49
}
50
+
51
+ fn xpu_smi ( ) -> Option < String > {
52
+ let output = Command :: new ( "xpu-smi" ) . arg ( "discovery" ) . output ( ) . ok ( ) ?;
53
+ let xpu_smi = String :: from_utf8 ( output. stdout ) . ok ( ) ?;
54
+ let output = xpu_smi. replace ( '\n' , "\n " ) ;
55
+ Some ( output. trim ( ) . to_string ( ) )
56
+ }
0 commit comments