diff --git a/sycl/include/CL/sycl/detail/pi.h b/sycl/include/CL/sycl/detail/pi.h index 22a3b290d8495..613db5fd1be2a 100644 --- a/sycl/include/CL/sycl/detail/pi.h +++ b/sycl/include/CL/sycl/detail/pi.h @@ -155,6 +155,34 @@ typedef enum { PI_BUFFER_CREATE_TYPE_REGION = CL_BUFFER_CREATE_TYPE_REGION } _pi_buffer_create_type; +typedef pi_bitfield pi_sampler_properties; +const pi_bool PI_TRUE = CL_TRUE; +const pi_bool PI_FALSE = CL_FALSE; + +typedef enum { + PI_SAMPLER_INFO_REFERENCE_COUNT = CL_SAMPLER_REFERENCE_COUNT, + PI_SAMPLER_INFO_CONTEXT = CL_SAMPLER_CONTEXT, + PI_SAMPLER_INFO_NORMALIZED_COORDS = CL_SAMPLER_NORMALIZED_COORDS, + PI_SAMPLER_INFO_ADDRESSING_MODE = CL_SAMPLER_ADDRESSING_MODE, + PI_SAMPLER_INFO_FILTER_MODE = CL_SAMPLER_FILTER_MODE, + PI_SAMPLER_INFO_MIP_FILTER_MODE = CL_SAMPLER_MIP_FILTER_MODE, + PI_SAMPLER_INFO_LOD_MIN = CL_SAMPLER_LOD_MIN, + PI_SAMPLER_INFO_LOD_MAX = CL_SAMPLER_LOD_MAX +} _pi_sampler_info; + +typedef enum { + PI_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT = CL_ADDRESS_MIRRORED_REPEAT, + PI_SAMPLER_ADDRESSING_MODE_REPEAT = CL_ADDRESS_REPEAT, + PI_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE = CL_ADDRESS_CLAMP_TO_EDGE, + PI_SAMPLER_ADDRESSING_MODE_CLAMP = CL_ADDRESS_CLAMP, + PI_SAMPLER_ADDRESSING_MODE_NONE = CL_ADDRESS_NONE +} _pi_sampler_addressing_mode; + +typedef enum { + PI_SAMPLER_FILTER_MODE_NEAREST = CL_FILTER_NEAREST, + PI_SAMPLER_FILTER_MODE_LINEAR = CL_FILTER_LINEAR, +} _pi_sampler_filter_mode; + // NOTE: this is made 64-bit to match the size of cl_mem_flags to // make the translation to OpenCL transparent. // TODO: populate @@ -187,6 +215,9 @@ typedef _pi_mem_type pi_mem_type; typedef _pi_image_channel_order pi_image_channel_order; typedef _pi_image_channel_type pi_image_channel_type; typedef _pi_buffer_create_type pi_buffer_create_type; +typedef _pi_sampler_addressing_mode pi_sampler_addressing_mode; +typedef _pi_sampler_filter_mode pi_sampler_filter_mode; +typedef _pi_sampler_info pi_sampler_info; // Opaque data type for compatibility with OpenMP. typedef void * _pi_offload_entry; @@ -631,12 +662,12 @@ pi_result piEventRelease(pi_event event); // pi_result piSamplerCreate( pi_context context, - const cl_sampler_properties * sampler_properties, // TODO: untie from OpenCL + const pi_sampler_properties * sampler_properties, pi_sampler * result_sampler); pi_result piSamplerGetInfo( pi_sampler sampler, - cl_sampler_info param_name, // TODO: untie from OpenCL + pi_sampler_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret); diff --git a/sycl/include/CL/sycl/detail/pi.hpp b/sycl/include/CL/sycl/detail/pi.hpp index b5c86b0639323..260f7f4ff6964 100644 --- a/sycl/include/CL/sycl/detail/pi.hpp +++ b/sycl/include/CL/sycl/detail/pi.hpp @@ -29,27 +29,31 @@ namespace pi { // Check for manually selected BE at run-time. bool useBackend(Backend Backend); - using PiResult = ::pi_result; - using PiPlatform = ::pi_platform; - using PiDevice = ::pi_device; - using PiDeviceType = ::pi_device_type; - using PiDeviceInfo = ::pi_device_info; - using PiDeviceBinaryType = ::pi_device_binary_type; - using PiContext = ::pi_context; - using PiProgram = ::pi_program; - using PiKernel = ::pi_kernel; - using PiQueue = ::pi_queue; - using PiQueueProperties = ::pi_queue_properties; - using PiMem = ::pi_mem; - using PiMemFlags = ::pi_mem_flags; - using PiEvent = ::pi_event; - using PiSampler = ::pi_sampler; - using PiMemImageFormat = ::pi_image_format; - using PiMemImageDesc = ::pi_image_desc; - using PiMemImageInfo = ::pi_image_info; - using PiMemObjectType = ::pi_mem_type; - using PiMemImageChannelOrder = ::pi_image_channel_order; - using PiMemImageChannelType = ::pi_image_channel_type; + using PiResult = ::pi_result; + using PiPlatform = ::pi_platform; + using PiDevice = ::pi_device; + using PiDeviceType = ::pi_device_type; + using PiDeviceInfo = ::pi_device_info; + using PiDeviceBinaryType = ::pi_device_binary_type; + using PiContext = ::pi_context; + using PiProgram = ::pi_program; + using PiKernel = ::pi_kernel; + using PiQueue = ::pi_queue; + using PiQueueProperties = ::pi_queue_properties; + using PiMem = ::pi_mem; + using PiMemFlags = ::pi_mem_flags; + using PiEvent = ::pi_event; + using PiSampler = ::pi_sampler; + using PiSamplerInfo = ::pi_sampler_info; + using PiSamplerProperties = ::pi_sampler_properties; + using PiSamplerAddressingMode = ::pi_sampler_addressing_mode; + using PiSamplerFilterMode = ::pi_sampler_filter_mode; + using PiMemImageFormat = ::pi_image_format; + using PiMemImageDesc = ::pi_image_desc; + using PiMemImageInfo = ::pi_image_info; + using PiMemObjectType = ::pi_mem_type; + using PiMemImageChannelOrder = ::pi_image_channel_order; + using PiMemImageChannelType = ::pi_image_channel_type; // Get a string representing a _pi_platform_info enum std::string platformInfoToString(pi_platform_info info); diff --git a/sycl/source/detail/pi_opencl.cpp b/sycl/source/detail/pi_opencl.cpp index 456ea158a3cc8..1d9995b134017 100644 --- a/sycl/source/detail/pi_opencl.cpp +++ b/sycl/source/detail/pi_opencl.cpp @@ -212,23 +212,23 @@ pi_result OCL(piProgramCreate)(pi_context context, const void *il, } pi_result OCL(piSamplerCreate)(pi_context context, - const cl_sampler_properties *sampler_properties, + const pi_sampler_properties *sampler_properties, pi_sampler *result_sampler) { // Initialize properties according to OpenCL 2.1 spec. pi_result error_code; - cl_bool normalizedCoords = CL_TRUE; - cl_addressing_mode addressingMode = CL_ADDRESS_CLAMP; - cl_filter_mode filterMode = CL_FILTER_NEAREST; + pi_bool normalizedCoords = PI_TRUE; + pi_sampler_addressing_mode addressingMode = PI_SAMPLER_ADDRESSING_MODE_CLAMP; + pi_sampler_filter_mode filterMode = PI_SAMPLER_FILTER_MODE_NEAREST; // Unpack sampler properties for (std::size_t i = 0; sampler_properties && sampler_properties[i] != 0; ++i) { - if (sampler_properties[i] == CL_SAMPLER_NORMALIZED_COORDS) { - normalizedCoords = sampler_properties[++i]; - } else if (sampler_properties[i] == CL_SAMPLER_ADDRESSING_MODE) { - addressingMode = sampler_properties[++i]; - } else if (sampler_properties[i] == CL_SAMPLER_FILTER_MODE) { - filterMode = sampler_properties[++i]; + if (sampler_properties[i] == PI_SAMPLER_INFO_NORMALIZED_COORDS) { + normalizedCoords = static_cast(sampler_properties[++i]); + } else if (sampler_properties[i] == PI_SAMPLER_INFO_ADDRESSING_MODE) { + addressingMode = static_cast(sampler_properties[++i]); + } else if (sampler_properties[i] == PI_SAMPLER_INFO_FILTER_MODE) { + filterMode = static_cast(sampler_properties[++i]); } else { PI_ASSERT(false, "Cannot recognize sampler property"); } diff --git a/sycl/source/detail/sampler_impl.cpp b/sycl/source/detail/sampler_impl.cpp index 4128159557487..656589430aed6 100644 --- a/sycl/source/detail/sampler_impl.cpp +++ b/sycl/source/detail/sampler_impl.cpp @@ -24,13 +24,13 @@ sampler_impl::sampler_impl(cl_sampler clSampler, const context &syclContext) { RT::PiSampler Sampler = pi::cast(clSampler); m_contextToSampler[syclContext] = Sampler; PI_CALL(RT::piSamplerRetain(Sampler)); - PI_CALL(RT::piSamplerGetInfo(Sampler, CL_SAMPLER_NORMALIZED_COORDS, - sizeof(cl_bool), &m_CoordNormMode, nullptr)); - PI_CALL(RT::piSamplerGetInfo(Sampler, CL_SAMPLER_ADDRESSING_MODE, - sizeof(cl_addressing_mode), &m_AddrMode, + PI_CALL(RT::piSamplerGetInfo(Sampler, PI_SAMPLER_INFO_NORMALIZED_COORDS, + sizeof(pi_bool), &m_CoordNormMode, nullptr)); + PI_CALL(RT::piSamplerGetInfo(Sampler, PI_SAMPLER_INFO_ADDRESSING_MODE, + sizeof(pi_sampler_addressing_mode), &m_AddrMode, nullptr)); - PI_CALL(RT::piSamplerGetInfo(Sampler, CL_SAMPLER_FILTER_MODE, - sizeof(cl_filter_mode), &m_FiltMode, + PI_CALL(RT::piSamplerGetInfo(Sampler, PI_SAMPLER_INFO_FILTER_MODE, + sizeof(pi_sampler_filter_mode), &m_FiltMode, nullptr)); } @@ -45,13 +45,13 @@ RT::PiSampler sampler_impl::getOrCreateSampler(const context &Context) { if (m_contextToSampler[Context]) return m_contextToSampler[Context]; - const cl_sampler_properties sprops[] = { - CL_SAMPLER_NORMALIZED_COORDS, - static_cast(m_CoordNormMode), - CL_SAMPLER_ADDRESSING_MODE, - static_cast(m_AddrMode), - CL_SAMPLER_FILTER_MODE, - static_cast(m_FiltMode), + const pi_sampler_properties sprops[] = { + PI_SAMPLER_INFO_NORMALIZED_COORDS, + static_cast(m_CoordNormMode), + PI_SAMPLER_INFO_ADDRESSING_MODE, + static_cast(m_AddrMode), + PI_SAMPLER_INFO_FILTER_MODE, + static_cast(m_FiltMode), 0}; RT::PiResult errcode_ret = PI_SUCCESS;