|
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 "common.h"
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
static FLOAT dm1 = -1.;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#ifdef CONJ
|
|
kusano |
2b45e8 |
#define GEMM_KERNEL GEMM_KERNEL_R
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
#define GEMM_KERNEL GEMM_KERNEL_N
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if GEMM_DEFAULT_UNROLL_M == 1
|
|
kusano |
2b45e8 |
#define GEMM_UNROLL_M_SHIFT 0
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if GEMM_DEFAULT_UNROLL_M == 2
|
|
kusano |
2b45e8 |
#define GEMM_UNROLL_M_SHIFT 1
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if GEMM_DEFAULT_UNROLL_M == 4
|
|
kusano |
2b45e8 |
#define GEMM_UNROLL_M_SHIFT 2
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if GEMM_DEFAULT_UNROLL_M == 8
|
|
kusano |
2b45e8 |
#define GEMM_UNROLL_M_SHIFT 3
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if GEMM_DEFAULT_UNROLL_M == 16
|
|
kusano |
2b45e8 |
#define GEMM_UNROLL_M_SHIFT 4
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if GEMM_DEFAULT_UNROLL_N == 1
|
|
kusano |
2b45e8 |
#define GEMM_UNROLL_N_SHIFT 0
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if GEMM_DEFAULT_UNROLL_N == 2
|
|
kusano |
2b45e8 |
#define GEMM_UNROLL_N_SHIFT 1
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if GEMM_DEFAULT_UNROLL_N == 4
|
|
kusano |
2b45e8 |
#define GEMM_UNROLL_N_SHIFT 2
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if GEMM_DEFAULT_UNROLL_N == 8
|
|
kusano |
2b45e8 |
#define GEMM_UNROLL_N_SHIFT 3
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if GEMM_DEFAULT_UNROLL_N == 16
|
|
kusano |
2b45e8 |
#define GEMM_UNROLL_N_SHIFT 4
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#ifndef COMPLEX
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
static inline void solve(BLASLONG m, BLASLONG n, FLOAT *a, FLOAT *b, FLOAT *c, BLASLONG ldc) {
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
FLOAT aa, bb;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
int i, j, k;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
for (i = 0; i < n; i++) {
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
bb = *(b + i);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
for (j = 0; j < m; j ++) {
|
|
kusano |
2b45e8 |
aa = *(c + j + i * ldc);
|
|
kusano |
2b45e8 |
aa *= bb;
|
|
kusano |
2b45e8 |
*a = aa;
|
|
kusano |
2b45e8 |
*(c + j + i * ldc) = aa;
|
|
kusano |
2b45e8 |
a ++;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
for (k = i + 1; k < n; k ++){
|
|
kusano |
2b45e8 |
*(c + j + k * ldc) -= aa * *(b + k);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
b += n;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
static inline void solve(BLASLONG m, BLASLONG n, FLOAT *a, FLOAT *b, FLOAT *c, BLASLONG ldc) {
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
FLOAT aa1, aa2;
|
|
kusano |
2b45e8 |
FLOAT bb1, bb2;
|
|
kusano |
2b45e8 |
FLOAT cc1, cc2;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
int i, j, k;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
ldc *= 2;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
for (i = 0; i < n; i++) {
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
bb1 = *(b + i * 2 + 0);
|
|
kusano |
2b45e8 |
bb2 = *(b + i * 2 + 1);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
for (j = 0; j < m; j ++) {
|
|
kusano |
2b45e8 |
aa1 = *(c + j * 2 + 0 + i * ldc);
|
|
kusano |
2b45e8 |
aa2 = *(c + j * 2 + 1 + i * ldc);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#ifndef CONJ
|
|
kusano |
2b45e8 |
cc1 = aa1 * bb1 - aa2 * bb2;
|
|
kusano |
2b45e8 |
cc2 = aa1 * bb2 + aa2 * bb1;
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
cc1 = aa1 * bb1 + aa2 * bb2;
|
|
kusano |
2b45e8 |
cc2 = -aa1 * bb2 + aa2 * bb1;
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
*(a + 0) = cc1;
|
|
kusano |
2b45e8 |
*(a + 1) = cc2;
|
|
kusano |
2b45e8 |
*(c + j * 2 + 0 + i * ldc) = cc1;
|
|
kusano |
2b45e8 |
*(c + j * 2 + 1 + i * ldc) = cc2;
|
|
kusano |
2b45e8 |
a += 2;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
for (k = i + 1; k < n; k ++){
|
|
kusano |
2b45e8 |
#ifndef CONJ
|
|
kusano |
2b45e8 |
*(c + j * 2 + 0 + k * ldc) -= cc1 * *(b + k * 2 + 0) - cc2 * *(b + k * 2 + 1);
|
|
kusano |
2b45e8 |
*(c + j * 2 + 1 + k * ldc) -= cc1 * *(b + k * 2 + 1) + cc2 * *(b + k * 2 + 0);
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
*(c + j * 2 + 0 + k * ldc) -= cc1 * *(b + k * 2 + 0) + cc2 * *(b + k * 2 + 1);
|
|
kusano |
2b45e8 |
*(c + j * 2 + 1 + k * ldc) -= - cc1 * *(b + k * 2 + 1) + cc2 * *(b + k * 2 + 0);
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
b += n * 2;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
int CNAME(BLASLONG m, BLASLONG n, BLASLONG k, FLOAT dummy1,
|
|
kusano |
2b45e8 |
#ifdef COMPLEX
|
|
kusano |
2b45e8 |
FLOAT dummy2,
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
FLOAT *a, FLOAT *b, FLOAT *c, BLASLONG ldc, BLASLONG offset){
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
FLOAT *aa, *cc;
|
|
kusano |
2b45e8 |
BLASLONG kk;
|
|
kusano |
2b45e8 |
BLASLONG i, j, jj;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if 0
|
|
kusano |
2b45e8 |
fprintf(stderr, "TRSM RN KERNEL m = %3ld n = %3ld k = %3ld offset = %3ld\n",
|
|
kusano |
2b45e8 |
m, n, k, offset);
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
jj = 0;
|
|
kusano |
2b45e8 |
j = (n >> GEMM_UNROLL_N_SHIFT);
|
|
kusano |
2b45e8 |
kk = -offset;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
while (j > 0) {
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
aa = a;
|
|
kusano |
2b45e8 |
cc = c;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
i = (m >> GEMM_UNROLL_M_SHIFT);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (i > 0) {
|
|
kusano |
2b45e8 |
do {
|
|
kusano |
2b45e8 |
if (kk > 0) {
|
|
kusano |
2b45e8 |
GEMM_KERNEL(GEMM_UNROLL_M, GEMM_UNROLL_N, kk, dm1,
|
|
kusano |
2b45e8 |
#ifdef COMPLEX
|
|
kusano |
2b45e8 |
ZERO,
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
aa, b, cc, ldc);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
solve(GEMM_UNROLL_M, GEMM_UNROLL_N,
|
|
kusano |
2b45e8 |
aa + kk * GEMM_UNROLL_M * COMPSIZE,
|
|
kusano |
2b45e8 |
b + kk * GEMM_UNROLL_N * COMPSIZE,
|
|
kusano |
2b45e8 |
cc, ldc);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
aa += GEMM_UNROLL_M * k * COMPSIZE;
|
|
kusano |
2b45e8 |
cc += GEMM_UNROLL_M * COMPSIZE;
|
|
kusano |
2b45e8 |
i --;
|
|
kusano |
2b45e8 |
} while (i > 0);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (m & (GEMM_UNROLL_M - 1)) {
|
|
kusano |
2b45e8 |
i = (GEMM_UNROLL_M >> 1);
|
|
kusano |
2b45e8 |
while (i > 0) {
|
|
kusano |
2b45e8 |
if (m & i) {
|
|
kusano |
2b45e8 |
if (kk > 0) {
|
|
kusano |
2b45e8 |
GEMM_KERNEL(i, GEMM_UNROLL_N, kk, dm1,
|
|
kusano |
2b45e8 |
#ifdef COMPLEX
|
|
kusano |
2b45e8 |
ZERO,
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
aa, b, cc, ldc);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
solve(i, GEMM_UNROLL_N,
|
|
kusano |
2b45e8 |
aa + kk * i * COMPSIZE,
|
|
kusano |
2b45e8 |
b + kk * GEMM_UNROLL_N * COMPSIZE,
|
|
kusano |
2b45e8 |
cc, ldc);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
aa += i * k * COMPSIZE;
|
|
kusano |
2b45e8 |
cc += i * COMPSIZE;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
i >>= 1;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
kk += GEMM_UNROLL_N;
|
|
kusano |
2b45e8 |
b += GEMM_UNROLL_N * k * COMPSIZE;
|
|
kusano |
2b45e8 |
c += GEMM_UNROLL_N * ldc * COMPSIZE;
|
|
kusano |
2b45e8 |
j --;
|
|
kusano |
2b45e8 |
jj += GEMM_UNROLL_M;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (n & (GEMM_UNROLL_N - 1)) {
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
j = (GEMM_UNROLL_N >> 1);
|
|
kusano |
2b45e8 |
while (j > 0) {
|
|
kusano |
2b45e8 |
if (n & j) {
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
aa = a;
|
|
kusano |
2b45e8 |
cc = c;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
i = (m >> GEMM_UNROLL_M_SHIFT);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
while (i > 0) {
|
|
kusano |
2b45e8 |
if (kk > 0) {
|
|
kusano |
2b45e8 |
GEMM_KERNEL(GEMM_UNROLL_M, j, kk, dm1,
|
|
kusano |
2b45e8 |
#ifdef COMPLEX
|
|
kusano |
2b45e8 |
ZERO,
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
aa,
|
|
kusano |
2b45e8 |
b,
|
|
kusano |
2b45e8 |
cc,
|
|
kusano |
2b45e8 |
ldc);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
solve(GEMM_UNROLL_M, j,
|
|
kusano |
2b45e8 |
aa + kk * GEMM_UNROLL_M * COMPSIZE,
|
|
kusano |
2b45e8 |
b + kk * j * COMPSIZE, cc, ldc);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
aa += GEMM_UNROLL_M * k * COMPSIZE;
|
|
kusano |
2b45e8 |
cc += GEMM_UNROLL_M * COMPSIZE;
|
|
kusano |
2b45e8 |
i --;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (m & (GEMM_UNROLL_M - 1)) {
|
|
kusano |
2b45e8 |
i = (GEMM_UNROLL_M >> 1);
|
|
kusano |
2b45e8 |
while (i > 0) {
|
|
kusano |
2b45e8 |
if (m & i) {
|
|
kusano |
2b45e8 |
if (kk > 0) {
|
|
kusano |
2b45e8 |
GEMM_KERNEL(i, j, kk, dm1,
|
|
kusano |
2b45e8 |
#ifdef COMPLEX
|
|
kusano |
2b45e8 |
ZERO,
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
aa,
|
|
kusano |
2b45e8 |
b,
|
|
kusano |
2b45e8 |
cc,
|
|
kusano |
2b45e8 |
ldc);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
solve(i, j,
|
|
kusano |
2b45e8 |
aa + kk * i * COMPSIZE,
|
|
kusano |
2b45e8 |
b + kk * j * COMPSIZE, cc, ldc);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
aa += i * k * COMPSIZE;
|
|
kusano |
2b45e8 |
cc += i * COMPSIZE;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
i >>= 1;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
b += j * k * COMPSIZE;
|
|
kusano |
2b45e8 |
c += j * ldc * COMPSIZE;
|
|
kusano |
2b45e8 |
kk += j;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
j >>= 1;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
return 0;
|
|
kusano |
2b45e8 |
}
|