Skip to content

[SYCL] Add support for image with pitch but without host ptr provided. #723

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 3 commits into from
Oct 16, 2019
Merged
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
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(UserPtr != nullptr);
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not understand this change. How are the fields Desc.image_row_pitch and Desc.image_slice_pitch used? What happens when the user is constructing an image without host_ptr but a valid pitch?
Eg with constructor:
image(image_channel_order order, image_channel_type type, const range &range, const range<dimensions - 1> &pitch, const property_list &propList = {});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are the fields Desc.image_row_pitch and Desc.image_slice_pitch used?

There are used as arguments to clCreateImage function.

What happens when the user is constructing an image without host_ptr but a valid pitch?

For OpenCL device image is created without host ptr and with pitch == 0.
For host device image is created without host ptr and with pitches that user specifies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read section 5.3.1.2 in OpenCL spec.
Thanks.

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;
Copy link
Contributor

@AGindinson AGindinson Oct 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this constexpr supposed to have a different namespace specification compared to the one on the next line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

constexpr auto SYCLWrite = 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;
}