Skip to content
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

Fix placeholder accessor wrong checking #683

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 63 additions & 35 deletions tests/accessor/accessor_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ struct tag_factory<accessor_type::host_accessor> {
* @param res_acc Instance of result accessor
*/
template <typename TestingAccT, typename ResultAccT>
void check_empty_accessor_constructor_post_conditions(TestingAccT testing_acc,
ResultAccT res_acc) {
void check_empty_accessor_constructor_post_conditions(
TestingAccT testing_acc, ResultAccT res_acc, bool check_iterator_methods) {
size_t res_i = 0;
// (empty() == true)
res_acc[res_i++] = testing_acc.empty() == true;
Expand All @@ -346,11 +346,13 @@ void check_empty_accessor_constructor_post_conditions(TestingAccT testing_acc,
res_acc[res_i++] = testing_acc.size() == 0;
res_acc[res_i++] = testing_acc.max_size() == 0;

// The only iterator that can be obtained is nullptr
res_acc[res_i++] = testing_acc.begin() == testing_acc.end();
res_acc[res_i++] = testing_acc.cbegin() == testing_acc.cend();
res_acc[res_i++] = testing_acc.rbegin() == testing_acc.rend();
res_acc[res_i++] = testing_acc.crbegin() == testing_acc.crend();
if (check_iterator_methods) {
// The only iterator that can be obtained is nullptr
res_acc[res_i++] = testing_acc.begin() == testing_acc.end();
res_acc[res_i++] = testing_acc.cbegin() == testing_acc.cend();
res_acc[res_i++] = testing_acc.rbegin() == testing_acc.rend();
res_acc[res_i++] = testing_acc.crbegin() == testing_acc.crend();
}
}
// FIXME: re-enable when handler.host_task and sycl::errc is implemented in
// hipsycl and computcpp
Expand All @@ -374,32 +376,54 @@ void check_def_constructor(GetAccFunctorT get_accessor_functor) {
auto queue = once_per_unit::get_queue();
sycl::range<1> r(1);
const size_t conditions_checks_size = 8;
bool conditions_check[conditions_checks_size]{false};
bool conditions_check[conditions_checks_size];
std::fill(conditions_check, conditions_check + conditions_checks_size, true);

auto acc = get_accessor_functor();
if constexpr (AccType != accessor_type::host_accessor) {
sycl::buffer res_buf(conditions_check, sycl::range(conditions_checks_size));
check_empty_accessor_constructor_post_conditions(acc, conditions_check,
false);
} else {
check_empty_accessor_constructor_post_conditions(acc, conditions_check,
true);
}

queue
.submit([&](sycl::handler& cgh) {
sycl::accessor res_acc(res_buf, cgh);
auto acc = get_accessor_functor();
if (acc.is_placeholder()) {
cgh.require(acc);
}
if constexpr (Target == sycl::target::host_task) {
cgh.host_task([=] {
check_empty_accessor_constructor_post_conditions(acc, res_acc);
});
} else if constexpr (Target == sycl::target::device) {
cgh.parallel_for_work_group(r, [=](sycl::group<1>) {
check_empty_accessor_constructor_post_conditions(acc, res_acc);
});
}
})
.wait_and_throw();
for (size_t i = 0; i < conditions_checks_size; i++) {
CHECK(conditions_check[i]);
}
}

/**
* @brief Common function that constructs placeholder accessor with zero-length
* buffer and checks post-conditions
*
* @tparam AccType Type of the accessor
* @tparam DataT Type of underlying data
* @tparam Dimension Dimensions of the accessor
* @tparam AccessMode Access mode of the accessor
* @tparam Target Target of accessor
* @tparam GetAccFunctorT Type of functor for accessor creation
*/
template <accessor_type AccType, typename DataT, int Dimension,
sycl::access_mode AccessMode = sycl::access_mode::read_write,
sycl::target Target = sycl::target::device, typename GetAccFunctorT>
void check_zero_length_buffer_placeholder_constructor(
GetAccFunctorT get_accessor_functor) {
auto queue = once_per_unit::get_queue();
sycl::range<Dimension> r =
util::get_cts_object::range<Dimension>::get(0, 0, 0);
sycl::buffer<DataT, Dimension> data_buf(r);
const size_t conditions_checks_size = 8;
bool conditions_check[conditions_checks_size];
std::fill(conditions_check, conditions_check + conditions_checks_size, true);

auto acc = get_accessor_functor(data_buf);
if constexpr (AccType != accessor_type::host_accessor) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a difference for iterators between host and device?

Copy link
Contributor Author

@aleksmesh aleksmesh Jun 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In paragraph 4.7.6.12. Common members for buffer and local accessors I found this:

iterator begin() const noexcept Returns an iterator to the first element of the memory this accessor may access.For a buffer accessor this is an iterator to the first element of the underlying buffer, unless this is a ranged accessor in which case it is an iterator to first element within the accessor’s range.For accessor and local_accessor, this function may only be called from within a command.

Also in paragraph 4.9.4.1. SYCL functions for adding requirements we have restriction for empty accessors:

template <typename DataT, int Dimensions, access_mode AccessMode, target AccessTarget, access::placeholder IsPlaceholder> void require( accessor<DataT, Dimensions, AccessMode, AccessTarget, IsPlaceholder> acc) Requires access to the memory object associated with the accessor.The command group now has a requirement to gain access to the given memory object before executing the kernel. If the accessor has already been registered with the command group, calling this function has no effect.Throws exception with the errc::invalid error code if (acc.empty() == true).

So we can't check iteration methods of empty placeholder sycl::accessor and we can check sycl::host_accessor iteration methods.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you summarize this in some comments around the code? We might forget about the rationale... :-)

Copy link
Contributor Author

@aleksmesh aleksmesh Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keryell Comments added.

check_empty_accessor_constructor_post_conditions(acc, conditions_check,
false);
} else {
auto acc = get_accessor_functor();
check_empty_accessor_constructor_post_conditions(acc, conditions_check);
check_empty_accessor_constructor_post_conditions(acc, conditions_check,
true);
}

for (size_t i = 0; i < conditions_checks_size; i++) {
Expand Down Expand Up @@ -427,29 +451,33 @@ void check_zero_length_buffer_constructor(GetAccFunctorT get_accessor_functor) {
util::get_cts_object::range<Dimension>::get(0, 0, 0);
sycl::buffer<DataT, Dimension> data_buf(r);
const size_t conditions_checks_size = 8;
bool conditions_check[conditions_checks_size]{false};
bool conditions_check[conditions_checks_size];
std::fill(conditions_check, conditions_check + conditions_checks_size, true);

if constexpr (AccType != accessor_type::host_accessor) {
sycl::buffer res_buf(conditions_check, sycl::range(conditions_checks_size));

queue
.submit([&](sycl::handler& cgh) {
sycl::accessor res_acc(res_buf);
sycl::accessor res_acc(res_buf, cgh);
auto acc = get_accessor_functor(data_buf, cgh);
if constexpr (Target == sycl::target::host_task) {
cgh.host_task([=] {
check_empty_accessor_constructor_post_conditions(acc, res_acc);
check_empty_accessor_constructor_post_conditions(acc, res_acc,
false);
});
} else if constexpr (Target == sycl::target::device) {
cgh.parallel_for_work_group(r, [=](sycl::group<Dimension>) {
check_empty_accessor_constructor_post_conditions(acc, res_acc);
check_empty_accessor_constructor_post_conditions(acc, res_acc,
false);
});
}
})
.wait_and_throw();
} else {
auto acc = get_accessor_functor(data_buf);
check_empty_accessor_constructor_post_conditions(acc, conditions_check);
check_empty_accessor_constructor_post_conditions(acc, conditions_check,
true);
}

for (size_t i = 0; i < conditions_checks_size; i++) {
Expand Down Expand Up @@ -655,7 +683,7 @@ void check_common_constructor(const sycl::range<Dimension>& r,

queue
.submit([&](sycl::handler& cgh) {
sycl::accessor res_acc(res_buf);
sycl::accessor res_acc(res_buf, cgh);
auto acc = get_accessor_functor(data_buf, cgh);

if constexpr (AccType == accessor_type::generic_accessor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ void test_placeholder_zero_length_buffer_constructor(
"From zero-length buffer placeholder constructor");

SECTION(section_name) {
auto get_acc_functor = [](sycl::buffer<DataT, Dimension>& data_buf,
sycl::handler& cgh) {
auto get_acc_functor = [](sycl::buffer<DataT, Dimension>& data_buf) {
return sycl::accessor<DataT, Dimension, AccessMode, Target>(data_buf);
};
check_zero_length_buffer_constructor<AccType, DataT, Dimension, AccessMode,
Target>(get_acc_functor);
check_zero_length_buffer_placeholder_constructor<AccType, DataT, Dimension,
AccessMode, Target>(
get_acc_functor);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ void test_placeholder_zero_length_buffer_range_constructor(
"From zero-length buffer and range placeholder constructor");

SECTION(section_name) {
auto get_acc_functor = [r_zero](sycl::buffer<DataT, Dimension>& data_buf,
sycl::handler& cgh) {
auto get_acc_functor = [r_zero](sycl::buffer<DataT, Dimension>& data_buf) {
return sycl::accessor<DataT, Dimension, AccessMode, Target>(data_buf,
r_zero);
};
check_zero_length_buffer_constructor<AccType, DataT, Dimension, AccessMode,
Target>(get_acc_functor);
check_zero_length_buffer_placeholder_constructor<AccType, DataT, Dimension,
AccessMode, Target>(
get_acc_functor);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ void test_placeholder_zero_length_buffser_range_offset_constructor(
"From zero-length buffer, range and offset placeholder constructor");

SECTION(section_name) {
auto get_acc_functor = [r_zero, offset](
sycl::buffer<DataT, Dimension>& data_buf,
sycl::handler& cgh) {
auto get_acc_functor = [r_zero,
offset](sycl::buffer<DataT, Dimension>& data_buf) {
return sycl::accessor<DataT, Dimension, AccessMode, Target>(
data_buf, r_zero, offset);
};
check_zero_length_buffer_constructor<AccType, DataT, Dimension, AccessMode,
Target>(get_acc_functor);
check_zero_length_buffer_placeholder_constructor<AccType, DataT, Dimension,
AccessMode, Target>(
get_acc_functor);
}
}

Expand Down