-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathhint_tests.cc
69 lines (59 loc) · 2.41 KB
/
hint_tests.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_all.hpp>
#include "handler.h"
#include "hint.h"
#include "task.h"
using namespace celerity;
using namespace celerity::detail;
class my_hint : public detail::hint_base {
public:
my_hint(int value) : m_value(value) {}
int get_value() const { return m_value; }
private:
int m_value;
};
class my_other_hint : public detail::hint_base {
private:
void validate(const hint_base& other) const override {
if(auto ptr = dynamic_cast<const my_hint*>(&other); ptr != nullptr) {
if(ptr->get_value() != 1337) throw std::runtime_error("not leet enough");
}
}
};
TEST_CASE("hints can be attached to and retrieved from tasks", "[handler][task-hints]") {
auto cg = invoke_command_group_function([](handler& cgh) {
experimental::hint(cgh, my_hint{1337});
cgh.parallel_for(range<1>{1}, [](item<1>) {});
});
const auto tsk = make_command_group_task(task_id(1), 1 /* num_collective_nodes */, std::move(cg));
const auto hint = tsk->get_hint<my_hint>();
REQUIRE(hint != nullptr);
CHECK(hint->get_value() == 1337);
}
TEST_CASE("providing a hint of a particular type more than once throws", "[handler][task-hints]") {
invoke_command_group_function([](handler& cgh) {
CHECK_NOTHROW(experimental::hint(cgh, my_hint{1337}));
CHECK_NOTHROW(experimental::hint(cgh, my_other_hint{}));
CHECK_THROWS_WITH(experimental::hint(cgh, my_hint{1337}), "Providing more than one hint of the same type is not allowed");
});
}
TEST_CASE("hints can ensure combinations with other hints are valid", "[handler][task-hints]") {
invoke_command_group_function([](handler& cgh) {
CHECK_NOTHROW(experimental::hint(cgh, my_other_hint{}));
CHECK_THROWS_WITH(experimental::hint(cgh, my_hint{1336}), "not leet enough");
});
}
TEST_CASE("split_1d and split_2d hints cannot be combined", "[handler][task-hints]") {
SECTION("1d then 2d") {
invoke_command_group_function([](handler& cgh) {
CHECK_NOTHROW(experimental::hint(cgh, experimental::hints::split_1d{}));
CHECK_THROWS_WITH(experimental::hint(cgh, experimental::hints::split_2d{}), "Cannot combine split_1d and split_2d hints");
});
}
SECTION("2d then 1d") {
invoke_command_group_function([](handler& cgh) {
CHECK_NOTHROW(experimental::hint(cgh, experimental::hints::split_2d{}));
CHECK_THROWS_WITH(experimental::hint(cgh, experimental::hints::split_1d{}), "Cannot combine split_1d and split_2d hints");
});
}
}