Skip to content
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
20 changes: 10 additions & 10 deletions candle-core/src/cpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ trait CpuBF16<const ARR: usize> {
use half::{bf16, f16};

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_feature = "avx")]
#[cfg(target_feature = "avx2")]
pub mod avx;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_feature = "avx")]
#[cfg(target_feature = "avx2")]
pub use avx::{CurrentCpu, CurrentCpuBF16, CurrentCpuF16};

#[cfg(target_arch = "wasm32")]
Expand All @@ -82,7 +82,7 @@ pub use neon::CurrentCpu;

#[cfg(any(
target_feature = "neon",
target_feature = "avx",
target_feature = "avx2",
target_feature = "simd128"
))]
#[inline(always)]
Expand Down Expand Up @@ -112,7 +112,7 @@ pub(crate) unsafe fn vec_dot_f32(a_row: *const f32, b_row: *const f32, c: *mut f

#[cfg(not(any(
target_feature = "neon",
target_feature = "avx",
target_feature = "avx2",
target_feature = "simd128"
)))]
#[inline(always)]
Expand All @@ -125,7 +125,7 @@ pub(crate) unsafe fn vec_dot_f32(a_row: *const f32, b_row: *const f32, c: *mut f

#[cfg(any(
target_feature = "neon",
target_feature = "avx",
target_feature = "avx2",
target_feature = "simd128"
))]
#[inline(always)]
Expand All @@ -152,7 +152,7 @@ pub(crate) unsafe fn vec_sum(row: *const f32, b: *mut f32, k: usize) {

#[cfg(not(any(
target_feature = "neon",
target_feature = "avx",
target_feature = "avx2",
target_feature = "simd128"
)))]
#[inline(always)]
Expand All @@ -163,7 +163,7 @@ pub(crate) unsafe fn vec_sum(row: *const f32, b: *mut f32, k: usize) {
}
}

