"Fossies" - the Fresh Open Source Software Archive

Member "pytorch-1.8.2/aten/src/ATen/native/quantized/cpu/qnnpack/src/sgemm/5x8-neon.c" (23 Jul 2021, 9104 Bytes) of package /linux/misc/pytorch-1.8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "5x8-neon.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) Facebook, Inc. and its affiliates.
    3  * All rights reserved.
    4  *
    5  * This source code is licensed under the BSD-style license found in the
    6  * LICENSE file in the root directory of this source tree.
    7  */
    8 
    9 #include <arm_neon.h>
   10 
   11 #include <qnnpack/sgemm.h>
   12 
   13 void pytorch_sgemm_ukernel_5x8__neon(
   14     size_t mr,
   15     size_t nr,
   16     size_t k,
   17     const float* restrict a,
   18     size_t a_stride,
   19     const float* restrict w,
   20     float* restrict c,
   21     size_t c_stride,
   22     const struct pytorch_qnnp_fp32_clamping_params
   23         clamping_params[restrict static 1]) {
   24   float32x4_t vacc0x0123 = vld1q_f32(w);
   25   w += 4;
   26   float32x4_t vacc0x4567 = vld1q_f32(w);
   27   w += 4;
   28   float32x4_t vacc1x0123 = vacc0x0123;
   29   float32x4_t vacc1x4567 = vacc0x4567;
   30   float32x4_t vacc2x0123 = vacc0x0123;
   31   float32x4_t vacc2x4567 = vacc0x4567;
   32   float32x4_t vacc3x0123 = vacc0x0123;
   33   float32x4_t vacc3x4567 = vacc0x4567;
   34   float32x4_t vacc4x0123 = vacc0x0123;
   35   float32x4_t vacc4x4567 = vacc0x4567;
   36 
   37   const float* a0 = a;
   38   const float* a1 = (const float*)((uintptr_t)a0 + a_stride);
   39   if (mr < 2) {
   40     a1 = a0;
   41   }
   42   const float* a2 = (const float*)((uintptr_t)a1 + a_stride);
   43   if (mr <= 2) {
   44     a2 = a1;
   45   }
   46   const float* a3 = (const float*)((uintptr_t)a2 + a_stride);
   47   if (mr < 4) {
   48     a3 = a2;
   49   }
   50   const float* a4 = (const float*)((uintptr_t)a3 + a_stride);
   51   if (mr <= 4) {
   52     a4 = a3;
   53   }
   54 
   55   for (; k >= 2; k -= 2) {
   56     const float32x2_t va0 = vld1_f32(a0);
   57     a0 += 2;
   58     const float32x2_t va1 = vld1_f32(a1);
   59     a1 += 2;
   60     const float32x2_t va2 = vld1_f32(a2);
   61     a2 += 2;
   62     const float32x2_t va3 = vld1_f32(a3);
   63     a3 += 2;
   64     const float32x2_t va4 = vld1_f32(a4);
   65     a4 += 2;
   66 
   67     {
   68       const float32x4_t vb0123 = vld1q_f32(w);
   69       w += 4;
   70       const float32x4_t vb4567 = vld1q_f32(w);
   71       w += 4;
   72 
   73 #if defined(__aarch64__)
   74       vacc0x0123 = vfmaq_lane_f32(vacc0x0123, vb0123, va0, 0);
   75       vacc0x4567 = vfmaq_lane_f32(vacc0x4567, vb4567, va0, 0);
   76       vacc1x0123 = vfmaq_lane_f32(vacc1x0123, vb0123, va1, 0);
   77       vacc1x4567 = vfmaq_lane_f32(vacc1x4567, vb4567, va1, 0);
   78       vacc2x0123 = vfmaq_lane_f32(vacc2x0123, vb0123, va2, 0);
   79       vacc2x4567 = vfmaq_lane_f32(vacc2x4567, vb4567, va2, 0);
   80       vacc3x0123 = vfmaq_lane_f32(vacc3x0123, vb0123, va3, 0);
   81       vacc3x4567 = vfmaq_lane_f32(vacc3x4567, vb4567, va3, 0);
   82       vacc4x0123 = vfmaq_lane_f32(vacc4x0123, vb0123, va4, 0);
   83       vacc4x4567 = vfmaq_lane_f32(vacc4x4567, vb4567, va4, 0);
   84 #else
   85       vacc0x0123 = vmlaq_lane_f32(vacc0x0123, vb0123, va0, 0);
   86       vacc0x4567 = vmlaq_lane_f32(vacc0x4567, vb4567, va0, 0);
   87       vacc1x0123 = vmlaq_lane_f32(vacc1x0123, vb0123, va1, 0);
   88       vacc1x4567 = vmlaq_lane_f32(vacc1x4567, vb4567, va1, 0);
   89       vacc2x0123 = vmlaq_lane_f32(vacc2x0123, vb0123, va2, 0);
   90       vacc2x4567 = vmlaq_lane_f32(vacc2x4567, vb4567, va2, 0);
   91       vacc3x0123 = vmlaq_lane_f32(vacc3x0123, vb0123, va3, 0);
   92       vacc3x4567 = vmlaq_lane_f32(vacc3x4567, vb4567, va3, 0);
   93       vacc4x0123 = vmlaq_lane_f32(vacc4x0123, vb0123, va4, 0);
   94       vacc4x4567 = vmlaq_lane_f32(vacc4x4567, vb4567, va4, 0);
   95 #endif
   96     }
   97 
   98     {
   99       const float32x4_t vb0123 = vld1q_f32(w);
  100       w += 4;
  101       const float32x4_t vb4567 = vld1q_f32(w);
  102       w += 4;
  103 
  104 #if defined(__aarch64__)
  105       vacc0x0123 = vfmaq_lane_f32(vacc0x0123, vb0123, va0, 1);
  106       vacc0x4567 = vfmaq_lane_f32(vacc0x4567, vb4567, va0, 1);
  107       vacc1x0123 = vfmaq_lane_f32(vacc1x0123, vb0123, va1, 1);
  108       vacc1x4567 = vfmaq_lane_f32(vacc1x4567, vb4567, va1, 1);
  109       vacc2x0123 = vfmaq_lane_f32(vacc2x0123, vb0123, va2, 1);
  110       vacc2x4567 = vfmaq_lane_f32(vacc2x4567, vb4567, va2, 1);
  111       vacc3x0123 = vfmaq_lane_f32(vacc3x0123, vb0123, va3, 1);
  112       vacc3x4567 = vfmaq_lane_f32(vacc3x4567, vb4567, va3, 1);
  113       vacc4x0123 = vfmaq_lane_f32(vacc4x0123, vb0123, va4, 1);
  114       vacc4x4567 = vfmaq_lane_f32(vacc4x4567, vb4567, va4, 1);
  115 #else
  116       vacc0x0123 = vmlaq_lane_f32(vacc0x0123, vb0123, va0, 1);
  117       vacc0x4567 = vmlaq_lane_f32(vacc0x4567, vb4567, va0, 1);
  118       vacc1x0123 = vmlaq_lane_f32(vacc1x0123, vb0123, va1, 1);
  119       vacc1x4567 = vmlaq_lane_f32(vacc1x4567, vb4567, va1, 1);
  120       vacc2x0123 = vmlaq_lane_f32(vacc2x0123, vb0123, va2, 1);
  121       vacc2x4567 = vmlaq_lane_f32(vacc2x4567, vb4567, va2, 1);
  122       vacc3x0123 = vmlaq_lane_f32(vacc3x0123, vb0123, va3, 1);
  123       vacc3x4567 = vmlaq_lane_f32(vacc3x4567, vb4567, va3, 1);
  124       vacc4x0123 = vmlaq_lane_f32(vacc4x0123, vb0123, va4, 1);
  125       vacc4x4567 = vmlaq_lane_f32(vacc4x4567, vb4567, va4, 1);
  126 #endif
  127     }
  128   }
  129   if (k != 0) {
  130     const float32x4_t va0 = vld1q_dup_f32(a0);
  131     const float32x4_t va1 = vld1q_dup_f32(a1);
  132     const float32x4_t va2 = vld1q_dup_f32(a2);
  133     const float32x4_t va3 = vld1q_dup_f32(a3);
  134     const float32x4_t va4 = vld1q_dup_f32(a4);
  135 
  136     const float32x4_t vb0123 = vld1q_f32(w);
  137     w += 4;
  138     const float32x4_t vb4567 = vld1q_f32(w);
  139     w += 4;
  140 
  141 #if defined(__aarch64__)
  142     vacc0x0123 = vfmaq_f32(vacc0x0123, vb0123, va0);
  143     vacc0x4567 = vfmaq_f32(vacc0x4567, vb4567, va0);
  144     vacc1x0123 = vfmaq_f32(vacc1x0123, vb0123, va1);
  145     vacc1x4567 = vfmaq_f32(vacc1x4567, vb4567, va1);
  146     vacc2x0123 = vfmaq_f32(vacc2x0123, vb0123, va2);
  147     vacc2x4567 = vfmaq_f32(vacc2x4567, vb4567, va2);
  148     vacc3x0123 = vfmaq_f32(vacc3x0123, vb0123, va3);
  149     vacc3x4567 = vfmaq_f32(vacc3x4567, vb4567, va3);
  150     vacc4x0123 = vfmaq_f32(vacc4x0123, vb0123, va4);
  151     vacc4x4567 = vfmaq_f32(vacc4x4567, vb4567, va4);
  152 #else
  153     vacc0x0123 = vmlaq_f32(vacc0x0123, vb0123, va0);
  154     vacc0x4567 = vmlaq_f32(vacc0x4567, vb4567, va0);
  155     vacc1x0123 = vmlaq_f32(vacc1x0123, vb0123, va1);
  156     vacc1x4567 = vmlaq_f32(vacc1x4567, vb4567, va1);
  157     vacc2x0123 = vmlaq_f32(vacc2x0123, vb0123, va2);
  158     vacc2x4567 = vmlaq_f32(vacc2x4567, vb4567, va2);
  159     vacc3x0123 = vmlaq_f32(vacc3x0123, vb0123, va3);
  160     vacc3x4567 = vmlaq_f32(vacc3x4567, vb4567, va3);
  161     vacc4x0123 = vmlaq_f32(vacc4x0123, vb0123, va4);
  162     vacc4x4567 = vmlaq_f32(vacc4x4567, vb4567, va4);
  163 #endif
  164   }
  165   const float32x4_t vmax = vld1q_dup_f32(&clamping_params->max);
  166   vacc0x0123 = vminq_f32(vacc0x0123, vmax);
  167   vacc0x4567 = vminq_f32(vacc0x4567, vmax);
  168   vacc1x0123 = vminq_f32(vacc1x0123, vmax);
  169   vacc1x4567 = vminq_f32(vacc1x4567, vmax);
  170   vacc2x0123 = vminq_f32(vacc2x0123, vmax);
  171   vacc2x4567 = vminq_f32(vacc2x4567, vmax);
  172   vacc3x0123 = vminq_f32(vacc3x0123, vmax);
  173   vacc3x4567 = vminq_f32(vacc3x4567, vmax);
  174   vacc4x0123 = vminq_f32(vacc4x0123, vmax);
  175   vacc4x4567 = vminq_f32(vacc4x4567, vmax);
  176 
  177   const float32x4_t vmin = vld1q_dup_f32(&clamping_params->min);
  178   vacc0x0123 = vmaxq_f32(vacc0x0123, vmin);
  179   vacc0x4567 = vmaxq_f32(vacc0x4567, vmin);
  180   vacc1x0123 = vmaxq_f32(vacc1x0123, vmin);
  181   vacc1x4567 = vmaxq_f32(vacc1x4567, vmin);
  182   vacc2x0123 = vmaxq_f32(vacc2x0123, vmin);
  183   vacc2x4567 = vmaxq_f32(vacc2x4567, vmin);
  184   vacc3x0123 = vmaxq_f32(vacc3x0123, vmin);
  185   vacc3x4567 = vmaxq_f32(vacc3x4567, vmin);
  186   vacc4x0123 = vmaxq_f32(vacc4x0123, vmin);
  187   vacc4x4567 = vmaxq_f32(vacc4x4567, vmin);
  188 
  189   float* c0 = c;
  190   float* c1 = (float*)((uintptr_t)c0 + c_stride);
  191   if (mr < 2) {
  192     c1 = c0;
  193   }
  194   float* c2 = (float*)((uintptr_t)c1 + c_stride);
  195   if (mr <= 2) {
  196     c2 = c1;
  197   }
  198   float* c3 = (float*)((uintptr_t)c2 + c_stride);
  199   if (mr < 4) {
  200     c3 = c2;
  201   }
  202   float* c4 = (float*)((uintptr_t)c3 + c_stride);
  203   if (mr <= 4) {
  204     c4 = c3;
  205   }
  206   if (nr == 8) {
  207     vst1q_f32(c0, vacc0x0123);
  208     c0 += 4;
  209     vst1q_f32(c1, vacc1x0123);
  210     c1 += 4;
  211     vst1q_f32(c2, vacc2x0123);
  212     c2 += 4;
  213     vst1q_f32(c3, vacc3x0123);
  214     c3 += 4;
  215     vst1q_f32(c4, vacc4x0123);
  216     c4 += 4;
  217 
  218     vst1q_f32(c0, vacc0x4567);
  219     vst1q_f32(c1, vacc1x4567);
  220     vst1q_f32(c2, vacc2x4567);
  221     vst1q_f32(c3, vacc3x4567);
  222     vst1q_f32(c4, vacc4x4567);
  223   } else {
  224     if (nr >= 4) {
  225       vst1q_f32(c0, vacc0x0123);
  226       c0 += 4;
  227       vst1q_f32(c1, vacc1x0123);
  228       c1 += 4;
  229       vst1q_f32(c2, vacc2x0123);
  230       c2 += 4;
  231       vst1q_f32(c3, vacc3x0123);
  232       c3 += 4;
  233       vst1q_f32(c4, vacc4x0123);
  234       c4 += 4;
  235       vacc0x0123 = vacc0x4567;
  236       vacc1x0123 = vacc1x4567;
  237       vacc2x0123 = vacc2x4567;
  238       vacc3x0123 = vacc3x4567;
  239       vacc4x0123 = vacc4x4567;
  240       nr -= 4;
  241     }
  242     if (nr >= 2) {
  243       vst1_f32(c0, vget_low_f32(vacc0x0123));
  244       c0 += 2;
  245       vst1_f32(c1, vget_low_f32(vacc1x0123));
  246       c1 += 2;
  247       vst1_f32(c2, vget_low_f32(vacc2x0123));
  248       c2 += 2;
  249       vst1_f32(c3, vget_low_f32(vacc3x0123));
  250       c3 += 2;
  251       vst1_f32(c4, vget_low_f32(vacc4x0123));
  252       c4 += 2;
  253       vacc0x0123 = vextq_f32(vacc0x0123, vacc0x0123, 2);
  254       vacc1x0123 = vextq_f32(vacc1x0123, vacc1x0123, 2);
  255       vacc2x0123 = vextq_f32(vacc2x0123, vacc2x0123, 2);
  256       vacc3x0123 = vextq_f32(vacc3x0123, vacc3x0123, 2);
  257       vacc4x0123 = vextq_f32(vacc4x0123, vacc4x0123, 2);
  258       nr -= 2;
  259     }
  260     if (nr != 0) {
  261       vst1q_lane_f32(c0, vacc0x0123, 0);
  262       vst1q_lane_f32(c1, vacc1x0123, 0);
  263       vst1q_lane_f32(c2, vacc2x0123, 0);
  264       vst1q_lane_f32(c3, vacc3x0123, 0);
  265       vst1q_lane_f32(c4, vacc4x0123, 0);
  266     }
  267   }
  268 }