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 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
|
/* ************************************************************************
* Copyright (C) 2016-2024 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* ************************************************************************ */
#pragma once
#include "cblas.h"
#include "hipblas.h"
#include "type_utils.h"
/*!\file
* \brief provide template functions interfaces to CBLAS C89 interfaces, it is only used for testing
* not part of the GPU library
*/
/*
* ===========================================================================
* level 1 BLAS
* ===========================================================================
*/
template <typename Ta, typename Tx = Ta>
void ref_axpy(int64_t n, const Ta alpha, const Tx* x, int64_t incx, Tx* y, int64_t incy);
template <typename T, typename U = T>
void ref_scal(int64_t n, const U alpha, T* x, int64_t incx);
template <typename T>
void ref_copy(int64_t n, T* x, int64_t incx, T* y, int64_t incy);
template <typename T>
void ref_swap(int64_t n, T* x, int64_t incx, T* y, int64_t incy);
template <typename T>
void ref_dot(int64_t n, const T* x, int64_t incx, const T* y, int64_t incy, T* result);
template <typename T>
void ref_dotc(int64_t n, const T* x, int64_t incx, const T* y, int64_t incy, T* result);
template <typename T1, typename T2>
void ref_nrm2(int64_t n, const T1* x, int64_t incx, T2* result);
// template <typename T>
// void ref_iamax(int64_t n, const T* x, int64_t incx, int64_t* result);
// template <typename T>
// void ref_iamin(int64_t n, const T* x, int64_t incx, int64_t* result);
template <typename T1, typename T2 = T1, typename T3 = T1>
void ref_rot(int64_t n, T1* x, int64_t incx, T1* y, int64_t incy, T2 c, T3 s);
template <typename T1, typename T2 = T1>
void ref_rotg(T1* a, T1* b, T2* c, T1* s);
// asum
template <typename T>
void ref_asum(int64_t n, const T* x, int64_t incx, real_t<T>* result);
template <>
inline void ref_asum(int64_t n, const double* x, int64_t incx, double* result)
{
*result = cblas_dasum(n, x, incx);
}
template <>
inline void ref_asum(int64_t n, const hipblasComplex* x, int64_t incx, float* result)
{
*result = cblas_scasum(n, x, incx);
}
template <>
inline void ref_asum(int64_t n, const hipblasDoubleComplex* x, int64_t incx, double* result)
{
*result = cblas_dzasum(n, x, incx);
}
// rotm
template <typename T1>
void ref_rotm(int64_t n, T1* x, int64_t incx, T1* y, int64_t incy, T1* param);
template <>
inline void ref_rotm<float>(int64_t n, float* x, int64_t incx, float* y, int64_t incy, float* param)
{
cblas_srotm(n, x, incx, y, incy, param);
}
template <>
inline void
ref_rotm<double>(int64_t n, double* x, int64_t incx, double* y, int64_t incy, double* param)
{
cblas_drotm(n, x, incx, y, incy, param);
}
// rotmg
template <typename T1>
void ref_rotmg(T1* d1, T1* d2, T1* x1, T1* y1, T1* param);
template <>
inline void ref_rotmg<float>(float* d1, float* d2, float* x1, float* y1, float* param)
{
cblas_srotmg(d1, d2, x1, *y1, param);
}
template <>
inline void ref_rotmg<double>(double* d1, double* d2, double* x1, double* y1, double* param)
{
cblas_drotmg(d1, d2, x1, *y1, param);
}
/*
* ===========================================================================
* BLAS 2
* ===========================================================================
*/
template <typename T>
void ref_gbmv(hipblasOperation_t transA,
int64_t m,
int64_t n,
int64_t kl,
int64_t ku,
T alpha,
T* A,
int64_t lda,
T* x,
int64_t incx,
T beta,
T* y,
int64_t incy);
template <typename T>
void ref_gemv(hipblasOperation_t transA,
int64_t m,
int64_t n,
T alpha,
T* A,
int64_t lda,
T* x,
int64_t incx,
T beta,
T* y,
int64_t incy);
template <typename T>
void ref_symv(hipblasFillMode_t uplo,
int64_t n,
T alpha,
T* A,
int64_t lda,
T* x,
int64_t incx,
T beta,
T* y,
int64_t incy);
// ger (ger, geru, gerc)
template <typename T, bool CONJ>
void ref_ger(
int64_t m, int64_t n, T alpha, T* x, int64_t incx, T* y, int64_t incy, T* A, int64_t lda);
// hbmv
template <typename T>
void ref_hbmv(hipblasFillMode_t uplo,
int64_t n,
int64_t k,
T alpha,
T* A,
int64_t lda,
T* x,
int64_t incx,
T beta,
T* y,
int64_t incy);
// hemv
template <typename T, typename U>
void ref_hemv(hipblasFillMode_t uplo,
int64_t n,
U alpha,
T* A,
int64_t lda,
T* x,
int64_t incx,
T beta,
T* y,
int64_t incy);
// spr
template <typename T>
void ref_spr(hipblasFillMode_t uplo, int64_t n, T alpha, T* x, int64_t incx, T* AP);
// spr2
template <typename T>
void ref_spr2(
hipblasFillMode_t uplo, int64_t n, T alpha, T* x, int64_t incx, T* y, int64_t incy, T* AP);
// syr
template <typename T>
void ref_syr(hipblasFillMode_t uplo, int64_t n, T alpha, T* x, int64_t incx, T* A, int64_t lda);
// syr2
template <typename T>
void ref_syr2(hipblasFillMode_t uplo,
int64_t n,
T alpha,
T* x,
int64_t incx,
T* y,
int64_t incy,
T* A,
int64_t lda);
// her
template <typename T, typename U>
void ref_her(hipblasFillMode_t uplo, int64_t n, U alpha, T* x, int64_t incx, T* A, int64_t lda);
// her2
template <typename T>
void ref_her2(hipblasFillMode_t uplo,
int64_t n,
T alpha,
T* x,
int64_t incx,
T* y,
int64_t incy,
T* A,
int64_t lda);
// hpmv
template <typename T>
void ref_hpmv(hipblasFillMode_t uplo,
int64_t n,
T alpha,
T* AP,
T* x,
int64_t incx,
T beta,
T* y,
int64_t incy);
// hpr
template <typename T, typename U>
void ref_hpr(hipblasFillMode_t uplo, int64_t n, U alpha, T* x, int64_t incx, T* AP);
// hpr2
template <typename T>
void ref_hpr2(
hipblasFillMode_t uplo, int64_t n, T alpha, T* x, int64_t incx, T* y, int64_t incy, T* AP);
// hemv
template <typename T, typename U>
void ref_hemv(hipblasFillMode_t uplo,
int64_t n,
U alpha,
T* A,
int64_t lda,
T* x,
int64_t incx,
T beta,
T* y,
int64_t incy);
// spr
template <typename T>
void ref_spr(hipblasFillMode_t uplo, int64_t n, T alpha, T* x, int64_t incx, T* AP);
// spr2
template <typename T>
void ref_spr2(
hipblasFillMode_t uplo, int64_t n, T alpha, T* x, int64_t incx, T* y, int64_t incy, T* AP);
// syr
template <typename T>
void ref_syr(hipblasFillMode_t uplo, int64_t n, T alpha, T* x, int64_t incx, T* A, int64_t lda);
// syr2
template <typename T>
void ref_syr2(hipblasFillMode_t uplo,
int64_t n,
T alpha,
T* x,
int64_t incx,
T* y,
int64_t incy,
T* A,
int64_t lda);
// her
template <typename T, typename U>
void ref_her(hipblasFillMode_t uplo, int64_t n, U alpha, T* x, int64_t incx, T* A, int64_t lda);
// her2
template <typename T>
void ref_her2(hipblasFillMode_t uplo,
int64_t n,
T alpha,
T* x,
int64_t incx,
T* y,
int64_t incy,
T* A,
int64_t lda);
// hemv
template <typename T>
void ref_hemv(hipblasFillMode_t uplo,
int64_t n,
T alpha,
T* A,
int64_t lda,
T* x,
int64_t incx,
T beta,
T* y,
int64_t incy);
// hpmv
template <typename T>
void ref_hpmv(hipblasFillMode_t uplo,
int64_t n,
T alpha,
T* AP,
T* x,
int64_t incx,
T beta,
T* y,
int64_t incy);
// hpr
template <typename T, typename U>
void ref_hpr(hipblasFillMode_t uplo, int64_t n, U alpha, T* x, int64_t incx, T* AP);
// hpr2
template <typename T>
void ref_hpr2(
hipblasFillMode_t uplo, int64_t n, T alpha, T* x, int64_t incx, T* y, int64_t incy, T* AP);
// sbmv
template <typename T>
void ref_sbmv(hipblasFillMode_t uplo,
int64_t n,
int64_t k,
T alpha,
T* A,
int64_t lda,
T* x,
int64_t incx,
T beta,
T* y,
int64_t incy);
// spmv
template <typename T>
void ref_spmv(hipblasFillMode_t uplo,
int64_t n,
T alpha,
T* AP,
T* x,
int64_t incx,
T beta,
T* y,
int64_t incy);
// symv
template <typename T>
void ref_symv(hipblasFillMode_t uplo,
int64_t n,
T alpha,
T* A,
int64_t lda,
T* x,
int64_t incx,
T beta,
T* y,
int64_t incy);
// spmv
template <typename T>
void ref_spmv(hipblasFillMode_t uplo,
int64_t n,
T alpha,
T* AP,
T* x,
int64_t incx,
T beta,
T* y,
int64_t incy);
// symv
template <typename T>
void ref_symv(hipblasFillMode_t uplo,
int64_t n,
T alpha,
T* A,
int64_t lda,
T* x,
int64_t incx,
T beta,
T* y,
int64_t incy);
// tbmv
template <typename T>
void ref_tbmv(hipblasFillMode_t uplo,
hipblasOperation_t transA,
hipblasDiagType_t diag,
int64_t m,
int64_t k,
const T* A,
int64_t lda,
T* x,
int64_t incx);
// tbsv
template <typename T>
void ref_tbsv(hipblasFillMode_t uplo,
hipblasOperation_t transA,
hipblasDiagType_t diag,
int64_t m,
int64_t k,
const T* A,
int64_t lda,
T* x,
int64_t incx);
// tpmv
template <typename T>
void ref_tpmv(hipblasFillMode_t uplo,
hipblasOperation_t transA,
hipblasDiagType_t diag,
int64_t m,
const T* A,
T* x,
int64_t incx);
// tpsv
template <typename T>
void ref_tpsv(hipblasFillMode_t uplo,
hipblasOperation_t transA,
hipblasDiagType_t diag,
int64_t n,
const T* AP,
T* x,
int64_t incx);
// trmv
template <typename T>
void ref_trmv(hipblasFillMode_t uplo,
hipblasOperation_t transA,
hipblasDiagType_t diag,
int64_t m,
const T* A,
int64_t lda,
T* x,
int64_t incx);
// trsv
template <typename T>
void ref_trsv(hipblasHandle_t handle,
hipblasFillMode_t uplo,
hipblasOperation_t transA,
hipblasDiagType_t diag,
int64_t m,
const T* A,
int64_t lda,
T* x,
int64_t incx);
/*
* ===========================================================================
* BLAS 3
* ===========================================================================
*/
// herk
template <typename T, typename U>
void ref_herk(hipblasFillMode_t uplo,
hipblasOperation_t transA,
int64_t n,
int64_t k,
U alpha,
T* A,
int64_t lda,
U beta,
T* C,
int64_t ldc);
// herkx
template <typename T, typename U>
void ref_herkx(hipblasFillMode_t uplo,
hipblasOperation_t transA,
int64_t n,
int64_t k,
T alpha,
T* A,
int64_t lda,
T* B,
int64_t ldb,
U beta,
T* C,
int64_t ldc);
// her2k
template <typename T, typename U>
void ref_her2k(hipblasFillMode_t uplo,
hipblasOperation_t transA,
int64_t n,
int64_t k,
T alpha,
T* A,
int64_t lda,
T* B,
int64_t ldb,
U beta,
T* C,
int64_t ldc);
// geam
template <typename T>
void ref_geam(hipblasOperation_t transa,
hipblasOperation_t transb,
int64_t m,
int64_t n,
T* alpha,
T* A,
int64_t lda,
T* beta,
T* B,
int64_t ldb,
T* C,
int64_t ldc);
// gemm
template <typename Ti, typename To = Ti, typename Tc = To>
void ref_gemm(hipblasOperation_t transA,
hipblasOperation_t transB,
int64_t m,
int64_t n,
int64_t k,
Tc alpha,
Ti* A,
int64_t lda,
Ti* B,
int64_t ldb,
Tc beta,
To* C,
int64_t ldc);
// dgmm
template <typename T>
void ref_dgmm(hipblasSideMode_t side,
int64_t M,
int64_t N,
const T* dA,
int64_t lda,
const T* dx,
int64_t incx,
T* dC,
int64_t ldc);
// hemm
template <typename T>
void ref_hemm(hipblasSideMode_t side,
hipblasFillMode_t uplo,
int64_t m,
int64_t n,
T alpha,
T* A,
int64_t lda,
T* B,
int64_t ldb,
T beta,
T* C,
int64_t ldc);
// symm
template <typename T>
void ref_symm(hipblasSideMode_t side,
hipblasFillMode_t uplo,
int64_t m,
int64_t n,
T alpha,
T* A,
int64_t lda,
T* B,
int64_t ldb,
T beta,
T* C,
int64_t ldc);
// syrk
template <typename T>
void ref_syrk(hipblasFillMode_t uplo,
hipblasOperation_t transA,
int64_t n,
int64_t k,
T alpha,
T* A,
int64_t lda,
T beta,
T* C,
int64_t ldc);
// syr2k
template <typename T>
void ref_syr2k(hipblasFillMode_t uplo,
hipblasOperation_t transA,
int64_t n,
int64_t k,
T alpha,
T* A,
int64_t lda,
T* B,
int64_t ldb,
T beta,
T* C,
int64_t ldc);
// syrkx
template <typename T>
void ref_syrkx(hipblasFillMode_t uplo,
hipblasOperation_t transA,
int64_t n,
int64_t k,
T alpha,
T* A,
int64_t lda,
T* B,
int64_t ldb,
T beta,
T* C,
int64_t ldc);
// trsm
template <typename T>
inline void ref_trsm(hipblasSideMode_t side,
hipblasFillMode_t uplo,
hipblasOperation_t transA,
hipblasDiagType_t diag,
int64_t m,
int64_t n,
T alpha,
const T* A,
int64_t lda,
T* B,
int64_t ldb);
// trsm
template <>
inline void ref_trsm<float>(hipblasSideMode_t side,
hipblasFillMode_t uplo,
hipblasOperation_t transA,
hipblasDiagType_t diag,
int64_t m,
int64_t n,
float alpha,
const float* A,
int64_t lda,
float* B,
int64_t ldb)
{
// just directly cast, since transA, transB are integers in the enum
cblas_strsm(CblasColMajor,
(CBLAS_SIDE)side,
(CBLAS_UPLO)uplo,
(CBLAS_TRANSPOSE)transA,
(CBLAS_DIAG)diag,
m,
n,
alpha,
A,
lda,
B,
ldb);
}
template <>
inline void ref_trsm<double>(hipblasSideMode_t side,
hipblasFillMode_t uplo,
hipblasOperation_t transA,
hipblasDiagType_t diag,
int64_t m,
int64_t n,
double alpha,
const double* A,
int64_t lda,
double* B,
int64_t ldb)
{
// just directly cast, since transA, transB are integers in the enum
cblas_dtrsm(CblasColMajor,
(CBLAS_SIDE)side,
(CBLAS_UPLO)uplo,
(CBLAS_TRANSPOSE)transA,
(CBLAS_DIAG)diag,
m,
n,
alpha,
A,
lda,
B,
ldb);
}
template <>
inline void ref_trsm<hipblasComplex>(hipblasSideMode_t side,
hipblasFillMode_t uplo,
hipblasOperation_t transA,
hipblasDiagType_t diag,
int64_t m,
int64_t n,
hipblasComplex alpha,
const hipblasComplex* A,
int64_t lda,
hipblasComplex* B,
int64_t ldb)
{
cblas_ctrsm(CblasColMajor,
(CBLAS_SIDE)side,
(CBLAS_UPLO)uplo,
(CBLAS_TRANSPOSE)transA,
(CBLAS_DIAG)diag,
m,
n,
&alpha,
A,
lda,
B,
ldb);
}
template <>
inline void ref_trsm<hipblasDoubleComplex>(hipblasSideMode_t side,
hipblasFillMode_t uplo,
hipblasOperation_t transA,
hipblasDiagType_t diag,
int64_t m,
int64_t n,
hipblasDoubleComplex alpha,
const hipblasDoubleComplex* A,
int64_t lda,
hipblasDoubleComplex* B,
int64_t ldb)
{
cblas_ztrsm(CblasColMajor,
(CBLAS_SIDE)side,
(CBLAS_UPLO)uplo,
(CBLAS_TRANSPOSE)transA,
(CBLAS_DIAG)diag,
m,
n,
&alpha,
A,
lda,
B,
ldb);
}
// trtri
template <typename T>
void ref_trtri(char uplo, char diag, int64_t n, T* A, int64_t lda);
// trmm
template <typename T>
void ref_trmm(hipblasSideMode_t side,
hipblasFillMode_t uplo,
hipblasOperation_t transA,
hipblasDiagType_t diag,
int64_t m,
int64_t n,
T alpha,
const T* A,
int64_t lda,
T* B,
int64_t ldb);
/*
* ===========================================================================
* LAPACK OR OTHER
* ===========================================================================
*/
#ifdef BUILD_SOLVER_TESTS
// potrf
template <typename T>
int64_t ref_potrf(char uplo, int64_t m, T* A, int64_t lda);
template <typename T>
int64_t ref_getrf(int64_t m, int64_t n, T* A, int64_t lda, int64_t* ipiv);
template <typename T>
int64_t ref_getrs(
char trans, int64_t n, int64_t nrhs, T* A, int64_t lda, int64_t* ipiv, T* B, int64_t ldb);
template <typename T>
int64_t ref_getri(int64_t n, T* A, int64_t lda, int64_t* ipiv, T* work, int64_t lwork);
template <typename T>
int64_t ref_geqrf(int64_t m, int64_t n, T* A, int64_t lda, T* tau, T* work, int64_t lwork);
template <typename T>
int64_t ref_gels(char trans,
int64_t m,
int64_t n,
int64_t nrhs,
T* A,
int64_t lda,
T* B,
int64_t ldb,
T* work,
int64_t lwork);
#endif
/* ============================================================================================ */
|