Skip to content

Commit

Permalink
feat: Warn when CPU without AVX/AVX2 support is used (#7)
Browse files Browse the repository at this point in the history
* feat: Warn when CPU with AVX/AVX2 support is used

* Detect when CPU supports AVX(2), but feature not enabled
  • Loading branch information
sbernauer committed Jun 17, 2023
1 parent 8829b71 commit 74e95c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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

0 comments on commit 74e95c9

Please sign in to comment.