@@ -98,6 +98,33 @@ void *getValueFromDynamicParameter(
98
98
99
99
// Bindless image helpers
100
100
101
+ constexpr size_t get_channel_size (
102
+ const sycl::ext::oneapi::experimental::image_descriptor &Desc) {
103
+ switch (Desc.channel_type ) {
104
+ case sycl::image_channel_type::fp16:
105
+ return sizeof (sycl::half);
106
+ case sycl::image_channel_type::fp32:
107
+ return sizeof (float );
108
+ case sycl::image_channel_type::snorm_int8:
109
+ case sycl::image_channel_type::unorm_int8:
110
+ case sycl::image_channel_type::signed_int8:
111
+ case sycl::image_channel_type::unsigned_int8:
112
+ return sizeof (uint8_t );
113
+ case sycl::image_channel_type::snorm_int16:
114
+ case sycl::image_channel_type::unorm_int16:
115
+ case sycl::image_channel_type::signed_int16:
116
+ case sycl::image_channel_type::unsigned_int16:
117
+ return sizeof (uint16_t );
118
+ case sycl::image_channel_type::signed_int32:
119
+ case sycl::image_channel_type::unsigned_int32:
120
+ return sizeof (uint32_t );
121
+ default :
122
+ throw sycl::exception (make_error_code (errc::invalid),
123
+ " Unsupported channel type" );
124
+ return 0 ;
125
+ }
126
+ }
127
+
101
128
// Fill image type and return depth or array_size
102
129
static unsigned int
103
130
fill_image_type (const ext::oneapi::experimental::image_descriptor &Desc,
@@ -257,16 +284,8 @@ fill_copy_args(detail::handler_impl *impl,
257
284
impl->MDstImageDesc .depth = DestExtent[2 ];
258
285
}
259
286
260
- if (impl->MImageCopyFlags == UR_EXP_IMAGE_COPY_FLAG_HOST_TO_DEVICE) {
261
- impl->MSrcImageDesc .rowPitch = 0 ;
262
- impl->MDstImageDesc .rowPitch = DestPitch;
263
- } else if (impl->MImageCopyFlags == UR_EXP_IMAGE_COPY_FLAG_DEVICE_TO_HOST) {
264
- impl->MSrcImageDesc .rowPitch = SrcPitch;
265
- impl->MDstImageDesc .rowPitch = 0 ;
266
- } else {
267
- impl->MSrcImageDesc .rowPitch = SrcPitch;
268
- impl->MDstImageDesc .rowPitch = DestPitch;
269
- }
287
+ impl->MSrcImageDesc .rowPitch = SrcPitch;
288
+ impl->MDstImageDesc .rowPitch = DestPitch;
270
289
}
271
290
272
291
static void
@@ -279,9 +298,11 @@ fill_copy_args(detail::handler_impl *impl,
279
298
sycl::range<3 > DestExtent = {0 , 0 , 0 },
280
299
sycl::range<3 > CopyExtent = {0 , 0 , 0 }) {
281
300
282
- fill_copy_args (impl, Desc, Desc, ImageCopyFlags, 0 /* SrcPitch*/ ,
283
- 0 /* DestPitch*/ , SrcOffset, SrcExtent, DestOffset, DestExtent,
284
- CopyExtent);
301
+ size_t SrcPitch = SrcExtent[0 ] * Desc.num_channels * get_channel_size (Desc);
302
+ size_t DestPitch = DestExtent[0 ] * Desc.num_channels * get_channel_size (Desc);
303
+
304
+ fill_copy_args (impl, Desc, Desc, ImageCopyFlags, SrcPitch, DestPitch,
305
+ SrcOffset, SrcExtent, DestOffset, DestExtent, CopyExtent);
285
306
}
286
307
287
308
static void
@@ -309,8 +330,13 @@ fill_copy_args(detail::handler_impl *impl,
309
330
sycl::range<3 > DestExtent = {0 , 0 , 0 },
310
331
sycl::range<3 > CopyExtent = {0 , 0 , 0 }) {
311
332
312
- fill_copy_args (impl, SrcImgDesc, DestImgDesc, ImageCopyFlags, 0 /* SrcPitch*/ ,
313
- 0 /* DestPitch*/ , SrcOffset, SrcExtent, DestOffset, DestExtent,
333
+ size_t SrcPitch =
334
+ SrcExtent[0 ] * SrcImgDesc.num_channels * get_channel_size (SrcImgDesc);
335
+ size_t DestPitch =
336
+ DestExtent[0 ] * DestImgDesc.num_channels * get_channel_size (DestImgDesc);
337
+
338
+ fill_copy_args (impl, SrcImgDesc, DestImgDesc, ImageCopyFlags, SrcPitch,
339
+ DestPitch, SrcOffset, SrcExtent, DestOffset, DestExtent,
314
340
CopyExtent);
315
341
}
316
342
@@ -1618,10 +1644,17 @@ void handler::ext_oneapi_copy(
1618
1644
get_pointer_type (Dest,
1619
1645
createSyclObjFromImpl<context>(impl->get_context ())));
1620
1646
1621
- if (ImageCopyFlags == UR_EXP_IMAGE_COPY_FLAG_HOST_TO_DEVICE ||
1622
- ImageCopyFlags == UR_EXP_IMAGE_COPY_FLAG_DEVICE_TO_HOST) {
1623
- detail::fill_copy_args (get_impl (), Desc, ImageCopyFlags, DeviceRowPitch,
1647
+ // Calculate host pitch, where host memory is always assumed to be tightly
1648
+ // packed.
1649
+ size_t HostRowPitch =
1650
+ Desc.width * Desc.num_channels * detail::get_channel_size (Desc);
1651
+
1652
+ if (ImageCopyFlags == UR_EXP_IMAGE_COPY_FLAG_HOST_TO_DEVICE) {
1653
+ detail::fill_copy_args (get_impl (), Desc, ImageCopyFlags, HostRowPitch,
1624
1654
DeviceRowPitch);
1655
+ } else if (ImageCopyFlags == UR_EXP_IMAGE_COPY_FLAG_DEVICE_TO_HOST) {
1656
+ detail::fill_copy_args (get_impl (), Desc, ImageCopyFlags, DeviceRowPitch,
1657
+ HostRowPitch);
1625
1658
} else {
1626
1659
throw sycl::exception (make_error_code (errc::invalid),
1627
1660
" Copy Error: This copy function only performs host "
@@ -1650,14 +1683,19 @@ void handler::ext_oneapi_copy(
1650
1683
get_pointer_type (Dest,
1651
1684
createSyclObjFromImpl<context>(impl->get_context ())));
1652
1685
1686
+ // Calculate host pitch, where host memory is always assumed to be tightly
1687
+ // packed.
1688
+ size_t HostRowPitch = HostExtent[0 ] * DeviceImgDesc.num_channels *
1689
+ detail::get_channel_size (DeviceImgDesc);
1690
+
1653
1691
// Fill the host extent based on the type of copy.
1654
1692
if (ImageCopyFlags == UR_EXP_IMAGE_COPY_FLAG_HOST_TO_DEVICE) {
1655
1693
detail::fill_copy_args (get_impl (), DeviceImgDesc, ImageCopyFlags,
1656
- DeviceRowPitch , DeviceRowPitch, SrcOffset,
1657
- HostExtent, DestOffset, {0 , 0 , 0 }, CopyExtent);
1694
+ HostRowPitch , DeviceRowPitch, SrcOffset, HostExtent ,
1695
+ DestOffset, {0 , 0 , 0 }, CopyExtent);
1658
1696
} else if (ImageCopyFlags == UR_EXP_IMAGE_COPY_FLAG_DEVICE_TO_HOST) {
1659
1697
detail::fill_copy_args (get_impl (), DeviceImgDesc, ImageCopyFlags,
1660
- DeviceRowPitch, DeviceRowPitch , SrcOffset, {0 , 0 , 0 },
1698
+ DeviceRowPitch, HostRowPitch , SrcOffset, {0 , 0 , 0 },
1661
1699
DestOffset, HostExtent, CopyExtent);
1662
1700
} else {
1663
1701
throw sycl::exception (make_error_code (errc::invalid),
0 commit comments