Skip to content

Commit

Permalink
Port GramSchmidt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cz4rs committed Feb 6, 2023
1 parent 62b8421 commit 36bc91e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 63 deletions.
3 changes: 1 addition & 2 deletions core/perf_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ IF(KOKKOS_ENABLE_TESTS)

SET(SOURCES
PerfTestMain.cpp
PerfTestGramSchmidt.cpp
PerfTest_ExecSpacePartitioning.cpp
)


IF(Kokkos_ENABLE_OPENMPTARGET)
# FIXME OPENMPTARGET requires TeamPolicy Reductions and Custom Reduction
LIST(REMOVE_ITEM SOURCES
Expand Down Expand Up @@ -176,6 +174,7 @@ SET(
BENCHMARK_SOURCES
BenchmarkMain.cpp
Benchmark_Context.cpp
PerfTestGramSchmidt.cpp
PerfTest_CustomReduction.cpp
PerfTestHexGrad.cpp
PerfTest_ViewAllocate.cpp
Expand Down
87 changes: 26 additions & 61 deletions core/perf_test/PerfTestGramSchmidt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//@HEADER

#include <Kokkos_Core.hpp>
#include <gtest/gtest.h>
#include <benchmark/benchmark.h>
#include <PerfTest_Category.hpp>

#include <cmath>
Expand Down Expand Up @@ -137,87 +137,52 @@ struct ModifiedGramSchmidt {

//--------------------------------------------------------------------------

static double test(const size_type length, const size_type count,
const size_t iter = 1) {
static double test(const size_type length, const size_type count) {
multivector_type Q_("Q", length, count);
multivector_type R_("R", count, count);

typename multivector_type::HostMirror A = Kokkos::create_mirror(Q_);

// Create and fill A on the host

for (size_type j = 0; j < count; ++j) {
for (size_type i = 0; i < length; ++i) {
A(i, j) = (i + 1) * (j + 1);
}
}

double dt_min = 0;

for (size_t i = 0; i < iter; ++i) {
Kokkos::deep_copy(Q_, A);

// A = Q * R
Kokkos::deep_copy(Q_, A);

const double dt = factorization(Q_, R_);
// A = Q * R
const double dt = factorization(Q_, R_);

if (0 == i)
dt_min = dt;
else
dt_min = dt < dt_min ? dt : dt_min;
}

return dt_min;
return dt;
}
};

template <class DeviceType>
void run_test_gramschmidt(int exp_beg, int exp_end, int num_trials,
const char deviceTypeName[]) {
template <class Scalar>
static void GramSchmidt(benchmark::State& state) {
std::string label_gramschmidt;
label_gramschmidt.append("\"GramSchmidt< double , ");
label_gramschmidt.append(deviceTypeName);
label_gramschmidt.append(" >\"");

for (int i = exp_beg; i < exp_end; ++i) {
double min_seconds = 0.0;
double max_seconds = 0.0;
double avg_seconds = 0.0;

const int parallel_work_length = 1 << i;

for (int j = 0; j < num_trials; ++j) {
const double seconds = ModifiedGramSchmidt<double, DeviceType>::test(
parallel_work_length, 32);

if (0 == j) {
min_seconds = seconds;
max_seconds = seconds;
} else {
if (seconds < min_seconds) min_seconds = seconds;
if (seconds > max_seconds) max_seconds = seconds;
}
avg_seconds += seconds;
}
avg_seconds /= num_trials;

std::cout << label_gramschmidt << " , " << parallel_work_length << " , "
<< min_seconds << " , " << (min_seconds / parallel_work_length)
<< ", " << avg_seconds << std::endl;
}
}

TEST(default_exec, gramschmidt) {
int exp_beg = 10;
int exp_end = 20;
int num_trials = 5;
const int parallel_work_length = state.range(0);

if (command_line_num_args() > 1) exp_beg = std::stoi(command_line_arg(1));
if (command_line_num_args() > 2) exp_end = std::stoi(command_line_arg(2));
if (command_line_num_args() > 3) num_trials = std::stoi(command_line_arg(3));
for (auto _ : state) {
const double seconds =
ModifiedGramSchmidt<Scalar, Kokkos::DefaultExecutionSpace>::test(
parallel_work_length, 32);

EXPECT_NO_THROW(run_test_gramschmidt<Kokkos::DefaultExecutionSpace>(
exp_beg, exp_end, num_trials, Kokkos::DefaultExecutionSpace::name()));
state.SetIterationTime(seconds);
state.counters["Count"] = benchmark::Counter(parallel_work_length);
state.counters["Time normalized"] =
benchmark::Counter(seconds / parallel_work_length);
}
}

BENCHMARK(GramSchmidt<double>)
->ArgName("Count")
->ArgsProduct({
benchmark::CreateRange(1 << 10, 1 << 19, 2),
})
->UseManualTime()
->Iterations(5);

} // namespace Test

0 comments on commit 36bc91e

Please sign in to comment.