fma code added
This commit is contained in:
@@ -141,22 +141,26 @@ typedef void(SN_DECL *PNL_PROC_RAS)(mat_panel *right, mat_panel *ans, scalar_pac
|
||||
|
||||
#define PNL_PROC(T_type, T_arch, T_op_name) T_type##_pnl_##T_op_name##_##T_arch
|
||||
|
||||
#define DECLARE_PNL_PROC_LEFT_RIGHT_ANS(T_type, T_arch, T_op_name) \
|
||||
INTERNAL void SN_DECL PNL_PROC(T_type, T_arch, T_op_name)( \
|
||||
MAT_PANEL##T_arch##(T_type) const *left, MAT_PANEL##T_arch##(T_type) const *right, \
|
||||
MAT_PANEL##T_arch##(T_type) *restrict ans)
|
||||
#define DECLARE_PNL_PROC_LEFT_RIGHT_ANS(T_type, T_arch, T_op_name) \
|
||||
INTERNAL void SN_DECL PNL_PROC(T_type, T_arch, T_op_name)( \
|
||||
MAT_PANEL##T_arch##(T_type) const *left, MAT_PANEL##T_arch##(T_type) const *right, \
|
||||
MAT_PANEL##T_arch##(T_type) *restrict ans)
|
||||
#define DECLARE_PNL_PROC_LEFT_RIGHT_ANS_SCALAR(T_type, T_arch, T_op_name) \
|
||||
INTERNAL void SN_DECL PNL_PROC(T_type, T_arch, T_op_name)( \
|
||||
MAT_PANEL##T_arch##(T_type) const *left, MAT_PANEL##T_arch##(T_type) const *right, \
|
||||
MAT_PANEL##T_arch##(T_type) *restrict ans, scalar_pack const *scalar)
|
||||
#define DECLARE_PNL_PROC_LEFT_RIGHT_ANS_SCALAR(T_type, T_arch, T_op_name) \
|
||||
INTERNAL void SN_DECL PNL_PROC(T_type, T_arch, T_op_name)( \
|
||||
MAT_PANEL##T_arch##(T_type) const *left, MAT_PANEL##T_arch##(T_type) const *right, \
|
||||
MAT_PANEL##T_arch##(T_type) *restrict ans, scalar_pack const *scalar)
|
||||
#define DECLARE_PNL_PROC_LEFT_RIGHT_ANS(T_type, T_arch, T_op_name) \
|
||||
INTERNAL void SN_DECL PNL_PROC(T_type, T_arch, \
|
||||
T_op_name)(MAT_PANEL_##T_arch##(T_type) const *left, \
|
||||
MAT_PANEL_##T_arch##(T_type) const *right, \
|
||||
MAT_PANEL_##T_arch##(T_type) *restrict ans)
|
||||
#define DECLARE_PNL_PROC_LEFT_RIGHT_ANS(T_type, T_arch, T_op_name) \
|
||||
INTERNAL void SN_DECL PNL_PROC(T_type, T_arch, \
|
||||
T_op_name)(MAT_PANEL_##T_arch##(T_type) const *left, \
|
||||
MAT_PANEL_##T_arch##(T_type) const *right, \
|
||||
MAT_PANEL_##T_arch##(T_type) *restrict ans)
|
||||
#define DECLARE_PNL_PROC_LEFT_RIGHT_ANS_SCALAR(T_type, T_arch, T_op_name) \
|
||||
INTERNAL void SN_DECL PNL_PROC(T_type, T_arch, T_op_name)( \
|
||||
MAT_PANEL_##T_arch##(T_type) const *left, \
|
||||
MAT_PANEL_##T_arch##(T_type) const *right, \
|
||||
MAT_PANEL_##T_arch##(T_type) *restrict ans, scalar_pack const *scalar)
|
||||
#define DECLARE_PNL_PROC_LEFT_RIGHT_ANS_SCALAR(T_type, T_arch, T_op_name) \
|
||||
INTERNAL void SN_DECL PNL_PROC(T_type, T_arch, T_op_name)( \
|
||||
MAT_PANEL_##T_arch##(T_type) const *left, \
|
||||
MAT_PANEL_##T_arch##(T_type) const *right, \
|
||||
MAT_PANEL_##T_arch##(T_type) *restrict ans, scalar_pack const *scalar)
|
||||
|
||||
#pragma endregion
|
||||
|
||||
@@ -219,7 +223,8 @@ DECLARE_BUF_PROC_ANS_SCALAR(float, 512, fill);
|
||||
|
||||
#pragma region fma
|
||||
|
||||
DECLARE_KER_PROC_LEFT_RIGHT_ANS(float, sse, fma);
|
||||
DECLARE_PNL_PROC_LEFT_RIGHT_ANS(float, sse, fma);
|
||||
DECLARE_PNL_PROC_LEFT_RIGHT_ANS(float, avx, fma);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
@@ -67,15 +67,19 @@ typedef MAT_KERNEL(uint64_t) sn_zero_kernel_u64;
|
||||
/* SSE panel layout: column-major buffer holding 4 logical columns with MINQ=4.
|
||||
Columns: each column packs up to four scalars so ALIGN equals sizeof(__m128).
|
||||
Alignment: every column boundary lands on a 16-byte multiple for XMM loads. */
|
||||
#define MAT_PANEL_SSE(T) SN_ALIGNAS(16) MAT_PANEL_SQ_MIN_NOALIGN(T, __m128, 4)
|
||||
#define MAT_PANEL_sse(T) SN_ALIGNAS(16) MAT_PANEL_SQ_MIN_NOALIGN(T, __m128, 4)
|
||||
/* AVX2 panel layout: column-major buffer holding 8 logical columns with MINQ=8.
|
||||
Columns: each column stores eight elements via two 256-bit chunks when T is 32-bit.
|
||||
Alignment: column starts are 32-byte aligned so AVX2 loads/stores remain contiguous. */
|
||||
#define MAT_PANEL_AVX(T) SN_ALIGNAS(32) MAT_PANEL_SQ_MIN_NOALIGN(T, __m256, 8)
|
||||
#define MAT_PANEL_avx(T) SN_ALIGNAS(32) MAT_PANEL_SQ_MIN_NOALIGN(T, __m256, 8)
|
||||
/* AVX2 panel layout: column-major buffer holding 8 logical columns with MINQ=8.
|
||||
Columns: each column stores eight elements via two 256-bit chunks when T is 32-bit.
|
||||
Alignment: column starts are 32-byte aligned so AVX2 loads/stores remain contiguous. */
|
||||
#define MAT_PANEL_avx_fma(T) SN_ALIGNAS(32) MAT_PANEL_SQ_MIN_NOALIGN(T, __m256, 8)
|
||||
/* AVX-512 panel layout: column-major buffer holding 8 or more columns depending on T.
|
||||
Columns: each column expands to ceil(Q/lanes) ZMM chunks; default MINQ=8 keeps double-wide tiles.
|
||||
Columns: each column expands to ceil(Q/lanes) ZMM chunks; default MINQ=8 keeps doublse-wide tiles.
|
||||
Alignment: column starts sit on 64-byte boundaries to match AVX-512 streaming access. */
|
||||
#define MAT_PANEL_512(T) SN_ALIGNAS(64) MAT_PANEL_SQ_MIN_NOALIGN(T, __m512, 8)
|
||||
#define MAT_PANEL_512(T) SN_ALIGNAS(64) MAT_PANEL_SQ_MIN_NOALIGN(T, __m512, 8)
|
||||
|
||||
/* Global zero kernel declaration (defined in dllmain.c), aligned to 64 bytes */
|
||||
#ifdef __cplusplus
|
||||
@@ -113,7 +117,7 @@ extern __declspec(align(64)) sn_zero_kernel_u64 SN_ZERO_KERNEL;
|
||||
int col_index, int row_index)
|
||||
|
||||
/* Declarations for AVX float variant */
|
||||
DECLARE_BUILD_PANEL(AVX, float);
|
||||
DECLARE_STORE_PANEL(AVX, float);
|
||||
DECLARE_BUILD_PANEL(avx, float);
|
||||
DECLARE_STORE_PANEL(avx, float);
|
||||
|
||||
#endif /* SN_MATKERNEL */
|
||||
|
||||
+152
-25
@@ -1,35 +1,162 @@
|
||||
#include "sn_intrinsic.h"
|
||||
|
||||
#define _FMA_SELECT(i) _MM_SHUFFLE(i, i, i, i)
|
||||
|
||||
// ans = left * right + ans
|
||||
// right is not transposed
|
||||
DECLARE_KER_PROC_LEFT_RIGHT_ANS(float, sse, fma)
|
||||
DECLARE_PNL_PROC_LEFT_RIGHT_ANS(float, sse, fma)
|
||||
{
|
||||
register __m128 source0 = _mm_load_ps(&left->xmm[0]);
|
||||
register __m128 source1 = _mm_load_ps(&left->xmm[1]);
|
||||
register __m128 source2 = _mm_load_ps(&left->xmm[2]);
|
||||
register __m128 source3 = _mm_load_ps(&left->xmm[3]);
|
||||
const __m128 a0 = PANEL_COL_VEC((*left), 0, 0);
|
||||
const __m128 a1 = PANEL_COL_VEC((*left), 1, 0);
|
||||
const __m128 a2 = PANEL_COL_VEC((*left), 2, 0);
|
||||
const __m128 a3 = PANEL_COL_VEC((*left), 3, 0);
|
||||
|
||||
register __m128 ans0 = _mm_load_ps(&ans->xmm[0]);
|
||||
register __m128 ans1 = _mm_load_ps(&ans->xmm[1]);
|
||||
register __m128 ans2 = _mm_load_ps(&ans->xmm[2]);
|
||||
register __m128 ans3 = _mm_load_ps(&ans->xmm[3]);
|
||||
__m128 c0 = PANEL_COL_VEC((*ans), 0, 0);
|
||||
__m128 c1 = PANEL_COL_VEC((*ans), 1, 0);
|
||||
__m128 c2 = PANEL_COL_VEC((*ans), 2, 0);
|
||||
__m128 c3 = PANEL_COL_VEC((*ans), 3, 0);
|
||||
|
||||
register __m128 broadcast;
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
broadcast = _mm_load_ps(&right->xmm[i]);
|
||||
__m128 bcol;
|
||||
|
||||
ans0 = _mm_add_ps(ans0,
|
||||
_mm_mul_ps(source0, _mm_shuffle_ps(broadcast, broadcast, 0x00)));
|
||||
ans1 = _mm_add_ps(ans1,
|
||||
_mm_mul_ps(source1, _mm_shuffle_ps(broadcast, broadcast, 0x55)));
|
||||
ans2 = _mm_add_ps(ans2,
|
||||
_mm_mul_ps(source2, _mm_shuffle_ps(broadcast, broadcast, 0xAA)));
|
||||
ans3 = _mm_add_ps(ans3,
|
||||
_mm_mul_ps(source3, _mm_shuffle_ps(broadcast, broadcast, 0xFF)));
|
||||
}
|
||||
/* Column 0 */
|
||||
bcol = PANEL_COL_VEC((*right), 0, 0);
|
||||
c0 = _mm_add_ps(c0, _mm_mul_ps(a0, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(0))));
|
||||
c0 = _mm_add_ps(c0, _mm_mul_ps(a1, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(1))));
|
||||
c0 = _mm_add_ps(c0, _mm_mul_ps(a2, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(2))));
|
||||
c0 = _mm_add_ps(c0, _mm_mul_ps(a3, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(3))));
|
||||
|
||||
_mm_store_ps(&ans->xmm[0], ans0);
|
||||
_mm_store_ps(&ans->xmm[1], ans1);
|
||||
_mm_store_ps(&ans->xmm[2], ans2);
|
||||
_mm_store_ps(&ans->xmm[3], ans3);
|
||||
/* Column 1 */
|
||||
bcol = PANEL_COL_VEC((*right), 1, 0);
|
||||
c1 = _mm_add_ps(c1, _mm_mul_ps(a0, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(0))));
|
||||
c1 = _mm_add_ps(c1, _mm_mul_ps(a1, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(1))));
|
||||
c1 = _mm_add_ps(c1, _mm_mul_ps(a2, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(2))));
|
||||
c1 = _mm_add_ps(c1, _mm_mul_ps(a3, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(3))));
|
||||
|
||||
/* Column 2 */
|
||||
bcol = PANEL_COL_VEC((*right), 2, 0);
|
||||
c2 = _mm_add_ps(c2, _mm_mul_ps(a0, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(0))));
|
||||
c2 = _mm_add_ps(c2, _mm_mul_ps(a1, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(1))));
|
||||
c2 = _mm_add_ps(c2, _mm_mul_ps(a2, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(2))));
|
||||
c2 = _mm_add_ps(c2, _mm_mul_ps(a3, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(3))));
|
||||
|
||||
/* Column 3 */
|
||||
bcol = PANEL_COL_VEC((*right), 3, 0);
|
||||
c3 = _mm_add_ps(c3, _mm_mul_ps(a0, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(0))));
|
||||
c3 = _mm_add_ps(c3, _mm_mul_ps(a1, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(1))));
|
||||
c3 = _mm_add_ps(c3, _mm_mul_ps(a2, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(2))));
|
||||
c3 = _mm_add_ps(c3, _mm_mul_ps(a3, _mm_shuffle_ps(bcol, bcol, _FMA_SELECT(3))));
|
||||
|
||||
PANEL_COL_VEC((*ans), 0, 0) = c0;
|
||||
PANEL_COL_VEC((*ans), 1, 0) = c1;
|
||||
PANEL_COL_VEC((*ans), 2, 0) = c2;
|
||||
PANEL_COL_VEC((*ans), 3, 0) = c3;
|
||||
}
|
||||
|
||||
// ans = left * right + ans
|
||||
// right is not transposed
|
||||
DECLARE_PNL_PROC_LEFT_RIGHT_ANS(float, avx, fma)
|
||||
{
|
||||
static const __m256i idx0 = { 1, 1, 1, 1, 1, 1, 1, 1 };
|
||||
|
||||
for (int col = 0; col < 8; ++col) {
|
||||
register __m256 bcol = _mm256_load_ps((float *)&right->vec[col][0]);
|
||||
register __m256 ccol = _mm256_load_ps((float *)&ans->vec[col][0]);
|
||||
register __m256i idx = _mm256_setzero_si256();
|
||||
register __m256i increament = _mm256_load_si256(&idx0);
|
||||
|
||||
register __m256 a0 = _mm256_load_ps((float *)&left->vec[0][0]);
|
||||
register __m256 a1 = _mm256_load_ps((float *)&left->vec[1][0]);
|
||||
register __m256 a2 = _mm256_load_ps((float *)&left->vec[2][0]);
|
||||
register __m256 a3 = _mm256_load_ps((float *)&left->vec[3][0]);
|
||||
|
||||
ccol = _mm256_add_ps(ccol, _mm256_mul_ps(a0, _mm256_permutevar8x32_ps(bcol, idx)));
|
||||
idx = _mm256_add_epi32(idx, increament);
|
||||
ccol = _mm256_add_ps(ccol, _mm256_mul_ps(a1, _mm256_permutevar8x32_ps(bcol, idx)));
|
||||
idx = _mm256_add_epi32(idx, increament);
|
||||
ccol = _mm256_add_ps(ccol, _mm256_mul_ps(a2, _mm256_permutevar8x32_ps(bcol, idx)));
|
||||
idx = _mm256_add_epi32(idx, increament);
|
||||
ccol = _mm256_add_ps(ccol, _mm256_mul_ps(a3, _mm256_permutevar8x32_ps(bcol, idx)));
|
||||
idx = _mm256_add_epi32(idx, increament);
|
||||
|
||||
a0 = _mm256_load_ps((float *)&left->vec[4][0]);
|
||||
a1 = _mm256_load_ps((float *)&left->vec[5][0]);
|
||||
a2 = _mm256_load_ps((float *)&left->vec[6][0]);
|
||||
a3 = _mm256_load_ps((float *)&left->vec[7][0]);
|
||||
|
||||
ccol = _mm256_add_ps(ccol, _mm256_mul_ps(a0, _mm256_permutevar8x32_ps(bcol, idx)));
|
||||
idx = _mm256_add_epi32(idx, increament);
|
||||
ccol = _mm256_add_ps(ccol, _mm256_mul_ps(a1, _mm256_permutevar8x32_ps(bcol, idx)));
|
||||
idx = _mm256_add_epi32(idx, increament);
|
||||
ccol = _mm256_add_ps(ccol, _mm256_mul_ps(a2, _mm256_permutevar8x32_ps(bcol, idx)));
|
||||
idx = _mm256_add_epi32(idx, increament);
|
||||
ccol = _mm256_add_ps(ccol, _mm256_mul_ps(a3, _mm256_permutevar8x32_ps(bcol, idx)));
|
||||
|
||||
_mm256_store_ps((float *)&ans->vec[col][0], ccol);
|
||||
}
|
||||
}
|
||||
|
||||
DECLARE_PNL_PROC_LEFT_RIGHT_ANS(float, 512, fma)
|
||||
{
|
||||
const __m512i ones = _mm512_set1_epi32(1);
|
||||
|
||||
for (int col = 0; col < 8; ++col) {
|
||||
register __m512 bcol = _mm512_load_ps((float *)&right->vec[col][0]);
|
||||
register __m512 ccol = _mm512_load_ps((float *)&ans->vec[col][0]);
|
||||
register __m512i idx = _mm512_setzero_si512();
|
||||
register __m512i increament = _mm512_load_si512(&ones);
|
||||
|
||||
register __m512 a0 = _mm512_load_ps((float *)&left->vec[0][0]);
|
||||
register __m512 a1 = _mm512_load_ps((float *)&left->vec[1][0]);
|
||||
register __m512 a2 = _mm512_load_ps((float *)&left->vec[2][0]);
|
||||
register __m512 a3 = _mm512_load_ps((float *)&left->vec[3][0]);
|
||||
register __m512 a4 = _mm512_load_ps((float *)&left->vec[4][0]);
|
||||
register __m512 a5 = _mm512_load_ps((float *)&left->vec[5][0]);
|
||||
register __m512 a6 = _mm512_load_ps((float *)&left->vec[6][0]);
|
||||
register __m512 a7 = _mm512_load_ps((float *)&left->vec[7][0]);
|
||||
|
||||
ccol = _mm512_fmadd_ps(a0, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
ccol = _mm512_fmadd_ps(a1, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
ccol = _mm512_fmadd_ps(a2, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
ccol = _mm512_fmadd_ps(a3, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
ccol = _mm512_fmadd_ps(a4, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
ccol = _mm512_fmadd_ps(a5, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
ccol = _mm512_fmadd_ps(a6, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
ccol = _mm512_fmadd_ps(a7, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
|
||||
a0 = _mm512_load_ps((float *)&left->vec[8][0]);
|
||||
a1 = _mm512_load_ps((float *)&left->vec[9][0]);
|
||||
a2 = _mm512_load_ps((float *)&left->vec[10][0]);
|
||||
a3 = _mm512_load_ps((float *)&left->vec[11][0]);
|
||||
a4 = _mm512_load_ps((float *)&left->vec[12][0]);
|
||||
a5 = _mm512_load_ps((float *)&left->vec[13][0]);
|
||||
a6 = _mm512_load_ps((float *)&left->vec[14][0]);
|
||||
a7 = _mm512_load_ps((float *)&left->vec[15][0]);
|
||||
|
||||
ccol = _mm512_fmadd_ps(a0, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
ccol = _mm512_fmadd_ps(a1, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
ccol = _mm512_fmadd_ps(a2, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
ccol = _mm512_fmadd_ps(a3, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
ccol = _mm512_fmadd_ps(a4, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
ccol = _mm512_fmadd_ps(a5, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
ccol = _mm512_fmadd_ps(a6, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
ccol = _mm512_fmadd_ps(a7, _mm512_permutexvar_ps(idx, bcol), ccol);
|
||||
idx = _mm512_add_epi32(idx, increament);
|
||||
|
||||
_mm512_store_ps((float *)&ans->vec[col][0], ccol);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "sn_matkernel.h"
|
||||
|
||||
DECLARE_BUILD_PANEL(AVX, float)
|
||||
DECLARE_BUILD_PANEL(avx, float)
|
||||
{
|
||||
const int Q = 8; /* fixed for AVX float panel */
|
||||
|
||||
@@ -41,7 +41,7 @@ DECLARE_BUILD_PANEL(AVX, float)
|
||||
}
|
||||
}
|
||||
|
||||
DECLARE_STORE_PANEL(AVX, float)
|
||||
DECLARE_STORE_PANEL(avx, float)
|
||||
{
|
||||
const int Q = 8; /* fixed for AVX float panel */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user