/usr/include/trilinos/Kokkos_Blas1_MV.hpp is in libtrilinos-tpetra-dev 12.10.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*
//@HEADER
// ************************************************************************
//
// Kokkos: Node API and Parallel Node Kernels
// Copyright (2008) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// 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. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "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 SANDIA CORPORATION OR THE
// 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.
//
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
//
// ************************************************************************
//@HEADER
*/
#ifndef KOKKOS_BLAS1_MV_HPP_
#define KOKKOS_BLAS1_MV_HPP_
/// \file Kokkos_Blas1_MV.hpp
/// \brief BLAS 1 kernels specifically optimized for typical
/// Tpetra::Vector and Tpetra::MultiVector use cases.
#include <Kokkos_Blas1.hpp>
#include <Kokkos_Blas1_MV_impl_abs.hpp>
#include <Kokkos_Blas1_MV_impl_axpby.hpp>
#include <Kokkos_Blas1_MV_impl_dot.hpp>
#include <Kokkos_Blas1_MV_impl_fill.hpp>
#include <Kokkos_Blas1_MV_impl_mult.hpp>
#include <Kokkos_Blas1_MV_impl_nrm1.hpp>
#include <Kokkos_Blas1_MV_impl_nrm2.hpp>
#include <Kokkos_Blas1_MV_impl_nrm2w.hpp>
#include <Kokkos_Blas1_MV_impl_nrmInf.hpp>
#include <Kokkos_Blas1_MV_impl_recip.hpp>
#include <Kokkos_Blas1_MV_impl_scal.hpp>
#include <Kokkos_Blas1_MV_impl_sum.hpp>
#include <Kokkos_Blas1_MV_impl_update.hpp>
#include <type_traits> // requires C++11
// Define this if you want some of the methods below to print out
// information about the types that they use internally. This is
// useful for figuring out whether they are using the right
// specialization of the kernel.
//
// #define TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO 1
#ifdef TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
# include <cxxabi.h>
namespace {
// Print the type of t in demangled (human-readable) form. This is
// useful for debugging whether KokkosBlas::axpby() is calling one
// of the full specializations, or the generic version of the
// kernel. See the following link for information about the
// demangling function we call below:
//
// https://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html
template<class T>
std::string demangledTypeName (const T& t) {
int status = 0;
return abi::__cxa_demangle (typeid (t).name (), 0, 0, &status);
}
}
#endif // TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
namespace KokkosBlas {
namespace Impl {
// parallel_for functor for computing the square root, in place, of a
// one-dimensional View. This is useful for following the MPI
// all-reduce that computes the square of the two-norms of the local
// columns of a Tpetra::MultiVector.
//
// mfh 14 Jul 2014: Carter says that, for now, the standard idiom for
// operating on a single scalar value on the device, is to run in a
// parallel_for with N = 1.
//
// FIXME (mfh 14 Jul 2014): If we could assume C++11, this functor
// would go away.
template<class ViewType>
class SquareRootFunctor {
public:
typedef typename ViewType::execution_space execution_space;
typedef typename ViewType::size_type size_type;
SquareRootFunctor (const ViewType& theView) : theView_ (theView) {}
KOKKOS_INLINE_FUNCTION void operator() (const size_type i) const {
typedef typename ViewType::value_type value_type;
theView_(i) = Kokkos::Details::ArithTraits<value_type>::sqrt (theView_(i));
}
private:
ViewType theView_;
};
}
/// \brief Compute the column-wise dot products of two multivectors.
///
/// \tparam RV 0-D resp. 1-D output View
/// \tparam XMV 1-D resp. 2-D input View
/// \tparam YMV 1-D resp. 2-D input View
///
/// \param dots [out] Output 1-D View to which to write results.
/// \param x [in] Input 2-D View.
/// \param y [in] Input 2-D View.
///
/// \note To implementers: We use enable_if here so that the compiler
/// doesn't confuse this version of dot() with the three-argument
/// version of dot() in Kokkos_Blas1.hpp.
template<class RV, class XMV, class YMV>
void
dot (const RV& R, const XMV& X, const YMV& Y,
typename std::enable_if<Kokkos::Impl::is_view<RV>::value, int>::type = 0)
{
static_assert (Kokkos::Impl::is_view<RV>::value, "KokkosBlas::dot: "
"R is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_view<XMV>::value, "KokkosBlas::dot: "
"X is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_view<YMV>::value, "KokkosBlas::dot: "
"Y is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_same<typename RV::value_type,
typename RV::non_const_value_type>::value,
"KokkosBlas::dot: R is const. "
"It must be nonconst, because it is an output argument "
"(we have to be able to write to its entries).");
static_assert (XMV::rank == YMV::rank, "KokkosBlas::dot: "
"X and Y must have the same rank.");
static_assert ((RV::rank == 0 && XMV::rank == 1) ||
(RV::rank == 1 && XMV::rank == 2),
"KokkosBlas::dot: Either RV has rank 0 and XMV and YMV have "
"rank 1, or RV has rank 1 and XMV and YMV have rank 2.");
// Check compatibility of dimensions at run time.
if (X.dimension_0 () != Y.dimension_0 () ||
X.dimension_1 () != Y.dimension_1 () ||
(RV::rank == 1 && R.dimension_0 () != X.dimension_1 ())) {
std::ostringstream os;
os << "KokkosBlas::dot: Dimensions of R, X, and Y do not match: ";
if (RV::rank == 1) {
os << "R: " << R.dimension_0 () << " x " << X.dimension_1 () << ", ";
}
os << "X: " << X.dimension_0 () << " x " << X.dimension_1 ()
<< ", Y: " << Y.dimension_0 () << " x " << Y.dimension_1 ();
Kokkos::Impl::throw_runtime_exception (os.str ());
}
// Create unmanaged versions of the input Views.
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
RV::rank == 0,
typename RV::non_const_value_type,
typename RV::non_const_value_type* >::type,
typename RV::array_layout,
typename RV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > RV_Internal;
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
XMV::rank == 1,
typename XMV::const_value_type*,
typename XMV::const_value_type** >::type,
typename XMV::array_layout,
typename XMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > XMV_Internal;
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
YMV::rank == 1,
typename YMV::const_value_type*,
typename YMV::const_value_type** >::type,
typename YMV::array_layout,
typename YMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > YMV_Internal;
RV_Internal R_internal = R;
XMV_Internal X_internal = X;
YMV_Internal Y_internal = Y;
#ifdef TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
using std::cerr;
using std::endl;
cerr << "KokkosBlas::dot:" << endl
<< " RV_Internal: " << demangledTypeName (R_internal) << endl
<< " XMV_Internal: " << demangledTypeName (X_internal) << endl
<< " YMV_Internal: " << demangledTypeName (Y_internal) << endl
<< endl;
#endif // TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
Impl::Dot_MV<RV_Internal, XMV_Internal, YMV_Internal>::dot (R_internal, X_internal, Y_internal);
}
/// \brief Fill the multivector or single vector X with the given value.
///
/// \tparam XMV 1-D or 2-D output View
///
/// \param X [out] Output View (1-D or 2-D).
/// \param val [in] Value with which to fill the entries of X.
template<class XMV>
void
fill (const XMV& X, const typename XMV::non_const_value_type& val)
{
static_assert (Kokkos::Impl::is_view<XMV>::value,
"KokkosBlas::fill: X is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_same<typename XMV::value_type,
typename XMV::non_const_value_type>::value,
"KokkosBlas::fill: X is const. It must be nonconst, "
"because it is an output argument (we must be able to write "
"to its entries).");
static_assert (XMV::rank == 1 || XMV::rank == 2, "KokkosBlas::fill: "
"X must have rank 1 or rank 2.");
// Assign to the View type for which Impl::Fill is most likely to
// have a full specialization.
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
XMV::rank == 1,
typename XMV::non_const_value_type*,
typename XMV::non_const_value_type** >::type,
typename XMV::array_layout,
typename XMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > XMV_Internal;
XMV_Internal X_internal = X;
Impl::Fill<XMV_Internal>::fill (X_internal, val);
}
/// \brief Compute the squares of the 2-norm(s) of the column(s) of
/// the multivector or single vector X.
///
/// \tparam RV 0-D or 1-D output View
/// \tparam XMV 1-D or 2-D input View
///
/// \param R [out] Output View to which to write results.
/// \param X [in] Input View.
template<class RV, class XMV>
void
nrm2_squared (const RV& R, const XMV& X)
{
static_assert (Kokkos::Impl::is_view<RV>::value, "KokkosBlas::nrm2_squared: "
"R is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_view<XMV>::value, "KokkosBlas::nrm2_squared: "
"X is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_same<typename RV::value_type,
typename RV::non_const_value_type>::value,
"KokkosBlas::nrm2_squared: The output argument is const. "
"It must be nonconst, because it is an output argument "
"(we have to be able to write to its entries).");
static_assert ((RV::rank == 0 && XMV::rank == 1) ||
(RV::rank == 1 && XMV::rank == 2),
"KokkosBlas::nrm2_squared: Either RV has rank 0 and XMV has "
"rank 1, or RV has rank 1 and XMV has rank 2.");
// Check compatibility of dimensions at run time.
if (RV::rank == 1 && R.dimension_0 () != X.dimension_1 ()) {
std::ostringstream os;
os << "KokkosBlas::nrm2_squared: Dimensions do not match: "
<< "R: " << R.dimension_0 () << " x 1"
<< ", X: " << X.dimension_0 () << " x " << X.dimension_1 ();
Kokkos::Impl::throw_runtime_exception (os.str ());
}
// Create unmanaged versions of the input Views.
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
RV::rank == 0,
typename RV::non_const_value_type,
typename RV::non_const_value_type* >::type,
typename RV::array_layout,
typename RV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > RV_Internal;
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
XMV::rank == 1,
typename XMV::const_value_type*,
typename XMV::const_value_type** >::type,
typename XMV::array_layout,
typename XMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > XMV_Internal;
RV_Internal R_internal = R;
XMV_Internal X_internal = X;
#ifdef TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
using std::cerr;
using std::endl;
cerr << "KokkosBlas::nrm2_squared:" << endl
<< " RV_Internal: " << demangledTypeName (R_internal) << endl
<< " XMV_Internal: " << demangledTypeName (X_internal) << endl
<< endl;
#endif // TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
Impl::Nrm2_MV<RV_Internal, XMV_Internal>::nrm2_squared (R_internal, X_internal);
}
/// \brief Compute the 1-norm(s) of the column(s) of the multivector
/// or single vector X.
///
/// \tparam RV 0-D or 1-D output View
/// \tparam XMV 1-D or 2-D input View
///
/// \param R [out] Output View to which to write results.
/// \param X [in] Input View.
template<class RV, class XMV>
void
nrm1 (const RV& R, const XMV& X)
{
static_assert (Kokkos::Impl::is_view<RV>::value, "KokkosBlas::nrm1: "
"R is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_view<XMV>::value, "KokkosBlas::nrm1: "
"X is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_same<typename RV::value_type,
typename RV::non_const_value_type>::value,
"KokkosBlas::nrm1: The output argument is const. "
"It must be nonconst, because it is an output argument "
"(we have to be able to write to its entries).");
static_assert ((RV::rank == 0 && XMV::rank == 1) ||
(RV::rank == 1 && XMV::rank == 2),
"KokkosBlas::nrm1: Either RV has rank 0 and XMV has "
"rank 1, or RV has rank 1 and XMV has rank 2.");
// Check compatibility of dimensions at run time.
if (RV::rank == 1 && R.dimension_0 () != X.dimension_1 ()) {
std::ostringstream os;
os << "KokkosBlas::nrm1: Dimensions do not match: "
<< "R: " << R.dimension_0 () << " x 1"
<< ", X: " << X.dimension_0 () << " x " << X.dimension_1 ();
Kokkos::Impl::throw_runtime_exception (os.str ());
}
// Create unmanaged versions of the input Views.
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
RV::rank == 0,
typename RV::non_const_value_type,
typename RV::non_const_value_type* >::type,
typename RV::array_layout,
typename RV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > RV_Internal;
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
XMV::rank == 1,
typename XMV::const_value_type*,
typename XMV::const_value_type** >::type,
typename XMV::array_layout,
typename XMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > XMV_Internal;
RV_Internal R_internal = R;
XMV_Internal X_internal = X;
#ifdef TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
using std::cerr;
using std::endl;
cerr << "KokkosBlas::nrm1:" << endl
<< " RV_Internal: " << demangledTypeName (R_internal) << endl
<< " XMV_Internal: " << demangledTypeName (X_internal) << endl
<< endl;
#endif // TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
Impl::Nrm1_MV<RV_Internal, XMV_Internal>::nrm1 (R_internal, X_internal);
}
/// \brief Compute the inf-norm(s) of the column(s) of the multivector
/// or single vector X.
///
/// \tparam RV 0-D or 1-D output View
/// \tparam XMV 1-D or 2-D input View
///
/// \param R [out] Output View to which to write results.
/// \param X [in] Input View.
template<class RV, class XMV>
void
nrmInf (const RV& R, const XMV& X)
{
static_assert (Kokkos::Impl::is_view<RV>::value, "KokkosBlas::nrmInf: "
"R is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_view<XMV>::value, "KokkosBlas::nrmInf: "
"X is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_same<typename RV::value_type,
typename RV::non_const_value_type>::value,
"KokkosBlas::nrmInf: The output argument is const. "
"It must be nonconst, because it is an output argument "
"(we have to be able to write to its entries).");
static_assert ((RV::rank == 0 && XMV::rank == 1) ||
(RV::rank == 1 && XMV::rank == 2),
"KokkosBlas::nrmInf: Either RV has rank 0 and XMV has "
"rank 1, or RV has rank 1 and XMV has rank 2.");
// Check compatibility of dimensions at run time.
if (RV::rank == 1 && R.dimension_0 () != X.dimension_1 ()) {
std::ostringstream os;
os << "KokkosBlas::nrmInf: Dimensions do not match: "
<< "R: " << R.dimension_0 () << " x 1"
<< ", X: " << X.dimension_0 () << " x " << X.dimension_1 ();
Kokkos::Impl::throw_runtime_exception (os.str ());
}
// Create unmanaged versions of the input Views.
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
RV::rank == 0,
typename RV::non_const_value_type,
typename RV::non_const_value_type* >::type,
typename RV::array_layout,
typename RV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > RV_Internal;
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
XMV::rank == 1,
typename XMV::const_value_type*,
typename XMV::const_value_type** >::type,
typename XMV::array_layout,
typename XMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > XMV_Internal;
RV_Internal R_internal = R;
XMV_Internal X_internal = X;
#ifdef TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
using std::cerr;
using std::endl;
cerr << "KokkosBlas::nrmInf:" << endl
<< " RV_Internal: " << demangledTypeName (R_internal) << endl
<< " XMV_Internal: " << demangledTypeName (X_internal) << endl
<< endl;
#endif // TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
Impl::NrmInf_MV<RV_Internal, XMV_Internal>::nrmInf (R_internal, X_internal);
}
namespace { // (anonymous)
// axpby() accepts both scalar coefficients a and b, and vector
// coefficients (apply one for each column of the input multivectors).
// This traits class helps axpby() select the correct specialization
// of AV and BV (the type of a resp. b) for invoking the
// implementation.
template<class T, bool isView>
struct GetInternalTypeForAxpby {
typedef T type;
};
template<class T>
struct GetInternalTypeForAxpby<T, true> {
typedef Kokkos::View<typename T::const_value_type*,
typename T::array_layout,
typename T::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > type;
};
// typedef typename Kokkos::Impl::if_c<
// Kokkos::Impl::is_view<BV>::value, // if BV is a Kokkos::View,
// Kokkos::View<typename BV::const_value_type*,
// typename BV::array_layout,
// typename BV::device_type,
// Kokkos::MemoryTraits<Kokkos::Unmanaged> >, // use the unmanaged version of BV,
// BV >::type BV_Internal; // else just use BV.
} // namespace (anonymous)
template<class AV, class XMV, class BV, class YMV>
void
axpby (const AV& a, const XMV& X, const BV& b, const YMV& Y)
{
static_assert (Kokkos::Impl::is_view<XMV>::value, "KokkosBlas::axpby: "
"X is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_view<YMV>::value, "KokkosBlas::axpby: "
"Y is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_same<typename YMV::value_type,
typename YMV::non_const_value_type>::value,
"KokkosBlas::axpby: Y is const. It must be nonconst, "
"because it is an output argument "
"(we must be able to write to its entries).");
static_assert (YMV::rank == XMV::rank, "KokkosBlas::axpby: "
"X and Y must have the same rank.");
static_assert (YMV::rank == 1 || YMV::rank == 2, "KokkosBlas::axpby: "
"XMV and YMV must either have rank 1 or rank 2.");
// Check compatibility of dimensions at run time.
if (X.dimension_0 () != Y.dimension_0 () ||
X.dimension_1 () != Y.dimension_1 ()) {
std::ostringstream os;
os << "KokkosBlas::axpby: Dimensions of X and Y do not match: "
<< "X: " << X.dimension_0 () << " x " << X.dimension_1 ()
<< ", Y: " << Y.dimension_0 () << " x " << Y.dimension_1 ();
Kokkos::Impl::throw_runtime_exception (os.str ());
}
// Create unmanaged versions of the input Views. XMV and YMV may be
// rank 1 or rank 2. AV and BV may be either rank-1 Views, or
// scalar values.
typedef typename GetInternalTypeForAxpby<
AV, Kokkos::Impl::is_view<AV>::value>::type AV_Internal;
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
XMV::rank == 1,
typename XMV::const_value_type*,
typename XMV::const_value_type** >::type,
typename XMV::array_layout,
typename XMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > XMV_Internal;
typedef typename GetInternalTypeForAxpby<
BV, Kokkos::Impl::is_view<BV>::value>::type BV_Internal;
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
YMV::rank == 1,
typename YMV::non_const_value_type*,
typename YMV::non_const_value_type** >::type,
typename YMV::array_layout,
typename YMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > YMV_Internal;
AV_Internal a_internal = a;
XMV_Internal X_internal = X;
BV_Internal b_internal = b;
YMV_Internal Y_internal = Y;
#ifdef TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
using std::cerr;
using std::endl;
cerr << "KokkosBlas::axpby:" << endl
<< " AV_Internal: " << demangledTypeName (a_internal) << endl
<< " XMV_Internal: " << demangledTypeName (X_internal) << endl
<< " BV_Internal: " << demangledTypeName (b_internal) << endl
<< " YMV_Internal: " << demangledTypeName (Y_internal) << endl
<< endl;
#endif // TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
return Impl::Axpby<AV_Internal, XMV_Internal, BV_Internal,
YMV_Internal>::axpby (a_internal, X_internal, b_internal, Y_internal);
}
template<class RMV, class AV, class XMV>
void
scal (const RMV& R, const AV& a, const XMV& X)
{
static_assert (Kokkos::Impl::is_view<RMV>::value, "KokkosBlas::scal: "
"R is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_view<XMV>::value, "KokkosBlas::scal: "
"X is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_same<typename RMV::value_type,
typename RMV::non_const_value_type>::value,
"KokkosBlas::scal: R is const. "
"It must be nonconst, because it is an output argument "
"(we have to be able to write to its entries).");
static_assert ((int) RMV::rank == (int) XMV::rank, "KokkosBlas::scal: "
"R and X must have the same rank.");
static_assert (RMV::rank == 1 || RMV::rank == 2, "KokkosBlas::scal: "
"RMV and XMV must either have rank 1 or rank 2.");
// Check compatibility of dimensions at run time.
if (X.dimension_0 () != R.dimension_0 () ||
X.dimension_1 () != R.dimension_1 ()) {
std::ostringstream os;
os << "KokkosBlas::scal: Dimensions of R and X do not match: "
<< "R: " << R.dimension_0 () << " x " << R.dimension_1 ()
<< ", X: " << X.dimension_0 () << " x " << X.dimension_1 ();
Kokkos::Impl::throw_runtime_exception (os.str ());
}
// Create unmanaged versions of the input Views. RMV and XMV may be
// rank 1 or rank 2. AV may be either a rank-1 View, or a scalar
// value.
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
RMV::rank == 1,
typename RMV::non_const_value_type*,
typename RMV::non_const_value_type** >::type,
typename RMV::array_layout,
typename RMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > RMV_Internal;
typedef typename GetInternalTypeForAxpby<
AV, Kokkos::Impl::is_view<AV>::value>::type AV_Internal;
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
XMV::rank == 1,
typename XMV::non_const_value_type*,
typename XMV::non_const_value_type** >::type,
typename XMV::array_layout,
typename XMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > XMV_Internal;
RMV_Internal R_internal = R;
AV_Internal a_internal = a;
XMV_Internal X_internal = X;
#ifdef TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
using std::cerr;
using std::endl;
cerr << "KokkosBlas::scal:" << endl
<< " RMV_Internal: " << demangledTypeName (R_internal) << endl
<< " AV_Internal: " << demangledTypeName (a_internal) << endl
<< " XMV_Internal: " << demangledTypeName (X_internal) << endl
<< endl;
#endif // TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
Impl::Scal<RMV_Internal, AV_Internal, XMV_Internal>::scal (R_internal, a_internal, X_internal);
}
/// \brief R(i,j) = abs(X(i,j))
///
/// Replace each entry in R with the absolute value (magnitude) of the
/// corresponding entry in X.
///
/// \tparam RMV 1-D or 2-D Kokkos::View specialization.
/// \tparam XMV 1-D or 2-D Kokkos::View specialization. It must have
/// the same rank as RMV, and its entries must be assignable to
/// those of RMV.
template<class RMV, class XMV>
void
abs (const RMV& R, const XMV& X)
{
static_assert (Kokkos::Impl::is_view<RMV>::value, "KokkosBlas::abs: "
"R is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_view<XMV>::value, "KokkosBlas::abs: "
"X is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_same<typename RMV::value_type,
typename RMV::non_const_value_type>::value,
"KokkosBlas::abs: R is const. "
"It must be nonconst, because it is an output argument "
"(we have to be able to write to its entries).");
static_assert (RMV::rank == XMV::rank, "KokkosBlas::abs: "
"R and X must have the same rank.");
static_assert (RMV::rank == 1 || RMV::rank == 2, "KokkosBlas::abs: "
"RMV and XMV must either have rank 1 or rank 2.");
// Check compatibility of dimensions at run time.
if (X.dimension_0 () != R.dimension_0 () ||
X.dimension_1 () != R.dimension_1 ()) {
std::ostringstream os;
os << "KokkosBlas::abs (MV): Dimensions of R and X do not match: "
<< "R: " << R.dimension_0 () << " x " << R.dimension_1 ()
<< ", X: " << X.dimension_0 () << " x " << X.dimension_1 ();
Kokkos::Impl::throw_runtime_exception (os.str ());
}
// Create unmanaged versions of the input Views. RMV and XMV may be
// rank 1 or rank 2.
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
RMV::rank == 1,
typename RMV::non_const_value_type*,
typename RMV::non_const_value_type** >::type,
typename RMV::array_layout,
typename RMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > RMV_Internal;
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
XMV::rank == 1,
typename XMV::non_const_value_type*,
typename XMV::non_const_value_type** >::type,
typename XMV::array_layout,
typename XMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > XMV_Internal;
RMV_Internal R_internal = R;
XMV_Internal X_internal = X;
#ifdef TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
using std::cerr;
using std::endl;
cerr << "KokkosBlas::abs:" << endl
<< " RMV_Internal: " << demangledTypeName (R_internal) << endl
<< " XMV_Internal: " << demangledTypeName (X_internal) << endl
<< endl;
#endif // TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
Impl::Abs<RMV_Internal, XMV_Internal>::abs (R_internal, X_internal);
}
/// \brief Compute Z := alpha*X + beta*Y + gamma*Z.
///
/// \tparam XMV 1-D or 2-D Kokkos::View specialization.
/// \tparam YMV 1-D or 2-D Kokkos::View specialization. It must have
/// the same rank as XMV.
/// \tparam ZMV 1-D or 2-D Kokkos::View specialization. It must have
/// the same rank as XMV and YMV, and it must make sense to add up
/// the entries of XMV and YMV and assign them to the entries of
/// ZMV.
template<class XMV, class YMV, class ZMV>
void
update (const typename XMV::non_const_value_type& alpha, const XMV& X,
const typename YMV::non_const_value_type& beta, const YMV& Y,
const typename ZMV::non_const_value_type& gamma, const ZMV& Z)
{
static_assert (Kokkos::Impl::is_view<XMV>::value, "KokkosBlas::update: "
"X is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_view<YMV>::value, "KokkosBlas::update: "
"Y is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_view<ZMV>::value, "KokkosBlas::update: "
"Z is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_same<typename ZMV::value_type,
typename ZMV::non_const_value_type>::value,
"KokkosBlas::update: Z is const. "
"It must be nonconst, because it is an output argument "
"(we have to be able to write to its entries).");
static_assert (ZMV::rank == XMV::rank, "KokkosBlas::update: "
"X and Z must have the same rank.");
static_assert (ZMV::rank == YMV::rank, "KokkosBlas::update: "
"Y and Z must have the same rank.");
static_assert (ZMV::rank == 1 || ZMV::rank == 2, "KokkosBlas::update: "
"XMV, YMV, and ZMV must either have rank 1 or rank 2.");
// Check compatibility of dimensions at run time.
if (X.dimension_0 () != Y.dimension_0 () ||
X.dimension_1 () != Y.dimension_1 () ||
X.dimension_0 () != Z.dimension_0 () ||
X.dimension_1 () != Z.dimension_1 ()) {
std::ostringstream os;
os << "KokkosBlas::update (MV): Dimensions of X, Y, and Z do not match: "
<< "Z: " << Z.dimension_0 () << " x " << Z.dimension_1 ()
<< ", X: " << X.dimension_0 () << " x " << X.dimension_1 ()
<< ", Y: " << Y.dimension_0 () << " x " << Y.dimension_1 ();
Kokkos::Impl::throw_runtime_exception (os.str ());
}
// Create unmanaged versions of the input Views. XMV, YMV, and ZMV
// may be rank 1 or rank 2, but they must all have the same rank.
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
XMV::rank == 1,
typename XMV::const_value_type*,
typename XMV::const_value_type** >::type,
typename XMV::array_layout,
typename XMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > XMV_Internal;
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
YMV::rank == 1,
typename YMV::const_value_type*,
typename YMV::const_value_type** >::type,
typename YMV::array_layout,
typename YMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > YMV_Internal;
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
ZMV::rank == 1,
typename ZMV::non_const_value_type*,
typename ZMV::non_const_value_type** >::type,
typename ZMV::array_layout,
typename ZMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > ZMV_Internal;
XMV_Internal X_internal = X;
YMV_Internal Y_internal = Y;
ZMV_Internal Z_internal = Z;
#ifdef TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
using std::cerr;
using std::endl;
cerr << "KokkosBlas::update:" << endl
<< " XMV_Internal: " << demangledTypeName (X_internal) << endl
<< " YMV_Internal: " << demangledTypeName (Y_internal) << endl
<< " ZMV_Internal: " << demangledTypeName (Z_internal) << endl
<< endl;
#endif // TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
return Impl::Update<XMV_Internal, YMV_Internal,
ZMV_Internal>::update (alpha, X_internal, beta, Y_internal,
gamma, Z_internal);
}
/// \brief R(i,j) = 1 / X(i,j)
///
/// Replace each entry in R with the reciprocal of the corresponding
/// entry in X.
template<class RMV, class XMV>
void
reciprocal (const RMV& R, const XMV& X)
{
static_assert (Kokkos::Impl::is_view<RMV>::value, "KokkosBlas::reciprocal: "
"R is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_view<XMV>::value, "KokkosBlas::reciprocal: "
"X is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_same<typename RMV::value_type,
typename RMV::non_const_value_type>::value,
"KokkosBlas::reciprocal: R is const. "
"It must be nonconst, because it is an output argument "
"(we have to be able to write to its entries).");
static_assert (RMV::rank == XMV::rank, "KokkosBlas::reciprocal: "
"R and X must have the same rank.");
static_assert (RMV::rank == 1 || RMV::rank == 2, "KokkosBlas::reciprocal: "
"RMV and XMV must either have rank 1 or rank 2.");
// Check compatibility of dimensions at run time.
if (X.dimension_0 () != R.dimension_0 () ||
X.dimension_1 () != R.dimension_1 ()) {
std::ostringstream os;
os << "KokkosBlas::reciprocal (MV): Dimensions of R and X do not match: "
<< "R: " << R.dimension_0 () << " x " << R.dimension_1 ()
<< ", X: " << X.dimension_0 () << " x " << X.dimension_1 ();
Kokkos::Impl::throw_runtime_exception (os.str ());
}
// Create unmanaged versions of the input Views. RMV and XMV may be
// rank 1 or rank 2.
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
RMV::rank == 1,
typename RMV::non_const_value_type*,
typename RMV::non_const_value_type** >::type,
typename RMV::array_layout,
typename RMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > RMV_Internal;
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
XMV::rank == 1,
typename XMV::non_const_value_type*,
typename XMV::non_const_value_type** >::type,
typename XMV::array_layout,
typename XMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > XMV_Internal;
RMV_Internal R_internal = R;
XMV_Internal X_internal = X;
#ifdef TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
using std::cerr;
using std::endl;
cerr << "KokkosBlas::reciprocal:" << endl
<< " RMV_Internal: " << demangledTypeName (R_internal) << endl
<< " XMV_Internal: " << demangledTypeName (X_internal) << endl
<< endl;
#endif // TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
Impl::Reciprocal<RMV_Internal, XMV_Internal>::reciprocal (R_internal, X_internal);
}
//! Compute sum of each column of X, and write to corresponding entry of R.
template<class RV, class XMV>
void
sum (const RV& R, const XMV& X)
{
static_assert (Kokkos::Impl::is_view<RV>::value, "KokkosBlas::sum: "
"R is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_view<XMV>::value, "KokkosBlas::sum: "
"X is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_same<typename RV::value_type,
typename RV::non_const_value_type>::value,
"KokkosBlas::sum: R is const. "
"It must be nonconst, because it is an output argument "
"(we have to be able to write to its entries).");
static_assert ((RV::rank == 0 && XMV::rank == 1) || (RV::rank == 1 && XMV::rank == 2),
"KokkosBlas::sum: Ranks of R and X do not match.");
// Check compatibility of dimensions at run time.
if (RV::rank == 1 && R.dimension_0 () != X.dimension_1 ()) {
std::ostringstream os;
os << "KokkosBlas::sum: Dimensions of R and X do not match: ";
os << "R: " << R.dimension_0 () << " x 1, "
<< "X: " << X.dimension_0 () << " x " << X.dimension_1 ();
Kokkos::Impl::throw_runtime_exception (os.str ());
}
// Create unmanaged versions of the input Views. XMV may be rank 1
// or rank 2, and RV may be rank 0 or rank 1.
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
RV::rank == 0,
typename RV::non_const_value_type,
typename RV::non_const_value_type* >::type,
typename RV::array_layout,
typename RV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > RV_Internal;
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
XMV::rank == 1,
typename XMV::const_value_type*,
typename XMV::const_value_type** >::type,
typename XMV::array_layout,
typename XMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > XMV_Internal;
RV_Internal R_internal = R;
XMV_Internal X_internal = X;
#ifdef TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
using std::cerr;
using std::endl;
cerr << "KokkosBlas::sum:" << endl
<< " RV_Internal: " << demangledTypeName (R_internal) << endl
<< " XMV_Internal: " << demangledTypeName (X_internal) << endl
<< endl;
#endif // TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
Impl::Sum<RV_Internal, XMV_Internal>::sum (R_internal, X_internal);
}
/// \brief Compute the "weighted 2-norm" of each column of X, using
/// weights in the corresponding column of W, and write the result
/// to the corresponding entry of R.
///
/// For single vectors X and W, the "weighted 2-norm" is the 2-norm of
/// the entry-wise quotient X(i) / W(i). X and W have the same type.
template<class RV, class XMV>
void
nrm2w_squared (const RV& R, const XMV& X, const XMV& W)
{
static_assert (Kokkos::Impl::is_view<RV>::value, "KokkosBlas::nrm2w_squared: "
"R is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_view<XMV>::value, "KokkosBlas::nrm2w_squared: "
"X is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_same<typename RV::value_type,
typename RV::non_const_value_type>::value,
"KokkosBlas::nrm2w_squared: R is const. "
"It must be nonconst, because it is an output argument "
"(we have to be able to write to its entries).");
static_assert ((RV::rank == 0 && XMV::rank == 1) || (RV::rank == 1 && XMV::rank == 2),
"KokkosBlas::nrm2w_squared: Ranks of R and X do not match. "
"If R has rank 0, X and W must have rank 1. "
"If R has rank 1, X and W must have rank 2.");
// Check compatibility of dimensions at run time.
if (X.dimension_0 () != W.dimension_0 () ||
X.dimension_1 () != W.dimension_1 () ||
R.dimension_0 () != X.dimension_1 ()) {
std::ostringstream os;
os << "KokkosBlas::nrm2w_squared: Dimensions do not match: "
<< "R: " << R.dimension_0 () << " x 1"
<< ", X: " << X.dimension_0 () << " x " << X.dimension_1 ()
<< ", W: " << W.dimension_0 () << " x " << W.dimension_1 ();
Kokkos::Impl::throw_runtime_exception (os.str ());
}
// Create unmanaged versions of the input Views. XMV may be rank 1
// or rank 2, and RV may be rank 0 or rank 1.
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
RV::rank == 0,
typename RV::non_const_value_type,
typename RV::non_const_value_type* >::type,
typename RV::array_layout,
typename RV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > RV_Internal;
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
XMV::rank == 1,
typename XMV::const_value_type*,
typename XMV::const_value_type** >::type,
typename XMV::array_layout,
typename XMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > XMV_Internal;
RV_Internal R_internal = R;
XMV_Internal X_internal = X;
XMV_Internal W_internal = W;
#ifdef TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
using std::cerr;
using std::endl;
cerr << "KokkosBlas::nrm2w_squared:" << endl
<< " RV_Internal: " << demangledTypeName (R_internal) << endl
<< " XMV_Internal: " << demangledTypeName (X_internal) << endl
<< endl;
#endif // TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
Impl::Nrm2w<RV_Internal, XMV_Internal>::nrm2w_squared (R_internal, X_internal, W_internal);
}
template<class CMV, class AV, class BMV>
void
mult (typename CMV::const_value_type& c,
const CMV& C,
typename AV::const_value_type& ab,
const AV& A,
const BMV& B)
{
static_assert (Kokkos::Impl::is_view<CMV>::value, "KokkosBlas::mult: "
"C is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_view<AV>::value, "KokkosBlas::mult: "
"A is not a Kokkos::View.");
static_assert (Kokkos::Impl::is_same<typename CMV::value_type,
typename CMV::non_const_value_type>::value,
"KokkosBlas::mult: C is const. "
"It must be nonconst, because it is an output argument "
"(we have to be able to write to its entries).");
static_assert ((BMV::rank == 1 && CMV::rank == 1) ||
(BMV::rank == 2 && CMV::rank == 2),
"KokkosBlas::mult: C and B must be either both rank 1, "
"or both rank 2.");
static_assert (AV::rank == 1, "KokkosBlas::mult: A must have rank 1.");
// Check compatibility of dimensions at run time.
if (C.dimension_0 () != A.dimension_0 () ||
C.dimension_0 () != B.dimension_0 () ||
C.dimension_1 () != B.dimension_1 ()) {
std::ostringstream os;
os << "KokkosBlas::mult: Dimensions do not match: "
<< "C: " << C.dimension_0 () << " x " << C.dimension_1 ()
<< ", A: " << A.dimension_0 () << " x " << A.dimension_0 ()
<< ", B: " << B.dimension_0 () << " x " << B.dimension_1 ();
Kokkos::Impl::throw_runtime_exception (os.str ());
}
// Create unmanaged versions of the input Views.
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
CMV::rank == 1,
typename CMV::non_const_value_type*,
typename CMV::non_const_value_type** >::type,
typename CMV::array_layout,
typename CMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > CMV_Internal;
typedef Kokkos::View<
typename AV::const_value_type*,
typename AV::array_layout,
typename AV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > AV_Internal;
typedef Kokkos::View<
typename Kokkos::Impl::if_c<
BMV::rank == 1,
typename BMV::const_value_type*,
typename BMV::const_value_type** >::type,
typename BMV::array_layout,
typename BMV::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> > BMV_Internal;
CMV_Internal C_internal = C;
AV_Internal A_internal = A;
BMV_Internal B_internal = B;
#ifdef TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
using std::cerr;
using std::endl;
cerr << "KokkosBlas::mult:" << endl
<< " CMV_Internal: " << demangledTypeName (C_internal) << endl
<< " AV_Internal: " << demangledTypeName (A_internal) << endl
<< " BMV_Internal: " << demangledTypeName (B_internal) << endl
<< endl;
#endif // TPETRAKERNELS_PRINT_DEMANGLED_TYPE_INFO
Impl::Mult<CMV_Internal, AV_Internal, BMV_Internal>::mult (c, C_internal, ab,
A_internal, B_internal);
}
} // namespace KokkosBlas
#endif // KOKKOS_BLAS1_MV_HPP_
|