| @@ -11,11 +11,11 @@ SBGEMM_SMALL_K_TT = sbgemm_small_kernel_tt_cooperlake.c | |||||
| SBGEMM_SMALL_K_B0_TT = sbgemm_small_kernel_tt_cooperlake.c | SBGEMM_SMALL_K_B0_TT = sbgemm_small_kernel_tt_cooperlake.c | ||||
| SBGEMM_BETA = sgemm_beta_skylakex.c | SBGEMM_BETA = sgemm_beta_skylakex.c | ||||
| SBGEMMKERNEL = sbgemm_kernel_32x8_cooperlake.c | |||||
| SBGEMMINCOPY = sbgemm_ncopy_32_cooperlake.c | |||||
| SBGEMMITCOPY = sbgemm_tcopy_32_cooperlake.c | |||||
| SBGEMMONCOPY = sbgemm_ncopy_8_cooperlake.c | |||||
| SBGEMMOTCOPY = sbgemm_tcopy_8_cooperlake.c | |||||
| SBGEMMKERNEL = sbgemm_kernel_16x4_cooperlake.c | |||||
| SBGEMMINCOPY = sbgemm_ncopy_16_cooperlake.c | |||||
| SBGEMMITCOPY = sbgemm_tcopy_16_cooperlake.c | |||||
| SBGEMMONCOPY = sbgemm_ncopy_4_cooperlake.c | |||||
| SBGEMMOTCOPY = sbgemm_tcopy_4_cooperlake.c | |||||
| SBGEMMINCOPYOBJ = sbgemm_incopy$(TSUFFIX).$(SUFFIX) | SBGEMMINCOPYOBJ = sbgemm_incopy$(TSUFFIX).$(SUFFIX) | ||||
| SBGEMMITCOPYOBJ = sbgemm_itcopy$(TSUFFIX).$(SUFFIX) | SBGEMMITCOPYOBJ = sbgemm_itcopy$(TSUFFIX).$(SUFFIX) | ||||
| SBGEMMONCOPYOBJ = sbgemm_oncopy$(TSUFFIX).$(SUFFIX) | SBGEMMONCOPYOBJ = sbgemm_oncopy$(TSUFFIX).$(SUFFIX) | ||||
| @@ -0,0 +1,126 @@ | |||||
| /*************************************************************************** | |||||
| Copyright (c) 2021, The OpenBLAS Project | |||||
| All rights reserved. | |||||
| Redistribution and use in source and binary forms, with or without | |||||
| modification, are permitted provided that the following conditions are | |||||
| met: | |||||
| 1. Redistributions of source code must retain the above copyright | |||||
| notice, this list of conditions and the following disclaimer. | |||||
| 2. Redistributions in binary form must reproduce the above copyright | |||||
| notice, this list of conditions and the following disclaimer in | |||||
| the documentation and/or other materials provided with the | |||||
| distribution. | |||||
| 3. Neither the name of the OpenBLAS project nor the names of | |||||
| its contributors may be used to endorse or promote products | |||||
| derived from this software without specific prior written permission. | |||||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
| ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE | |||||
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||||
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |||||
| USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| *****************************************************************************/ | |||||
| #include <immintrin.h> | |||||
| #include "common.h" | |||||
| #define VMOVLDUP(addr, zmm) asm("vmovsldup (%1), %0": "=v"(zmm): "r"(addr)) | |||||
| #define VMOVHDUP(addr, zmm) asm("vmovshdup (%1), %0": "=v"(zmm): "r"(addr)) | |||||
| #define BROADCAST64(base, step, n, offset, zmm) \ | |||||
| if (n == 0) asm("vbroadcastsd %2(%1), %0": "=v"(zmm): "r"(base), "n"(offset*2)); \ | |||||
| else asm("vbroadcastsd %4(%1, %2, %3), %0": "=v"(zmm): "r"(base), "r"(step), "n"(n*2), "n"(offset*2)) | |||||
| #define DECLARE_A_PAIR(A) \ | |||||
| __m512i A_lo_##A; __m512i A_hi_##A; | |||||
| #define LOAD_A_PAIR(A) \ | |||||
| VMOVLDUP(ptr_a##A, A_lo_##A); \ | |||||
| VMOVHDUP(ptr_a##A, A_hi_##A); | |||||
| #define LOAD_A_PAIR_TAIL(A) { \ | |||||
| __m256i ymm = _mm256_loadu_si256(ptr_a##A); \ | |||||
| __m512 zmm = (__m512) _mm512_cvtepu16_epi32(ymm); \ | |||||
| A_lo_##A = (__m512i) _mm512_moveldup_ps(zmm); \ | |||||
| A_hi_##A = (__m512i) _mm512_movehdup_ps(zmm); \ | |||||
| } | |||||
| #define DECLARE_B_PAIR() \ | |||||
| __m512i B_lo; __m512i B_hi; | |||||
| #define BROADCAST_B_PAIR(Bx, By) \ | |||||
| BROADCAST64(ptr_b##Bx, n_blksize, By, 0, B_lo); \ | |||||
| BROADCAST64(ptr_b##Bx, n_blksize, By, 2, B_hi); | |||||
| #define BROADCAST_B_PAIR_TAIL(Bx, By) {\ | |||||
| __m128i xmm = (__m128i) _mm_load_sd(ptr_b##Bx + n_blksize * By); \ | |||||
| xmm = _mm_cvtepu16_epi32(xmm); \ | |||||
| B_lo = _mm512_broadcastd_epi32(xmm); \ | |||||
| B_hi = _mm512_broadcastd_epi32((__m128i) _mm_permute_pd((__m128d) xmm, 0x1)); \ | |||||
| } | |||||
| #define DECLARE_RESULT_4X(A, Bx, By) \ | |||||
| __m512 result_00_##A##Bx##By = _mm512_setzero_ps(); \ | |||||
| __m512 result_01_##A##Bx##By = _mm512_setzero_ps(); \ | |||||
| __m512 result_10_##A##Bx##By = _mm512_setzero_ps(); \ | |||||
| __m512 result_11_##A##Bx##By = _mm512_setzero_ps(); | |||||
| #define FMA(a, b, r) r = _mm512_dpbf16_ps(r, (__m512bh)a, (__m512bh)b) | |||||
| #define MATMUL_4X(A, Bx, By) \ | |||||
| FMA(A_lo_##A, B_lo, result_00_##A##Bx##By); \ | |||||
| FMA(A_hi_##A, B_lo, result_01_##A##Bx##By); \ | |||||
| FMA(A_lo_##A, B_hi, result_10_##A##Bx##By); \ | |||||
| FMA(A_hi_##A, B_hi, result_11_##A##Bx##By); | |||||
| #define STORE_4X(A, Bx, By) | |||||
| int CNAME (BLASLONG m, BLASLONG n, BLASLONG k, FLOAT alpha, IFLOAT * A, IFLOAT * B, FLOAT * C, BLASLONG ldc) | |||||
| { | |||||
| IFLOAT *ptr_a = A, *ptr_b = B, *ptr_c = C; | |||||
| IFLOAT *ptr_b0, *ptr_b1; | |||||
| IFLOAT *ptr_a0, *ptr_a1; | |||||
| BLASLONG n_count = n; | |||||
| BLASLONG m_count, k_count; | |||||
| BLASLONG n_blksize = 4 * k; | |||||
| for (; n_count > 23; n_count -= 24) { | |||||
| m_count = m; | |||||
| ptr_b0 = ptr_b; | |||||
| ptr_b1 = ptr_b0 + n_blksize * 3; | |||||
| for (; m_count > 15; m_count -= 16) { | |||||
| DECLARE_A_PAIR(0); DECLARE_B_PAIR(); | |||||
| DECLARE_RESULT_4X(0, 0, 0); DECLARE_RESULT_4X(0, 0, 1); DECLARE_RESULT_4X(0, 0, 2); | |||||
| DECLARE_RESULT_4X(0, 1, 0); DECLARE_RESULT_4X(0, 1, 1); DECLARE_RESULT_4X(0, 1, 2); | |||||
| for (k_count = k; k_count > 1; k_count -=2) { | |||||
| LOAD_A_PAIR(0); | |||||
| BROADCAST_B_PAIR(0, 0); MATMUL_4X(0, 0, 0); | |||||
| BROADCAST_B_PAIR(0, 1); MATMUL_4X(0, 0, 1); | |||||
| BROADCAST_B_PAIR(0, 2); MATMUL_4X(0, 0, 2); | |||||
| BROADCAST_B_PAIR(1, 0); MATMUL_4X(0, 1, 0); | |||||
| BROADCAST_B_PAIR(1, 1); MATMUL_4X(0, 1, 1); | |||||
| BROADCAST_B_PAIR(1, 2); MATMUL_4X(0, 1, 2); | |||||
| ptr_b0 += 24 * 2; | |||||
| ptr_b1 += 24 * 2; | |||||
| ptr_a0 += 16 * 2; | |||||
| } | |||||
| if (k_count > 0) { | |||||
| LOAD_A_PAIR_TAIL(0); | |||||
| BROADCAST_B_PAIR_TAIL(0, 0); MATMUL_4X(0, 0, 0); | |||||
| BROADCAST_B_PAIR_TAIL(0, 1); MATMUL_4X(0, 0, 1); | |||||
| BROADCAST_B_PAIR_TAIL(0, 2); MATMUL_4X(0, 0, 2); | |||||
| BROADCAST_B_PAIR_TAIL(1, 0); MATMUL_4X(0, 1, 0); | |||||
| BROADCAST_B_PAIR_TAIL(1, 1); MATMUL_4X(0, 1, 1); | |||||
| BROADCAST_B_PAIR_TAIL(1, 2); MATMUL_4X(0, 1, 2); | |||||
| ptr_b0 += 24; | |||||
| ptr_b1 += 24; | |||||
| ptr_a0 += 16; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,32 +0,0 @@ | |||||
| /*************************************************************************** | |||||
| Copyright (c) 2021, The OpenBLAS Project | |||||
| All rights reserved. | |||||
| Redistribution and use in source and binary forms, with or without | |||||
| modification, are permitted provided that the following conditions are | |||||
| met: | |||||
| 1. Redistributions of source code must retain the above copyright | |||||
| notice, this list of conditions and the following disclaimer. | |||||
| 2. Redistributions in binary form must reproduce the above copyright | |||||
| notice, this list of conditions and the following disclaimer in | |||||
| the documentation and/or other materials provided with the | |||||
| distribution. | |||||
| 3. Neither the name of the OpenBLAS project nor the names of | |||||
| its contributors may be used to endorse or promote products | |||||
| derived from this software without specific prior written permission. | |||||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
| ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE | |||||
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||||
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |||||
| USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| *****************************************************************************/ | |||||
| #include "common.h" | |||||
| int CNAME (BLASLONG m, BLASLONG n, BLASLONG k, FLOAT alpha, IFLOAT * A, IFLOAT * B, FLOAT * C, BLASLONG ldc) | |||||
| { | |||||
| } | |||||
| @@ -0,0 +1,207 @@ | |||||
| /*************************************************************************** | |||||
| Copyright (c) 2021, The OpenBLAS Project | |||||
| All rights reserved. | |||||
| Redistribution and use in source and binary forms, with or without | |||||
| modification, are permitted provided that the following conditions are | |||||
| met: | |||||
| 1. Redistributions of source code must retain the above copyright | |||||
| notice, this list of conditions and the following disclaimer. | |||||
| 2. Redistributions in binary form must reproduce the above copyright | |||||
| notice, this list of conditions and the following disclaimer in | |||||
| the documentation and/or other materials provided with the | |||||
| distribution. | |||||
| 3. Neither the name of the OpenBLAS project nor the names of | |||||
| its contributors may be used to endorse or promote products | |||||
| derived from this software without specific prior written permission. | |||||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
| ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE | |||||
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||||
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |||||
| USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| *****************************************************************************/ | |||||
| #include <stdio.h> | |||||
| #include <immintrin.h> | |||||
| #include "common.h" | |||||
| #define REORDER_4x32(r0, r1, r2, r3) {\ | |||||
| __m512i t0, t1, t2, t3; \ | |||||
| t0 = _mm512_unpacklo_epi32(r0, r1); \ | |||||
| t1 = _mm512_unpackhi_epi32(r0, r1); \ | |||||
| t2 = _mm512_unpacklo_epi32(r2, r3); \ | |||||
| t3 = _mm512_unpackhi_epi32(r2, r3); \ | |||||
| r0 = _mm512_unpacklo_epi64(t0, t2); \ | |||||
| r1 = _mm512_unpackhi_epi64(t0, t2); \ | |||||
| r2 = _mm512_unpacklo_epi64(t1, t3); \ | |||||
| r3 = _mm512_unpackhi_epi64(t1, t3); \ | |||||
| t0 = _mm512_permutex2var_epi32(r0, idx_lo_128, r1); \ | |||||
| t1 = _mm512_permutex2var_epi32(r0, idx_hi_128, r1); \ | |||||
| t2 = _mm512_permutex2var_epi32(r2, idx_lo_128, r3); \ | |||||
| t3 = _mm512_permutex2var_epi32(r2, idx_hi_128, r3); \ | |||||
| r0 = _mm512_permutex2var_epi32(t0, idx_lo_256, t2); \ | |||||
| r1 = _mm512_permutex2var_epi32(t1, idx_lo_256, t3); \ | |||||
| r2 = _mm512_permutex2var_epi32(t0, idx_hi_256, t2); \ | |||||
| r3 = _mm512_permutex2var_epi32(t1, idx_hi_256, t3); \ | |||||
| } | |||||
| #define REORDER_4x8(r0, r1, r2, r3) {\ | |||||
| __m128i t0, t1, t2, t3; \ | |||||
| t0 = _mm_unpacklo_epi32(r0, r1); \ | |||||
| t1 = _mm_unpackhi_epi32(r0, r1); \ | |||||
| t2 = _mm_unpacklo_epi32(r2, r3); \ | |||||
| t3 = _mm_unpackhi_epi32(r2, r3); \ | |||||
| r0 = _mm_unpacklo_epi64(t0, t2); \ | |||||
| r1 = _mm_unpackhi_epi64(t0, t2); \ | |||||
| r2 = _mm_unpacklo_epi64(t1, t3); \ | |||||
| r3 = _mm_unpackhi_epi64(t1, t3); \ | |||||
| } | |||||
| #define GET_TAIL(tail, remain_m) \ | |||||
| switch((remain_m + 1)/2) { \ | |||||
| case 1: tail = r0; break; \ | |||||
| case 2: tail = r1; break; \ | |||||
| case 3: tail = r2; break; \ | |||||
| case 4: tail = r3; break; \ | |||||
| } | |||||
| int CNAME(BLASLONG m, BLASLONG n, IFLOAT *a, BLASLONG lda, IFLOAT *b){ | |||||
| BLASLONG i, j; | |||||
| IFLOAT *aoffset; | |||||
| IFLOAT *aoffset0, *aoffset1, *aoffset2, *aoffset3; | |||||
| IFLOAT *boffset; | |||||
| aoffset = a; | |||||
| boffset = b; | |||||
| BLASLONG m32 = n & ~31; | |||||
| BLASLONG m8 = n & ~7; | |||||
| BLASLONG n4 = n & ~3; | |||||
| int permute_table[] = { | |||||
| 0x0, 0x1, 0x2, 0x3, 0x10, 0x11, 0x12, 0x13, 0x8, 0x9, 0xa, 0xb, 0x18, 0x19, 0x1a, 0x1b, | |||||
| 0x4, 0x5, 0x6, 0x7, 0x14, 0x15, 0x16, 0x17, 0xc, 0xd, 0xe, 0xf, 0x1c, 0x1d, 0x1e, 0x1f, | |||||
| 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | |||||
| 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, | |||||
| }; | |||||
| __m512i idx_lo_128 = _mm512_loadu_si512(permute_table); | |||||
| __m512i idx_hi_128 = _mm512_loadu_si512(permute_table + 16); | |||||
| __m512i idx_lo_256 = _mm512_loadu_si512(permute_table + 32); | |||||
| __m512i idx_hi_256 = _mm512_loadu_si512(permute_table + 48); | |||||
| for (j = 0; j < n4; j += 4) { | |||||
| aoffset0 = aoffset; | |||||
| aoffset1 = aoffset0 + lda; | |||||
| aoffset2 = aoffset1 + lda; | |||||
| aoffset3 = aoffset2 + lda; | |||||
| aoffset += 4 * lda; | |||||
| for (i = 0; i < m32; i += 32) { | |||||
| __m512i r0, r1, r2, r3; | |||||
| r0 = _mm512_loadu_si512(aoffset0 + i); | |||||
| r1 = _mm512_loadu_si512(aoffset1 + i); | |||||
| r2 = _mm512_loadu_si512(aoffset2 + i); | |||||
| r3 = _mm512_loadu_si512(aoffset3 + i); | |||||
| REORDER_4x32(r0, r1, r2, r3); | |||||
| _mm512_storeu_si512(boffset + 32*0, r0); | |||||
| _mm512_storeu_si512(boffset + 32*1, r1); | |||||
| _mm512_storeu_si512(boffset + 32*2, r2); | |||||
| _mm512_storeu_si512(boffset + 32*3, r3); | |||||
| boffset += 32 * 4; | |||||
| } | |||||
| for (; i < m8; i += 8) { | |||||
| __m128i r0 = _mm_loadu_si128(aoffset0 + i); | |||||
| __m128i r1 = _mm_loadu_si128(aoffset1 + i); | |||||
| __m128i r2 = _mm_loadu_si128(aoffset2 + i); | |||||
| __m128i r3 = _mm_loadu_si128(aoffset3 + i); | |||||
| REORDER_4x8(r0, r1, r2, r3); | |||||
| _mm_storeu_si128(boffset + 8*0, r0); | |||||
| _mm_storeu_si128(boffset + 8*1, r1); | |||||
| _mm_storeu_si128(boffset + 8*2, r2); | |||||
| _mm_storeu_si128(boffset + 8*3, r3); | |||||
| boffset += 8 * 4; | |||||
| } | |||||
| if (i < m) { | |||||
| int remain_m = m - i; | |||||
| __mmask8 r_mask = (1UL << remain_m) - 1; | |||||
| __m128i r0 = _mm_maskz_loadu_epi16(r_mask, aoffset0 + i); | |||||
| __m128i r1 = _mm_maskz_loadu_epi16(r_mask, aoffset1 + i); | |||||
| __m128i r2 = _mm_maskz_loadu_epi16(r_mask, aoffset2 + i); | |||||
| __m128i r3 = _mm_maskz_loadu_epi16(r_mask, aoffset3 + i); | |||||
| REORDER_4x8(r0, r1, r2, r3); | |||||
| // store should skip the tail odd line | |||||
| int num_store = remain_m/2; | |||||
| switch(num_store) { | |||||
| case 3: _mm_storeu_si128(boffset + 8*2, r0); | |||||
| case 2: _mm_storeu_si128(boffset + 8*1, r0); | |||||
| case 1: _mm_storeu_si128(boffset + 8*0, r0); | |||||
| } | |||||
| boffset += 8 * num_store; | |||||
| if (m & 0x1) { // handling the tail | |||||
| __m128i tail; | |||||
| GET_TAIL(tail, remain_m); | |||||
| /* tail vector is fill with zero like: | |||||
| * a, 0, b, 0, c, 0, d, 0 | |||||
| * need to extract lo words of data and store | |||||
| */ | |||||
| tail = _mm_cvtepi32_epi16(tail); | |||||
| _mm_store_sd(boffset, (__m128d) tail); // only lower 4 bfloat valid | |||||
| boffset += 4; | |||||
| } | |||||
| } | |||||
| } | |||||
| if (j < n) { | |||||
| int remain_n = n - j; | |||||
| __mmask8 nmask = (1UL << remain_n) - 1; | |||||
| aoffset0 = aoffset; | |||||
| aoffset1 = aoffset0 + lda; | |||||
| aoffset2 = aoffset1 + lda; | |||||
| aoffset3 = aoffset2 + lda; | |||||
| __m128i r0, r1, r2, r3; | |||||
| for (i = 0; i < m8; i += 8) { | |||||
| switch (remain_n) { | |||||
| case 3: r2 = _mm_loadu_si128(aoffset2 + i); | |||||
| case 2: r1 = _mm_loadu_si128(aoffset1 + i); | |||||
| case 1: r0 = _mm_loadu_si128(aoffset0 + i); | |||||
| } | |||||
| REORDER_4x8(r0, r1, r2, r3); | |||||
| _mm_mask_storeu_epi16(boffset + remain_n * 0, nmask, r0); | |||||
| _mm_mask_storeu_epi16(boffset + remain_n * 1, nmask, r1); | |||||
| _mm_mask_storeu_epi16(boffset + remain_n * 2, nmask, r2); | |||||
| _mm_mask_storeu_epi16(boffset + remain_n * 3, nmask, r3); | |||||
| boffset += 4 * remain_n; | |||||
| } | |||||
| if (i < m) { | |||||
| int remain_m = m - i; | |||||
| __mmask8 mmask = (1UL << remain_m) - 1; | |||||
| switch (remain_n) { | |||||
| case 3: r2 = _mm_maskz_loadu_epi16(mmask, aoffset2 + i); | |||||
| case 2: r1 = _mm_maskz_loadu_epi16(mmask, aoffset1 + i); | |||||
| case 1: r0 = _mm_maskz_loadu_epi16(mmask, aoffset0 + i); | |||||
| } | |||||
| REORDER_4x8(r0, r1, r2, r3); | |||||
| int num_store = remain_m/2; | |||||
| switch (num_store) { | |||||
| case 3: _mm_mask_storeu_epi16(boffset + remain_n * 2, nmask, r2); | |||||
| case 2: _mm_mask_storeu_epi16(boffset + remain_n * 1, nmask, r1); | |||||
| case 1: _mm_mask_storeu_epi16(boffset + remain_n * 0, nmask, r0); | |||||
| } | |||||
| boffset += 2 * num_store * remain_n; | |||||
| if (m & 0x1) { | |||||
| __m128i tail; | |||||
| GET_TAIL(tail, remain_m); | |||||
| tail = _mm_cvtepi32_epi16(tail); | |||||
| _mm_mask_storeu_epi16(boffset, nmask, tail); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -32,23 +32,25 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| int CNAME(BLASLONG m, BLASLONG n, IFLOAT *a, BLASLONG lda, IFLOAT *b){ | int CNAME(BLASLONG m, BLASLONG n, IFLOAT *a, BLASLONG lda, IFLOAT *b){ | ||||
| BLASLONG i, j; | BLASLONG i, j; | ||||
| IFLOAT *boffset; | |||||
| IFLOAT *boffset0, *boffset1; | |||||
| boffset = b; | |||||
| boffset0 = b; | |||||
| BLASLONG n32 = n & ~31; | BLASLONG n32 = n & ~31; | ||||
| BLASLONG m4 = m & ~3; | BLASLONG m4 = m & ~3; | ||||
| BLASLONG m2 = m & ~1; | BLASLONG m2 = m & ~1; | ||||
| uint32_t permute_table = { | uint32_t permute_table = { | ||||
| 0, 0x10|0, 1, 0x10|1, 2, 0x10|2, 3, 0x10|3, 4, 0x10|4, 5, 0x10|5, 6, 0x10|6, 7, 0x10, 7, | |||||
| 8, 0x10|8, 9, 0x10|9, 10, 0x10|10, 11, 0x10|11, 12, 0x10|12, 13, 0x10|13, 14, 0x10|14, 15, 0x10|15, | |||||
| 0x00, 0x10, 0x01, 0x11, 0x02, 0x12, 0x03, 0x13, 0x04, 0x14, 0x05, 0x15, 0x06, 0x16, 0x07, 0x17, | |||||
| 0x08, 0x18, 0x09, 0x19, 0x0a, 0x1a, 0x0b, 0x1b, 0x0c, 0x1c, 0x0d, 0x1d, 0x0e, 0x1e, 0x0f, 0x1f, | |||||
| }; | }; | ||||
| __m512i idx_lo = _mm512_loadu_si512(permute_table); | __m512i idx_lo = _mm512_loadu_si512(permute_table); | ||||
| __m512i idx_hi = _mm512_loadu_si512(permute_table + 16); | __m512i idx_hi = _mm512_loadu_si512(permute_table + 16); | ||||
| for (j = 0; j < n32; j += 32) { | for (j = 0; j < n32; j += 32) { | ||||
| /* process 2x16 n at the same time */ | |||||
| boffset1 = boffset0 + m * 16; | |||||
| for (i = 0; i < m4; i += 4) { | for (i = 0; i < m4; i += 4) { | ||||
| /* bf16 fma need special memory layout: | /* bf16 fma need special memory layout: | ||||
| * for memory layout like below: | * for memory layout like below: | ||||
| @@ -72,11 +74,12 @@ int CNAME(BLASLONG m, BLASLONG n, IFLOAT *a, BLASLONG lda, IFLOAT *b){ | |||||
| a2 = _mm512_permutex2var_epi32(a10, idx_lo, a11); | a2 = _mm512_permutex2var_epi32(a10, idx_lo, a11); | ||||
| a3 = _mm512_permutex2var_epi32(a10, idx_hi, a11); | a3 = _mm512_permutex2var_epi32(a10, idx_hi, a11); | ||||
| _mm512_storeu_si512(boffset, a0); | |||||
| _mm512_storeu_si512(boffset + 32, a1); | |||||
| _mm512_storeu_si512(boffset + 64, a2); | |||||
| _mm512_storeu_si512(boffset + 96, a3); | |||||
| boffset += 128; | |||||
| _mm512_storeu_si512(boffset0, a0); | |||||
| _mm512_storeu_si512(boffset1, a1); | |||||
| _mm512_storeu_si512(boffset0 + 32, a2); | |||||
| _mm512_storeu_si512(boffset1 + 32, a3); | |||||
| boffset0 += 64; | |||||
| boffset1 += 64; | |||||
| } | } | ||||
| for (; i < m2; i += 2) { | for (; i < m2; i += 2) { | ||||
| __m512i a0 = _mm512_loadu_si512(&a[(i + 0)*lda + j]); | __m512i a0 = _mm512_loadu_si512(&a[(i + 0)*lda + j]); | ||||
| @@ -88,22 +91,29 @@ int CNAME(BLASLONG m, BLASLONG n, IFLOAT *a, BLASLONG lda, IFLOAT *b){ | |||||
| a0 = _mm512_permutex2var_epi32(a00, idx_lo, a01); | a0 = _mm512_permutex2var_epi32(a00, idx_lo, a01); | ||||
| a1 = _mm512_permutex2var_epi32(a00, idx_hi, a01); | a1 = _mm512_permutex2var_epi32(a00, idx_hi, a01); | ||||
| _mm512_storeu_si512(boffset, a0); | |||||
| _mm512_storeu_si512(boffset + 32, a1); | |||||
| boffset += 64; | |||||
| _mm512_storeu_si512(boffset0, a0); | |||||
| _mm512_storeu_si512(boffset1, a1); | |||||
| boffset0 += 32; | |||||
| boffset1 += 32; | |||||
| } | } | ||||
| for (; i < m; i++) { | for (; i < m; i++) { | ||||
| /* just copy the only remains row */ | /* just copy the only remains row */ | ||||
| __m512i a0 = _mm512_loadu_si512(&a[(i + 0)*lda + j]); | |||||
| _mm512_storeu_si512(boffset, a0); | |||||
| boffset += 32; | |||||
| __m256i a0 = _mm256_loadu_si256(&a[(i + 0)*lda + j]); | |||||
| __m256i a1 = _mm256_loadu_si256(&a[(i + 0)*lda + j + 16]); | |||||
| _mm256_storeu_si256(boffset0, a0); | |||||
| _mm256_storeu_si256(boffset1, a1); | |||||
| boffset0 += 16; | |||||
| boffset1 += 16; | |||||
| } | } | ||||
| boffset0 = boffset1; | |||||
| } | } | ||||
| if (j < n) { | if (j < n) { | ||||
| uint32_t remains = n - j; | uint32_t remains = n - j; | ||||
| __mmask32 r_mask = (1UL << remains) - 1; | __mmask32 r_mask = (1UL << remains) - 1; | ||||
| if (remains > 16) { | if (remains > 16) { | ||||
| __mmask16 w_mask = (1UL << (remains - 16)) - 1; | |||||
| boffset1 = boffset0 + m * 16; | |||||
| uint32_t tail1 = remains - 16; | |||||
| __mmask16 w_mask1 = (1UL << tail1) - 1; | |||||
| for (i = 0; i < m2; i += 2) { | for (i = 0; i < m2; i += 2) { | ||||
| __m512i a0 = _mm512_maskz_loadu_epi16(r_mask, &a[(i + 0)*lda + j]); | __m512i a0 = _mm512_maskz_loadu_epi16(r_mask, &a[(i + 0)*lda + j]); | ||||
| __m512i a1 = _mm512_maskz_loadu_epi16(r_mask, &a[(i + 1)*lda + j]); | __m512i a1 = _mm512_maskz_loadu_epi16(r_mask, &a[(i + 1)*lda + j]); | ||||
| @@ -114,9 +124,19 @@ int CNAME(BLASLONG m, BLASLONG n, IFLOAT *a, BLASLONG lda, IFLOAT *b){ | |||||
| a0 = _mm512_permutex2var_epi32(a00, idx_lo, a01); | a0 = _mm512_permutex2var_epi32(a00, idx_lo, a01); | ||||
| a1 = _mm512_permutex2var_epi32(a00, idx_hi, a01); | a1 = _mm512_permutex2var_epi32(a00, idx_hi, a01); | ||||
| _mm512_storeu_si512(boffset, a0); | |||||
| _mm512_mask_storeu_epi32(boffset + 32, w_mask, a1); | |||||
| boffset += 2 * remains; | |||||
| _mm512_storeu_si512(boffset0, a0); | |||||
| _mm512_mask_storeu_epi32(boffset1, w_mask1, a1); | |||||
| boffset0 += 32; | |||||
| boffset1 += 2 * tail1; | |||||
| } | |||||
| for (; i < m; i++) { | |||||
| __m256i a0 = _mm256_loadu_si256(&a[(i + 0)*lda + j]); | |||||
| __m256i a1 = _mm256_maskz_loadu_epi16(w_mask1, &a[(i + 0)*lda + j + 16]); | |||||
| _mm256_storeu_si256(boffset0, a0); | |||||
| _mm256_mask_storeu_epi16(boffset1, w_mask1, a1); | |||||
| boffset0 += 16; | |||||
| boffset1 += tail1; | |||||
| } | } | ||||
| } else { | } else { | ||||
| __mmask16 w_mask = (1UL << remains ) - 1; | __mmask16 w_mask = (1UL << remains ) - 1; | ||||
| @@ -128,14 +148,15 @@ int CNAME(BLASLONG m, BLASLONG n, IFLOAT *a, BLASLONG lda, IFLOAT *b){ | |||||
| __m512i a01 = _mm512_unpackhi_epi16(a0, a1); | __m512i a01 = _mm512_unpackhi_epi16(a0, a1); | ||||
| a0 = _mm512_permutex2var_epi32(a00, idx_lo, a01); | a0 = _mm512_permutex2var_epi32(a00, idx_lo, a01); | ||||
| _mm512_mask_storeu_epi32(boffset, w_mask, a0); | |||||
| boffset += 2 * remains; | |||||
| _mm512_mask_storeu_epi32(boffset0, w_mask, a0); | |||||
| boffset0 += 2 * remains; | |||||
| } | |||||
| for (; i < m; i++) { | |||||
| __m256i a0 = _mm256_maskz_loadu_epi16(w_mask, &a[(i + 0)*lda + j]); | |||||
| _mm256_mask_storeu_epi16(boffset0, w_mask, a0); | |||||
| boffset0 += remains; | |||||
| } | } | ||||
| } | |||||
| for (; i < m; i++) { | |||||
| __m512i a0 = _mm512_maskz_loadu_epi16(r_mask, &a[(i + 0)*lda + j]); | |||||
| _mm512_mask_storeu_epi16(boffset, r_mask, a0); | |||||
| boffset += remains; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,33 +0,0 @@ | |||||
| /*************************************************************************** | |||||
| Copyright (c) 2021, The OpenBLAS Project | |||||
| All rights reserved. | |||||
| Redistribution and use in source and binary forms, with or without | |||||
| modification, are permitted provided that the following conditions are | |||||
| met: | |||||
| 1. Redistributions of source code must retain the above copyright | |||||
| notice, this list of conditions and the following disclaimer. | |||||
| 2. Redistributions in binary form must reproduce the above copyright | |||||
| notice, this list of conditions and the following disclaimer in | |||||
| the documentation and/or other materials provided with the | |||||
| distribution. | |||||
| 3. Neither the name of the OpenBLAS project nor the names of | |||||
| its contributors may be used to endorse or promote products | |||||
| derived from this software without specific prior written permission. | |||||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
| ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE | |||||
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||||
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |||||
| USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| *****************************************************************************/ | |||||
| #include <stdio.h> | |||||
| #include "common.h" | |||||
| int CNAME(BLASLONG m, BLASLONG n, IFLOAT *a, BLASLONG lda, IFLOAT *b){ | |||||
| } | |||||