Skip to content

Commit

Permalink
[SYCL] Add support for image with pitch but without host ptr provided.
Browse files Browse the repository at this point in the history
In this case pitches passed to OpenCL must be 0.
+ Aligned image constructor with the SYCL specification.

Signed-off-by: Vlad Romanov <vlad.romanov@intel.com>
  • Loading branch information
romanovvlad committed Oct 16, 2019
1 parent 630ad1f commit d1931fd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
9 changes: 5 additions & 4 deletions sycl/include/CL/sycl/detail/image_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class image_impl final : public SYCLMemObjT<AllocatorT> {
RT::PiEvent &OutEventToWait) override {
void *UserPtr = InitFromUserData ? BaseT::getUserPtr() : nullptr;

RT::PiMemImageDesc Desc = getImageDesc();
RT::PiMemImageDesc Desc = getImageDesc((bool)UserPtr);
assert(checkImageDesc(Desc, Context, UserPtr) &&
"The check an image desc failed.");

Expand Down Expand Up @@ -376,16 +376,17 @@ class image_impl final : public SYCLMemObjT<AllocatorT> {
return PI_MEM_TYPE_IMAGE3D;
}

RT::PiMemImageDesc getImageDesc() {
RT::PiMemImageDesc getImageDesc(bool InitFromHostPtr) {
RT::PiMemImageDesc Desc;
Desc.image_type = getImageType();
Desc.image_width = MRange[0];
Desc.image_height = Dimensions > 1 ? MRange[1] : 1;
Desc.image_depth = Dimensions > 2 ? MRange[2] : 1;
// TODO handle cases with IMAGE1D_ARRAY and IMAGE2D_ARRAY
Desc.image_array_size = 0;
Desc.image_row_pitch = MRowPitch;
Desc.image_slice_pitch = MSlicePitch;
// Pitches must be 0 if host ptr is not provided.
Desc.image_row_pitch = InitFromHostPtr ? MRowPitch: 0;
Desc.image_slice_pitch = InitFromHostPtr ? MSlicePitch: 0;

Desc.num_mip_levels = 0;
Desc.num_samples = 0;
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class image {
template <bool B = (Dimensions > 1)>
image(image_channel_order Order, image_channel_type Type,
const range<Dimensions> &Range,
typename std::enable_if<B, range<Dimensions - 1>>::type &Pitch,
const typename std::enable_if<B, range<Dimensions - 1>>::type &Pitch,
const property_list &PropList = {}) {
impl = std::make_shared<detail::image_impl<Dimensions, AllocatorT>>(
Order, Type, Range, Pitch, PropList);
Expand Down
15 changes: 13 additions & 2 deletions sycl/test/basic_tests/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ int main() {
const sycl::image_channel_order ChanOrder = sycl::image_channel_order::rgba;
const sycl::image_channel_type ChanType = sycl::image_channel_type::fp32;

constexpr auto SYCLRead = sycl::access::mode::read;
constexpr auto SYCLWrite = cl::sycl::access::mode::write;

const sycl::range<2> Img1Size(4, 4);
const sycl::range<2> Img2Size(4, 4);

Expand All @@ -35,8 +38,6 @@ int main() {
sycl::image<2> Img2(Img2HostData.data(), ChanOrder, ChanType, Img2Size);
TestQueue Q{sycl::default_selector()};
Q.submit([&](sycl::handler &CGH) {
constexpr auto SYCLRead = sycl::access::mode::read;
constexpr auto SYCLWrite = cl::sycl::access::mode::write;

auto Img1Acc = Img1.get_access<sycl::float4, SYCLRead>(CGH);
auto Img2Acc = Img2.get_access<sycl::float4, SYCLWrite>(CGH);
Expand All @@ -62,6 +63,16 @@ int main() {
}
}

{
const sycl::range<1> ImgPitch(4 * 4 * 4 * 2);
sycl::image<2> Img(ChanOrder, ChanType, Img1Size, ImgPitch);
TestQueue Q{sycl::default_selector()};
Q.submit([&](sycl::handler &CGH) {
auto ImgAcc = Img.get_access<sycl::float4, SYCLRead>(CGH);
CGH.single_task<class EmptyKernel>([=]() { ImgAcc.get_size(); });
});
}

std::cout << "Success" << std::endl;
return 0;
}

0 comments on commit d1931fd

Please sign in to comment.