diff --git a/example/wiki/blas/CMakeLists.txt b/example/wiki/blas/CMakeLists.txt index 245957bc89..5061c54b7d 100644 --- a/example/wiki/blas/CMakeLists.txt +++ b/example/wiki/blas/CMakeLists.txt @@ -3,6 +3,26 @@ KOKKOSKERNELS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) KOKKOSKERNELS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../../../test_common) +KOKKOSKERNELS_ADD_EXECUTABLE_AND_TEST( + wiki_blas1_dot + SOURCES KokkosBlas1_wiki_dot.cpp + ) + +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_dot.cpp b/example/wiki/blas/KokkosBlas1_wiki_dot.cpp new file mode 100644 index 0000000000..fc0d258ac3 --- /dev/null +++ b/example/wiki/blas/KokkosBlas1_wiki_dot.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +int main(int argc, char* argv[]) { + Kokkos::initialize(); + { + int N = 100; + if (argc >= 2) { + N = atoi(argv[1]); + } + + Kokkos::View x("X", N); + Kokkos::View y("Y", N); + Kokkos::deep_copy(x, 3.0); + Kokkos::deep_copy(y, 2.0); + + double x_y = KokkosBlas::dot(x, y); + + std::cout << "X_dot_Y: " << x_y << " Expected: " << 1.0 * N * (3.0 * 2.0) + << " Diff: " << x_y - 1.0 * N * (3.0 * 2.0) << std::endl; + } + Kokkos::finalize(); +} diff --git a/example/wiki/blas/KokkosBlas1_wiki_iamax.cpp b/example/wiki/blas/KokkosBlas1_wiki_iamax.cpp new file mode 100644 index 0000000000..382db24848 --- /dev/null +++ b/example/wiki/blas/KokkosBlas1_wiki_iamax.cpp @@ -0,0 +1,44 @@ +#include +#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; + } + } + + std::cout << "Iamax of X: " << max_loc << ", Expected: " << expected_max_loc << std::endl; + } + 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(); +}