1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
|
/*
* Automatically Tuned Linear Algebra Software v3.10.3
* Copyright (C) 2011 R. Clint Whaley
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the ATLAS group or the names of its contributers may
* not be used to endorse or promote products derived from this
* software without specific written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "atlas_misc.h"
#include "atlas_tst.h"
#include "atlas_lvl2.h"
#include "atlas_level1.h"
#include <ctype.h>
int FAx=0, MAx=0, FAy=0, MAy=0, FAa=0, MAa=0;
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
struct FA_allocs
{
void *mem, *memA;
struct FA_allocs *next;
} *allocQ=NULL;
struct FA_allocs *NewAlloc(size_t size, struct FA_allocs *next,
int align, int misalign)
/*
* Allocates size allocation that is aligned to [align], but not aligned
* to [misalign]. Therefore, misalign > align. Align must minimally be sizeof
* while misalign may be 0 if we don't need to avoid a particular alignment.
*/
{
void *vp;
char *cp;
struct FA_allocs *ap;
int n, i;
const int malign = align >= misalign ? align : misalign;
n = size + align + align + malign;
i = (n >> 3)<<3;
if (n != i)
n += n - i;
cp = malloc(n + sizeof(struct FA_allocs));
assert(cp);
ap = (struct FA_allocs *) (cp + n);
ap->mem = cp;
/*
* Align to min alignment
*/
ap->memA = align ? (void*) ((((size_t) cp)/align)*align + align) : cp;
/*
* Misalign to misalign
* We often need to make sure to unaligned addresses share the same modulo
* so that they have the *same* degree of misalignment (so that their alignment
* can be fixed by simple peeling), and so in this case force the address
* modulo the misalign to be the exact align value.
*/
if (misalign)
ap->memA = (void*)((((size_t)ap->memA)/malign)*malign + malign + align);
ap->next = next;
return(ap);
}
/*
* no-align malloc free retaining system default behavior
*/
void *NA_malloc(size_t size)
{
return(malloc(size));
}
void *NA_calloc(size_t n, size_t size)
{
return(calloc(n, size));
}
void NA_free(void *ptr)
{
free(ptr);
}
/*
* malloc/free pair that aligns data to align, but not to misalign
*/
void *FA_malloc(size_t size, int align, int misalign)
{
if ((!misalign && align <= 8) || !size)
return(malloc(size));
else
{
allocQ = NewAlloc(size, allocQ, align, misalign);
return(allocQ->memA);
}
}
void *FA_calloc(size_t n, size_t size, int align, int misalign)
{
char *cp;
int *ip;
double *dp;
size_t i;
size_t tsize;
tsize = n * size;
cp = FA_malloc(tsize, align, misalign);
if (size == sizeof(int))
for (ip=(int*)cp,i=0; i < n; i++)
ip[i] = 0;
else if (size == sizeof(double))
for (dp=(double*)cp,i=0; i < n; i++)
dp[i] = 0.0;
else
for (i=0; i < tsize; i++)
cp[i] = 0;
return(cp);
}
void FA_free(void *ptr, int align, int misalign)
/*
* Part of malloc/free pair that aligns data to FALIGN
*/
{
struct FA_allocs *ap, *prev;
if (ptr)
{
if ((!misalign && align <= 8))
free(ptr);
else
{
for (ap=allocQ; ap && ap->memA != ptr; ap = ap->next) prev = ap;
if (!ap)
{
fprintf(stderr, "Couldn't find mem=%ld\nmemQ=\n", (size_t)ptr);
for (ap=allocQ; ap; ap = ap->next)
fprintf(stderr, " %ld, %ld\n", (size_t)ap->memA,
(size_t)ap->mem);
}
assert(ap);
if (ap == allocQ)
allocQ = allocQ->next;
else
prev->next = ap->next;
free(ap->mem);
}
}
}
static void dumb_ger(int Conj, int M, int N, const SCALAR alpha, TYPE *X,
int incX, TYPE *Y, int incY, TYPE *A, int lda)
{
#ifdef TCPLX
TYPE tmp[2];
const TYPE ra = alpha[0], ia = alpha[1];
#endif
int j;
for (j=0; j < N; j++)
{
#ifdef TREAL
const TYPE al = alpha * Y[j*incY];
Mjoin(PATL,axpy)(M, al, X, incX, A+lda*j, 1);
#else
const TYPE rY = Y[2*j*incY], iY = Y[2*j*incY+1];
tmp[0] = rY*ra - iY*ia;
tmp[1] = rY*ia + iY*ra;
if (Conj) tmp[1] = -tmp[1];
Mjoin(PATL,axpy)(M, tmp, X, incX, A+2*lda*j, 1);
#endif
}
}
static void dumb_ger2(int Conj, int M, int N,
SCALAR alpha0, TYPE *X0, int incX0, TYPE *Y0, int incY0,
SCALAR alpha1, TYPE *X1, int incX1, TYPE *Y1, int incY1,
TYPE *A, int lda)
{
dumb_ger(Conj, M, N, alpha0, X0, incX0, Y0, incY0, A, lda);
dumb_ger(Conj, M, N, alpha1, X1, incX1, Y1, incY1, A, lda);
}
static int CheckAns(int M, int N, TYPE *G, int ldg, TYPE *U, int ldu)
{
TYPE diff, eps;
int i, j, ierr=0;
#ifdef TREAL
const int M2 = M, emul=8;
#else
const int M2 = M<<1, emul=4*8;
ldg <<= 1; ldu <<= 1;
#endif
eps = Mjoin(PATL,epsilon)();
for (j=0; j < N; j++, G += ldg, U += ldu)
{
for (i=0; i < M2; i++)
{
diff = G[i] - U[i];
if (diff < ATL_rzero) diff = -diff;
if (diff > emul*eps)
{
fprintf(stderr, "A(%d,%d): Good=%f, Computed=%f\n",
i, j, G[i], U[i]);
if (!ierr) ierr = i+j*M+1;
}
}
}
return(ierr);
}
#define NX M
#define NY N
#define ATL_rS2C(sc_) \
(((sc_) == ATL_rzero) ? '0' : ( ((sc_) == ATL_rone) ? '1' : 'X'))
#ifdef TCPLX
#define ATL_S2C(sc_) ATL_rS2C(sc_[0]), ATL_rS2C(sc_[1])
#else
#define ATL_S2C(sc_) ATL_rS2C(sc_)
#endif
static int RunTest(int CONJ, int M, int N, int incY, int lda, int II)
{
#ifdef TCPLX
TYPE one[2] = {ATL_rone, ATL_rzero};
#else
TYPE one = ATL_rone;
#endif
TYPE *A, *A0, *X, *Y, *y;
TYPE *X1, *Y1;
ATL_CINT aincY = Mabs(incY), incX=1, aincX=1;
#ifdef TCPLX
char *frm = "%6d %5d %5d %5d %4d %4d %c,%c %4x %4x %4x %6s\n";
#else
char *frm = "%6d %5d %5d %5d %4d %4d %c %4x %4x %4x %6s\n";
#endif
int ierr;
if (!II)
{
printf("\n");
printf(
" M N lda incY incX alp A X Y PASS?\n");
printf(
"====== ===== ===== ===== ==== ==== === ==== ==== ==== ======\n");
}
A = FA_malloc(ATL_MulBySize(lda)*N, FAa, MAa);
A0 = FA_malloc(ATL_MulBySize(M)*N, FAa, MAa);
Y = FA_malloc(ATL_MulBySize(NY)*aincY, FAy, MAy);
X = FA_malloc(ATL_MulBySize(NX), FAx, MAx);
ATL_assert(A && A0 && X && Y);
X1 = FA_malloc(ATL_MulBySize(NX), FAx, MAx);
Y1 = FA_malloc(ATL_MulBySize(NY)*aincY, FAy, MAy);
ATL_assert(X1 && Y1);
if (aincY != 1)
Mjoin(PATLU,set)(NY*aincY SHIFT, 1000000000.0, Y1, 1);
if (aincX != 1)
Mjoin(PATLU,set)(NY*aincX SHIFT, 5000000000.0, X1, 1);
Mjoin(PATL,gegen)(1, NY, Y1, aincY, ((N*aincY)<<4)+0xFFABCD);
Mjoin(PATL,gegen)(1, NX, X1, aincX, NY*aincY+0xAC3955F);
printf(frm, II, M, N, lda, incY, incX, ATL_S2C(alpha), ((size_t)A)&0xFFFF,
((size_t)X)&0xFFFF, ((size_t)Y)&0xFFFF, " START");
Mjoin(PATL,gegen)(1, NY, Y, aincY, NY*aincY);
Mjoin(PATL,gegen)(1, NX, X, aincX, NY*aincY+127*50+77);
Mjoin(PATL,gegen)(M, N, A0, M, N*M+513*7+90);
Mjoin(PATL,gegen)(M, N, A, lda, N*M+513*7+90);
if (incY < 0) Y += (NY-1) * (aincY SHIFT);
if (incY < 0) Y1 += (NY-1) * (aincY SHIFT);
ATL_UGER2K(M, N, X, Y, X1, Y1, A, lda);
dumb_ger2(CONJ, M, N, one, X, 1, Y, incY, one, X1, 1, Y1, incY, A0, lda);
if (incY < 0) Y1 -= (N-1) * (aincY SHIFT);
FA_free(Y1, FAy, MAy);
FA_free(X1, FAx, MAx);
if (incY < 0) Y -= (N-1) * (aincY SHIFT);
FA_free(Y, FAy, MAy);
FA_free(X, FAx, MAx);
ierr = CheckAns(M, N, A0, M, A, lda);
FA_free(A, FAa, MAa);
FA_free(A0, FAa, MAa);
printf(frm, II, M, N, lda, incY, incX, ATL_S2C(alpha), ((size_t)A)&0xFFFF,
((size_t) X)&0xFFFF, ((size_t) Y)&0xFFFF, (ierr) ? "FAILED":"PASSED");
return(ierr);
}
#undef NX
#undef NY
int RunTests(int verb, int *CONJs, int *Ms, int *Ns, int *incYs, int *ldas)
{
int iy, ix, ic, in, im, iax, iay, iaa;
ATL_INT m, n, lda, conj, incy;
int nerr=0, II=0;
assert(ldas[0] == Ms[0]);
for (in=1; in <= Ns[0]; in++)
{
n = Ns[in];
for (im=1; im <= Ms[0]; im++)
{
m = Ms[im];
lda = ldas[im];
for (iy=1; iy <= incYs[0]; iy++)
{
incy = incYs[iy];
for (ic=1; ic <= CONJs[0]; ic++)
{
conj = CONJs[ic];
for (iaa=0; iaa < 8; iaa++)
{
FAa = iaa*sizeof(TYPE);
MAa = FAa + sizeof(TYPE);
for (iay=0; iay < 8; iay++)
{
FAy = iay*sizeof(TYPE);
MAy = FAy + sizeof(TYPE);
for (iax=0; iax < 8; iax++)
{
FAx = iax*sizeof(TYPE);
MAx = FAx + sizeof(TYPE);
nerr += RunTest(conj, m, n, incy, lda, II++);
if (nerr && !verb)
return(nerr);
}
}
}
}
}
}
}
if (nerr)
printf("FAILED: %d of %d tests!\n", nerr, II);
else
printf("PASSED: all %d tests.\n", II);
return(nerr);
}
void PrintUsage(char *name, int ierr, char *flag)
{
if (ierr > 0)
fprintf(stderr, "Bad argument #%d: '%s'\n",
ierr, flag ? flag : "Not enough arguments");
else if (ierr < 0)
fprintf(stderr, "ERROR: %s\n", flag);
fprintf(stderr, "USAGE: %s [flags]:\n", name);
fprintf(stderr, " -n <#> <N1> ... <N#>\n");
fprintf(stderr, " -N <Nstart> <Nend> <Ninc>\n");
fprintf(stderr, " -m <#> <M1> ... <M#>\n");
fprintf(stderr, " -M <Mstart> <Mend> <Minc>\n");
fprintf(stderr, " -l <#> <lda1> ... <lda#>\n");
fprintf(stderr, " -g <ldagap> : lda = M + <ldagap> foreach M\n");
fprintf(stderr, " -y <#> <incY1> ... <incY#>\n");
fprintf(stderr, " -x <#> <incX1> ... <incX#>\n");
fprintf(stderr, " -C <#> <conj1> ... <conj#>\n");
fprintf(stderr,
" -v [0,1] : 0 - stop on first error, else keep testing\n");
fprintf(stderr,
" -F[x,y,a] <#> : if(# > 0) -> force op to be aligned to at least # bytes\n");
fprintf(stderr,
" if(# < 0) -> force op to be aligned to < # bytes.\n");
exit(ierr ? ierr : -1);
}
/* procedure 1 */
int *GetIntList1(int ival)
/*
* returns integer array with iarr[0] = 1, iarr[1] = ival
*/
{
int *iarr;
iarr = malloc(2*sizeof(int));
ATL_assert(iarr);
iarr[0] = 1;
iarr[1] = ival;
return(iarr);
}
#ifdef TYPE
/* procedure 2 */
TYPE *GetTypeList1(const SCALAR val)
/*
* Returns a TYPE array with arr[0] = 1.0, arr[1] = val
*/
{
TYPE *arr;
arr = malloc(ATL_MulBySize(2));
ATL_assert(arr);
arr[0] = 1;
#ifdef TCPLX
arr[2] = *val;
arr[3] = val[1];
#else
arr[1] = val;
#endif
return(arr);
}
#endif
/* procedure 3 */
int *GetIntList2(int ival1, int ival2)
/*
* returns integer array with iarr[0] = 1, iarr[1] = ival1, ival[2] = ival2
*/
{
int *iarr;
iarr = malloc(3*sizeof(int));
ATL_assert(iarr);
iarr[0] = 1;
iarr[1] = ival1;
iarr[2] = ival2;
return(iarr);
}
/* procedure 4 */
int *DupIntList(int *list)
/*
* Duplicates list of integers, list[0] holds the length, not including 0
*/
{
int i, n, *ip;
assert(list);
n = list[0] + 1;
ip = malloc(sizeof(int)*n);
assert(ip);
for (i=0; i < n; i++)
ip[i] = list[i];
return(ip);
}
/* procedure 5 */
int *GetIntList(int nargs, char **args, int i, int nmul)
/*
* Gets a list of integers, whose length is given by atoi(args[i])*nmul
* list is this length+1, since 0'th location gets atoi(args[i])
*/
{
int n, *iarr, k;
if (++i >= nargs)
PrintUsage(args[0], i, NULL);
n = atoi(args[i]) * nmul;
ATL_assert(n > 0);
iarr = malloc(sizeof(int)*(n+1));
ATL_assert(iarr);
iarr[0] = n / nmul;
for (k=0; k < n; k++)
{
if (++i >= nargs)
PrintUsage(args[0], i, NULL);
iarr[k+1] = atoi(args[i]);
}
return(iarr);
}
#ifdef TYPE
/* procedure 6 */
TYPE *GetTypeList(int nargs, char **args, int i, int nmul)
/*
* Gets a list of TYPEs, whose length is given by atoi(args[i])*nmul
* list is this length+1, since 0'th location gets atof(args[i])
*/
{
int n, k;
TYPE *arr;
if (++i >= nargs)
PrintUsage(args[0], i, NULL);
n = atoi(args[i]) * nmul;
ATL_assert(n > 0);
arr = malloc(ATL_MulBySize(n+1));
ATL_assert(arr);
arr[0] = n / nmul;
for (k=0; k < n; k++)
{
if (++i >= nargs)
PrintUsage(args[0], i, NULL);
arr[k+(1 SHIFT)] = atof(args[i]);
}
return(arr);
}
#endif
/* procedure 7 */
int *IntRange2IntList(int N0, int NN, int incN)
{
int i, n;
int *iarr;
for (i=N0, n=0; i <= NN; i += incN) n++;
iarr = malloc(sizeof(int)*(n+1));
ATL_assert(iarr);
iarr[0] = n;
for (i=N0, n=1 ; i <= NN; i += incN, n++)
iarr[n] = i;
return(iarr);
}
int GetFlags(int nargs, char **args, int **CONJs, int **Ms, int **Ns,
int **LDAs, int **incYs, int **incXs)
{
int verb, i, k, *ip;
char ch;
int ldagap = 8;
*Ns = *Ms = *LDAs = *incYs = *incXs = *CONJs = NULL;
verb = 0;
for (i=1; i < nargs; i++)
{
if (args[i][0] != '-')
PrintUsage(args[0], i, args[i]);
ch = args[i][1];
switch(ch)
{
case 'v':
if (++i >= nargs)
PrintUsage(args[0], i-1, "out of flags in -g ");
verb = atoi(args[i]);
break;
case 'g':
if (++i >= nargs)
PrintUsage(args[0], i-1, "out of flags in -g ");
ldagap = atoi(args[i]);
break;
case 'M':
case 'N':
if (i+3 >= nargs)
PrintUsage(args[0], i-1, "out of flags in -N/M ");
ip = IntRange2IntList(atoi(args[i+1]),atoi(args[i+2]),atoi(args[i+3]));
if (ch == 'M')
*Ms = ip;
else
*Ns = ip;
i += 3;
break;
case 'n':
case 'm':
case 'l':
case 'y':
case 'x':
ip = GetIntList(nargs, args, i, 1);
i += ip[0] + 1;
switch(ch)
{
case 'n':
*Ns = ip;
break;
case 'm':
*Ms = ip;
break;
case 'l':
*LDAs = ip;
break;
case 'y':
*incYs = ip;
break;
case 'x':
*incXs = ip;
break;
}
break;
default:
PrintUsage(args[0], i, args[i]);
}
}
if (*CONJs == NULL)
#ifdef TCPX
*CONJs = GetIntList2(0, 1);
#else
*CONJs = GetIntList1(0);
#endif
if (*incXs == NULL)
*incXs = GetIntList1(1);
if (*incYs == NULL)
*incYs = GetIntList1(1);
if (*Ms == NULL)
*Ms = GetIntList1(977);
if (*Ns == NULL)
*Ns = GetIntList1(77);
if (*LDAs == NULL)
{
*LDAs = DupIntList(*Ms);
for (i=1; i <= (*LDAs)[0]; i++)
(*LDAs)[i] += ldagap;
}
assert((*LDAs)[0] == (*Ms)[0]);
return(verb);
}
int main(int nargs, char **args)
{
int *Ms, *Ns, *LDAs, *incYs, *incXs, *CONJs;
int verb, ierr=0;
verb = GetFlags(nargs, args, &CONJs, &Ms, &Ns, &LDAs, &incYs, &incXs);
ierr = RunTests(verb, CONJs, Ms, Ns, incYs, LDAs);
free(CONJs);
free(incXs);
free(incYs);
free(Ms);
free(Ns);
free(LDAs);
exit(ierr);
}
|