Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bea67ed

Browse files
committed
Updated Oracle to work with new spaces of Morpheus_Core
1 parent 4688c39 commit bea67ed

11 files changed

+106
-40
lines changed

examples/run-first-tuner/run_first_tuner.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,17 @@
2424
#include <Morpheus_Oracle.hpp>
2525

2626
#if defined(EXAMPLE_ENABLE_SERIAL)
27-
using Space = Kokkos::Serial;
27+
using Space = Morpheus::Serial;
2828
#elif defined(EXAMPLE_ENABLE_OPENMP)
29-
using Space = Kokkos::OpenMP;
29+
using Space = Morpheus::OpenMP;
3030
#elif defined(EXAMPLE_ENABLE_CUDA)
31-
using Space = Kokkos::Cuda;
31+
using Space = Morpheus::Cuda;
3232
#elif defined(EXAMPLE_ENABLE_HIP)
33-
using Space = Kokkos::HIP;
33+
using Space = Morpheus::HIP;
3434
#endif
3535

36-
using memory_space = typename Space::memory_space;
37-
using DynamicMatrix = Morpheus::DynamicMatrix<double, memory_space>;
38-
using CooMatrix = Morpheus::CooMatrix<double, memory_space>;
36+
using backend = typename Space::backend;
37+
using DynamicMatrix = Morpheus::DynamicMatrix<double, backend>;
3938

