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 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869
|
/* ************************************************************************
* Copyright (C) 2020-2022 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
#ifndef TESTING_SPMV_HPP
#define TESTING_SPMV_HPP
#include "auto_testing_bad_arg.hpp"
template <rocsparse_format FORMAT, typename I, typename J, typename T>
struct testing_matrix_type_traits;
//
// TRAITS FOR CSR FORMAT.
//
template <typename I, typename J, typename T>
struct testing_matrix_type_traits<rocsparse_format_csr, I, J, T>
{
template <typename U>
using host_sparse_matrix = host_csr_matrix<U, I, J>;
template <typename U>
using device_sparse_matrix = device_csr_matrix<U, I, J>;
};
//
// TRAITS FOR CSC FORMAT.
//
template <typename I, typename J, typename T>
struct testing_matrix_type_traits<rocsparse_format_csc, I, J, T>
{
template <typename U>
using host_sparse_matrix = host_csc_matrix<U, I, J>;
template <typename U>
using device_sparse_matrix = device_csc_matrix<U, I, J>;
};
//
// TRAITS FOR BSR FORMAT.
//
template <typename I, typename J, typename T>
struct testing_matrix_type_traits<rocsparse_format_bsr, I, J, T>
{
template <typename U>
using host_sparse_matrix = host_gebsr_matrix<U, I, J>;
template <typename U>
using device_sparse_matrix = device_gebsr_matrix<U, I, J>;
};
//
// TRAITS FOR COO FORMAT.
//
template <typename I, typename T>
struct testing_matrix_type_traits<rocsparse_format_coo, I, I, T>
{
template <typename U>
using host_sparse_matrix = host_coo_matrix<U, I>;
template <typename U>
using device_sparse_matrix = device_coo_matrix<U, I>;
};
//
// TRAITS FOR COO AOS FORMAT.
//
template <typename I, typename T>
struct testing_matrix_type_traits<rocsparse_format_coo_aos, I, I, T>
{
template <typename U>
using host_sparse_matrix = host_coo_aos_matrix<U, I>;
template <typename U>
using device_sparse_matrix = device_coo_aos_matrix<U, I>;
};
//
// TRAITS FOR ELL FORMAT.
//
template <typename I, typename T>
struct testing_matrix_type_traits<rocsparse_format_ell, I, I, T>
{
template <typename U>
using host_sparse_matrix = host_ell_matrix<U, I>;
template <typename U>
using device_sparse_matrix = device_ell_matrix<U, I>;
};
template <rocsparse_format FORMAT, typename I, typename J, typename T>
struct testing_spmv_dispatch_traits;
//
// TRAITS FOR CSR FORMAT.
//
template <typename I, typename J, typename T>
struct testing_spmv_dispatch_traits<rocsparse_format_csr, I, J, T>
{
using traits = testing_matrix_type_traits<rocsparse_format_csr, I, J, T>;
template <typename U>
using host_sparse_matrix = typename traits::template host_sparse_matrix<U>;
template <typename U>
using device_sparse_matrix = typename traits::template device_sparse_matrix<U>;
static void sparse_initialization(rocsparse_matrix_factory<T, I, J>& matrix_factory,
host_sparse_matrix<T>& hA,
J& m,
J& n,
rocsparse_index_base base)
{
matrix_factory.init_csr(hA, m, n, base);
}
template <typename... Ts>
static void display_info(const Arguments& arg,
const char* trans,
const char* trans_value,
device_sparse_matrix<T>& dA,
Ts&&... ts)
{
display_timing_info(trans, trans_value, "M", dA.m, "N", dA.n, "nnz", dA.nnz, ts...);
}
static void host_calculation(rocsparse_operation trans,
T* h_alpha,
host_sparse_matrix<T>& hA,
T* hx,
T* h_beta,
T* hy,
rocsparse_spmv_alg alg,
rocsparse_matrix_type matrix_type = rocsparse_matrix_type_general)
{
host_csrmv<I, J, T>(trans,
hA.m,
hA.n,
hA.nnz,
*h_alpha,
hA.ptr,
hA.ind,
hA.val,
hx,
*h_beta,
hy,
hA.base,
matrix_type,
alg,
false);
}
static double gflop_count(host_sparse_matrix<T>& hA, bool nonzero_beta)
{
return spmv_gflop_count(hA.m, hA.nnz, nonzero_beta);
}
static double byte_count(host_sparse_matrix<T>& hA, bool nonzero_beta)
{
return csrmv_gbyte_count<T>(hA.m, hA.n, hA.nnz, nonzero_beta);
}
};
//
// TRAITS FOR CSC FORMAT.
//
template <typename I, typename J, typename T>
struct testing_spmv_dispatch_traits<rocsparse_format_csc, I, J, T>
{
using traits = testing_matrix_type_traits<rocsparse_format_csc, I, J, T>;
template <typename U>
using host_sparse_matrix = typename traits::template host_sparse_matrix<U>;
template <typename U>
using device_sparse_matrix = typename traits::template device_sparse_matrix<U>;
static void sparse_initialization(rocsparse_matrix_factory<T, I, J>& matrix_factory,
host_sparse_matrix<T>& hA,
J& m,
J& n,
rocsparse_index_base base)
{
matrix_factory.init_csc(hA, m, n, base);
}
template <typename... Ts>
static void display_info(const Arguments& arg,
const char* trans,
const char* trans_value,
device_sparse_matrix<T>& dA,
Ts&&... ts)
{
display_timing_info(trans, trans_value, "M", dA.m, "N", dA.n, "nnz", dA.nnz, ts...);
}
static void host_calculation(rocsparse_operation trans,
T* h_alpha,
host_sparse_matrix<T>& hA,
T* hx,
T* h_beta,
T* hy,
rocsparse_spmv_alg alg,
rocsparse_matrix_type matrix_type = rocsparse_matrix_type_general)
{
host_cscmv<I, J, T>(trans,
hA.m,
hA.n,
hA.nnz,
*h_alpha,
hA.ptr,
hA.ind,
hA.val,
hx,
*h_beta,
hy,
hA.base,
matrix_type,
alg);
}
static double gflop_count(host_sparse_matrix<T>& hA, bool nonzero_beta)
{
return spmv_gflop_count(hA.m, hA.nnz, nonzero_beta);
}
static double byte_count(host_sparse_matrix<T>& hA, bool nonzero_beta)
{
return cscmv_gbyte_count<T>(hA.m, hA.n, hA.nnz, nonzero_beta);
}
};
//
// TRAITS FOR BSR FORMAT.
//
template <typename I, typename J, typename T>
struct testing_spmv_dispatch_traits<rocsparse_format_bsr, I, J, T>
{
using traits = testing_matrix_type_traits<rocsparse_format_bsr, I, J, T>;
template <typename U>
using host_sparse_matrix = typename traits::template host_sparse_matrix<U>;
template <typename U>
using device_sparse_matrix = typename traits::template device_sparse_matrix<U>;
static void sparse_initialization(rocsparse_matrix_factory<T, I, J>& matrix_factory,
host_sparse_matrix<T>& hA,
J& m,
J& n,
rocsparse_index_base base)
{
J block_dim = matrix_factory.m_arg.block_dim;
matrix_factory.init_gebsr(hA, m, n, block_dim, block_dim, base);
m *= block_dim;
n *= block_dim;
}
template <typename... Ts>
static void display_info(const Arguments& arg,
const char* trans,
const char* trans_value,
device_sparse_matrix<T>& dA,
Ts&&... ts)
{
display_timing_info(trans,
trans_value,
"M",
dA.mb * dA.row_block_dim,
"N",
dA.nb * dA.col_block_dim,
"nnz",
dA.nnzb * dA.row_block_dim * dA.col_block_dim,
"bdim",
dA.row_block_dim,
"bdir",
rocsparse_direction2string(dA.block_direction),
ts...);
}
static void host_calculation(rocsparse_operation trans,
T* h_alpha,
host_sparse_matrix<T>& hA,
T* hx,
T* h_beta,
T* hy,
rocsparse_spmv_alg alg,
rocsparse_matrix_type matrix_type = rocsparse_matrix_type_general)
{
host_bsrmv<T, I, J>(hA.block_direction,
trans,
hA.mb,
hA.nb,
hA.nnzb,
*h_alpha,
hA.ptr,
hA.ind,
hA.val,
hA.row_block_dim,
hx,
*h_beta,
hy,
hA.base);
}
static double byte_count(host_sparse_matrix<T>& hA, bool nonzero_beta)
{
return bsrmv_gbyte_count<T>(hA.mb, hA.nb, hA.nnzb, hA.row_block_dim, nonzero_beta);
}
static double gflop_count(host_sparse_matrix<T>& hA, bool nonzero_beta)
{
return spmv_gflop_count(
hA.mb * hA.row_block_dim, hA.nnzb * hA.row_block_dim * hA.col_block_dim, nonzero_beta);
}
};
//
// TRAITS FOR COO FORMAT.
//
template <typename I, typename T>
struct testing_spmv_dispatch_traits<rocsparse_format_coo, I, I, T>
{
using traits = testing_matrix_type_traits<rocsparse_format_coo, I, I, T>;
template <typename U>
using host_sparse_matrix = typename traits::template host_sparse_matrix<U>;
template <typename U>
using device_sparse_matrix = typename traits::template device_sparse_matrix<U>;
static void sparse_initialization(rocsparse_matrix_factory<T, I, I>& matrix_factory,
host_sparse_matrix<T>& hA,
I& m,
I& n,
rocsparse_index_base base)
{
matrix_factory.init_coo(hA, m, n, base);
}
template <typename... Ts>
static void display_info(const Arguments& arg,
const char* trans,
const char* trans_value,
device_sparse_matrix<T>& dA,
Ts&&... ts)
{
display_timing_info(trans, trans_value, "M", dA.m, "N", dA.n, "nnz", dA.nnz, ts...);
}
static void host_calculation(rocsparse_operation trans,
T* h_alpha,
host_sparse_matrix<T>& hA,
T* hx,
T* h_beta,
T* hy,
rocsparse_spmv_alg alg,
rocsparse_matrix_type matrix_type = rocsparse_matrix_type_general)
{
host_coomv<I, T>(trans,
hA.m,
hA.n,
hA.nnz,
*h_alpha,
hA.row_ind,
hA.col_ind,
hA.val,
hx,
*h_beta,
hy,
hA.base);
}
static double byte_count(host_sparse_matrix<T>& hA, bool nonzero_beta)
{
return coomv_gbyte_count<T>(hA.m, hA.n, hA.nnz, nonzero_beta);
}
static double gflop_count(host_sparse_matrix<T>& hA, bool nonzero_beta)
{
return spmv_gflop_count(hA.m, hA.nnz, nonzero_beta);
}
};
//
// TRAITS FOR COO AOS FORMAT.
//
template <typename I, typename T>
struct testing_spmv_dispatch_traits<rocsparse_format_coo_aos, I, I, T>
{
using traits = testing_matrix_type_traits<rocsparse_format_coo_aos, I, I, T>;
template <typename U>
using host_sparse_matrix = typename traits::template host_sparse_matrix<U>;
template <typename U>
using device_sparse_matrix = typename traits::template device_sparse_matrix<U>;
static void sparse_initialization(rocsparse_matrix_factory<T, I, I>& matrix_factory,
host_sparse_matrix<T>& hA,
I& m,
I& n,
rocsparse_index_base base)
{
matrix_factory.init_coo_aos(hA, m, n, base);
}
template <typename... Ts>
static void display_info(const Arguments& arg,
const char* trans,
const char* trans_value,
device_sparse_matrix<T>& dA,
Ts&&... ts)
{
display_timing_info(trans, trans_value, "M", dA.m, "N", dA.n, "nnz", dA.nnz, ts...);
}
static void host_calculation(rocsparse_operation trans,
T* h_alpha,
host_sparse_matrix<T>& hA,
T* hx,
T* h_beta,
T* hy,
rocsparse_spmv_alg alg,
rocsparse_matrix_type matrix_type = rocsparse_matrix_type_general)
{
host_coomv_aos<I, T>(
trans, hA.m, hA.n, hA.nnz, *h_alpha, hA.ind, hA.val, hx, *h_beta, hy, hA.base);
}
static double byte_count(host_sparse_matrix<T>& hA, bool nonzero_beta)
{
return coomv_gbyte_count<T>(hA.m, hA.n, hA.nnz, nonzero_beta);
}
static double gflop_count(host_sparse_matrix<T>& hA, bool nonzero_beta)
{
return spmv_gflop_count(hA.m, hA.nnz, nonzero_beta);
}
};
//
// TRAITS FOR ELL FORMAT.
//
template <typename I, typename T>
struct testing_spmv_dispatch_traits<rocsparse_format_ell, I, I, T>
{
using traits = testing_matrix_type_traits<rocsparse_format_ell, I, I, T>;
template <typename U>
using host_sparse_matrix = typename traits::template host_sparse_matrix<U>;
template <typename U>
using device_sparse_matrix = typename traits::template device_sparse_matrix<U>;
static void sparse_initialization(rocsparse_matrix_factory<T, I, I>& matrix_factory,
host_sparse_matrix<T>& hA,
I& m,
I& n,
rocsparse_index_base base)
{
matrix_factory.init_ell(hA, m, n, base);
}
template <typename... Ts>
static void display_info(const Arguments& arg,
const char* trans,
const char* trans_value,
device_sparse_matrix<T>& dA,
Ts&&... ts)
{
display_timing_info(trans, trans_value, "M", dA.m, "N", dA.n, "nnz", dA.nnz, ts...);
}
static void host_calculation(rocsparse_operation trans,
T* h_alpha,
host_sparse_matrix<T>& hA,
T* hx,
T* h_beta,
T* hy,
rocsparse_spmv_alg alg,
rocsparse_matrix_type matrix_type = rocsparse_matrix_type_general)
{
host_ellmv<I, T>(
trans, hA.m, hA.n, *h_alpha, hA.ind, hA.val, hA.width, hx, *h_beta, hy, hA.base);
}
static double byte_count(host_sparse_matrix<T>& hA, bool nonzero_beta)
{
return ellmv_gbyte_count<T>(hA.m, hA.n, hA.nnz, nonzero_beta);
}
static double gflop_count(host_sparse_matrix<T>& hA, bool nonzero_beta)
{
return spmv_gflop_count(hA.m, hA.nnz, nonzero_beta);
}
};
template <rocsparse_format FORMAT, typename I, typename J, typename T>
struct testing_spmv_dispatch
{
private:
using traits = testing_spmv_dispatch_traits<FORMAT, I, J, T>;
template <typename U>
using host_sparse_matrix = typename traits::template host_sparse_matrix<U>;
template <typename U>
using device_sparse_matrix = typename traits::template device_sparse_matrix<U>;
public:
static void testing_spmv_bad_arg(const Arguments& arg)
{
T alpha = 0.6;
T beta = 0.1;
rocsparse_local_handle local_handle;
rocsparse_handle handle = local_handle;
rocsparse_operation trans = rocsparse_operation_none;
const void* p_alpha = (const void*)α
const void* p_beta = (const void*)β
rocsparse_spmv_alg alg = rocsparse_spmv_alg_default;
size_t buffer_size;
size_t* p_buffer_size = &buffer_size;
void* temp_buffer = (void*)0x4;
rocsparse_datatype ttype = get_datatype<T>();
#define PARAMS \
handle, trans, p_alpha, (const rocsparse_spmat_descr&)A, (const rocsparse_dnvec_descr&)x, \
p_beta, (rocsparse_dnvec_descr&)y, ttype, alg, p_buffer_size, temp_buffer
//
// NOT IMPLEMENTED CASES
//
{
//
// MIXED DATA TYPES
//
device_dense_matrix<T> dx;
device_dense_matrix<T> dy;
rocsparse_local_dnvec x(dx);
rocsparse_local_dnvec y(dy);
switch(ttype)
{
case rocsparse_datatype_f32_r:
{
device_sparse_matrix<double> dA;
rocsparse_local_spmat A(dA);
EXPECT_ROCSPARSE_STATUS(rocsparse_spmv(PARAMS), rocsparse_status_not_implemented);
break;
}
case rocsparse_datatype_f64_r:
case rocsparse_datatype_f32_c:
case rocsparse_datatype_f64_c:
{
device_sparse_matrix<float> dA;
rocsparse_local_spmat A(dA);
EXPECT_ROCSPARSE_STATUS(rocsparse_spmv(PARAMS), rocsparse_status_not_implemented);
break;
}
}
}
{
//
// MIXED DATA TYPES
//
device_dense_matrix<T> dx;
device_sparse_matrix<T> dA;
rocsparse_local_spmat A(dA);
rocsparse_local_dnvec x(dx);
switch(ttype)
{
case rocsparse_datatype_f32_r:
{
device_dense_matrix<double> dy;
rocsparse_local_dnvec y(dy);
EXPECT_ROCSPARSE_STATUS(rocsparse_spmv(PARAMS), rocsparse_status_not_implemented);
break;
}
case rocsparse_datatype_f64_r:
case rocsparse_datatype_f32_c:
case rocsparse_datatype_f64_c:
{
device_dense_matrix<float> dy;
rocsparse_local_dnvec y(dy);
EXPECT_ROCSPARSE_STATUS(rocsparse_spmv(PARAMS), rocsparse_status_not_implemented);
break;
}
}
}
{
//
// MIXED DATA TYPES
//
device_dense_matrix<T> dy;
device_sparse_matrix<T> dA;
rocsparse_local_spmat A(dA);
rocsparse_local_dnvec y(dy);
switch(ttype)
{
case rocsparse_datatype_f32_r:
{
device_dense_matrix<double> dx;
rocsparse_local_dnvec x(dx);
EXPECT_ROCSPARSE_STATUS(rocsparse_spmv(PARAMS), rocsparse_status_not_implemented);
break;
}
case rocsparse_datatype_f64_r:
case rocsparse_datatype_f32_c:
case rocsparse_datatype_f64_c:
{
device_dense_matrix<float> dx;
rocsparse_local_dnvec x(dx);
EXPECT_ROCSPARSE_STATUS(rocsparse_spmv(PARAMS), rocsparse_status_not_implemented);
break;
}
}
}
//
// AUTOMATIC BAD ARGS.
//
{
device_dense_matrix<T> dx, dy;
device_sparse_matrix<T> dA;
rocsparse_local_spmat A(dA);
rocsparse_local_dnvec x(dx);
rocsparse_local_dnvec y(dy);
//
// WITH 2 ARGUMENTS BEING SKIPPED DURING THE CHECK.
//
static const int nex = 2;
static const int ex[2] = {9, 10};
auto_testing_bad_arg(rocsparse_spmv, nex, ex, PARAMS);
p_buffer_size = nullptr;
temp_buffer = nullptr;
EXPECT_ROCSPARSE_STATUS(rocsparse_spmv(PARAMS), rocsparse_status_invalid_pointer);
}
#undef PARAMS
}
static void testing_spmv(const Arguments& arg)
{
J M = arg.M;
J N = arg.N;
rocsparse_operation trans = arg.transA;
rocsparse_index_base base = arg.baseA;
rocsparse_spmv_alg alg = arg.spmv_alg;
rocsparse_matrix_type matrix_type = arg.matrix_type;
rocsparse_fill_mode uplo = arg.uplo;
rocsparse_storage_mode storage = arg.storage;
rocsparse_datatype ttype = get_datatype<T>();
// Create rocsparse handle
rocsparse_local_handle handle;
host_scalar<T> h_alpha(arg.get_alpha<T>());
host_scalar<T> h_beta(arg.get_beta<T>());
#define PARAMS(alpha_, A_, x_, beta_, y_) \
handle, trans, alpha_, A_, x_, beta_, y_, ttype, alg, &buffer_size, dbuffer
// Argument sanity check before allocating invalid memory
// Allocate memory on device
// Pointer mode
// Check structures
// Check SpMV when structures can be created
if(M <= 0 || N <= 0 || (matrix_type == rocsparse_matrix_type_symmetric && M != N)
|| (matrix_type == rocsparse_matrix_type_triangular && M != N))
{
if(M == 0 || N == 0)
{
CHECK_ROCSPARSE_ERROR(
rocsparse_set_pointer_mode(handle, rocsparse_pointer_mode_host));
device_sparse_matrix<T> dA;
device_dense_matrix<T> dx, dy;
rocsparse_local_spmat A(dA);
rocsparse_local_dnvec x(dx);
rocsparse_local_dnvec y(dy);
EXPECT_ROCSPARSE_STATUS(
rocsparse_spmat_set_attribute(
A, rocsparse_spmat_matrix_type, &matrix_type, sizeof(matrix_type)),
rocsparse_status_success);
EXPECT_ROCSPARSE_STATUS(rocsparse_spmat_set_attribute(
A, rocsparse_spmat_fill_mode, &uplo, sizeof(uplo)),
rocsparse_status_success);
EXPECT_ROCSPARSE_STATUS(
rocsparse_spmat_set_attribute(
A, rocsparse_spmat_storage_mode, &storage, sizeof(storage)),
rocsparse_status_success);
size_t buffer_size;
void* dbuffer = nullptr;
EXPECT_ROCSPARSE_STATUS(rocsparse_spmv(PARAMS(h_alpha, A, x, h_beta, y)),
rocsparse_status_success);
CHECK_HIP_ERROR(rocsparse_hipMalloc(&dbuffer, 10));
EXPECT_ROCSPARSE_STATUS(rocsparse_spmv(PARAMS(h_alpha, A, x, h_beta, y)),
rocsparse_status_success);
CHECK_HIP_ERROR(rocsparse_hipFree(dbuffer));
return;
}
return;
}
// Wavefront size
int dev;
hipGetDevice(&dev);
hipDeviceProp_t prop;
hipGetDeviceProperties(&prop, dev);
//
// INITIALIZATE THE SPARSE MATRIX
//
host_sparse_matrix<T> hA;
{
const bool has_datafile = rocsparse_arguments_has_datafile(arg);
bool to_int = false;
to_int |= (prop.warpSize == 32);
to_int |= (alg != rocsparse_spmv_alg_csr_stream);
to_int |= (trans != rocsparse_operation_none && has_datafile);
to_int |= (matrix_type == rocsparse_matrix_type_symmetric && has_datafile);
static constexpr bool full_rank = false;
rocsparse_matrix_factory<T, I, J> matrix_factory(
arg, arg.unit_check ? to_int : false, full_rank);
traits::sparse_initialization(matrix_factory, hA, M, N, base);
}
if((matrix_type == rocsparse_matrix_type_symmetric && M != N)
|| (matrix_type == rocsparse_matrix_type_triangular && M != N))
{
return;
}
device_sparse_matrix<T> dA(hA);
host_dense_matrix<T> hx((trans == rocsparse_operation_none) ? N : M, 1);
rocsparse_matrix_utils::init_exact(hx);
device_dense_matrix<T> dx(hx);
host_dense_matrix<T> hy((trans == rocsparse_operation_none) ? M : N, 1);
rocsparse_matrix_utils::init_exact(hy);
device_dense_matrix<T> dy(hy);
rocsparse_local_spmat A(dA);
rocsparse_local_dnvec x(dx);
rocsparse_local_dnvec y(dy);
EXPECT_ROCSPARSE_STATUS(
rocsparse_spmat_set_attribute(
A, rocsparse_spmat_matrix_type, &matrix_type, sizeof(matrix_type)),
rocsparse_status_success);
EXPECT_ROCSPARSE_STATUS(
rocsparse_spmat_set_attribute(A, rocsparse_spmat_fill_mode, &uplo, sizeof(uplo)),
rocsparse_status_success);
EXPECT_ROCSPARSE_STATUS(rocsparse_spmat_set_attribute(
A, rocsparse_spmat_storage_mode, &storage, sizeof(storage)),
rocsparse_status_success);
void* dbuffer = nullptr;
size_t buffer_size = 0;
CHECK_ROCSPARSE_ERROR(rocsparse_spmv(PARAMS(h_alpha, A, x, h_beta, y)));
CHECK_HIP_ERROR(rocsparse_hipMalloc(&dbuffer, buffer_size));
if(arg.unit_check)
{
// Pointer mode host
CHECK_ROCSPARSE_ERROR(rocsparse_set_pointer_mode(handle, rocsparse_pointer_mode_host));
CHECK_ROCSPARSE_ERROR(rocsparse_spmv(PARAMS(h_alpha, A, x, h_beta, y)));
//
// CPU spmv
//
{
host_dense_matrix<T> hy_copy(hy);
//
// HOST CALCULATION
//
traits::host_calculation(trans, h_alpha, hA, hx, h_beta, hy, alg, matrix_type);
hy.near_check(dy);
dy.transfer_from(hy_copy);
}
//
// Pointer mode device
//
{
device_scalar<T> d_alpha(h_alpha), d_beta(h_beta);
CHECK_ROCSPARSE_ERROR(
rocsparse_set_pointer_mode(handle, rocsparse_pointer_mode_device));
CHECK_ROCSPARSE_ERROR(rocsparse_spmv(PARAMS(d_alpha, A, x, d_beta, y)));
}
hy.near_check(dy);
}
if(arg.timing)
{
const int number_cold_calls = 2;
const int number_hot_calls = arg.iters;
CHECK_ROCSPARSE_ERROR(rocsparse_set_pointer_mode(handle, rocsparse_pointer_mode_host));
// Warm up
for(int iter = 0; iter < number_cold_calls; ++iter)
{
CHECK_ROCSPARSE_ERROR(rocsparse_spmv(PARAMS(h_alpha, A, x, h_beta, y)));
}
double gpu_time_used = get_time_us();
// Performance run
for(int iter = 0; iter < number_hot_calls; ++iter)
{
CHECK_ROCSPARSE_ERROR(rocsparse_spmv(PARAMS(h_alpha, A, x, h_beta, y)));
}
gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls;
const double gflop_count = traits::gflop_count(hA, *h_beta != static_cast<T>(0));
const double gbyte_count = traits::byte_count(hA, *h_beta != static_cast<T>(0));
const double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count);
const double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count);
traits::display_info(arg,
"trans",
rocsparse_operation2string(trans),
dA,
"alpha",
*h_alpha,
"beta",
*h_beta,
"Algorithm",
rocsparse_spmvalg2string(alg),
s_timing_info_perf,
gpu_gflops,
s_timing_info_bandwidth,
gpu_gbyte,
s_timing_info_time,
get_gpu_time_msec(gpu_time_used));
}
CHECK_HIP_ERROR(rocsparse_hipFree(dbuffer));
return;
}
};
#endif // TESTING_SPMV_HPP
|