Skip to content

Commit

Permalink
Merge pull request #731 from steffenlarsen/steffen/accessor_test_fixes
Browse files Browse the repository at this point in the history
Fix faulty accessor tests
  • Loading branch information
bader authored Jun 30, 2023
2 parents e482f09 + 258613d commit ad2f682
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions tests/accessor/generic_accessor_api_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ class run_api_tests {
: 8;
constexpr size_t offset = 4;
constexpr size_t index = 2;
constexpr size_t first_elem = (dims == 3 ? offset * 8 * 8 : 0) +
(dims >= 2 ? offset * 8 : 0) + offset;
constexpr size_t last_elem =
(dims == 3 ? (acc_range_size - 1) * 8 * 8 : 0) +
(dims >= 2 ? (acc_range_size - 1) * 8 : 0) + (acc_range_size - 1) +
first_elem;
int linear_index = 0;
for (size_t i = 0; i < dims; i++) {
linear_index += (offset + index) * pow(buff_range_size, dims - i - 1);
Expand Down Expand Up @@ -337,13 +343,13 @@ class run_api_tests {
cgh.host_task([=] {
test_accessor_ptr_host(acc, T());
test_begin_end_host(
acc, value_operations::init<T>(0),
value_operations::init<T>(buff_size - 1), false);
acc, value_operations::init<T>(first_elem),
value_operations::init<T>(last_elem), false);
auto &acc_ref1 =
get_subscript_overload<T, AccT, dims>(acc, index);
auto &acc_ref2 = acc[sycl::id<dims>()];
CHECK(value_operations::are_equal(acc_ref1, linear_index));
CHECK(value_operations::are_equal(acc_ref2, 0));
CHECK(value_operations::are_equal(acc_ref2, first_elem));
if constexpr (AccessMode != sycl::access_mode::read) {
value_operations::assign(acc_ref1, changed_val);
value_operations::assign(acc_ref2, expected_val);
Expand All @@ -355,14 +361,15 @@ class run_api_tests {
cgh.single_task<kname>([=]() {
test_accessor_ptr_device(acc, T(), res_acc);
res_acc[0] &= test_begin_end_device(
acc, value_operations::init<T>(0),
value_operations::init<T>(buff_size - 1), true);
acc, value_operations::init<T>(first_elem),
value_operations::init<T>(last_elem), true);
auto &acc_ref1 =
get_subscript_overload<T, AccT, dims>(acc, index);
auto &acc_ref2 = acc[sycl::id<dims>()];
res_acc[0] &=
value_operations::are_equal(acc_ref1, linear_index);
res_acc[0] &= value_operations::are_equal(acc_ref2, 0);
res_acc[0] &=
value_operations::are_equal(acc_ref2, first_elem);
if constexpr (AccessMode != sycl::access_mode::read) {
value_operations::assign(acc_ref1, changed_val);
value_operations::assign(acc_ref2, expected_val);
Expand All @@ -375,7 +382,7 @@ class run_api_tests {
if constexpr (Target == sycl::target::device) CHECK(res);
if constexpr (AccessMode != sycl::access_mode::read) {
CHECK(value_operations::are_equal(data[linear_index], changed_val));
CHECK(value_operations::are_equal(data[0], expected_val));
CHECK(value_operations::are_equal(data[first_elem], expected_val));
}
}
}
Expand Down Expand Up @@ -410,19 +417,17 @@ class run_api_tests {
using kname = kernel_swap<T, AccessT, DimensionT, TargetT>;
sycl::accessor res_acc(res_buf, cgh);
cgh.single_task<kname>([=]() {
if constexpr (0 < dims) {
typename AccT::reference acc_ref1 =
get_accessor_reference<dims>(acc1);
typename AccT::reference acc_ref2 =
get_accessor_reference<dims>(acc2);
res_acc[0] =
value_operations::are_equal(acc_ref1, changed_val);
res_acc[0] &=
value_operations::are_equal(acc_ref2, expected_val);
if constexpr (AccessMode != sycl::access_mode::read) {
value_operations::assign(acc_ref1, expected_val);
value_operations::assign(acc_ref2, changed_val);
}
typename AccT::reference acc_ref1 =
get_accessor_reference<dims>(acc1);
typename AccT::reference acc_ref2 =
get_accessor_reference<dims>(acc2);
res_acc[0] =
value_operations::are_equal(acc_ref1, changed_val);
res_acc[0] &=
value_operations::are_equal(acc_ref2, expected_val);
if constexpr (AccessMode != sycl::access_mode::read) {
value_operations::assign(acc_ref1, expected_val);
value_operations::assign(acc_ref2, changed_val);
}
});
}
Expand Down

0 comments on commit ad2f682

Please sign in to comment.