|
| 1 | +/*************************************************************************** |
| 2 | +Copyright (c) 2017, The OpenBLAS Project |
| 3 | +Copyright (c) 2022, Arm Ltd |
| 4 | +All rights reserved. |
| 5 | +Redistribution and use in source and binary forms, with or without |
| 6 | +modification, are permitted provided that the following conditions are |
| 7 | +met: |
| 8 | +1. Redistributions of source code must retain the above copyright |
| 9 | +notice, this list of conditions and the following disclaimer. |
| 10 | +2. Redistributions in binary form must reproduce the above copyright |
| 11 | +notice, this list of conditions and the following disclaimer in |
| 12 | +the documentation and/or other materials provided with the |
| 13 | +distribution. |
| 14 | +3. Neither the name of the OpenBLAS project nor the names of |
| 15 | +its contributors may be used to endorse or promote products |
| 16 | +derived from this software without specific prior written permission. |
| 17 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | +ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE |
| 21 | +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 23 | +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 24 | +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 25 | +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 26 | +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | +*****************************************************************************/ |
| 28 | + |
| 29 | + |
| 30 | +#include "common.h" |
| 31 | + |
| 32 | +#ifdef HAVE_SVE |
| 33 | +#include "dot_kernel_sve.c" |
| 34 | +#endif |
| 35 | +#include "dot_kernel_asimd.c" |
| 36 | + |
| 37 | +#if defined(SMP) |
| 38 | +extern int blas_level1_thread_with_return_value(int mode, BLASLONG m, BLASLONG n, |
| 39 | + BLASLONG k, void *alpha, void *a, BLASLONG lda, void *b, BLASLONG ldb, |
| 40 | + void *c, BLASLONG ldc, int (*function)(), int nthreads); |
| 41 | +#endif |
| 42 | + |
| 43 | +static RETURN_TYPE dot_compute(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y) |
| 44 | +{ |
| 45 | + RETURN_TYPE dot = 0.0 ; |
| 46 | + |
| 47 | + if ( n <= 0 ) return dot; |
| 48 | + |
| 49 | +#ifdef HAVE_SVE |
| 50 | + if (inc_x == 1 && inc_y == 1) { |
| 51 | + return dot_kernel_sve(n, x, y); |
| 52 | + } |
| 53 | +#endif |
| 54 | + |
| 55 | + return dot_kernel_asimd(n, x, inc_x, y, inc_y); |
| 56 | +} |
| 57 | + |
| 58 | +#if defined(SMP) |
| 59 | +static int dot_thread_function(BLASLONG n, BLASLONG dummy0, |
| 60 | + BLASLONG dummy1, FLOAT dummy2, FLOAT *x, BLASLONG inc_x, FLOAT *y, |
| 61 | + BLASLONG inc_y, FLOAT *result, BLASLONG dummy3) |
| 62 | +{ |
| 63 | + *(RETURN_TYPE *)result = dot_compute(n, x, inc_x, y, inc_y); |
| 64 | + |
| 65 | + return 0; |
| 66 | +} |
| 67 | +#endif |
| 68 | + |
| 69 | +RETURN_TYPE CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y) |
| 70 | +{ |
| 71 | +#if defined(SMP) |
| 72 | + int nthreads; |
| 73 | + FLOAT dummy_alpha; |
| 74 | +#endif |
| 75 | + RETURN_TYPE dot = 0.0; |
| 76 | + |
| 77 | +#if defined(SMP) |
| 78 | + if (inc_x == 0 || inc_y == 0 || n <= 10000) |
| 79 | + nthreads = 1; |
| 80 | + else |
| 81 | + nthreads = num_cpu_avail(1); |
| 82 | + |
| 83 | + if (nthreads == 1) { |
| 84 | + dot = dot_compute(n, x, inc_x, y, inc_y); |
| 85 | + } else { |
| 86 | + int mode, i; |
| 87 | + char result[MAX_CPU_NUMBER * sizeof(double) * 2]; |
| 88 | + RETURN_TYPE *ptr; |
| 89 | + |
| 90 | +#if !defined(DOUBLE) |
| 91 | + mode = BLAS_SINGLE | BLAS_REAL; |
| 92 | +#else |
| 93 | + mode = BLAS_DOUBLE | BLAS_REAL; |
| 94 | +#endif |
| 95 | + |
| 96 | + blas_level1_thread_with_return_value(mode, n, 0, 0, &dummy_alpha, |
| 97 | + x, inc_x, y, inc_y, result, 0, |
| 98 | + ( void *)dot_thread_function, nthreads); |
| 99 | + |
| 100 | + ptr = (RETURN_TYPE *)result; |
| 101 | + for (i = 0; i < nthreads; i++) { |
| 102 | + dot = dot + (*ptr); |
| 103 | + ptr = (RETURN_TYPE *)(((char *)ptr) + sizeof(double) * 2); |
| 104 | + } |
| 105 | + } |
| 106 | +#else |
| 107 | + dot = dot_compute(n, x, inc_x, y, inc_y); |
| 108 | +#endif |
| 109 | + |
| 110 | + return dot; |
| 111 | +} |
0 commit comments