-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Carl Pearson <[email protected]>
- Loading branch information
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <Kokkos_Core.hpp> | ||
#include <Kokkos_Random.hpp> | ||
#include <KokkosBlas1_iamax.hpp> | ||
|
||
int main(int argc, char* argv[]) { | ||
Kokkos::initialize(); | ||
{ | ||
int N = atoi(argv[1]); | ||
|
||
using ViewType = Kokkos::View<double*>; | ||
using Scalar = typename ViewType::non_const_value_type; | ||
using AT = Kokkos::Details::ArithTraits<Scalar>; | ||
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<typename ViewType::device_type::execution_space> 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::Details::ArithTraits<mag_type>::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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <iostream> | ||
#include <Kokkos_Core.hpp> | ||
#include <KokkosBlas1_nrm1.hpp> | ||
|
||
int main(int argc, char* argv[]) { | ||
Kokkos::initialize(); | ||
{ | ||
Kokkos::View<double*> 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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <cmath> | ||
#include <iostream> | ||
#include <Kokkos_Core.hpp> | ||
#include <KokkosBlas1_nrm2.hpp> | ||
|
||
int main(int argc, char* argv[]) { | ||
Kokkos::initialize(); | ||
{ | ||
Kokkos::View<double*> 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(); | ||
} |