diff --git a/example/wiki/blas/CMakeLists.txt b/example/wiki/blas/CMakeLists.txt index 245957bc89..48ba85f4d6 100644 --- a/example/wiki/blas/CMakeLists.txt +++ b/example/wiki/blas/CMakeLists.txt @@ -3,6 +3,21 @@ KOKKOSKERNELS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) KOKKOSKERNELS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../../../test_common) +KOKKOSKERNELS_ADD_EXECUTABLE_AND_TEST( + wiki_blas1_iamax + SOURCES KokkosBlas1_wiki_iamax.cpp + ) + +KOKKOSKERNELS_ADD_EXECUTABLE_AND_TEST( + wiki_blas1_nrm1 + SOURCES KokkosBlas1_wiki_nrm1.cpp + ) + +KOKKOSKERNELS_ADD_EXECUTABLE_AND_TEST( + wiki_blas1_nrm2 + SOURCES KokkosBlas1_wiki_nrm2.cpp + ) + KOKKOSKERNELS_ADD_EXECUTABLE_AND_TEST( wiki_blas2_ger SOURCES KokkosBlas2_wiki_ger.cpp diff --git a/example/wiki/blas/KokkosBlas1_wiki_iamax.cpp b/example/wiki/blas/KokkosBlas1_wiki_iamax.cpp new file mode 100644 index 0000000000..9e2e3e42b1 --- /dev/null +++ b/example/wiki/blas/KokkosBlas1_wiki_iamax.cpp @@ -0,0 +1,43 @@ +#include +#include +#include + +int main(int argc, char* argv[]) { + Kokkos::initialize(); + { + int N = 100; + if (argc >= 2) { + N = atoi(argv[1]); + } + + using ViewType = Kokkos::View; + using Scalar = typename ViewType::non_const_value_type; + using AT = Kokkos::ArithTraits; + using mag_type = typename AT::mag_type; + using size_type = typename ViewType::size_type; + + ViewType x("X", N); + + typename ViewType::HostMirror h_x = Kokkos::create_mirror_view(x); + + Kokkos::Random_XorShift64_Pool rand_pool(13718); + Kokkos::fill_random(x, rand_pool, Scalar(10)); + + Kokkos::deep_copy(h_x, x); + + size_type max_loc = KokkosBlas::iamax(x); + + mag_type expected_result = Kokkos::ArithTraits::min(); + size_type expected_max_loc = 0; + for (int i = 0; i < N; i++) { + mag_type val = AT::abs(h_x(i)); + if (val > expected_result) { + expected_result = val; + expected_max_loc = i + 1; + } + } + + printf("Iamax of X: %i, Expected: %i\n", max_loc, expected_max_loc); + } + Kokkos::finalize(); +} diff --git a/example/wiki/blas/KokkosBlas1_wiki_nrm1.cpp b/example/wiki/blas/KokkosBlas1_wiki_nrm1.cpp new file mode 100644 index 0000000000..99d147236f --- /dev/null +++ b/example/wiki/blas/KokkosBlas1_wiki_nrm1.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +int main(void) { + Kokkos::initialize(); + { + Kokkos::View x("X", 100); + Kokkos::deep_copy(x, -3.0); + + double x_nrm = KokkosBlas::nrm1(x); + + std::cout << "X_nrm: " << x_nrm << " Expected: " << 100 * 3.0 << std::endl; + } + Kokkos::finalize(); +} diff --git a/example/wiki/blas/KokkosBlas1_wiki_nrm2.cpp b/example/wiki/blas/KokkosBlas1_wiki_nrm2.cpp new file mode 100644 index 0000000000..5715c94dcb --- /dev/null +++ b/example/wiki/blas/KokkosBlas1_wiki_nrm2.cpp @@ -0,0 +1,17 @@ +#include +#include +#include +#include + +int main(void) { + Kokkos::initialize(); + { + Kokkos::View x("X", 100); + Kokkos::deep_copy(x, 3.0); + + double x_nrm = KokkosBlas::nrm2(x); + + std::cout << "X_nrm: " << x_nrm << " Expected: " << std::sqrt(100 * 3.0 * 3.0) << std::endl; + } + Kokkos::finalize(); +}