#[cfg(target_feature = "avx")]
#[cfg(target_feature = "avx2")]
#[inline(always)]
pub(crate) unsafe fn vec_dot_f16(a_row: *const f16, b_row: *const f16, c: *mut f32, k: usize) {
let mut sumf = 0.0f32;
Expand Down Expand Up @@ -191,7 +191,7 @@ pub(crate) unsafe fn vec_dot_f16(a_row: *const f16, b_row: *const f16, c: *mut f
*c = sumf;
}

#[cfg(target_feature = "avx")]
#[cfg(target_feature = "avx2")]
#[inline(always)]
pub(crate) unsafe fn vec_dot_bf16(a_row: *const bf16, b_row: *const bf16, c: *mut f32, k: usize) {
let mut sumf = 0.0f32;
Expand Down Expand Up @@ -219,7 +219,7 @@ pub(crate) unsafe fn vec_dot_bf16(a_row: *const bf16, b_row: *const bf16, c: *mu
*c = sumf;
}

#[cfg(not(target_feature = "avx"))]
#[cfg(not(target_feature = "avx2"))]
#[inline(always)]
pub(crate) unsafe fn vec_dot_f16(a_row: *const f16, b_row: *const f16, c: *mut f32, k: usize) {
// leftovers
Expand All @@ -230,7 +230,7 @@ pub(crate) unsafe fn vec_dot_f16(a_row: *const f16, b_row: *const f16, c: *mut f
*c = sum;
}

#[cfg(not(target_feature = "avx"))]
#[cfg(not(target_feature = "avx2"))]
#[inline(always)]
pub(crate) unsafe fn vec_dot_bf16(a_row: *const bf16, b_row: *const bf16, c: *mut f32, k: usize) {
// leftovers
Expand Down
16 changes: 8 additions & 8 deletions candle-core/src/quantized/k_quants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl GgmlType for BlockQ4_0 {
// https://github.com/ggerganov/llama.cpp/blob/b5ffb2849d23afe73647f68eec7b68187af09be6/ggml.c#L2361C10-L2361C122
#[allow(unreachable_code)]
fn vec_dot(n: usize, xs: &[Self], ys: &[Self::VecDotType]) -> Result<f32> {
#[cfg(target_feature = "avx")]
#[cfg(target_feature = "avx2")]
return super::avx::vec_dot_q4_0_q8_0(n, xs, ys);

#[cfg(target_feature = "neon")]
Expand Down Expand Up @@ -616,7 +616,7 @@ impl GgmlType for BlockQ8_0 {

#[allow(unreachable_code)]
fn vec_dot(n: usize, xs: &[Self], ys: &[Self::VecDotType]) -> Result<f32> {
#[cfg(target_feature = "avx")]
#[cfg(target_feature = "avx2")]
return super::avx::vec_dot_q8_0_q8_0(n, xs, ys);

#[cfg(target_feature = "neon")]
Expand Down Expand Up @@ -702,7 +702,7 @@ impl GgmlType for BlockQ2K {

#[allow(unreachable_code)]
fn vec_dot(n: usize, xs: &[Self], ys: &[Self::VecDotType]) -> Result<f32> {
#[cfg(target_feature = "avx")]
#[cfg(target_feature = "avx2")]
return super::avx::vec_dot_q2k_q8k(n, xs, ys);

#[cfg(target_feature = "neon")]
Expand Down Expand Up @@ -878,7 +878,7 @@ impl GgmlType for BlockQ3K {

#[allow(unreachable_code)]
fn vec_dot(n: usize, xs: &[Self], ys: &[Self::VecDotType]) -> Result<f32> {
#[cfg(target_feature = "avx")]
#[cfg(target_feature = "avx2")]
return super::avx::vec_dot_q3k_q8k(n, xs, ys);

#[cfg(target_feature = "neon")]
Expand Down Expand Up @@ -1156,7 +1156,7 @@ impl GgmlType for BlockQ4K {

#[allow(unreachable_code)]
fn vec_dot(n: usize, xs: &[Self], ys: &[Self::VecDotType]) -> Result<f32> {
#[cfg(target_feature = "avx")]
#[cfg(target_feature = "avx2")]
return super::avx::vec_dot_q4k_q8k(n, xs, ys);

#[cfg(target_feature = "neon")]
Expand Down Expand Up @@ -1349,7 +1349,7 @@ impl GgmlType for BlockQ5K {

#[allow(unreachable_code)]
fn vec_dot(n: usize, xs: &[Self], ys: &[Self::VecDotType]) -> Result<f32> {
#[cfg(target_feature = "avx")]
#[cfg(target_feature = "avx2")]
return super::avx::vec_dot_q5k_q8k(n, xs, ys);

#[cfg(target_feature = "neon")]
Expand Down Expand Up @@ -1570,7 +1570,7 @@ impl GgmlType for BlockQ6K {

#[allow(unreachable_code)]
fn vec_dot(n: usize, xs: &[Self], ys: &[Self::VecDotType]) -> Result<f32> {
#[cfg(target_feature = "avx")]
#[cfg(target_feature = "avx2")]
return super::avx::vec_dot_q6k_q8k(n, xs, ys);

#[cfg(target_feature = "neon")]
Expand Down Expand Up @@ -1753,7 +1753,7 @@ impl GgmlType for BlockQ8K {

#[allow(unreachable_code)]
fn vec_dot(n: usize, xs: &[Self], ys: &[Self::VecDotType]) -> Result<f32> {
#[cfg(target_feature = "avx")]
#[cfg(target_feature = "avx2")]
return super::avx::vec_dot_q8k_q8k(n, xs, ys);

#[cfg(target_feature = "neon")]
Expand Down
2 changes: 1 addition & 1 deletion candle-core/src/quantized/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{Context, CpuStorage, DType, Device, Result, Shape, Storage, Tensor};
use k_quants::*;
use std::borrow::Cow;

#[cfg(target_feature = "avx")]
#[cfg(target_feature = "avx2")]
pub mod avx;
mod dummy_cuda;
mod dummy_metal;
Expand Down
2 changes: 1 addition & 1 deletion candle-core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn metal_is_available() -> bool {
}

pub fn with_avx() -> bool {
cfg!(target_feature = "avx")
cfg!(target_feature = "avx2")
}

pub fn with_neon() -> bool {
Expand Down
Loading