Skip to content
Closed
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
165 changes: 9 additions & 156 deletions sycl/include/sycl/accessor_image.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <sycl/accessor.hpp>
#include <sycl/accessor_image_base.hpp>
#include <sycl/detail/image_accessor_util.hpp>
#include <sycl/device.hpp>
#include <sycl/image.hpp>
Expand Down Expand Up @@ -61,156 +62,11 @@ void __SYCL_EXPORT sampledImageConstructorNotification(
const std::optional<image_target> &Target, const void *Type,
uint32_t ElemSize, const code_location &CodeLoc);

class UnsampledImageAccessorImplHost;
class SampledImageAccessorImplHost;
using UnsampledImageAccessorImplPtr =
std::shared_ptr<UnsampledImageAccessorImplHost>;
using SampledImageAccessorImplPtr =
std::shared_ptr<SampledImageAccessorImplHost>;

void __SYCL_EXPORT
addHostUnsampledImageAccessorAndWait(UnsampledImageAccessorImplHost *Req);
void __SYCL_EXPORT
addHostSampledImageAccessorAndWait(SampledImageAccessorImplHost *Req);

class __SYCL_EXPORT UnsampledImageAccessorBaseHost {
protected:
UnsampledImageAccessorBaseHost(const UnsampledImageAccessorImplPtr &Impl)
: impl{Impl} {}

public:
UnsampledImageAccessorBaseHost(sycl::range<3> Size, access_mode AccessMode,
void *SYCLMemObject, int Dims, int ElemSize,
id<3> Pitch, image_channel_type ChannelType,
image_channel_order ChannelOrder,
const property_list &PropertyList = {});
const sycl::range<3> &getSize() const;
void *getMemoryObject() const;
detail::AccHostDataT &getAccData();
void *getPtr();
void *getPtr() const;
int getNumOfDims() const;
int getElementSize() const;
id<3> getPitch() const;
image_channel_type getChannelType() const;
image_channel_order getChannelOrder() const;
const property_list &getPropList() const;

protected:
template <class Obj>
friend const decltype(Obj::impl) &
detail::getSyclObjImpl(const Obj &SyclObject);

template <class T>
friend T detail::createSyclObjFromImpl(
std::add_rvalue_reference_t<decltype(T::impl)> ImplObj);

template <class T>
friend T detail::createSyclObjFromImpl(
std::add_lvalue_reference_t<const decltype(T::impl)> ImplObj);

UnsampledImageAccessorImplPtr impl;

// The function references helper methods required by GDB pretty-printers
void GDBMethodsAnchor() {
#ifndef NDEBUG
const auto *this_const = this;
(void)getSize();
(void)this_const->getSize();
(void)getPtr();
(void)this_const->getPtr();
#endif
}

#ifndef __SYCL_DEVICE_ONLY__
// Reads a pixel of the underlying image at the specified coordinate. It is
// the responsibility of the caller to ensure that the coordinate type is
// valid.
template <typename DataT, typename CoordT>
DataT read(const CoordT &Coords) const noexcept {
image_sampler Smpl{addressing_mode::none,
coordinate_normalization_mode::unnormalized,
filtering_mode::nearest};
return imageReadSamplerHostImpl<CoordT, DataT>(
Coords, Smpl, getSize(), getPitch(), getChannelType(),
getChannelOrder(), getPtr(), getElementSize());
}

// Writes to a pixel of the underlying image at the specified coordinate. It
// is the responsibility of the caller to ensure that the coordinate type is
// valid.
template <typename DataT, typename CoordT>
void write(const CoordT &Coords, const DataT &Color) const {
imageWriteHostImpl(Coords, Color, getPitch(), getElementSize(),
getChannelType(), getChannelOrder(), getPtr());
}
#endif
};

