-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make avx512 fp16 a runtime check (#1884)
Makes [avx512 fp16](https://networkbuilders.intel.com/solutionslibrary/intel-avx-512-fp16-instruction-set-for-intel-xeon-processor-based-products-technology-guide) support a runtime check. This will allow binaries compiled w/ the avx512fp16 feature to run hardware that doesn't support this feature (e.g. x86 before saphire rapids). Check does not add performance penalty: ``` albertlockett@albert-ubuntu-saphire:~/lance/rust/lance-linalg$ TARGET_TIME=55 cargo bench \ --bench dot \ -F avx512fp16 Compiling lance-linalg v0.9.9 (/home/albertlockett/lance/rust/lance-linalg) Finished bench [optimized + debuginfo] target(s) in 55.77s Running benches/dot.rs (/home/albertlockett/lance/rust/target/release/deps/dot-f42dee3ad61e0342) Gnuplot not found, using plotters backend Dot(half::binary16::f16, arrow_artiy) time: [2.5228 s 2.5230 s 2.5233 s] change: [-0.0915% -0.0641% -0.0381%] (p = 0.00 < 0.10) Change within noise threshold. Dot(half::binary16::f16, auto-vectorization) time: [167.90 ms 168.05 ms 168.34 ms] change: [-0.3945% -0.1097% +0.1731%] (p = 0.47 > 0.10) No change in performance detected. Dot(f16, SIMD) time: [167.03 ms 167.22 ms 167.50 ms] change: [-1.4038% -0.9215% -0.4951%] (p = 0.00 < 0.10) Change within noise threshold. ```
- Loading branch information
1 parent
2f67cf9
commit 628f7a3
Showing
7 changed files
with
119 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2024 Lance Developers. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#[cfg(target_arch = "x86_64")] | ||
pub mod x86 { | ||
use core::arch::x86_64::__cpuid; | ||
|
||
use lazy_static::lazy_static; | ||
|
||
#[inline] | ||
fn check_flag(x: usize, position: u32) -> bool { | ||
x & (1 << position) != 0 | ||
} | ||
|
||
lazy_static! { | ||
pub static ref AVX512_F16_SUPPORTED: bool = { | ||
// this macro does many OS checks/etc. to determine if allowed to use AVX512 | ||
if !is_x86_feature_detected!("avx512f") { | ||
return false; | ||
} | ||
|
||
// EAX=7, ECX=0: Extended Features (includes AVX512) | ||
// More info on calling CPUID can be found here (section 1.4) | ||
// https://www.intel.com/content/dam/develop/external/us/en/documents/architecture-instruction-set-extensions-programming-reference.pdf | ||
let ext_cpuid_result = unsafe { __cpuid(7) }; | ||
check_flag(ext_cpuid_result.edx as usize, 23) | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters