Skip to content

Commit

Permalink
feat: check_cpu_compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabrielides committed Nov 22, 2024
1 parent 6264496 commit 7a4fd91
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ regex = "1.11"
zmq = "0.10"

[target.'cfg(target_os = "windows")'.dependencies]
zeromq = "0.4.1"
zeromq = "0.4.1"

[target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dependencies]
native-dialog = "0.7.0"
raw-cpuid = "11.2.0"
38 changes: 38 additions & 0 deletions src/cpu_compatibility.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
use native_dialog::MessageDialog;

pub fn check_cpu_compatibility() {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
{
use raw_cpuid::CpuId;

let cpuid = CpuId::new();

if let Some(feature_info) = cpuid.get_feature_info() {
let avx_supported = feature_info.has_avx();
let avx2_supported = cpuid
.get_extended_feature_info()
.map_or(false, |ext_info| ext_info.has_avx2());
let avx512_supported = cpuid
.get_extended_feature_info()
.map_or(false, |ext_info| ext_info.has_avx512f()); // AVX-512 Foundation
if (!avx_supported || !avx2_supported) || !avx512_supported {
MessageDialog::new()
.set_type(native_dialog::MessageType::Error)
.set_title("Compatibility Error")
.set_text("Your CPU does not support AVX/AVX2/AVX512 instructions. Please use a compatible CPU.")
.show_alert()
.unwrap();
std::process::exit(1);
}
} else {
MessageDialog::new()
.set_type(native_dialog::MessageType::Error)
.set_title("Compatibility Error")
.set_text("Unable to determine CPU features.")
.show_alert()
.unwrap();
std::process::exit(1);
}
}
}
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
use crate::cpu_compatibility::check_cpu_compatibility;

mod app;
mod app_dir;
mod backend_task;
mod components;
mod config;
mod context;
mod context_provider;
mod cpu_compatibility;
mod database;
mod logging;
mod model;
mod sdk_wrapper;
mod ui;

fn main() -> eframe::Result<()> {
check_cpu_compatibility();
// Initialize the Tokio runtime
let runtime = tokio::runtime::Builder::new_multi_thread()
.worker_threads(40)
Expand Down

0 comments on commit 7a4fd91

Please sign in to comment.