USM Image Accessor

Description

USM Image accessor provides access to a USM image.

Include Files

oneapi/ipl.hpp

Domain Dependencies

Headers: oneapi/ipl.hpp

Libraries: oneipl.lib

Syntax

template<formats Format, typename DataT, sycl::access_mode AccessMode, typename AccessDataT>
class oneapi::ipl::usm_image_accessor

Provides access to a USM image.

Template Parameters
  • Format – the given format of an image

  • DataT – the given type of a pixel component

  • AccessMode – the given acccess mode (sycl::access_mode)

  • AccessDataT – the given access type

Public Types

using data_t = typename usm_image_accessor_base_t::data_t

Alias for the type of a pixel component.

template<typename SomeDataT>
using pixel_t = sycl::vec<SomeDataT, channel_count_v>

Alias for the pixel type.

template<typename SomeDataT>
using pixel4_t = sycl::vec<SomeDataT, sycl_channel_count_v>

Alias for the 4-component pixel type corresponding to RGBA images.

using native_pixel_t = pixel_t<data_t>

Alias for the pixel type with the given type of a pixel component.

using native_pixel4_t = pixel4_t<data_t>

Alias for the 4-component pixel type corresponding to RGBA images with the given type of a pixel component.

using access_data_t = AccessDataT

Alias for the type of a pixel component for computations.

using access_pixel_t = pixel_t<access_data_t>

Alias for the pixel type with the type of a pixel component for computations.

using access_pixel4_t = pixel4_t<access_data_t>

Alias for the 4-component pixel type corresponding to RGBA images with the type of a pixel component for computations.

Public Functions

auto read(const sycl::int2 &coordinates) const -> access_pixel4_t

Reads and returns an element of the image at the coordinates specified by coordinates.

Parameters

coordinates[in] the given pixel coordinates

template<sycl::access_mode AccessMode2 = access_mode_v>
auto write(const sycl::int2 &coordinates, const access_pixel4_t &pixel) const -> void

Writes the value specified by pixel to the element of the image at the coordinates specified by coordinates.

Template Parameters

AccessMode2 – the given access mode (sycl::access_mode)

Parameters
  • coordinates[in] the given pixel coordinates

  • pixel[in] the given pixel

std::size_t get_pitch() const noexcept

Returns the image stride in bytes.

Returns

the image stride in bytes

Public Static Attributes

static constexpr int sycl_channel_count_v = {4}

Alias for the number of channels corresponding to RGBA images.

static constexpr auto channel_count_v

Alias for the number of image channels.

static constexpr auto access_mode_v

Alias for the access mode.

Supported values for AccessMode:

sycl::access_mode::write

sycl::access_mode::read

Supported values for AccessDataT:

std::int8_t

std::uint8_t

std::int16_t

std::uint16_t

std::int32_t

std::uint32_t

float

The code example below demonstrates how to use the oneapi::ipl::usm_image_accessor:

using image_t = image<formats::rgb, std::uint8_t>;

const roi_rect roi_rect{ image_size / 6, image_size / 3 };

// Create queue
sycl::queue queue{};

// Create allocator
shared_usm_allocator_t allocator{ queue };

// RGB image (usm_image)
image_t usm_image{ queue, image_data_pointer, image_size, allocator };

// USM image accessor
const image_t::accessor_t<sycl::access_mode::read, float> usm_image_accessor(usm_image);

// Reading first pixel
const sycl::int2 coords2d{ 0, 0 };
const auto       pixel = usm_image_accessor.read(coords2d);

std::cout << "Pixel: " << pixel[0] << " " << pixel[1] << " " << pixel[2] << std::endl;