From c435f7b3e3fea87c3afc55b7b1b756cd8a2296f3 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Tue, 27 Jul 2021 23:28:30 -0600 Subject: [PATCH] validator: add avx2 runtime check --- core/src/validator.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/src/validator.rs b/core/src/validator.rs index 97642b03ea..4424a7b72c 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -1469,6 +1469,7 @@ pub fn report_target_features() { if !is_rosetta_emulated() { unsafe { check_avx() }; + unsafe { check_avx2() }; } } @@ -1482,7 +1483,7 @@ unsafe fn check_avx() { info!("AVX detected"); } else { error!( - "Your machine does not have AVX support, please rebuild from source on your machine" + "Incompatible CPU detected: missing AVX support. Please build from source on the target" ); abort(); } @@ -1491,6 +1492,22 @@ unsafe fn check_avx() { #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] unsafe fn check_avx() {} +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +#[target_feature(enable = "avx2")] +unsafe fn check_avx2() { + if is_x86_feature_detected!("avx2") { + info!("AVX2 detected"); + } else { + error!( + "Incompatible CPU detected: missing AVX2 support. Please build from source on the target" + ); + abort(); + } +} + +#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] +unsafe fn check_avx2() {} + // Get the activated stake percentage (based on the provided bank) that is visible in gossip fn get_stake_percent_in_gossip(bank: &Bank, cluster_info: &ClusterInfo, log: bool) -> u64 { let mut online_stake = 0;