-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test marray on device #854
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,81 +31,125 @@ template <typename DataT, typename NumElementsT> | |
class run_marray_constructor_test { | ||
static constexpr std::size_t NumElements = NumElementsT::value; | ||
|
||
using marray_t = sycl::marray<DataT, NumElements>; | ||
static constexpr size_t num_test_cases = 7; | ||
|
||
private: | ||
template <size_t num_elements = NumElements, | ||
std::enable_if_t<num_elements == 1, bool> = true> | ||
void check_constexpr_single_element() {} | ||
static constexpr const char* check_names[num_test_cases] = { | ||
"default constructor", | ||
"scalar constructor", | ||
"variadic constructor (NumElements DataT instances)", | ||
"variadic constructor (one DataT instance, one marray instance)", | ||
"variadic constructor (one marray instance, one DataT instance)", | ||
"copy constructor", | ||
"copy constructor rval reference"}; | ||
|
||
template <size_t num_elements = NumElements, | ||
std::enable_if_t<num_elements != 1, bool> = true> | ||
void check_constexpr_single_element() { | ||
// one DataT instance, one marray instance | ||
{ | ||
constexpr sycl::marray<DataT, num_elements - 1> ma_const = | ||
marray_common::iota_marray<DataT, num_elements - 1, 2>(); | ||
constexpr marray_t ma{1, ma_const}; | ||
marray_t ma_inc; | ||
std::iota(ma_inc.begin(), ma_inc.end(), 1); | ||
CHECK(value_operations::are_equal(ma_inc, ma)); | ||
} | ||
|
||
// one marray instance, one DataT instance | ||
{ | ||
constexpr sycl::marray<DataT, num_elements - 1> ma_const = | ||
marray_common::iota_marray<DataT, num_elements - 1, 1>(); | ||
constexpr marray_t ma{ma_const, DataT(num_elements)}; | ||
marray_t ma_inc; | ||
std::iota(ma_inc.begin(), ma_inc.end(), 1); | ||
CHECK(value_operations::are_equal(ma_inc, ma)); | ||
} | ||
} | ||
|
||
public: | ||
void operator()(const std::string&) { | ||
INFO("for number of elements \"" << NumElements << "\": "); | ||
using marray_t = sycl::marray<DataT, NumElements>; | ||
|
||
template <typename IteratorT> | ||
static void run_checks(IteratorT results) { | ||
// default constructor | ||
{ | ||
marray_t ma; | ||
CHECK(value_operations::are_equal(ma, DataT{})); | ||
*(results++) = value_operations::are_equal(ma, DataT{}); | ||
} | ||
|
||
// scalar constructor | ||
{ | ||
constexpr DataT value{1}; | ||
constexpr marray_t ma{value}; | ||
CHECK(value_operations::are_equal(ma, value)); | ||
*(results++) = value_operations::are_equal(ma, value); | ||
} | ||
|
||
// variadic constructor | ||
{ | ||
// NumElements DataT instances | ||
constexpr auto a = marray_common::iota_marray<DataT, NumElements, 1>(); | ||
marray_t ma_inc; | ||
std::iota(ma_inc.begin(), ma_inc.end(), 1); | ||
CHECK(value_operations::are_equal(ma_inc, a)); | ||
marray_common::iota(ma_inc.begin(), ma_inc.end(), 1); | ||
*(results++) = value_operations::are_equal(ma_inc, a); | ||
|
||
// only compiled when NumElements != 1 | ||
check_constexpr_single_element(); | ||
if constexpr (NumElements != 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the problem with 1? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These test cases try to construct an
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see, by looking at the called function. |
||
// one DataT instance, one marray instance | ||
{ | ||
constexpr sycl::marray<DataT, NumElements - 1> ma_const = | ||
marray_common::iota_marray<DataT, NumElements - 1, 2>(); | ||
constexpr marray_t ma{1, ma_const}; | ||
marray_t ma_inc; | ||
marray_common::iota(ma_inc.begin(), ma_inc.end(), 1); | ||
*(results++) = value_operations::are_equal(ma_inc, ma); | ||
} | ||
|
||
// one marray instance, one DataT instance | ||
{ | ||
constexpr sycl::marray<DataT, NumElements - 1> ma_const = | ||
marray_common::iota_marray<DataT, NumElements - 1, 1>(); | ||
constexpr marray_t ma{ma_const, DataT(NumElements)}; | ||
marray_t ma_inc; | ||
marray_common::iota(ma_inc.begin(), ma_inc.end(), 1); | ||
*(results++) = value_operations::are_equal(ma_inc, ma); | ||
} | ||
} else { | ||
// Two checks were skipped. | ||
*(results++) = true; | ||
*(results++) = true; | ||
} | ||
} | ||
|
||
// copy constructor | ||
{ | ||
constexpr DataT value{1}; | ||
constexpr marray_t rhs{value}; | ||
constexpr marray_t ma{rhs}; | ||
CHECK(value_operations::are_equal(ma, value)); | ||
*(results++) = value_operations::are_equal(ma, value); | ||
} | ||
|
||
// copy constructor rval reference | ||
{ | ||
constexpr marray_t ma{ | ||
marray_common::iota_marray<DataT, NumElements, 1>()}; | ||
marray_t ma_inc; | ||
std::iota(ma_inc.begin(), ma_inc.end(), 1); | ||
CHECK(value_operations::are_equal(ma_inc, ma)); | ||
marray_common::iota(ma_inc.begin(), ma_inc.end(), 1); | ||
*(results++) = value_operations::are_equal(ma_inc, ma); | ||
} | ||
} | ||
|
||
public: | ||
void operator()(const std::string&) { | ||
INFO("for number of elements \"" << NumElements << "\": "); | ||
|
||
{ | ||
INFO("validation on host"); | ||
|
||
bool check_results[num_test_cases] = {false}; | ||
run_checks(check_results); | ||
for (size_t i = 0; i < num_test_cases; ++i) { | ||
INFO(check_names[i]); | ||
CHECK(check_results[i]); | ||
} | ||
} | ||
|
||
{ | ||
INFO("validation on device"); | ||
|
||
auto queue = sycl_cts::util::get_cts_object::queue(); | ||
bool check_results[num_test_cases] = {false}; | ||
{ | ||
sycl::buffer<bool, 1> check_results_buff{ | ||
check_results, sycl::range<1>{num_test_cases}}; | ||
|
||
queue | ||
.submit([&](sycl::handler& cgh) { | ||
sycl::accessor check_results_acc{check_results_buff, cgh, | ||
sycl::read_write}; | ||
cgh.single_task([=]() { run_checks(check_results_acc.begin()); }); | ||
}) | ||
.wait_and_throw(); | ||
} | ||
run_checks(check_results); | ||
for (size_t i = 0; i < num_test_cases; ++i) { | ||
INFO(check_names[i]); | ||
CHECK(check_results[i]); | ||
} | ||
} | ||
} | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
()
are redundant but it might be clearer too. So no problem.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are absolutely right, but since they are unary operators on each side of the expression I think it's one of those cases where the precedence rules get hard to remember, so I personally prefer the parenthesis. 😄