4039
int main(int argc, char* argv[]) {
4140
Morpheus::initialize();
@@ -60,21 +59,20 @@ int main(int argc, char* argv[]) {
6059
std::cout << "\tFilename : " << filename << "\n";
6160
std::cout << "\tVerbosity : " << (verbose ? "ON" : "OFF") << "\n\n";
6261

63-
typename CooMatrix::HostMirror Acoo_h;
62+
typename DynamicMatrix::HostMirror Ah;
6463
try {
65-
Morpheus::IO::read_matrix_market_file(Acoo_h, filename);
64+
Morpheus::IO::read_matrix_market_file(Ah, filename);
6665
} catch (Morpheus::NotImplementedException& e) {
6766
std::cerr << "Exception Raised:: " << e.what() << std::endl;
6867
exit(0);
6968
}
7069

71-
typename DynamicMatrix::HostMirror A_h = Acoo_h;
72-
DynamicMatrix A = Morpheus::create_mirror<Space>(A_h);
73-
Morpheus::copy(A_h, A);
70+
DynamicMatrix A = Morpheus::create_mirror<Space>(Ah);
71+
Morpheus::copy(Ah, A);
7472

7573
Morpheus::Oracle::RunFirstTuner tuner(reps, verbose);
7674

77-
Morpheus::Oracle::tune_multiply<Kokkos::Serial>(A, tuner);
75+
Morpheus::Oracle::tune_multiply<Morpheus::Serial>(A, tuner);
7876
tuner.print();
7977
}
8078
Morpheus::finalize();

main.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <functional>
2+
#include <iostream>
3+
using namespace std;
4+
5+
struct A {};
6+
struct B {};
7+
struct C {};
8+
9+
namespace Impl {
10+
template <typename T1, typename T2>
11+
void f(T2 b,
12+
typename std::enable_if<std::is_same<T1, A>::value>::type* = nullptr) {
13+
std::cout << "Was here in A" << std::endl;
14+
}
15+
16+
template <typename T1, typename T2>
17+
void f(T2 b,
18+
typename std::enable_if<std::is_same<T1, C>::value>::type* = nullptr) {
19+
std::cout << "Was here in C" << std::endl;
20+
}
21+
} // namespace Impl
22+
23+
template <typename T1, typename T2>
24+
void f(T2 b) {
25+
Impl::f<T1>(b);
26+
}
27+
28+
template <typename T>
29+
void invoke_f(std::function<void(T)> f, B& t) {
30+
f(t);
31+
}
32+
33+
int main() {
34+
B t;
35+
f<A>(t);
36+
f<C>(t);
37+
38+
// std::function<void(int)> f_display = print_num;
39+
std::function<void(B)> f_ptr_A = f<A, B>;
40+
f_ptr_A(t);
41+
42+
std::function<void(B)> f_ptr_C = f<C, B>;
43+
f_ptr_C(t);
44+
45+
invoke_f(f_ptr_A, t);
46+
invoke_f(f_ptr_C, t);
47+
return 0;
48+
}

src/MorpheusOracle_RunFirstTuner.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#ifndef MORPHEUSORACLE_RUNFIRSTTUNER_HPP
2525
#define MORPHEUSORACLE_RUNFIRSTTUNER_HPP
2626

27+
#include <Morpheus_Core.hpp>
28+
2729
#include <iomanip>
2830
#include <iostream>
2931
#include <limits>
@@ -92,7 +94,7 @@ namespace Oracle {
9294
class RunFirstTuner {
9395
public:
9496
/*! A two-dimensional vector of doubles */
95-
using vec2d = Morpheus::DenseMatrix<double, int, Kokkos::HostSpace>;
97+
using vec2d = Morpheus::DenseMatrix<double, size_t, Kokkos::HostSpace>;
9698
/*! A one-dimensional vector of doubles */
9799
using vec = Morpheus::DenseVector<double, Kokkos::HostSpace>;
98100

src/MorpheusOracle_TuneMultiply.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ template <typename ExecSpace, typename DynamicMatrix, typename Tuner>
4545
void tune_multiply(DynamicMatrix& mat, Tuner& tuner) {
4646
static_assert(Morpheus::is_dynamic_matrix_container<DynamicMatrix>::value,
4747
"Input Matrix for the tuner must be a valid DynamicMatrix.");
48-
static_assert(Morpheus::is_execution_space<ExecSpace>::value,
49-
"Input Execution Space must be a valid Execution Space.");
48+
static_assert(
49+
Morpheus::is_execution_space<typename ExecSpace::execution_space>::value,
50+
"Input Execution Space must be a valid Execution Space.");
5051

5152
Impl::tune_multiply<ExecSpace>(mat, tuner);
5253
}

src/impl/RunFirst/MorpheusOracle_TuneMultiply_Impl.hpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <MorpheusOracle_TypeTraits.hpp>
2828

2929
#include <chrono>
30+
#include <limits>
3031

3132
namespace Morpheus {
3233
namespace Oracle {
@@ -47,29 +48,37 @@ void tune_multiply(
4748

4849
vector x(mat.ncols(), value_type(2)), y(mat.nrows(), value_type(0));
4950

50-
auto mat_mirror = Morpheus::create_mirror<typename Matrix::execution_space>(mat);
51+
auto mat_mirror =
52+
Morpheus::create_mirror<typename Matrix::execution_space>(mat);
5153
Morpheus::copy(mat, mat_mirror);
5254

5355
auto mat_mirror_h = Morpheus::create_mirror_container(mat_mirror);
5456
Morpheus::copy(mat_mirror, mat_mirror_h);
5557

5658
size_t current_format = Morpheus::Oracle::RunFirstTuner::INVALID_FORMAT_STATE;
59+
Morpheus::conversion_error_e status = Morpheus::CONV_SUCCESS;
5760
while (!tuner.finished()) {
5861
if (current_format != tuner.format_count()) {
5962
// Convert only when we start a new format_count
60-
Morpheus::convert<Kokkos::Serial>(mat_mirror_h, tuner.format_count());
61-
mat_mirror.activate(mat_mirror_h.active_index());
62-
mat_mirror.resize(mat_mirror_h);
63-
Morpheus::copy(mat_mirror_h, mat_mirror);
64-
current_format = tuner.format_count();
63+
status = Morpheus::convert<Morpheus::Serial>(mat_mirror_h,
64+
tuner.format_count());
65+
if (status == Morpheus::CONV_SUCCESS) {
66+
mat_mirror.activate(mat_mirror_h.active_index());
67+
mat_mirror.resize(mat_mirror_h);
68+
Morpheus::copy(mat_mirror_h, mat_mirror);
69+
current_format = tuner.format_count();
70+
}
6571
}
72+
double runtime;
73+
if (status == Morpheus::CONV_SUCCESS) {
74+
auto start = std::chrono::steady_clock::now();
75+
Morpheus::multiply<ExecSpace>(mat_mirror, x, y, true);
76+
auto end = std::chrono::steady_clock::now();
6677

67-
auto start = std::chrono::steady_clock::now();
68-
Morpheus::multiply<ExecSpace>(mat_mirror, x, y, true);
69-
auto end = std::chrono::steady_clock::now();
70-
71-
double runtime = std::chrono::duration_cast<ns>(end - start).count() * 1e-9;
72-
78+
runtime = std::chrono::duration_cast<ns>(end - start).count() * 1e-9;
79+
} else {
80+
runtime = std::numeric_limits<double>::max();
81+
}
7382
tuner.register_run(runtime);
7483
++tuner;
7584
}

tests/Test_RunFirstTuner.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ TEST(RunFirstTunerTest, DefaultConstruction) {
3737
EXPECT_EQ(tuner.timings().nrows(), nfmts);
3838
EXPECT_EQ(tuner.timings().ncols(), reps);
3939
// Check timings values
40-
for (auto i = 0; i < tuner.timings().nrows(); i++) {
41-
for (auto j = 0; j < tuner.timings().ncols(); j++) {
40+
for (size_t i = 0; i < tuner.timings().nrows(); i++) {
41+
for (size_t j = 0; j < tuner.timings().ncols(); j++) {
4242
EXPECT_EQ(tuner.timings()(i, j), 0);
4343
}
4444
}
@@ -79,8 +79,8 @@ TEST(RunFirstTunerTest, Construction) {
7979
EXPECT_EQ(tuner.timings().nrows(), nfmts);
8080
EXPECT_EQ(tuner.timings().ncols(), reps);
8181
// Check timings values
82-
for (auto i = 0; i < tuner.timings().nrows(); i++) {
83-
for (auto j = 0; j < tuner.timings().ncols(); j++) {
82+
for (size_t i = 0; i < tuner.timings().nrows(); i++) {
83+
for (size_t j = 0; j < tuner.timings().ncols(); j++) {
8484
EXPECT_EQ(tuner.timings()(i, j), 0);
8585
}
8686
}
@@ -199,8 +199,8 @@ TEST(RunFirstTunerTest, Reset) {
199199
EXPECT_EQ(tuner.timings().nrows(), nfmts);
200200
EXPECT_EQ(tuner.timings().ncols(), reps);
201201
// Check timings values
202-
for (auto i = 0; i < tuner.timings().nrows(); i++) {
203-
for (auto j = 0; j < tuner.timings().ncols(); j++) {
202+
for (size_t i = 0; i < tuner.timings().nrows(); i++) {
203+
for (size_t j = 0; j < tuner.timings().ncols(); j++) {
204204
EXPECT_EQ(tuner.timings()(i, j), 0);
205205
}
206206
}

tests/Test_TuneMultiply.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
#include <Morpheus_Oracle.hpp>
2828

2929
TEST(TuneMultiply, RunFirstTuner) {
30-
using memory_space = typename TEST_EXECSPACE::memory_space;
31-
using DynamicMatrix = Morpheus::DynamicMatrix<double, memory_space>;
32-
using CsrMatrix = Morpheus::CsrMatrix<double, memory_space>;
30+
using backend = typename TEST_CUSTOM_EXECSPACE::backend;
31+
using DynamicMatrix = Morpheus::DynamicMatrix<double, backend>;
32+
using CsrMatrix = Morpheus::CsrMatrix<double, backend>;
3333

3434
Morpheus::Oracle::RunFirstTuner tuner(10, false);
3535
DynamicMatrix A;
@@ -55,12 +55,12 @@ TEST(TuneMultiply, RunFirstTuner) {
5555
Acsr_h.column_indices(5) = 2;
5656
Acsr_h.values(5) = 60;
5757

58-
auto Acsr = Morpheus::create_mirror_container<TEST_EXECSPACE>(Acsr_h);
58+
CsrMatrix Acsr(4, 3, 6);
5959
Morpheus::copy(Acsr_h, Acsr);
6060

6161
A = Acsr;
6262

63-
Morpheus::Oracle::tune_multiply<TEST_EXECSPACE>(A, tuner);
63+
Morpheus::Oracle::tune_multiply<TEST_CUSTOM_EXECSPACE>(A, tuner);
6464

6565
EXPECT_TRUE(tuner.finished());
6666
// Check average timings were recorded

tests/category_files/TestCuda_Category.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#define TEST_CATEGORY cuda
3030
#define TEST_CATEGORY_NUMBER 5
3131
#define TEST_EXECSPACE Kokkos::Cuda
32+
#define TEST_CUSTOM_EXECSPACE Morpheus::Custom::Cuda
33+
#define TEST_GENERIC_EXECSPACE Morpheus::Generic::Cuda
3234
#define TEST_CATEGORY_FIXTURE(name) cuda_##name
3335

3436
#endif // MORPHEUS_ORACLE_TEST_CUDA_HPP

tests/category_files/TestHIP_Category.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929
#define TEST_CATEGORY hip
3030
#define TEST_CATEGORY_NUMBER 7
31-
#define TEST_EXECSPACE Kokkos::Experimental::HIP
31+
#define TEST_EXECSPACE Kokkos::HIP
32+
#define TEST_CUSTOM_EXECSPACE Morpheus::Custom::HIP
33+
#define TEST_GENERIC_EXECSPACE Morpheus::Generic::HIP
3234
#define TEST_CATEGORY_FIXTURE(name) hip_##name
3335

3436
#endif // MORPHEUS_ORACLE_TEST_HIP_HPP

tests/category_files/TestOpenMP_Category.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#define TEST_CATEGORY openmp
3030
#define TEST_CATEGORY_NUMBER 2
3131
#define TEST_EXECSPACE Kokkos::OpenMP
32+
#define TEST_CUSTOM_EXECSPACE Morpheus::Custom::OpenMP
33+
#define TEST_GENERIC_EXECSPACE Morpheus::Generic::OpenMP
3234
#define TEST_CATEGORY_FIXTURE(name) openmp_##name
3335

3436
#endif // MORPHEUS_ORACLE_TEST_OPENMP_HPP

0 commit comments

Comments
 (0)