pub(crate) fn cmd_tune(reset: bool, retune: bool, json: bool) -> anyhow::Result<()> {
#[cfg(all(feature = "gpu-metal", target_os = "macos"))]
{
use uhash::metal_miner;
let mut miner = metal_miner::MetalMiner::new()?;
let cache_path = miner
.tune_cache_path_for_current_device()
.map(|p| p.display().to_string());
let mut reset_done = false;
if reset {
reset_done = miner.clear_tune_cache_for_current_device()?;
}
if retune {
let header = b"benchmark input data for UniversalHash v4";
miner.force_retune_now(header)?;
}
let telemetry = serde_json::json!(miner.telemetry());
if json {
println!(
"{}",
serde_json::to_string(&serde_json::json!({
"backend": "metal",
"reset_requested": reset,
"reset_done": reset_done,
"retune_requested": retune,
"cache_path": cache_path,
"telemetry": telemetry
}))?
);
} else {
println!("Metal tune status:");
if let Some(path) = cache_path {
println!(" Cache path: {}", path);
} else {
println!(" Cache path: unavailable");
}
if reset {
println!(
" Cache reset: {}",
if reset_done { "done" } else { "not found" }
);
}
if retune {
println!(" Retune: done");
}
println!(" Telemetry: {}", telemetry);
}
Ok(())
}
#[cfg(not(all(feature = "gpu-metal", target_os = "macos")))]
{
let _ = (reset, retune, json);
anyhow::bail!("tune command requires macOS + --features gpu-metal");
}
}