Skip to content

[SYCL] Ensure correct access mode in handler::copy (#3109) #3111

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 1 commit into from
Jan 28, 2021
Merged
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
25 changes: 25 additions & 0 deletions sycl/include/CL/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,19 @@ class __SYCL_EXPORT handler {
return isConstOrGlobal(AccessTarget) || isImageOrImageArray(AccessTarget);
}

constexpr static bool isValidModeForSourceAccessor(access::mode AccessMode) {
return AccessMode == access::mode::read ||
AccessMode == access::mode::read_write;
}

constexpr static bool
isValidModeForDestinationAccessor(access::mode AccessMode) {
return AccessMode == access::mode::write ||
AccessMode == access::mode::read_write ||
AccessMode == access::mode::discard_write ||
AccessMode == access::mode::discard_read_write;
}

/// Defines and invokes a SYCL kernel function for the specified range.
///
/// The SYCL kernel function is defined as a lambda function or a named
Expand Down Expand Up @@ -1674,6 +1687,8 @@ class __SYCL_EXPORT handler {
throwIfActionIsCreated();
static_assert(isValidTargetForExplicitOp(AccessTarget),
"Invalid accessor target for the copy method.");
static_assert(isValidModeForSourceAccessor(AccessMode),
"Invalid accessor mode for the copy method.");
// Make sure data shared_ptr points to is not released until we finish
// work with it.
MSharedPtrStorage.push_back(Dst);
Expand All @@ -1697,6 +1712,8 @@ class __SYCL_EXPORT handler {
throwIfActionIsCreated();
static_assert(isValidTargetForExplicitOp(AccessTarget),
"Invalid accessor target for the copy method.");
static_assert(isValidModeForDestinationAccessor(AccessMode),
"Invalid accessor mode for the copy method.");
// Make sure data shared_ptr points to is not released until we finish
// work with it.
MSharedPtrStorage.push_back(Src);
Expand All @@ -1719,6 +1736,8 @@ class __SYCL_EXPORT handler {
throwIfActionIsCreated();
static_assert(isValidTargetForExplicitOp(AccessTarget),
"Invalid accessor target for the copy method.");
static_assert(isValidModeForSourceAccessor(AccessMode),
"Invalid accessor mode for the copy method.");
#ifndef __SYCL_DEVICE_ONLY__
if (MIsHost) {
// TODO: Temporary implementation for host. Should be handled by memory
Expand Down Expand Up @@ -1756,6 +1775,8 @@ class __SYCL_EXPORT handler {
throwIfActionIsCreated();
static_assert(isValidTargetForExplicitOp(AccessTarget),
"Invalid accessor target for the copy method.");
static_assert(isValidModeForDestinationAccessor(AccessMode),
"Invalid accessor mode for the copy method.");
#ifndef __SYCL_DEVICE_ONLY__
if (MIsHost) {
// TODO: Temporary implementation for host. Should be handled by memory
Expand Down Expand Up @@ -1801,6 +1822,10 @@ class __SYCL_EXPORT handler {
"Invalid source accessor target for the copy method.");
static_assert(isValidTargetForExplicitOp(AccessTarget_Dst),
"Invalid destination accessor target for the copy method.");
static_assert(isValidModeForSourceAccessor(AccessMode_Src),
"Invalid source accessor mode for the copy method.");
static_assert(isValidModeForDestinationAccessor(AccessMode_Dst),
"Invalid destination accessor mode for the copy method.");
assert(Dst.get_size() >= Src.get_size() &&
"The destination accessor does not fit the copied memory.");
if (copyAccToAccHelper(Src, Dst))
Expand Down