From ef5fb6fa46e71eb0e152c493d60858a4d73ef07b Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Fri, 7 Feb 2020 16:01:45 -0700 Subject: [PATCH] Check for AVX512 at runtime to avoid invalid opcode trap (#8166) automerge --- core/build.rs | 8 ++++++++ core/src/validator.rs | 10 ++++++++++ 2 files changed, 18 insertions(+) create mode 100644 core/build.rs diff --git a/core/build.rs b/core/build.rs new file mode 100644 index 000000000..a2fbf3bef --- /dev/null +++ b/core/build.rs @@ -0,0 +1,8 @@ +fn main() { + // Until https://github.com/rust-lang/rust/issues/44839 is resolved + // `#[target_feature(enable = "avx512f")]` is not available. + // Use an env flag instead: + if is_x86_feature_detected!("avx512f") { + println!("cargo:rustc-env=TARGET_FEATURE_AVX512F=1"); + } +} diff --git a/core/src/validator.rs b/core/src/validator.rs index ed79c5fe2..a504b7469 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -646,6 +646,16 @@ fn report_target_features() { process::exit(1); } } + + // TARGET_FEATURE_AVX512F is defined by build.rs + if option_env!("TARGET_FEATURE_AVX512F").is_some() { + if is_x86_feature_detected!("avx512f") { + info!("AVX512 detected"); + } else { + error!("Your machine does not have AVX512 support, please rebuild from source on your machine"); + process::exit(1); + } + } } // Get the activated stake percentage (based on the provided bank) that is visible in gossip