1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
use crate::frame::mmm::*;

extern "C" {
    fn fma_mmm_f32_16x6(op: *const MatMatMulKerSpec<f32>) -> isize;
    fn fma_mmm_i8_8x8(op: *const MatMatMulKerSpec<i32>) -> isize;
}

#[derive(Copy, Clone, Debug)]
pub struct MatMatMulF32x16x6;

impl MatMatMulKer<f32> for MatMatMulF32x16x6 {
    #[inline(always)]
    fn name() -> &'static str {
        "fma"
    }
    #[inline(always)]
    fn mr() -> usize {
        16
    }
    #[inline(always)]
    fn nr() -> usize {
        6
    }
    fn alignment_bytes_packed_a() -> usize {
        32
    }
    fn alignment_bytes_packed_b() -> usize {
        4
    }
    fn end_padding_packed_a() -> usize {
        0
    }
    fn end_padding_packed_b() -> usize {
        0
    }
    #[inline(never)]
    fn kernel(spec: &MatMatMulKerSpec<f32>) -> isize {
        unsafe { fma_mmm_f32_16x6(spec) }
    }
}

#[derive(Copy, Clone, Debug)]
pub struct MatMatMulI8x8x8;

impl MatMatMulKer<i32> for MatMatMulI8x8x8 {
    #[inline(always)]
    fn name() -> &'static str {
        "avx2"
    }
    #[inline(always)]
    fn mr() -> usize {
        8
    }
    #[inline(always)]
    fn nr() -> usize {
        8
    }
    fn alignment_bytes_packed_a() -> usize {
        32
    }
    fn alignment_bytes_packed_b() -> usize {
        4
    }
    fn end_padding_packed_a() -> usize {
        0
    }
    fn end_padding_packed_b() -> usize {
        0
    }
    #[inline(never)]
    fn kernel(spec: &MatMatMulKerSpec<i32>) -> isize {
        unsafe { fma_mmm_i8_8x8(spec) }
    }
}

#[derive(Copy, Clone, Debug)]
pub struct MatMatMulI8xI32x8x8;

impl MatMatMulKer<i32> for MatMatMulI8xI32x8x8 {
    #[inline(always)]
    fn name() -> &'static str {
        "avx2"
    }
    #[inline(always)]
    fn mr() -> usize {
        8
    }
    #[inline(always)]
    fn nr() -> usize {
        8
    }
    fn alignment_bytes_packed_a() -> usize {
        32
    }
    fn alignment_bytes_packed_b() -> usize {
        4
    }
    fn end_padding_packed_a() -> usize {
        0
    }
    fn end_padding_packed_b() -> usize {
        0
    }
    #[inline(never)]
    fn kernel(spec: &MatMatMulKerSpec<i32>) -> isize {
        unsafe { fma_mmm_i8_8x8(spec as *const _ as _) }
    }
}

test_mmm_kernel_f32!(
    crate::x86_64_fma::mmm::MatMatMulF32x16x6,
    test_MatMatMulF32x16x6,
    is_x86_feature_detected!("fma")
);

test_mmm_kernel_i8!(
    crate::x86_64_fma::mmm::MatMatMulI8x8x8,
    test_MatMatMulI8x8x8,
    is_x86_feature_detected!("fma")
);

test_mmm_kernel_i8_i32!(
    crate::x86_64_fma::mmm::MatMatMulI8xI32x8x8,
    test_MatMatMulI8xI32x8x8,
    is_x86_feature_detected!("avx2")
);