class __SYCL_EXPORT SampledImageAccessorBaseHost {
protected:
SampledImageAccessorBaseHost(const SampledImageAccessorImplPtr &Impl)
: impl{Impl} {}

public:
SampledImageAccessorBaseHost(sycl::range<3> Size, void *SYCLMemObject,
int Dims, int ElemSize, id<3> Pitch,
image_channel_type ChannelType,
image_channel_order ChannelOrder,
image_sampler Sampler,
const property_list &PropertyList = {});
const sycl::range<3> &getSize() const;
void *getMemoryObject() const;
detail::AccHostDataT &getAccData();
void *getPtr();
void *getPtr() const;
int getNumOfDims() const;
int getElementSize() const;
id<3> getPitch() const;
image_channel_type getChannelType() const;
image_channel_order getChannelOrder() const;
image_sampler getSampler() const;
const property_list &getPropList() const;

protected:
template <class Obj>
friend const decltype(Obj::impl) &
detail::getSyclObjImpl(const Obj &SyclObject);

template <class T>
friend T detail::createSyclObjFromImpl(
std::add_rvalue_reference_t<decltype(T::impl)> ImplObj);

template <class T>
friend T detail::createSyclObjFromImpl(
std::add_lvalue_reference_t<const decltype(T::impl)> ImplObj);

SampledImageAccessorImplPtr impl;

// The function references helper methods required by GDB pretty-printers
void GDBMethodsAnchor() {
#ifndef NDEBUG
const auto *this_const = this;
(void)getSize();
(void)this_const->getSize();
(void)getPtr();
(void)this_const->getPtr();
#endif
}

#ifndef __SYCL_DEVICE_ONLY__
// Reads a pixel of the underlying image at the specified coordinate. It is
// the responsibility of the caller to ensure that the coordinate type is
// valid.
template <typename DataT, typename CoordT>
DataT read(const CoordT &Coords) const {
return imageReadSamplerHostImpl<CoordT, DataT>(
Coords, getSampler(), getSize(), getPitch(), getChannelType(),
getChannelOrder(), getPtr(), getElementSize());
}
#endif
};

template <typename DataT, int Dimensions, access::mode AccessMode,
access::placeholder IsPlaceholder>
class __image_array_slice__;
Expand Down Expand Up @@ -904,10 +760,9 @@ class __SYCL_EBO unsampled_image_accessor :
typename = std::enable_if_t<AccessMode == access_mode::read &&
detail::IsValidUnsampledCoord2020DataT<
Dimensions, CoordT>::value>>
DataT read(const CoordT &Coords) const noexcept {
DataT read([[maybe_unused]] const CoordT &Coords) const noexcept {
#ifdef __SYCL_DEVICE_ONLY__
// Currently not reachable on device.
std::ignore = Coords;
return {0, 0, 0, 0};
#else
return host_base_class::read<DataT>(Coords);
Expand All @@ -922,23 +777,22 @@ class __SYCL_EBO unsampled_image_accessor :
typename = std::enable_if_t<AccessMode == access_mode::write &&
detail::IsValidUnsampledCoord2020DataT<
Dimensions, CoordT>::value>>
void write(const CoordT &Coords, const DataT &Color) const {
void write([[maybe_unused]] const CoordT &Coords,
[[maybe_unused]] const DataT &Color) const {
#ifdef __SYCL_DEVICE_ONLY__
// Currently not reachable on device.
std::ignore = Coords;
std::ignore = Color;
#else
host_base_class::write<DataT>(Coords, Color);
#endif // __SYCL_DEVICE_ONLY__
}

private:
unsampled_image_accessor(const detail::UnsampledImageAccessorImplPtr &Impl)
unsampled_image_accessor(
[[maybe_unused]] const detail::UnsampledImageAccessorImplPtr &Impl)
#ifndef __SYCL_DEVICE_ONLY__
: host_base_class{Impl}
#endif // __SYCL_DEVICE_ONLY__
{
std::ignore = Impl;
}

template <class Obj>
Expand Down Expand Up @@ -1213,23 +1067,22 @@ class __SYCL_EBO sampled_image_accessor :
template <typename CoordT,
typename = std::enable_if_t<detail::IsValidSampledCoord2020DataT<
Dimensions, CoordT>::value>>
DataT read(const CoordT &Coords) const noexcept {
DataT read([[maybe_unused]] const CoordT &Coords) const noexcept {
#ifdef __SYCL_DEVICE_ONLY__
// Currently not reachable on device.
std::ignore = Coords;
return {0, 0, 0, 0};
#else
return host_base_class::read<DataT>(Coords);
#endif // __SYCL_DEVICE_ONLY__
}

private:
sampled_image_accessor(const detail::SampledImageAccessorImplPtr &Impl)
sampled_image_accessor(
[[maybe_unused]] const detail::SampledImageAccessorImplPtr &Impl)
#ifndef __SYCL_DEVICE_ONLY__
: host_base_class{Impl}
#endif // __SYCL_DEVICE_ONLY__
{
std::ignore = Impl;
}

template <class Obj>
Expand Down
Loading