Skip to content

[SYCL] Modifies accessor::ConcreteASPtrType to be const for readonly accessor #9651

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

Merged
merged 3 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion sycl/include/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,10 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
!IsConst || IsAccessReadOnly,
"A const qualified DataT is only allowed for a read-only accessor");

using ConcreteASPtrType = typename detail::DecoratedType<DataT, AS>::type *;
using ConcreteASPtrType = typename detail::DecoratedType<
typename std::conditional_t<IsAccessReadOnly && !IsConstantBuf,
const DataT, DataT>,
AS>::type *;

using RefType = detail::const_if_const_AS<AS, DataT> &;
using ConstRefType = const DataT &;
Expand Down
43 changes: 33 additions & 10 deletions sycl/test-e2e/Basic/accessor/accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,16 @@ template <typename Acc> struct Wrapper3 {
Wrapper2<Acc> w2;
};

void implicit_conversion(
const sycl::accessor<const int, 1, sycl::access::mode::read> &acc,
const sycl::accessor<int, 1, sycl::access::mode::read_write> &res_acc) {
using ResAccT = sycl::accessor<int, 1, sycl::access::mode::read_write>;
using AccT = sycl::accessor<int, 1, sycl::access::mode::read>;
using AccCT = sycl::accessor<const int, 1, sycl::access::mode::read>;

void implicit_conversion(const AccCT &acc, const ResAccT &res_acc) {
auto v = acc[0];
res_acc[0] = v;
}

void implicit_conversion(const AccT &acc, const ResAccT &res_acc) {
auto v = acc[0];
res_acc[0] = v;
}
Expand Down Expand Up @@ -769,7 +776,6 @@ int main() {
{
sycl::queue q;
try {
using AccT = sycl::accessor<int, 1, sycl::access::mode::read_write>;
AccT acc;

q.submit([&](sycl::handler &cgh) { cgh.require(acc); });
Expand Down Expand Up @@ -1313,9 +1319,6 @@ int main() {

// accessor<T> to accessor<const T> implicit conversion.
{
using ResAccT = sycl::accessor<int, 1, sycl::access::mode::read_write>;
using AccT = sycl::accessor<int, 1, sycl::access::mode::read>;

int data = 123;
int result = 0;
{
Expand All @@ -1333,11 +1336,31 @@ int main() {
assert(result == 123 && "Expected value not seen.");
}

// accessor swap
{
using ResAccT = sycl::accessor<int, 1, sycl::access::mode::read_write>;
using AccT = sycl::accessor<int, 1, sycl::access::mode::read>;
const int data = 123;
int result = 0;

// accessor<const T, read_only> to accessor<T, read_only> implicit conversion.
{
sycl::buffer<const int, 1> data_buf(&data, 1);
sycl::buffer<int, 1> res_buf(&result, 1);

sycl::queue queue;
queue
.submit([&](sycl::handler &cgh) {
ResAccT res_acc = res_buf.get_access(cgh);
AccCT acc(data_buf, cgh);
cgh.parallel_for_work_group(sycl::range(1), [=](sycl::group<1>) {
implicit_conversion(acc, res_acc);
});
})
.wait_and_throw();
}
assert(result == 123 && "Expected value not seen.");
}

// accessor swap
{
int data[2] = {2, 100};
int data2[2] = {23, 4};
int results[2] = {0, 0};
Expand Down