Blame thirdparty/openblas/xianyi-OpenBLAS-e6e87a2/driver/level2/ger_thread.c

kusano 2b45e8
/*********************************************************************/
kusano 2b45e8
/* Copyright 2009, 2010 The University of Texas at Austin.           */
kusano 2b45e8
/* All rights reserved.                                              */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/* Redistribution and use in source and binary forms, with or        */
kusano 2b45e8
/* without modification, are permitted provided that the following   */
kusano 2b45e8
/* conditions are met:                                               */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/*   1. Redistributions of source code must retain the above         */
kusano 2b45e8
/*      copyright notice, this list of conditions and the following  */
kusano 2b45e8
/*      disclaimer.                                                  */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/*   2. Redistributions in binary form must reproduce the above      */
kusano 2b45e8
/*      copyright notice, this list of conditions and the following  */
kusano 2b45e8
/*      disclaimer in the documentation and/or other materials       */
kusano 2b45e8
/*      provided with the distribution.                              */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/*    THIS  SOFTWARE IS PROVIDED  BY THE  UNIVERSITY OF  TEXAS AT    */
kusano 2b45e8
/*    AUSTIN  ``AS IS''  AND ANY  EXPRESS OR  IMPLIED WARRANTIES,    */
kusano 2b45e8
/*    INCLUDING, BUT  NOT LIMITED  TO, THE IMPLIED  WARRANTIES OF    */
kusano 2b45e8
/*    MERCHANTABILITY  AND FITNESS FOR  A PARTICULAR  PURPOSE ARE    */
kusano 2b45e8
/*    DISCLAIMED.  IN  NO EVENT SHALL THE UNIVERSITY  OF TEXAS AT    */
kusano 2b45e8
/*    AUSTIN OR CONTRIBUTORS BE  LIABLE FOR ANY DIRECT, INDIRECT,    */
kusano 2b45e8
/*    INCIDENTAL,  SPECIAL, EXEMPLARY,  OR  CONSEQUENTIAL DAMAGES    */
kusano 2b45e8
/*    (INCLUDING, BUT  NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE    */
kusano 2b45e8
/*    GOODS  OR  SERVICES; LOSS  OF  USE,  DATA,  OR PROFITS;  OR    */
kusano 2b45e8
/*    BUSINESS INTERRUPTION) HOWEVER CAUSED  AND ON ANY THEORY OF    */
kusano 2b45e8
/*    LIABILITY, WHETHER  IN CONTRACT, STRICT  LIABILITY, OR TORT    */
kusano 2b45e8
/*    (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY OUT    */
kusano 2b45e8
/*    OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF ADVISED  OF  THE    */
kusano 2b45e8
/*    POSSIBILITY OF SUCH DAMAGE.                                    */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/* The views and conclusions contained in the software and           */
kusano 2b45e8
/* documentation are those of the authors and should not be          */
kusano 2b45e8
/* interpreted as representing official policies, either expressed   */
kusano 2b45e8
/* or implied, of The University of Texas at Austin.                 */
kusano 2b45e8
/*********************************************************************/
kusano 2b45e8
kusano 2b45e8
#include <stdio.h></stdio.h>
kusano 2b45e8
#include <stdlib.h></stdlib.h>
kusano 2b45e8
#include "common.h"
kusano 2b45e8
#include "symcopy.h"
kusano 2b45e8
kusano 2b45e8
#ifndef XCONJ
kusano 2b45e8
#define AXPY	AXPYU_K
kusano 2b45e8
#else
kusano 2b45e8
#define AXPY	AXPYC_K
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
static int ger_kernel(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *dummy1, FLOAT *buffer, BLASLONG pos){
kusano 2b45e8
kusano 2b45e8
  FLOAT *a, *x, *y;
kusano 2b45e8
  FLOAT alpha_r;
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
  FLOAT alpha_i;
kusano 2b45e8
#endif
kusano 2b45e8
  BLASLONG lda, incx, incy;
kusano 2b45e8
  BLASLONG m, n_from, n_to;
kusano 2b45e8
  BLASLONG i;
kusano 2b45e8
kusano 2b45e8
  x = (FLOAT *)args -> a;
kusano 2b45e8
  y = (FLOAT *)args -> b;
kusano 2b45e8
  a = (FLOAT *)args -> c;
kusano 2b45e8
kusano 2b45e8
  incx = args -> lda;
kusano 2b45e8
  incy = args -> ldb;
kusano 2b45e8
  lda  = args -> ldc;
kusano 2b45e8
kusano 2b45e8
  m = args -> m;
kusano 2b45e8
kusano 2b45e8
  alpha_r = *((FLOAT *)args -> alpha + 0);
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
  alpha_i = *((FLOAT *)args -> alpha + 1);
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
  n_from = 0;
kusano 2b45e8
  n_to   = args -> n;
kusano 2b45e8
kusano 2b45e8
  if (range_n) {
kusano 2b45e8
    n_from = *(range_n + 0);
kusano 2b45e8
    n_to   = *(range_n + 1);
kusano 2b45e8
kusano 2b45e8
    y += n_from * incy * COMPSIZE;
kusano 2b45e8
    a += n_from * lda  * COMPSIZE;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (incx != 1) {
kusano 2b45e8
    COPY_K(m, x, incx, buffer, 1);
kusano 2b45e8
    x = buffer;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  for (i = n_from; i < n_to; i ++) {
kusano 2b45e8
kusano 2b45e8
    AXPY(m, 0, 0,
kusano 2b45e8
#ifndef COMPLEX
kusano 2b45e8
	 alpha_r * *y,
kusano 2b45e8
#else
kusano 2b45e8
#ifndef CONJ
kusano 2b45e8
	 alpha_r * *(y + 0) - alpha_i * *(y + 1),   alpha_r * *(y + 1) + alpha_i * *(y + 0),
kusano 2b45e8
#else
kusano 2b45e8
	 alpha_r * *(y + 0) + alpha_i * *(y + 1), - alpha_r * *(y + 1) + alpha_i * *(y + 0),
kusano 2b45e8
#endif
kusano 2b45e8
#endif
kusano 2b45e8
	 x, 1, a, 1, NULL, 0);
kusano 2b45e8
    
kusano 2b45e8
    y += incy * COMPSIZE;
kusano 2b45e8
    a += lda  * COMPSIZE;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  return 0;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
#ifndef COMPLEX
kusano 2b45e8
int CNAME(BLASLONG m, BLASLONG n, FLOAT  alpha, FLOAT *x, BLASLONG incx, FLOAT *y, BLASLONG incy, FLOAT *a, BLASLONG lda, FLOAT *buffer, int nthreads){
kusano 2b45e8
#else
kusano 2b45e8
int CNAME(BLASLONG m, BLASLONG n, FLOAT *alpha, FLOAT *x, BLASLONG incx, FLOAT *y, BLASLONG incy, FLOAT *a, BLASLONG lda, FLOAT *buffer, int nthreads){
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
  blas_arg_t args;
kusano 2b45e8
  blas_queue_t queue[MAX_CPU_NUMBER];
kusano 2b45e8
  BLASLONG range_n[MAX_CPU_NUMBER + 1];
kusano 2b45e8
kusano 2b45e8
  BLASLONG width, i, num_cpu;
kusano 2b45e8
kusano 2b45e8
#ifdef SMP
kusano 2b45e8
#ifndef COMPLEX
kusano 2b45e8
#ifdef XDOUBLE
kusano 2b45e8
  int mode  =  BLAS_XDOUBLE | BLAS_REAL;
kusano 2b45e8
#elif defined(DOUBLE)
kusano 2b45e8
  int mode  =  BLAS_DOUBLE  | BLAS_REAL;
kusano 2b45e8
#else
kusano 2b45e8
  int mode  =  BLAS_SINGLE  | BLAS_REAL;
kusano 2b45e8
#endif  
kusano 2b45e8
#else
kusano 2b45e8
#ifdef XDOUBLE
kusano 2b45e8
  int mode  =  BLAS_XDOUBLE | BLAS_COMPLEX;
kusano 2b45e8
#elif defined(DOUBLE)
kusano 2b45e8
  int mode  =  BLAS_DOUBLE  | BLAS_COMPLEX;
kusano 2b45e8
#else
kusano 2b45e8
  int mode  =  BLAS_SINGLE  | BLAS_COMPLEX;
kusano 2b45e8
#endif  
kusano 2b45e8
#endif
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
  args.m = m;
kusano 2b45e8
  args.n = n;
kusano 2b45e8
  
kusano 2b45e8
  args.a = (void *)x;
kusano 2b45e8
  args.b = (void *)y;
kusano 2b45e8
  args.c = (void *)a;
kusano 2b45e8
    
kusano 2b45e8
  args.lda = incx;
kusano 2b45e8
  args.ldb = incy;
kusano 2b45e8
  args.ldc = lda;
kusano 2b45e8
kusano 2b45e8
#ifndef COMPLEX
kusano 2b45e8
  args.alpha = (void *)α
kusano 2b45e8
#else
kusano 2b45e8
  args.alpha = (void *) alpha;
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
  num_cpu  = 0;
kusano 2b45e8
  
kusano 2b45e8
  range_n[0] = 0;
kusano 2b45e8
  i          = n;
kusano 2b45e8
    
kusano 2b45e8
  while (i > 0){
kusano 2b45e8
    
kusano 2b45e8
    width  = blas_quickdivide(i + nthreads - num_cpu - 1, nthreads - num_cpu);
kusano 2b45e8
    if (width < 4) width = 4;
kusano 2b45e8
    if (i < width) width = i;
kusano 2b45e8
kusano 2b45e8
    range_n[num_cpu + 1] = range_n[num_cpu] + width;
kusano 2b45e8
      
kusano 2b45e8
    queue[num_cpu].mode    = mode;
kusano 2b45e8
    queue[num_cpu].routine = ger_kernel;
kusano 2b45e8
    queue[num_cpu].args    = &args;
kusano 2b45e8
    queue[num_cpu].range_n = &range_n[num_cpu];
kusano 2b45e8
    queue[num_cpu].sa      = NULL;
kusano 2b45e8
    queue[num_cpu].sb      = NULL;
kusano 2b45e8
    queue[num_cpu].next    = &queue[num_cpu + 1];
kusano 2b45e8
    
kusano 2b45e8
    num_cpu ++;
kusano 2b45e8
    i -= width;
kusano 2b45e8
  }
kusano 2b45e8
  
kusano 2b45e8
  if (num_cpu) {
kusano 2b45e8
    queue[0].sa = NULL;
kusano 2b45e8
    queue[0].sb = buffer;
kusano 2b45e8
    
kusano 2b45e8
    queue[num_cpu - 1].next = NULL;
kusano 2b45e8
    
kusano 2b45e8
    exec_blas(num_cpu, queue);
kusano 2b45e8
  }
kusano 2b45e8
   
kusano 2b45e8
  return 0;
kusano 2b45e8
}