Skip to content

Commit d1931fd

Browse files
committed
[SYCL] Add support for image with pitch but without host ptr provided.
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>
1 parent 630ad1f commit d1931fd

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

sycl/include/CL/sycl/detail/image_impl.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class image_impl final : public SYCLMemObjT<AllocatorT> {
283283
RT::PiEvent &OutEventToWait) override {
284284
void *UserPtr = InitFromUserData ? BaseT::getUserPtr() : nullptr;
285285

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

@@ -376,16 +376,17 @@ class image_impl final : public SYCLMemObjT<AllocatorT> {
376376
return PI_MEM_TYPE_IMAGE3D;
377377
}
378378

379-
RT::PiMemImageDesc getImageDesc() {
379+
RT::PiMemImageDesc getImageDesc(bool InitFromHostPtr) {
380380
RT::PiMemImageDesc Desc;
381381
Desc.image_type = getImageType();
382382
Desc.image_width = MRange[0];
383383
Desc.image_height = Dimensions > 1 ? MRange[1] : 1;
384384
Desc.image_depth = Dimensions > 2 ? MRange[2] : 1;
385385
// TODO handle cases with IMAGE1D_ARRAY and IMAGE2D_ARRAY
386386
Desc.image_array_size = 0;
387-
Desc.image_row_pitch = MRowPitch;
388-
Desc.image_slice_pitch = MSlicePitch;
387+
// Pitches must be 0 if host ptr is not provided.
388+
Desc.image_row_pitch = InitFromHostPtr ? MRowPitch: 0;
389+
Desc.image_slice_pitch = InitFromHostPtr ? MSlicePitch: 0;
389390

390391
Desc.num_mip_levels = 0;
391392
Desc.num_samples = 0;

sycl/include/CL/sycl/image.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class image {
7878
template <bool B = (Dimensions > 1)>
7979
image(image_channel_order Order, image_channel_type Type,
8080
const range<Dimensions> &Range,
81-
typename std::enable_if<B, range<Dimensions - 1>>::type &Pitch,
81+
const typename std::enable_if<B, range<Dimensions - 1>>::type &Pitch,
8282
const property_list &PropList = {}) {
8383
impl = std::make_shared<detail::image_impl<Dimensions, AllocatorT>>(
8484
Order, Type, Range, Pitch, PropList);

sycl/test/basic_tests/image.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ int main() {
2424
const sycl::image_channel_order ChanOrder = sycl::image_channel_order::rgba;
2525
const sycl::image_channel_type ChanType = sycl::image_channel_type::fp32;
2626

27+
constexpr auto SYCLRead = sycl::access::mode::read;
28+
constexpr auto SYCLWrite = cl::sycl::access::mode::write;
29+
2730
const sycl::range<2> Img1Size(4, 4);
2831
const sycl::range<2> Img2Size(4, 4);
2932

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

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

66+
{
67+
const sycl::range<1> ImgPitch(4 * 4 * 4 * 2);
68+
sycl::image<2> Img(ChanOrder, ChanType, Img1Size, ImgPitch);
69+
TestQueue Q{sycl::default_selector()};
70+
Q.submit([&](sycl::handler &CGH) {
71+
auto ImgAcc = Img.get_access<sycl::float4, SYCLRead>(CGH);
72+
CGH.single_task<class EmptyKernel>([=]() { ImgAcc.get_size(); });
73+
});
74+
}
75+
6576
std::cout << "Success" << std::endl;
6677
return 0;
6778
}

0 commit comments

Comments
 (0)