Skip to content

Commit

Permalink
Merge pull request #433 from nokyan/ivpu-kernel-6.14
Browse files Browse the repository at this point in the history
Add support for ivpu memory statistic coming with 6.14
  • Loading branch information
nokyan authored Jan 9, 2025
2 parents 167684d + 02eb5df commit 9a5b357
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 47 deletions.
83 changes: 48 additions & 35 deletions src/ui/pages/npu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,37 +248,57 @@ impl ResNPU {
.push_data_point(usage_fraction.unwrap_or(0.0));
imp.npu_usage.graph().set_visible(usage_fraction.is_some());

let used_memory_fraction =
if let (Some(total_memory), Some(used_memory)) = (total_memory, used_memory) {
Some((*used_memory as f64 / *total_memory as f64).finite_or_default())
} else {
None
};

let memory_percentage_string = used_memory_fraction.as_ref().map_or_else(
|| i18n("N/A"),
|fraction| format!("{} %", (fraction * 100.0).round()),
);
let memory_subtitle = if let (Some(total_memory), Some(used_memory)) =
(total_memory, used_memory)
{
let used_memory_fraction =
(*used_memory as f64 / *total_memory as f64).finite_or_default();

imp.memory_usage
.graph()
.push_data_point(used_memory_fraction);

let memory_subtitle =
if let (Some(total_memory), Some(used_memory)) = (total_memory, used_memory) {
format!(
"{} / {} · {}",
convert_storage(*used_memory as f64, false),
convert_storage(*total_memory as f64, false),
memory_percentage_string
)
} else {
i18n("N/A")
};
let memory_percentage_string = format!("{} %", (used_memory_fraction * 100.0).round());

usage_percentage_string.push_str(" · ");
// Translators: This will be displayed in the sidebar, please try to keep your translation as short as (or even
// shorter than) 'Memory'
usage_percentage_string.push_str(&i18n_f("Memory: {}", &[&memory_percentage_string]));

format!(
"{} / {} · {}",
convert_storage(*used_memory as f64, false),
convert_storage(*total_memory as f64, false),
memory_percentage_string
)
} else if let Some(used_memory) = used_memory {
imp.memory_usage
.graph()
.push_data_point(*used_memory as f64);

let memory_string = convert_storage(*used_memory as f64, false);

let highest_memory_string =
convert_storage(imp.memory_usage.graph().get_highest_value(), false);

usage_percentage_string.push_str(" · ");
// Translators: This will be displayed in the sidebar, please try to keep your translation as short as (or even
// shorter than) 'Memory'
usage_percentage_string.push_str(&i18n_f("Memory: {}", &[&memory_string]));

format!(
"{} · {} {}",
&memory_string,
i18n("Highest:"),
highest_memory_string
)
} else {
i18n("N/A")
};

imp.memory_usage.graph().set_visible(used_memory.is_some());

imp.memory_usage.set_subtitle(&memory_subtitle);
imp.memory_usage
.graph()
.push_data_point(used_memory_fraction.unwrap_or(0.0));
imp.memory_usage
.graph()
.set_visible(used_memory_fraction.is_some());

imp.temperature.graph().set_visible(temperature.is_some());

Expand Down Expand Up @@ -309,13 +329,6 @@ impl ResNPU {

self.set_property("usage", usage_fraction.unwrap_or(0.0));

if used_memory_fraction.is_some() {
usage_percentage_string.push_str(" · ");
// Translators: This will be displayed in the sidebar, please try to keep your translation as short as (or even
// shorter than) 'Memory'
usage_percentage_string.push_str(&i18n_f("Memory: {}", &[&memory_percentage_string]));
}

if let Some(temperature) = temperature {
let temperature_string = convert_temperature(*temperature);

Expand Down
6 changes: 3 additions & 3 deletions src/utils/npu/intel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ impl NpuImpl for IntelNpu {
}

fn used_vram(&self) -> Result<usize> {
self.drm_used_vram().map(|usage| usage as usize)
self.drm_used_memory().map(|usage| usage as usize)
}

fn total_vram(&self) -> Result<usize> {
self.drm_total_vram().map(|usage| usage as usize)
self.drm_total_memory().map(|usage| usage as usize)
}

fn temperature(&self) -> Result<f64> {
Expand All @@ -103,7 +103,7 @@ impl NpuImpl for IntelNpu {
}

fn memory_frequency(&self) -> Result<f64> {
self.hwmon_vram_frequency()
self.hwmon_memory_frequency()
}

fn power_cap(&self) -> Result<f64> {
Expand Down
17 changes: 11 additions & 6 deletions src/utils/npu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,20 @@ pub trait NpuImpl {
}

fn drm_usage(&self) -> Result<isize> {
bail!("usage fallback not implemented")
// No NPU driver actually implements this yet, this is a guess for the future based on drm_usage() for GPUs
self.read_device_int("npu_busy_percent")
}

fn drm_used_vram(&self) -> Result<isize> {
self.read_device_int("mem_info_vram_used")
fn drm_used_memory(&self) -> Result<isize> {
// ivpu will implement this with kernel 6.14, using this as a fallback just in case other vendors start using
// this name as well
self.read_device_int("npu_memory_utilization")
}

fn drm_total_vram(&self) -> Result<isize> {
self.read_device_int("mem_info_vram_total")
fn drm_total_memory(&self) -> Result<isize> {
// No NPU driver actually implements this yet, this is a guess for the future based on ivpu's
// npu_memory_utilization
self.read_device_int("npu_memory_total")
}

fn hwmon_temperature(&self) -> Result<f64> {
Expand All @@ -177,7 +182,7 @@ pub trait NpuImpl {
Ok(self.read_hwmon_int("freq1_input")? as f64)
}

fn hwmon_vram_frequency(&self) -> Result<f64> {
fn hwmon_memory_frequency(&self) -> Result<f64> {
Ok(self.read_hwmon_int("freq2_input")? as f64)
}

Expand Down
6 changes: 3 additions & 3 deletions src/utils/npu/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ impl NpuImpl for OtherNpu {
}

fn used_vram(&self) -> Result<usize> {
self.drm_used_vram().map(|usage| usage as usize)
self.drm_used_memory().map(|usage| usage as usize)
}

fn total_vram(&self) -> Result<usize> {
self.drm_total_vram().map(|usage| usage as usize)
self.drm_total_memory().map(|usage| usage as usize)
}

fn temperature(&self) -> Result<f64> {
Expand All @@ -85,7 +85,7 @@ impl NpuImpl for OtherNpu {
}

fn memory_frequency(&self) -> Result<f64> {
self.hwmon_vram_frequency()
self.hwmon_memory_frequency()
}

fn power_cap(&self) -> Result<f64> {
Expand Down

0 comments on commit 9a5b357

Please sign in to comment.