~ubuntu-branches/ubuntu/vivid/atlas/vivid

« back to all changes in this revision

Viewing changes to src/blas/gemm/ATL_mmBPP.c

  • Committer: Bazaar Package Importer
  • Author(s): Sylvestre Ledru
  • Date: 2009-09-17 23:31:54 UTC
  • mto: (2.2.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090917233154-9esw88ub02twbuab
Tags: upstream-3.8.3
ImportĀ upstreamĀ versionĀ 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *             Automatically Tuned Linear Algebra Software v3.8.3
 
3
 *                    (C) Copyright 2007 R. Clint Whaley
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are 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 the
 
12
 *      documentation and/or other materials provided with the distribution.
 
13
 *   3. The name of the ATLAS group or the names of its contributers may
 
14
 *      not be used to endorse or promote products derived from this
 
15
 *      software without specific written permission.
 
16
 *
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
18
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 
19
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS
 
21
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
27
 * POSSIBILITY OF SUCH DAMAGE.
 
28
 *
 
29
 */
 
30
#include "atlas_misc.h"
 
31
#include "atlas_lvl3.h"
 
32
#include <stdlib.h>
 
33
 
 
34
int Mjoin(PATL,mmBPP)(const enum ATLAS_TRANS TA, const enum ATLAS_TRANS TB,
 
35
                      const int M, const int N, const int K,
 
36
                      const SCALAR alpha, const TYPE *A, const int lda,
 
37
                      const TYPE *B, const int ldb, const SCALAR beta,
 
38
                      TYPE *C, const int ldc0)
 
39
/*
 
40
 * Copy algorithm, assuming M <= MB && N <= NB, K large (shape: block, panel,
 
41
 * panel); copies A and B on-the-fly
 
42
 */
 
43
{
 
44
   void *vC;
 
45
   TYPE *pA, *pB, *pC;
 
46
   void (*A2blk)(int N, int M, const SCALAR alpha, const TYPE *A, int lda,
 
47
                 TYPE *C, int ldc);
 
48
   void (*B2blk)(int N, int M, const SCALAR alpha, const TYPE *A, int lda,
 
49
                 TYPE *C, int ldc);
 
50
   NBMM0 NBmm0, NBmm1;
 
51
   int ldc, m, n, nblk, k, kr, incA, incB;
 
52
 
 
53
   if (M > MB || N > NB)  /* don't handle multiple M/N blocks */
 
54
      return(1);
 
55
   if (M < MB && M+ATL_mmMU >= MB)
 
56
      m = MB;
 
57
   else
 
58
      m = M;
 
59
   if (N < NB && N+ATL_mmNU >= NB)
 
60
      n = NB;
 
61
   else
 
62
      n = N;
 
63
   ldc = (((m*sizeof(TYPE)+ATL_Cachelen-1)/ATL_Cachelen)*ATL_Cachelen)
 
64
          / sizeof(TYPE);
 
65
   vC = malloc(ATL_Cachelen+ATL_MulBySize(ldc*n+KB*(m+n)));
 
66
   if (!vC) return(-1);
 
67
   pC = ATL_AlignPtr(vC);
 
68
   pA = pC + ldc*n;
 
69
   pB = pA + KB*m;
 
70
   if (TA == AtlasNoTrans)
 
71
   {
 
72
      A2blk = Mjoin(PATL,gemoveT);
 
73
      incA = lda*KB;
 
74
   }
 
75
   else
 
76
   {
 
77
      A2blk = Mjoin(PATL,gemove);
 
78
      incA = KB;
 
79
   }
 
80
   if (TB == AtlasNoTrans)
 
81
   {
 
82
      B2blk = Mjoin(PATL,gemove);
 
83
      incB = KB;
 
84
   }
 
85
   else
 
86
   {
 
87
      B2blk = Mjoin(PATL,gemoveT);
 
88
      incB = ldb*KB;
 
89
   }
 
90
/*
 
91
 * If we are going to multiply zeros to avoid cleanup, zero workspace
 
92
 */
 
93
   if (m != M || n != N)
 
94
      Mjoin(PATL,zero)(ldc*n+KB*(m+n), pC, 1);
 
95
/*
 
96
 * See what kernel we're calling
 
97
 */
 
98
   if (m == MB)
 
99
   {
 
100
      if (n == NB)  /* no cleanup */
 
101
      {
 
102
         NBmm0 = NBmm_b0;
 
103
         NBmm1 = NBmm_b1;
 
104
      }
 
105
      else         /* need to call N-cleanup kernel */
 
106
      {
 
107
         NBmm0 = Mjoin(PATL,pNBmm_b0);
 
108
         NBmm1 = Mjoin(PATL,pNBmm_b1);
 
109
      }
 
110
   }
 
111
   else if (n == NB) /* call M-cleanup kernel */
 
112
   {
 
113
      NBmm0 = Mjoin(PATL,pMBmm_b0);
 
114
      NBmm1 =  Mjoin(PATL,pMBmm_b1);
 
115
   }
 
116
   else              /* both N & M are cleanup, call general K clean */
 
117
   {
 
118
      NBmm0 = Mjoin(PATL,pKBmm);
 
119
      NBmm1 = Mjoin(PATL,pKBmm);
 
120
      if (m == M && n == N)  /* must zero pC if not done above */
 
121
         Mjoin(PATL,zero)(ldc*n, pC, 1);
 
122
 
 
123
   }
 
124
   nblk = K / KB;
 
125
   kr = K - nblk*KB;
 
126
   if (!nblk && kr)
 
127
      Mjoin(PATL,zero)(ldc*n, pC, 1);
 
128
   Mjoin(PATL,mmK)(M, m, N, n, nblk, kr, (kr && kr+4 >= KB) ? KB : 0,
 
129
                   ATL_rone, ATL_rone, ATL_rzero, A, lda, incA, pA, 0,
 
130
                   B, ldb, incB, pB, 0, pC, ldc, A2blk, B2blk, NBmm0, NBmm1);
 
131
   Mjoin(PATL,geadd)(M, N, alpha, pC, ldc, beta, C, ldc0);
 
132
   free(vC);
 
133
   return(0);
 
134
}