Skip to content

Commit

Permalink
fix accessors for SYCL
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraPerego committed Aug 3, 2023
1 parent e793c4e commit e68f99c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/alpaka/kernel/TaskKernelGenericSycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace alpaka::detail
template<typename TElem, typename TIdx, std::size_t TDim, typename TAccessModes>
inline auto require(
sycl::handler& cgh,
experimental::Accessor<SyclAccessor<TElem, DimInt<TDim>::value, TAccessModes>, TElem, TIdx, TDim, TAccessModes>
Accessor<SyclAccessor<TElem, DimInt<TDim>::value, TAccessModes>, TElem, TIdx, TDim, TAccessModes>
acc,
special)
{
Expand Down
35 changes: 27 additions & 8 deletions include/alpaka/mem/buf/sycl/Accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,24 @@ namespace alpaka

namespace detail
{
//! Access tag type indicating read-only access.
struct ReadAccess
{
};

//! Access tag type indicating write-only access.
struct WriteAccess
{
};

template<typename... TAlpakaAccessModes>
inline constexpr auto sycl_access_mode = sycl::access_mode::read_write;

template<>
inline constexpr auto sycl_access_mode<experimental::ReadAccess> = sycl::access_mode::read;
inline constexpr auto sycl_access_mode<ReadAccess> = sycl::access_mode::read;

template<>
inline constexpr auto sycl_access_mode<experimental::WriteAccess> = sycl::access_mode::write;
inline constexpr auto sycl_access_mode<WriteAccess> = sycl::access_mode::write;

template<typename TElem, int TDim, typename... TAlpakaAccessModes>
using SyclAccessor = sycl::accessor<
Expand All @@ -38,15 +48,25 @@ namespace alpaka
sycl::access::placeholder::true_t>;
} // namespace detail

//! An accessor is an abstraction for accessing memory objects such as views and buffers.
//! @tparam TMemoryHandle A handle to a memory object.
//! @tparam TElem The type of the element stored by the memory object. Values and references to this type are
//! returned on access.
//! @tparam TBufferIdx The integral type used for indexing and index computations.
//! @tparam TDim The dimensionality of the accessed data.
//! @tparam TAccessModes Either a single access tag type or a `std::tuple` containing multiple access tag
//! types.
template<typename TMemoryHandle, typename TElem, typename TBufferIdx, std::size_t TDim, typename TAccessModes>
struct Accessor;

template<typename TElem, typename TIdx, typename TAccessModes>
struct experimental::
Accessor<detail::SyclAccessor<TElem, 1, TAccessModes>, TElem, TIdx, std::size_t{1}, TAccessModes>
struct Accessor<detail::SyclAccessor<TElem, 1, TAccessModes>, TElem, TIdx, std::size_t{1}, TAccessModes>
{
static constexpr auto sycl_access_mode = detail::sycl_access_mode<TAccessModes>;
using SyclAccessor = detail::SyclAccessor<TElem, 1, TAccessModes>;
using VecType = Vec<DimInt<1>, TIdx>;
using ReturnType = std::conditional_t<
std::is_same_v<TAccessModes, ReadAccess>,
std::is_same_v<TAccessModes, detail::ReadAccess>,
typename SyclAccessor::const_reference,
typename SyclAccessor::reference>;

Expand Down Expand Up @@ -77,14 +97,13 @@ namespace alpaka
};

template<typename TElem, typename TIdx, std::size_t TDim, typename TAccessModes>
struct experimental::
Accessor<detail::SyclAccessor<TElem, DimInt<TDim>::value, TAccessModes>, TElem, TIdx, TDim, TAccessModes>
struct Accessor<detail::SyclAccessor<TElem, DimInt<TDim>::value, TAccessModes>, TElem, TIdx, TDim, TAccessModes>
{
static constexpr auto sycl_access_mode = detail::sycl_access_mode<TAccessModes>;
using SyclAccessor = detail::SyclAccessor<TElem, DimInt<TDim>::value, TAccessModes>;
using VecType = Vec<DimInt<TDim>, TIdx>;
using ReturnType = std::conditional_t<
std::is_same_v<TAccessModes, ReadAccess>,
std::is_same_v<TAccessModes, detail::ReadAccess>,
typename SyclAccessor::const_reference,
typename SyclAccessor::reference>;

Expand Down

0 comments on commit e68f99c

Please sign in to comment.