Skip to content

Commit 9b1d8b8

Browse files
authored
[SYCL] Improve image accessors support on a host device (#1502)
- Support more image_channel_types in image_accessors read/write API for half4 datatype on host device. - Enable image_accessor_readwrite test on GPU. Signed-off-by: Garima Gupta <garima.gupta@intel.com>
1 parent 686e32b commit 9b1d8b8

File tree

3 files changed

+292
-224
lines changed

3 files changed

+292
-224
lines changed

sycl/include/CL/sycl/detail/image_accessor_util.hpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,26 @@ template <typename ChannelType>
423423
void convertReadData(const vec<ChannelType, 4> PixelData,
424424
const image_channel_type ImageChannelType,
425425
vec<cl_half, 4> &RetData) {
426-
426+
vec<cl_float, 4> RetDataFloat;
427427
switch (ImageChannelType) {
428428
case image_channel_type::snorm_int8:
429+
// max(-1.0f, (half)c / 127.0f)
430+
RetDataFloat = (PixelData.template convert<cl_float>()) / 127.0f;
431+
RetDataFloat = cl::sycl::fmax(RetDataFloat, -1);
432+
break;
429433
case image_channel_type::snorm_int16:
434+
// max(-1.0f, (half)c / 32767.0f)
435+
RetDataFloat = (PixelData.template convert<cl_float>()) / 32767.0f;
436+
RetDataFloat = cl::sycl::fmax(RetDataFloat, -1);
437+
break;
430438
case image_channel_type::unorm_int8:
439+
// (half)c / 255.0f
440+
RetDataFloat = (PixelData.template convert<cl_float>()) / 255.0f;
441+
break;
431442
case image_channel_type::unorm_int16:
443+
// (half)c / 65535.0f
444+
RetDataFloat = (PixelData.template convert<cl_float>()) / 65535.0f;
445+
break;
432446
case image_channel_type::unorm_short_565:
433447
case image_channel_type::unorm_short_555:
434448
case image_channel_type::unorm_int_101010:
@@ -452,7 +466,7 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
452466
PI_INVALID_VALUE);
453467
case image_channel_type::fp16:
454468
RetData = PixelData.template convert<cl_half>();
455-
break;
469+
return;
456470
case image_channel_type::fp32:
457471
throw cl::sycl::invalid_parameter_error(
458472
"Datatype to read - cl_half4 is incompatible with the "
@@ -461,6 +475,7 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
461475
default:
462476
break;
463477
}
478+
RetData = RetDataFloat.template convert<cl_half>();
464479
}
465480

466481
// Converts data to write into appropriate datatype based on the channel of the
@@ -629,12 +644,20 @@ template <typename ChannelType>
629644
vec<ChannelType, 4>
630645
convertWriteData(const vec<cl_half, 4> WriteData,
631646
const image_channel_type ImageChannelType) {
632-
647+
vec<cl_float, 4> WriteDataFloat = WriteData.convert<cl_float>();
633648
switch (ImageChannelType) {
634649
case image_channel_type::snorm_int8:
650+
// convert_char_sat_rte(h * 127.0f)
651+
return processFloatDataToPixel<ChannelType>(WriteDataFloat, 127.0f);
635652
case image_channel_type::snorm_int16:
653+
// convert_short_sat_rte(h * 32767.0f)
654+
return processFloatDataToPixel<ChannelType>(WriteDataFloat, 32767.0f);
636655
case image_channel_type::unorm_int8:
656+
// convert_uchar_sat_rte(h * 255.0f)
657+
return processFloatDataToPixel<ChannelType>(WriteDataFloat, 255.0f);
637658
case image_channel_type::unorm_int16:
659+
// convert_ushort_sat_rte(h * 65535.0f)
660+
return processFloatDataToPixel<ChannelType>(WriteDataFloat, 65535.0f);
638661
case image_channel_type::unorm_short_565:
639662
case image_channel_type::unorm_short_555:
640663
case image_channel_type::unorm_int_101010:
@@ -994,10 +1017,13 @@ DataT ReadPixelDataLinearFiltMode(const cl_int8 CoordValues,
9941017
// ImgChannelType.
9951018
// Convert to DataT as per conversion rules in section 8.3 in OpenCL Spec.
9961019
//
997-
// TODO:
998-
// Extend support for Step2 and Step3 for Linear Filtering Mode.
999-
// Extend support to find out of bounds Coordinates and return appropriate
1000-
// value based on Addressing Mode.
1020+
// TODO: Add additional check for half datatype read.
1021+
// Based on OpenCL spec 2.0:
1022+
// "The read_imageh calls that take integer coordinates must use a sampler with
1023+
// filter mode set to CLK_FILTER_NEAREST, normalized coordinates set to
1024+
// CLK_NORMALIZED_COORDS_FALSE and addressing mode set to
1025+
// CLK_ADDRESS_CLAMP_TO_EDGE, CLK_ADDRESS_CLAMP or CLK_ADDRESS_NONE; otherwise
1026+
// the values returned are undefined."
10011027

10021028
template <typename CoordT, typename DataT>
10031029
DataT imageReadSamplerHostImpl(const CoordT &Coords, const sampler &Smpl,

0 commit comments

Comments
 (0)