Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Warn when CPU without AVX/AVX2 support is used #7

Merged
merged 2 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
let args = Args::parse();

breakwater::parser::check_cpu_support();

let fb = Arc::new(FrameBuffer::new(args.width, args.height));

// If we make the channel to big, stats will start to lag behind
Expand Down
20 changes: 20 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::framebuffer::FrameBuffer;
use const_format::formatcp;
use log::{info, warn};
use std::simd::{u32x8, Simd, SimdUint};
use std::sync::Arc;
use tokio::io::AsyncWriteExt;
Expand Down Expand Up @@ -356,6 +357,25 @@ fn simd_unhex(value: &[u8]) -> u32 {
shifted.reduce_or()
}

pub fn check_cpu_support() {
#[cfg(target_arch = "x86_64")]
{
if !is_x86_feature_detected!("avx2") {
warn!("Your CPU does not support AVX2. Consider using a CPU supporting AVX2 for best performance");
} else if !is_x86_feature_detected!("avx") {
warn!("Your CPU does not support AVX. Consider using a CPU supporting AVX2 (or at least AVX) for best performance");
} else {
// At this point the CPU should support AVX und AVX2
// Warn the user when he has compiled breakwater without the needed target features
if cfg!(all(target_feature = "avx", target_feature = "avx2")) {
info!("Using AVX and AVX2 support");
} else {
warn!("Your CPU does support AVX and AVX2, but you have not enabled avx and avx2 support. Please re-compile using RUSTFLAGS='-C target-cpu=native' cargo build --release`");
}
}
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
Loading