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 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444
|
/*! \file */
/* ************************************************************************
* Copyright (C) 2022-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.
*
* ************************************************************************ */
#include "rocsparse_enum.hpp"
#include "testing.hpp"
//
// Split such that L is unit and U is non-unit.
//
template <typename I, typename J>
rocsparse_status rocsparse_host_csritsv_ptr_end(rocsparse_fill_mode fill_mode_,
rocsparse_diag_type diag_type_,
J m_,
I nnz_,
const I* __restrict__ ptr_,
I* __restrict__ ptr_end_,
const J* __restrict__ ind_,
rocsparse_index_base base_,
rocsparse_int* zero_pivot)
{
zero_pivot[0] = -1;
switch(fill_mode_)
{
case rocsparse_fill_mode_lower:
{
switch(diag_type_)
{
case rocsparse_diag_type_unit:
{
for(J i = 0; i < m_; ++i)
{
ptr_end_[i] = ptr_[i + 1];
for(I k = ptr_[i] - base_; k < ptr_[i + 1] - base_; ++k)
{
const J j = ind_[k] - base_;
if(j >= i)
{
ptr_end_[i] = k + base_;
break;
}
}
}
break;
}
case rocsparse_diag_type_non_unit:
{
zero_pivot[0] = std::numeric_limits<rocsparse_int>::max();
J count_symbolic_diag = 0;
for(J i = 0; i < m_; ++i)
{
ptr_end_[i] = ptr_[i + 1];
bool mark = false;
for(I k = ptr_[i] - base_; k < ptr_[i + 1] - base_; ++k)
{
const J j = ind_[k] - base_;
if(j == i)
{
mark = true;
ptr_end_[i] = k + 1 + base_;
break;
}
}
if(!mark)
{
zero_pivot[0] = std::min(zero_pivot[0], i + base_);
++count_symbolic_diag;
}
}
if(zero_pivot[0] == std::numeric_limits<rocsparse_int>::max())
{
zero_pivot[0] = -1;
}
if(count_symbolic_diag > 0)
{
return rocsparse_status_success;
}
break;
}
}
break;
}
case rocsparse_fill_mode_upper:
{
switch(diag_type_)
{
case rocsparse_diag_type_unit:
{
for(J i = 0; i < m_; ++i)
{
ptr_end_[i] = ptr_[i + 1];
for(I k = ptr_[i] - base_; k < ptr_[i + 1] - base_; ++k)
{
const J j = ind_[k] - base_;
if(j > i)
{
ptr_end_[i] = k + base_;
break;
}
}
}
break;
}
case rocsparse_diag_type_non_unit:
{
zero_pivot[0] = std::numeric_limits<rocsparse_int>::max();
J count_symbolic_diag = 0;
for(J i = 0; i < m_; ++i)
{
bool mark = false;
ptr_end_[i] = ptr_[i + 1];
for(I k = ptr_[i] - base_; k < ptr_[i + 1] - base_; ++k)
{
const J j = ind_[k] - base_;
if(j == i)
{
ptr_end_[i] = k + base_;
mark = true;
break;
}
}
if(!mark)
{
zero_pivot[0] = std::min(zero_pivot[0], i + base_);
;
++count_symbolic_diag;
}
}
if(zero_pivot[0] == std::numeric_limits<rocsparse_int>::max())
{
zero_pivot[0] = -1;
}
if(count_symbolic_diag > 0)
{
return rocsparse_status_success;
}
break;
}
}
break;
}
}
return rocsparse_status_success;
}
template <typename I, typename J, typename T>
rocsparse_status rocsparse_host_csritsv_buffer_size_template(rocsparse_handle handle,
rocsparse_operation trans,
J m,
I nnz,
const rocsparse_mat_descr descr,
const T* csr_val,
const I* csr_row_ptr,
const J* csr_col_ind,
rocsparse_mat_info info,
size_t* buffer_size)
{
buffer_size[0] = ((sizeof(I) * m - 1) / 256 + 1) * 256 + sizeof(T) * m;
const rocsparse_diag_type diag_type = rocsparse_get_mat_diag_type(descr);
if(diag_type == rocsparse_diag_type_non_unit)
{
buffer_size[0] += sizeof(T) * m;
}
return rocsparse_status_success;
}
//
// Non optimal host implementation.
//
template <typename I, typename J, typename T>
rocsparse_status rocsparse_host_csritsv_solve(rocsparse_handle handle,
rocsparse_int* host_nmaxiter,
const floating_data_t<T>* host_tol,
floating_data_t<T>* host_history,
rocsparse_operation trans,
J m,
I nnz,
const T* alpha,
const rocsparse_mat_descr descr,
const T* csr_val,
const I* csr_row_ptr,
const J* csr_col_ind,
const T* x,
T* y,
void* temp_buffer,
rocsparse_int* zero_pivot)
{
zero_pivot[0] = -1;
static constexpr bool verbose = false;
const rocsparse_fill_mode fill_mode = rocsparse_get_mat_fill_mode(descr);
const rocsparse_diag_type diag_type = rocsparse_get_mat_diag_type(descr);
const rocsparse_matrix_type mat_type = rocsparse_get_mat_type(descr);
if(verbose)
{
std::cout << "diag_type_" << diag_type << std::endl;
std::cout << "fill_mode_" << fill_mode << std::endl;
}
if(m == 0 || nnz == 0)
{
if(nnz == 0 && diag_type == rocsparse_diag_type_unit)
{
//
// copy and scal.
//
for(J i = 0; i < m; ++i)
y[i] = alpha[0] * x[i];
host_nmaxiter[0] = 1;
}
return rocsparse_status_success;
}
const I* ptr_end = nullptr;
T* y_p = nullptr;
T* inv_diag = nullptr;
rocsparse_index_base base = rocsparse_get_mat_index_base(descr);
if(mat_type == rocsparse_matrix_type_general)
{
ptr_end = (I*)temp_buffer;
rocsparse_status status = rocsparse_host_csritsv_ptr_end(fill_mode,
diag_type,
m,
nnz,
csr_row_ptr,
(I*)temp_buffer,
csr_col_ind,
base,
zero_pivot);
if(status != rocsparse_status_success)
{
return status;
}
temp_buffer = (void*)(((char*)temp_buffer) + ((sizeof(I) * m - 1) / 256 + 1) * 256);
y_p = (T*)temp_buffer;
temp_buffer = (void*)(y_p + m);
}
else if(mat_type == rocsparse_matrix_type_triangular)
{
y_p = (T*)temp_buffer;
temp_buffer = (void*)(y_p + m);
if(fill_mode == rocsparse_fill_mode_lower)
{
ptr_end = csr_row_ptr + 1;
}
else
{
ptr_end = csr_row_ptr;
}
switch(diag_type)
{
case rocsparse_diag_type_non_unit:
{
if(fill_mode == rocsparse_fill_mode_lower)
{
for(J i = 0; i < m; ++i)
{
const J j = csr_col_ind[csr_row_ptr[i + 1] - base - 1] - base;
if(i != j)
{
zero_pivot[0] = i + base;
break;
}
}
}
else
{
for(J i = 0; i < m; ++i)
{
const J j = csr_col_ind[csr_row_ptr[i] - base] - base;
if(i != j)
{
zero_pivot[0] = i + base;
break;
}
}
}
break;
}
case rocsparse_diag_type_unit:
{
break;
}
}
}
if(zero_pivot[0] != -1)
{
return rocsparse_status_success;
}
const I* b = nullptr;
const I* e = nullptr;
const I* d = nullptr;
switch(fill_mode)
{
case rocsparse_fill_mode_lower:
{
b = csr_row_ptr;
e = ptr_end;
break;
}
case rocsparse_fill_mode_upper:
{
b = ptr_end;
e = csr_row_ptr + 1;
break;
}
}
switch(diag_type)
{
case rocsparse_diag_type_non_unit:
{
d = ptr_end;
break;
}
case rocsparse_diag_type_unit:
{
break;
}
}
switch(diag_type)
{
case rocsparse_diag_type_unit:
{
break;
}
case rocsparse_diag_type_non_unit:
{
inv_diag = (T*)temp_buffer;
temp_buffer = (void*)(inv_diag + m);
for(J i = 0; i < m; ++i)
{
I k = (fill_mode == rocsparse_fill_mode_upper) ? (d[i] - base) : (d[i] - base - 1);
if(csr_val[k] == static_cast<T>(0))
{
zero_pivot[0] = i + base;
return rocsparse_status_success;
}
if(trans == rocsparse_operation_conjugate_transpose)
{
inv_diag[i] = static_cast<T>(1) / rocsparse_conj(csr_val[k]);
}
else
{
inv_diag[i] = static_cast<T>(1) / csr_val[k];
}
}
break;
}
}
const floating_data_t<T> nrm0 = static_cast<floating_data_t<T>>(1);
//
// Iterative Loop.
//
for(J iter = 0; iter < host_nmaxiter[0]; ++iter)
{
//
// Copy y to y_p.
//
for(J i = 0; i < m; ++i)
{
y_p[i] = y[i];
}
floating_data_t<T> mx_residual = static_cast<floating_data_t<T>>(0);
floating_data_t<T> mx = static_cast<floating_data_t<T>>(0);
//
// Compute y = alpha
//
switch(trans)
{
case rocsparse_operation_none:
{
switch(diag_type)
{
case rocsparse_diag_type_non_unit:
{
for(J i = 0; i < m; ++i)
{
T sum = static_cast<T>(0);
if((e[i] > b[i] + 1))
{
for(I k = b[i] - base; k < e[i] - base; ++k)
{
sum += csr_val[k] * y_p[csr_col_ind[k] - base];
}
const T h = inv_diag[i] * (alpha[0] * x[i] - sum);
mx = std::max(mx, std::abs(h));
mx_residual = std::max(mx_residual, std::abs(alpha[0] * x[i] - sum));
y[i] = y_p[i] + h;
}
else
{
y[i] = inv_diag[i] * alpha[0] * x[i];
mx = std::max(mx, std::abs(y[i] - y_p[i]));
mx_residual = std::max(mx_residual,
std::abs(alpha[0] * x[i] - y_p[i] / inv_diag[i]));
}
}
break;
}
case rocsparse_diag_type_unit:
{
for(J i = 0; i < m; ++i)
{
T sum = static_cast<T>(0);
for(I k = b[i] - base; k < e[i] - base; ++k)
sum += csr_val[k] * y_p[csr_col_ind[k] - base];
y[i] = alpha[0] * x[i] - sum;
const T h = y[i] - y_p[i];
mx = std::max(mx, std::abs(h));
mx_residual = mx;
}
break;
}
}
break;
}
case rocsparse_operation_transpose:
case rocsparse_operation_conjugate_transpose:
{
for(J i = 0; i < m; ++i)
{
y[i] = static_cast<T>(0);
}
for(J i = 0; i < m; ++i)
{
// row i, column csr_col_ind[k]
// row csr_col_ind[k]
for(I k = b[i] - base; k < e[i] - base; ++k)
{
const J j = csr_col_ind[k] - base;
const T a = (trans == rocsparse_operation_conjugate_transpose)
? rocsparse_conj(csr_val[k])
: csr_val[k];
y[j] += a * y_p[i];
}
}
switch(diag_type)
{
case rocsparse_diag_type_non_unit:
{
for(J i = 0; i < m; ++i)
{
mx_residual = std::max(mx, std::abs(alpha[0] * x[i] - y[i]));
const T h = inv_diag[i] * (alpha[0] * x[i] - y[i]);
mx = std::max(mx, std::abs(h));
y[i] = h + y_p[i];
}
break;
}
case rocsparse_diag_type_unit:
{
for(J i = 0; i < m; ++i)
{
y[i] = (alpha[0] * x[i] - y[i]);
const T h = y[i] - y_p[i];
mx = std::max(mx, std::abs(h));
mx_residual = mx;
}
break;
}
}
break;
}
}
//
// y_k+1 = yk + (alpha * x - (id + T) * yk )
//
if(verbose)
{
std::cout << "iter " << iter << ", mx " << mx / nrm0 << ", mx_residual "
<< mx_residual / nrm0 << std::endl;
}
if(host_history)
{
host_history[iter] = mx;
}
if(host_tol && (mx_residual <= host_tol[0]))
{
host_nmaxiter[0] = iter + 1;
break;
}
}
return rocsparse_status_success;
}
template <typename T>
void testing_csritsv_bad_arg(const Arguments& arg)
{
static constexpr bool verbose = false;
// Create rocsparse handle
rocsparse_local_handle local_handle;
// Create matrix descriptor
rocsparse_local_mat_descr local_descr;
// Create matrix info
rocsparse_local_mat_info local_info;
const T h_alpha = static_cast<T>(1);
rocsparse_handle handle = local_handle;
rocsparse_int* host_nmaxiter = (rocsparse_int*)0x4;
rocsparse_int host_nfreeiter = 2;
const floating_data_t<T>* host_tol = (const floating_data_t<T>*)0x4;
floating_data_t<T>* host_history = (floating_data_t<T>*)0x4;
rocsparse_operation trans = rocsparse_operation_none;
rocsparse_int m = 32;
rocsparse_int nnz = 32;
const T* alpha_device_host = &h_alpha;
const rocsparse_mat_descr descr = local_descr;
const T* csr_val = (const T*)0x4;
const rocsparse_int* csr_row_ptr = (const rocsparse_int*)0x4;
const rocsparse_int* csr_col_ind = (const rocsparse_int*)0x4;
rocsparse_mat_info info = local_info;
const T* x = (const T*)0x4;
T* y = (T*)0x4;
rocsparse_solve_policy solve = rocsparse_solve_policy_auto;
rocsparse_solve_policy policy = rocsparse_solve_policy_auto;
rocsparse_analysis_policy analysis = rocsparse_analysis_policy_force;
void* temp_buffer = (void*)0x4;
size_t* buffer_size = (size_t*)0x4;
#define PARAMS_BUFFER_SIZE \
handle, trans, m, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer_size
#define PARAMS_ANALYSIS \
handle, trans, m, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, analysis, solve, \
temp_buffer
#define PARAMS_SOLVE \
handle, host_nmaxiter, host_tol, host_history, trans, m, nnz, alpha_device_host, descr, \
csr_val, csr_row_ptr, csr_col_ind, info, x, y, policy, temp_buffer
#define PARAMSX_SOLVE \
handle, host_nmaxiter, host_nfreeiter, host_tol, host_history, trans, m, nnz, \
alpha_device_host, descr, csr_val, csr_row_ptr, csr_col_ind, info, x, y, policy, \
temp_buffer
//
//
//
if(verbose)
{
std::cout << "bad_arg_analysis(rocsparse_csritsv_buffer_size<T>, PARAMS_BUFFER_SIZE)"
<< std::endl;
}
bad_arg_analysis(rocsparse_csritsv_buffer_size<T>, PARAMS_BUFFER_SIZE);
//
//
//
if(verbose)
{
std::cout << "bad_arg_analysis(rocsparse_csritsv_analysis<T>, PARAMS_ANALYSIS)"
<< std::endl;
}
bad_arg_analysis(rocsparse_csritsv_analysis<T>, PARAMS_ANALYSIS);
//
//
//
if(verbose)
{
std::cout << "bad_arg_analysis(rocsparse_csritsv_solve<T>, PARAMS_SOLVE)" << std::endl;
}
//
//
//
{
static constexpr int nargs_to_exclude = 2;
static constexpr int args_to_exclude[nargs_to_exclude] = {2, 3};
select_bad_arg_analysis(
rocsparse_csritsv_solve<T>, nargs_to_exclude, args_to_exclude, PARAMS_SOLVE);
}
//
//
//
{
static constexpr int nargs_to_exclude = 2;
static constexpr int args_to_exclude[nargs_to_exclude] = {3, 4};
select_bad_arg_analysis(
rocsparse_csritsv_solve_ex<T>, nargs_to_exclude, args_to_exclude, PARAMSX_SOLVE);
}
for(auto matrix_type : rocsparse_matrix_type_t::values)
{
if(matrix_type != rocsparse_matrix_type_general
&& matrix_type != rocsparse_matrix_type_triangular)
{
CHECK_ROCSPARSE_ERROR(rocsparse_set_mat_type(descr, matrix_type));
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_buffer_size<T>(PARAMS_BUFFER_SIZE),
rocsparse_status_not_implemented);
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_analysis<T>(PARAMS_ANALYSIS),
rocsparse_status_not_implemented);
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_solve<T>(PARAMS_SOLVE),
rocsparse_status_not_implemented);
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_solve_ex<T>(PARAMSX_SOLVE),
rocsparse_status_not_implemented);
}
}
CHECK_ROCSPARSE_ERROR(rocsparse_set_mat_type(descr, rocsparse_matrix_type_general));
CHECK_ROCSPARSE_ERROR(rocsparse_set_mat_storage_mode(descr, rocsparse_storage_mode_unsorted));
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_buffer_size<T>(PARAMS_BUFFER_SIZE),
rocsparse_status_requires_sorted_storage);
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_analysis<T>(PARAMS_ANALYSIS),
rocsparse_status_requires_sorted_storage);
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_solve<T>(PARAMS_SOLVE),
rocsparse_status_requires_sorted_storage);
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_solve_ex<T>(PARAMSX_SOLVE),
rocsparse_status_requires_sorted_storage);
CHECK_ROCSPARSE_ERROR(rocsparse_set_mat_storage_mode(descr, rocsparse_storage_mode_sorted));
#undef PARAMS_BUFFER_SIZE
#undef PARAMS_ANALYSIS
#undef PARAMS_SOLVE
#undef PARAMSX_SOLVE
// Test rocsparse_csritsv_zero_pivot()
rocsparse_int position;
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_zero_pivot(nullptr, descr, info, &position),
rocsparse_status_invalid_handle);
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_zero_pivot(handle, descr, nullptr, &position),
rocsparse_status_invalid_pointer);
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_zero_pivot(handle, descr, info, nullptr),
rocsparse_status_invalid_pointer);
// Test rocsparse_csritsv_clear()
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_clear(nullptr, descr, info),
rocsparse_status_invalid_handle);
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_clear(handle, nullptr, info),
rocsparse_status_invalid_pointer);
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_clear(handle, descr, nullptr),
rocsparse_status_invalid_pointer);
}
template <typename T>
void testing_csritsv(const Arguments& arg)
{
static const bool verbose = false;
//
// Set nmaxiter.
//
rocsparse_int host_nmaxiter[1] = {arg.nmaxiter};
rocsparse_int host_nfreeiter = arg.nfreeiter;
//
// Tolerance for the iterative method.
//
floating_data_t<T> tol_iterative = static_cast<floating_data_t<T>>(1.0e-6);
if(std::is_same<floating_data_t<T>, double>{})
tol_iterative = static_cast<floating_data_t<T>>(1.0e-14);
floating_data_t<T> host_tol[1] = {tol_iterative};
//
// Tolerance for the comparison.
//
floating_data_t<T> tol_compare = static_cast<floating_data_t<T>>(1.0e-5);
if(std::is_same<floating_data_t<T>, double>{})
tol_compare = static_cast<floating_data_t<T>>(1.0e-10);
floating_data_t<T> tol_compare_with_direct = static_cast<floating_data_t<T>>(1.0e-3);
if(std::is_same<floating_data_t<T>, double>{})
tol_compare_with_direct = static_cast<floating_data_t<T>>(1.0e-10);
//
// Convergence history.
//
host_vector<floating_data_t<T>> host_history(host_nmaxiter[0]);
//
// Grab parametrization.
//
rocsparse_int M = arg.M;
rocsparse_int N = arg.N;
rocsparse_operation trans = arg.transA;
rocsparse_diag_type diag = arg.diag;
rocsparse_fill_mode uplo = arg.uplo;
rocsparse_analysis_policy apol = arg.apol;
rocsparse_solve_policy spol = arg.spol;
rocsparse_index_base base = arg.baseA;
//
// Create host alpha.
//
host_scalar<T> h_alpha(arg.get_alpha<T>());
//
// Create rocsparse handle
//
rocsparse_local_handle handle;
//
// Create matrix info.
//
rocsparse_local_mat_info info;
//
// Create matrix descriptor
//
rocsparse_local_mat_descr descr;
//
// Configure descriptor.
//
CHECK_ROCSPARSE_ERROR(rocsparse_set_mat_type(descr, arg.matrix_type));
CHECK_ROCSPARSE_ERROR(rocsparse_set_mat_diag_type(descr, diag));
CHECK_ROCSPARSE_ERROR(rocsparse_set_mat_fill_mode(descr, uplo));
CHECK_ROCSPARSE_ERROR(rocsparse_set_mat_index_base(descr, base));
//
// Define routine parameters.
//
#define PARAMS_BUFFER_SIZE(A_) \
handle, trans, A_.m, A_.nnz, descr, A_.val, A_.ptr, A_.ind, info, &buffer_size
#define PARAMS_ANALYSIS(A_) \
handle, trans, A_.m, A_.nnz, descr, A_.val, A_.ptr, A_.ind, info, apol, spol, dbuffer
#define PARAMS_SOLVE(alpha_, A_, x_, y_) \
handle, host_nmaxiter, host_tol, host_history, trans, A_.m, A_.nnz, alpha_, descr, A_.val, \
A_.ptr, A_.ind, info, x_, y_, spol, dbuffer
#define PARAMSX_SOLVE(alpha_, A_, x_, y_) \
handle, host_nmaxiter, host_nfreeiter, host_tol, host_history, trans, A_.m, A_.nnz, alpha_, \
descr, A_.val, A_.ptr, A_.ind, info, x_, y_, spol, dbuffer
rocsparse_int host_zero_pivot;
#define HOST_PARAMS_SOLVE(alpha_, A_, x_, y_) \
handle, host_nmaxiter, host_tol, host_history, trans, A_.m, A_.nnz, alpha_, descr, A_.val, \
A_.ptr, A_.ind, x_, y_, hbuffer, &host_zero_pivot
//
// Non-squared matrices are not supported
//
if(M != N)
{
if(verbose)
{
std::cerr
<< "// rocSPARSE.WARNING clients testing_csritsv, skipping non-squared matrices."
<< std::endl;
}
return;
}
if(M == 0)
{
size_t buffer_size;
rocsparse_int pivot;
device_vector<T> dx, dy, dbuffer;
device_csr_matrix<T> dA;
CHECK_ROCSPARSE_ERROR(rocsparse_set_pointer_mode(handle, rocsparse_pointer_mode_host));
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_buffer_size<T>(PARAMS_BUFFER_SIZE(dA)),
rocsparse_status_success);
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_analysis<T>(PARAMS_ANALYSIS(dA)),
rocsparse_status_success);
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_solve<T>(PARAMS_SOLVE(h_alpha, dA, dx, dy)),
rocsparse_status_success);
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_solve_ex<T>(PARAMSX_SOLVE(h_alpha, dA, dx, dy)),
rocsparse_status_success);
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_zero_pivot(handle, descr, info, &pivot),
rocsparse_status_success);
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_clear(handle, descr, info),
rocsparse_status_success);
return;
}
//
// Declare matrix A.
//
host_csr_matrix<T> hA;
if(diag == rocsparse_diag_type_unit && rocsparse_matrix_type_triangular == arg.matrix_type)
{
host_csr_matrix<T> hB;
static constexpr bool to_int = false;
static constexpr bool full_rank = true;
rocsparse_matrix_factory<T> matrix_factory(arg, to_int, full_rank);
matrix_factory.init_csr(hB, M, N);
//
// Let's remove the diagonal elements...
//
int ndiag = 0;
for(int i = 0; i < hB.m; ++i)
{
for(int k = hB.ptr[i] - hB.base; k < hB.ptr[i + 1] - hB.base; ++k)
{
const int j = hB.ind[k] - hB.base;
if(i == j)
{
++ndiag;
}
}
}
hA.define(hB.m, hB.n, hB.nnz - ndiag, hB.base);
if(ndiag > 0)
{
hA.ptr[0] = hA.base;
for(int i = 0; i < hB.m; ++i)
{
bool find = false;
for(int k = hB.ptr[i] - hB.base; k < hB.ptr[i + 1] - hB.base; ++k)
{
const int j = hB.ind[k] - hB.base;
if(i == j)
{
find = true;
break;
}
}
if(find)
{
hA.ptr[i + 1] = hB.ptr[i + 1] - hB.ptr[i] - 1;
}
else
{
hA.ptr[i + 1] = hB.ptr[i + 1] - hB.ptr[i];
}
}
for(int i = 1; i <= hA.m; ++i)
hA.ptr[i] += hA.ptr[i - 1];
for(int i = 0; i < hB.m; ++i)
{
int s = 0;
for(int k = hB.ptr[i] - hB.base; k < hB.ptr[i + 1] - hB.base; ++k)
{
if((hB.ind[k] - hB.base) != i)
{
hA.ind[hA.ptr[i] - hA.base + s] = hB.ind[k] - hB.base + hA.base;
hA.val[hA.ptr[i] - hA.base + s] = hB.val[k];
++s;
}
}
}
}
else
{
hA.transfer_from(hB);
}
}
else
{
static constexpr bool to_int = false;
static constexpr bool full_rank = true;
rocsparse_matrix_factory<T> matrix_factory(arg, to_int, full_rank);
matrix_factory.init_csr(hA, M, N);
}
//
// Again, since we import or generate the matrix, Non-squared matrices are not supported.
//
if(M != N)
{
if(verbose)
{
std::cerr
<< "// rocSPARSE.WARNING clients testing_csritsv, skipping non-squared matrices."
<< std::endl;
}
return;
}
//
// Let's normalize ... it helps on horrible matrices.
//
floating_data_t<T> mx = 0;
for(rocsparse_int i = 0; i < hA.nnz; ++i)
mx = std::max(mx, std::abs(hA.val[i]));
if(mx > 0)
{
for(rocsparse_int i = 0; i < hA.nnz; ++i)
hA.val[i] /= mx;
}
//
// Declare and initialize host X.
//
host_dense_matrix<T> hx(M, 1);
rocsparse_matrix_utils::init(hx);
//
// Define and transfer A and X from host to device.
//
device_csr_matrix<T> dA(hA);
device_dense_matrix<T> dx(hx);
//
// Define Y on device.
//
device_dense_matrix<T> dy(M, 1);
host_scalar<rocsparse_int> h_analysis_pivot, h_solve_pivot;
if(verbose)
{
std::cout << "M : " << M << std::endl;
std::cout << "N : " << N << std::endl;
std::cout << "NNZ : " << hA.nnz << std::endl;
}
//
// Buffer for calculation on device.
//
void* dbuffer;
{
size_t buffer_size;
CHECK_ROCSPARSE_ERROR(rocsparse_csritsv_buffer_size<T>(PARAMS_BUFFER_SIZE(dA)));
if(verbose)
{
std::cout << "csritsv_buffer_size " << buffer_size << std::endl;
}
CHECK_HIP_ERROR(rocsparse_hipMalloc(&dbuffer, buffer_size));
}
if(arg.unit_check)
{
if(verbose)
{
std::cout << "testing_csritsv unit_check pointer mode host ... " << std::endl;
}
if(verbose)
{
std::cout << " - compute host iterative" << std::endl;
}
//
// Buffer for calculation on host.
//
void* hbuffer;
{
size_t buffer_size;
CHECK_ROCSPARSE_ERROR(
(rocsparse_host_csritsv_buffer_size_template<rocsparse_int,
rocsparse_int,
T>)(PARAMS_BUFFER_SIZE(hA)));
if(verbose)
{
std::cout << "host_csritsv_buffer_size " << buffer_size << std::endl;
}
hbuffer = malloc(buffer_size);
}
//
// Calculate on host.
//
host_dense_matrix<T> hy_iterative(M, 1);
for(rocsparse_int i = 0; i < M; ++i)
{
hy_iterative[i] = static_cast<T>(0);
}
//
// Compute the iterative method on host.
//
CHECK_ROCSPARSE_ERROR(
(rocsparse_host_csritsv_solve<rocsparse_int, rocsparse_int, T>)(HOST_PARAMS_SOLVE(
h_alpha, hA, hx, hy_iterative)));
const bool host_iterative_convergence = (host_nmaxiter[0] < arg.nmaxiter);
if(false == host_iterative_convergence)
{
//
// it didn't converge, for some reasons ...
//
if(verbose)
{
std::cerr << "host csritsv didn't converge. " << std::endl;
}
}
//
// Calculate the direct method on host.
//
if(verbose)
{
std::cout << " - compute host direct" << std::endl;
}
host_dense_matrix<T> hy_direct(M, 1);
host_csrsv<rocsparse_int, rocsparse_int, T>(trans,
hA.m,
hA.nnz,
*h_alpha,
hA.ptr,
hA.ind,
hA.val,
hx,
(int64_t)1,
hy_direct,
diag,
uplo,
base,
h_analysis_pivot,
h_solve_pivot);
if(verbose)
{
std::cout << "h_analysis_pivot " << *h_analysis_pivot << std::endl;
std::cout << "h_solve_pivot " << *h_solve_pivot << std::endl;
}
if(*h_analysis_pivot == -1 && *h_solve_pivot == -1)
{
if(host_iterative_convergence)
{
if(verbose)
{
std::cout << " - compare host iterative and direct solutions" << std::endl;
}
//
// Compare direct solution and iterative solution calculated on host
// In other words, make sure what we calculate with the iterative method (even on host) makes sense.
//
hy_direct.near_check(hy_iterative, tol_compare_with_direct);
}
}
else
{
if(verbose)
{
std::cout << " - zero pivot detected with direct method" << std::endl;
}
}
if(verbose)
{
std::cout << " - compute device iterative" << std::endl;
}
//
// Now we calculate on gpu
//
host_scalar<rocsparse_int> analysis_no_pivot(-1);
host_scalar<rocsparse_int> analysis_pivot;
host_scalar<rocsparse_int> solve_pivot;
CHECK_ROCSPARSE_ERROR(rocsparse_set_pointer_mode(handle, rocsparse_pointer_mode_host));
if(verbose)
{
std::cout << " - compute device iterative, check if default zero pivot is -1"
<< std::endl;
}
//
// CHECK IF DEFAULT ZERO PIVOT IS -1
//
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_zero_pivot(handle, descr, info, analysis_pivot),
rocsparse_status_success);
analysis_no_pivot.unit_check(analysis_pivot);
if(verbose)
{
std::cout << " - compute device iterative, calling solve before analysis must fail"
<< std::endl;
}
//
// Call before analysis
//
host_nmaxiter[0] = arg.nmaxiter;
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_solve<T>(PARAMS_SOLVE(h_alpha, dA, dx, dy)),
rocsparse_status_invalid_pointer);
if(verbose)
{
std::cout << " - compute device iterative, call analysis" << std::endl;
}
// Call it twice, for code coverage.
CHECK_ROCSPARSE_ERROR(rocsparse_csritsv_analysis<T>(PARAMS_ANALYSIS(dA)));
if(verbose)
{
std::cout
<< " - compute device iterative, call analysis twice (second call for coverage)"
<< std::endl;
}
CHECK_ROCSPARSE_ERROR(rocsparse_csritsv_analysis<T>(PARAMS_ANALYSIS(dA)));
{
auto st = rocsparse_csritsv_zero_pivot(handle, descr, info, analysis_pivot);
EXPECT_ROCSPARSE_STATUS(st,
(*analysis_pivot != -1) ? rocsparse_status_zero_pivot
: rocsparse_status_success);
}
if(verbose)
{
std::cout << " - compute device iterative, call solve" << std::endl;
}
CHECK_HIP_ERROR(hipMemset(dy, 0, sizeof(T) * M));
host_nmaxiter[0] = arg.nmaxiter;
CHECK_ROCSPARSE_ERROR(rocsparse_csritsv_solve<T>(PARAMS_SOLVE(h_alpha, dA, dx, dy)));
{
auto st = rocsparse_csritsv_zero_pivot(handle, descr, info, solve_pivot);
EXPECT_ROCSPARSE_STATUS(
st, (*solve_pivot != -1) ? rocsparse_status_zero_pivot : rocsparse_status_success);
}
const bool device_iterative_convergence = (host_nmaxiter[0] < arg.nmaxiter);
h_analysis_pivot.unit_check(analysis_pivot);
h_solve_pivot.unit_check(solve_pivot);
if(*h_analysis_pivot == -1 && *h_solve_pivot == -1)
{
if(verbose)
{
std::cout
<< " - compute device iterative, compare solutions between host and device."
<< std::endl;
}
if(host_iterative_convergence)
{
hy_iterative.near_check(dy, tol_compare);
}
}
host_nmaxiter[0] = arg.nmaxiter;
CHECK_HIP_ERROR(hipMemset(dy, 0, sizeof(T) * M));
CHECK_ROCSPARSE_ERROR(rocsparse_csritsv_solve_ex<T>(PARAMSX_SOLVE(h_alpha, dA, dx, dy)));
{
auto st = rocsparse_csritsv_zero_pivot(handle, descr, info, solve_pivot);
EXPECT_ROCSPARSE_STATUS(
st, (*solve_pivot != -1) ? rocsparse_status_zero_pivot : rocsparse_status_success);
}
const bool device_iterative_convergence_ex = (host_nmaxiter[0] < arg.nmaxiter);
if(*h_analysis_pivot == -1 && *h_solve_pivot == -1)
{
if(verbose)
{
std::cout
<< " - compute device iterative_ex, compare solutions between host and device."
<< std::endl;
}
if(host_iterative_convergence)
{
hy_iterative.near_check(dy, tol_compare);
}
}
if(device_iterative_convergence != host_iterative_convergence)
{
if(verbose)
{
if(trans == rocsparse_operation_none)
{
std::cout << " - WARNING host and device iterative convergence differs on "
"NonTranspose case ... it happens rarely but it does."
<< std::endl;
}
else
{
std::cout
<< " - WARNING host and device iterative convergence differs, it happens "
"with transpose cases since csrmv uses atomics."
<< std::endl;
}
}
}
if(device_iterative_convergence_ex != host_iterative_convergence)
{
if(verbose)
{
if(trans == rocsparse_operation_none)
{
std::cout << " - WARNING host and device iterative_ex convergence differs on "
"NonTranspose case ... it happens rarely but it does."
<< std::endl;
}
else
{
std::cout << " - WARNING host and device iterative_ex convergence differs, it "
"happens "
"with transpose cases since csrmv uses atomics."
<< std::endl;
}
}
}
if(verbose)
{
std::cout << " - compute device iterative, check pivot." << std::endl;
std::cout << "h_analysis_pivot " << *h_analysis_pivot << std::endl;
std::cout << "h_solve_pivot " << *h_solve_pivot << std::endl;
}
//
// RESET MAT INFO.
//
info.reset();
if(verbose)
{
std::cout << "testing_csritsv unit_check pointer mode device ... " << std::endl;
}
if(verbose)
{
std::cout << " - compute device iterative" << std::endl;
}
device_scalar<rocsparse_int> d_analysis_pivot;
device_scalar<rocsparse_int> d_solve_pivot;
device_scalar<T> d_alpha(h_alpha);
//
// POINTER MODE DEVICE
//
CHECK_ROCSPARSE_ERROR(rocsparse_set_pointer_mode(handle, rocsparse_pointer_mode_device));
//
// CHECK IF DEFAULT ZERO PIVOT IS -1
//
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_zero_pivot(handle, descr, info, d_analysis_pivot),
rocsparse_status_success);
analysis_no_pivot.unit_check(d_analysis_pivot);
//
// Call before analysis
//
host_nmaxiter[0] = arg.nmaxiter;
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_solve<T>(PARAMS_SOLVE(h_alpha, dA, dx, dy)),
rocsparse_status_invalid_pointer);
//
// Call it twice.
//
CHECK_ROCSPARSE_ERROR(rocsparse_csritsv_analysis<T>(PARAMS_ANALYSIS(dA)));
CHECK_ROCSPARSE_ERROR(rocsparse_csritsv_analysis<T>(PARAMS_ANALYSIS(dA)));
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_zero_pivot(handle, descr, info, d_analysis_pivot),
(*h_analysis_pivot != -1) ? rocsparse_status_zero_pivot
: rocsparse_status_success);
CHECK_HIP_ERROR(hipMemset(dy, 0, sizeof(T) * M));
host_nmaxiter[0] = arg.nmaxiter;
CHECK_ROCSPARSE_ERROR(rocsparse_csritsv_solve<T>(PARAMS_SOLVE(d_alpha, dA, dx, dy)));
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_zero_pivot(handle, descr, info, d_solve_pivot),
(*h_solve_pivot != -1) ? rocsparse_status_zero_pivot
: rocsparse_status_success);
h_analysis_pivot.unit_check(d_analysis_pivot);
h_solve_pivot.unit_check(d_solve_pivot);
if(*h_analysis_pivot == -1 && *h_solve_pivot == -1)
{
if(ROCSPARSE_REPRODUCIBILITY)
{
rocsparse_reproducibility::save("Y", dy);
}
if(host_iterative_convergence)
{
hy_iterative.near_check(dy, tol_compare);
}
}
else
{
if(ROCSPARSE_REPRODUCIBILITY)
{
rocsparse_reproducibility::save(
"analysis_pivot", d_analysis_pivot, "solve_pivot", d_solve_pivot);
}
}
CHECK_HIP_ERROR(hipMemset(dy, 0, sizeof(T) * M));
host_nmaxiter[0] = arg.nmaxiter;
CHECK_ROCSPARSE_ERROR(rocsparse_csritsv_solve_ex<T>(PARAMSX_SOLVE(d_alpha, dA, dx, dy)));
EXPECT_ROCSPARSE_STATUS(rocsparse_csritsv_zero_pivot(handle, descr, info, d_solve_pivot),
(*h_solve_pivot != -1) ? rocsparse_status_zero_pivot
: rocsparse_status_success);
h_analysis_pivot.unit_check(d_analysis_pivot);
h_solve_pivot.unit_check(d_solve_pivot);
if(*h_analysis_pivot == -1 && *h_solve_pivot == -1)
{
if(host_iterative_convergence)
{
hy_iterative.near_check(dy, tol_compare);
}
}
free(hbuffer);
if(verbose)
{
std::cout << "testing_csritsv unit_check done. " << std::endl;
}
}
if(arg.timing)
{
host_nfreeiter = arg.nfreeiter;
int number_cold_calls = 2;
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_csritsv_analysis<T>(PARAMS_ANALYSIS(dA)));
CHECK_ROCSPARSE_ERROR(
rocsparse_csritsv_zero_pivot(handle, descr, info, h_analysis_pivot));
CHECK_ROCSPARSE_ERROR(
rocsparse_csritsv_solve_ex<T>(PARAMSX_SOLVE(h_alpha, dA, dx, dy)));
CHECK_ROCSPARSE_ERROR(rocsparse_csritsv_zero_pivot(handle, descr, info, h_solve_pivot));
CHECK_ROCSPARSE_ERROR(rocsparse_csritsv_clear(handle, descr, info));
}
double gpu_analysis_time_used = get_time_us();
CHECK_ROCSPARSE_ERROR(rocsparse_csritsv_analysis<T>(PARAMS_ANALYSIS(dA)));
gpu_analysis_time_used = get_time_us() - gpu_analysis_time_used;
double gpu_solve_time_used = 0;
// Performance run
for(int iter = 0; iter < number_hot_calls; ++iter)
{
CHECK_HIP_ERROR(hipMemset(dy, 0, sizeof(T) * M));
host_nmaxiter[0] = arg.nmaxiter;
double gpu_solve_time_used_1 = get_time_us();
CHECK_ROCSPARSE_ERROR(
rocsparse_csritsv_solve_ex<T>(PARAMSX_SOLVE(h_alpha, dA, dx, dy)));
gpu_solve_time_used_1 = (get_time_us() - gpu_solve_time_used_1);
gpu_solve_time_used += gpu_solve_time_used_1;
}
gpu_solve_time_used /= number_hot_calls;
double gflop_count = csrsv_gflop_count(M, dA.nnz, diag);
double gbyte_count = csrsv_gbyte_count<T>(M, dA.nnz);
double gpu_gflops = get_gpu_gflops(gpu_solve_time_used, gflop_count);
double gpu_gbyte = get_gpu_gbyte(gpu_solve_time_used, gbyte_count);
display_timing_info(display_key_t::M,
M,
display_key_t::nnz,
dA.nnz,
display_key_t::alpha,
*h_alpha,
display_key_t::nfreeiter,
host_nfreeiter,
display_key_t::nmaxiter,
host_nmaxiter[0],
display_key_t::pivot,
std::min(*h_analysis_pivot, *h_solve_pivot),
display_key_t::trans,
rocsparse_operation2string(trans),
display_key_t::diag_type,
rocsparse_diagtype2string(diag),
display_key_t::fill_mode,
rocsparse_fillmode2string(uplo),
display_key_t::analysis_policy,
rocsparse_analysis2string(apol),
display_key_t::solve_policy,
rocsparse_solve2string(spol),
display_key_t::gflops,
gpu_gflops,
display_key_t::bandwidth,
gpu_gbyte,
display_key_t::analysis_ms,
get_gpu_time_msec(gpu_analysis_time_used),
display_key_t::time_ms,
get_gpu_time_msec(gpu_solve_time_used));
}
// Clear csritsv meta data
CHECK_ROCSPARSE_ERROR(rocsparse_csritsv_clear(handle, descr, info));
// Free buffer
CHECK_HIP_ERROR(rocsparse_hipFree(dbuffer));
}
#define INSTANTIATE(TYPE) \
template void testing_csritsv_bad_arg<TYPE>(const Arguments& arg); \
template void testing_csritsv<TYPE>(const Arguments& arg)
INSTANTIATE(float);
INSTANTIATE(double);
INSTANTIATE(rocsparse_float_complex);
INSTANTIATE(rocsparse_double_complex);
void testing_csritsv_extra(const Arguments& arg) {}
|