Skip to content

Commit c2e50e0

Browse files
Ivan Karachunbader
authored andcommitted
[SYCL] Replace cl_sampler_properties with pi_sampler_properties (#477)
Signed-off-by: Ivan Karachun <[email protected]>
1 parent 62de0c4 commit c2e50e0

File tree

4 files changed

+81
-46
lines changed

4 files changed

+81
-46
lines changed

sycl/include/CL/sycl/detail/pi.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,34 @@ typedef enum {
155155
PI_BUFFER_CREATE_TYPE_REGION = CL_BUFFER_CREATE_TYPE_REGION
156156
} _pi_buffer_create_type;
157157

158+
typedef pi_bitfield pi_sampler_properties;
159+
const pi_bool PI_TRUE = CL_TRUE;
160+
const pi_bool PI_FALSE = CL_FALSE;
161+
162+
typedef enum {
163+
PI_SAMPLER_INFO_REFERENCE_COUNT = CL_SAMPLER_REFERENCE_COUNT,
164+
PI_SAMPLER_INFO_CONTEXT = CL_SAMPLER_CONTEXT,
165+
PI_SAMPLER_INFO_NORMALIZED_COORDS = CL_SAMPLER_NORMALIZED_COORDS,
166+
PI_SAMPLER_INFO_ADDRESSING_MODE = CL_SAMPLER_ADDRESSING_MODE,
167+
PI_SAMPLER_INFO_FILTER_MODE = CL_SAMPLER_FILTER_MODE,
168+
PI_SAMPLER_INFO_MIP_FILTER_MODE = CL_SAMPLER_MIP_FILTER_MODE,
169+
PI_SAMPLER_INFO_LOD_MIN = CL_SAMPLER_LOD_MIN,
170+
PI_SAMPLER_INFO_LOD_MAX = CL_SAMPLER_LOD_MAX
171+
} _pi_sampler_info;
172+
173+
typedef enum {
174+
PI_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT = CL_ADDRESS_MIRRORED_REPEAT,
175+
PI_SAMPLER_ADDRESSING_MODE_REPEAT = CL_ADDRESS_REPEAT,
176+
PI_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE = CL_ADDRESS_CLAMP_TO_EDGE,
177+
PI_SAMPLER_ADDRESSING_MODE_CLAMP = CL_ADDRESS_CLAMP,
178+
PI_SAMPLER_ADDRESSING_MODE_NONE = CL_ADDRESS_NONE
179+
} _pi_sampler_addressing_mode;
180+
181+
typedef enum {
182+
PI_SAMPLER_FILTER_MODE_NEAREST = CL_FILTER_NEAREST,
183+
PI_SAMPLER_FILTER_MODE_LINEAR = CL_FILTER_LINEAR,
184+
} _pi_sampler_filter_mode;
185+
158186
// NOTE: this is made 64-bit to match the size of cl_mem_flags to
159187
// make the translation to OpenCL transparent.
160188
// TODO: populate
@@ -187,6 +215,9 @@ typedef _pi_mem_type pi_mem_type;
187215
typedef _pi_image_channel_order pi_image_channel_order;
188216
typedef _pi_image_channel_type pi_image_channel_type;
189217
typedef _pi_buffer_create_type pi_buffer_create_type;
218+
typedef _pi_sampler_addressing_mode pi_sampler_addressing_mode;
219+
typedef _pi_sampler_filter_mode pi_sampler_filter_mode;
220+
typedef _pi_sampler_info pi_sampler_info;
190221

191222
// Opaque data type for compatibility with OpenMP.
192223
typedef void * _pi_offload_entry;
@@ -631,12 +662,12 @@ pi_result piEventRelease(pi_event event);
631662
//
632663
pi_result piSamplerCreate(
633664
pi_context context,
634-
const cl_sampler_properties * sampler_properties, // TODO: untie from OpenCL
665+
const pi_sampler_properties * sampler_properties,
635666
pi_sampler * result_sampler);
636667

637668
pi_result piSamplerGetInfo(
638669
pi_sampler sampler,
639-
cl_sampler_info param_name, // TODO: untie from OpenCL
670+
pi_sampler_info param_name,
640671
size_t param_value_size,
641672
void * param_value,
642673
size_t * param_value_size_ret);

sycl/include/CL/sycl/detail/pi.hpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,31 @@ namespace pi {
2929
// Check for manually selected BE at run-time.
3030
bool useBackend(Backend Backend);
3131

32-
using PiResult = ::pi_result;
33-
using PiPlatform = ::pi_platform;
34-
using PiDevice = ::pi_device;
35-
using PiDeviceType = ::pi_device_type;
36-
using PiDeviceInfo = ::pi_device_info;
37-
using PiDeviceBinaryType = ::pi_device_binary_type;
38-
using PiContext = ::pi_context;
39-
using PiProgram = ::pi_program;
40-
using PiKernel = ::pi_kernel;
41-
using PiQueue = ::pi_queue;
42-
using PiQueueProperties = ::pi_queue_properties;
43-
using PiMem = ::pi_mem;
44-
using PiMemFlags = ::pi_mem_flags;
45-
using PiEvent = ::pi_event;
46-
using PiSampler = ::pi_sampler;
47-
using PiMemImageFormat = ::pi_image_format;
48-
using PiMemImageDesc = ::pi_image_desc;
49-
using PiMemImageInfo = ::pi_image_info;
50-
using PiMemObjectType = ::pi_mem_type;
51-
using PiMemImageChannelOrder = ::pi_image_channel_order;
52-
using PiMemImageChannelType = ::pi_image_channel_type;
32+
using PiResult = ::pi_result;
33+
using PiPlatform = ::pi_platform;
34+
using PiDevice = ::pi_device;
35+
using PiDeviceType = ::pi_device_type;
36+
using PiDeviceInfo = ::pi_device_info;
37+
using PiDeviceBinaryType = ::pi_device_binary_type;
38+
using PiContext = ::pi_context;
39+
using PiProgram = ::pi_program;
40+
using PiKernel = ::pi_kernel;
41+
using PiQueue = ::pi_queue;
42+
using PiQueueProperties = ::pi_queue_properties;
43+
using PiMem = ::pi_mem;
44+
using PiMemFlags = ::pi_mem_flags;
45+
using PiEvent = ::pi_event;
46+
using PiSampler = ::pi_sampler;
47+
using PiSamplerInfo = ::pi_sampler_info;
48+
using PiSamplerProperties = ::pi_sampler_properties;
49+
using PiSamplerAddressingMode = ::pi_sampler_addressing_mode;
50+
using PiSamplerFilterMode = ::pi_sampler_filter_mode;
51+
using PiMemImageFormat = ::pi_image_format;
52+
using PiMemImageDesc = ::pi_image_desc;
53+
using PiMemImageInfo = ::pi_image_info;
54+
using PiMemObjectType = ::pi_mem_type;
55+
using PiMemImageChannelOrder = ::pi_image_channel_order;
56+
using PiMemImageChannelType = ::pi_image_channel_type;
5357

5458
// Get a string representing a _pi_platform_info enum
5559
std::string platformInfoToString(pi_platform_info info);

sycl/source/detail/pi_opencl.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,23 +212,23 @@ pi_result OCL(piProgramCreate)(pi_context context, const void *il,
212212
}
213213

214214
pi_result OCL(piSamplerCreate)(pi_context context,
215-
const cl_sampler_properties *sampler_properties,
215+
const pi_sampler_properties *sampler_properties,
216216
pi_sampler *result_sampler) {
217217
// Initialize properties according to OpenCL 2.1 spec.
218218
pi_result error_code;
219-
cl_bool normalizedCoords = CL_TRUE;
220-
cl_addressing_mode addressingMode = CL_ADDRESS_CLAMP;
221-
cl_filter_mode filterMode = CL_FILTER_NEAREST;
219+
pi_bool normalizedCoords = PI_TRUE;
220+
pi_sampler_addressing_mode addressingMode = PI_SAMPLER_ADDRESSING_MODE_CLAMP;
221+
pi_sampler_filter_mode filterMode = PI_SAMPLER_FILTER_MODE_NEAREST;
222222

223223
// Unpack sampler properties
224224
for (std::size_t i = 0; sampler_properties && sampler_properties[i] != 0;
225225
++i) {
226-
if (sampler_properties[i] == CL_SAMPLER_NORMALIZED_COORDS) {
227-
normalizedCoords = sampler_properties[++i];
228-
} else if (sampler_properties[i] == CL_SAMPLER_ADDRESSING_MODE) {
229-
addressingMode = sampler_properties[++i];
230-
} else if (sampler_properties[i] == CL_SAMPLER_FILTER_MODE) {
231-
filterMode = sampler_properties[++i];
226+
if (sampler_properties[i] == PI_SAMPLER_INFO_NORMALIZED_COORDS) {
227+
normalizedCoords = static_cast<pi_bool>(sampler_properties[++i]);
228+
} else if (sampler_properties[i] == PI_SAMPLER_INFO_ADDRESSING_MODE) {
229+
addressingMode = static_cast<pi_sampler_addressing_mode>(sampler_properties[++i]);
230+
} else if (sampler_properties[i] == PI_SAMPLER_INFO_FILTER_MODE) {
231+
filterMode = static_cast<pi_sampler_filter_mode>(sampler_properties[++i]);
232232
} else {
233233
PI_ASSERT(false, "Cannot recognize sampler property");
234234
}

sycl/source/detail/sampler_impl.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ sampler_impl::sampler_impl(cl_sampler clSampler, const context &syclContext) {
2424
RT::PiSampler Sampler = pi::cast<RT::PiSampler>(clSampler);
2525
m_contextToSampler[syclContext] = Sampler;
2626
PI_CALL(RT::piSamplerRetain(Sampler));
27-
PI_CALL(RT::piSamplerGetInfo(Sampler, CL_SAMPLER_NORMALIZED_COORDS,
28-
sizeof(cl_bool), &m_CoordNormMode, nullptr));
29-
PI_CALL(RT::piSamplerGetInfo(Sampler, CL_SAMPLER_ADDRESSING_MODE,
30-
sizeof(cl_addressing_mode), &m_AddrMode,
27+
PI_CALL(RT::piSamplerGetInfo(Sampler, PI_SAMPLER_INFO_NORMALIZED_COORDS,
28+
sizeof(pi_bool), &m_CoordNormMode, nullptr));
29+
PI_CALL(RT::piSamplerGetInfo(Sampler, PI_SAMPLER_INFO_ADDRESSING_MODE,
30+
sizeof(pi_sampler_addressing_mode), &m_AddrMode,
3131
nullptr));
32-
PI_CALL(RT::piSamplerGetInfo(Sampler, CL_SAMPLER_FILTER_MODE,
33-
sizeof(cl_filter_mode), &m_FiltMode,
32+
PI_CALL(RT::piSamplerGetInfo(Sampler, PI_SAMPLER_INFO_FILTER_MODE,
33+
sizeof(pi_sampler_filter_mode), &m_FiltMode,
3434
nullptr));
3535
}
3636

@@ -45,13 +45,13 @@ RT::PiSampler sampler_impl::getOrCreateSampler(const context &Context) {
4545
if (m_contextToSampler[Context])
4646
return m_contextToSampler[Context];
4747

48-
const cl_sampler_properties sprops[] = {
49-
CL_SAMPLER_NORMALIZED_COORDS,
50-
static_cast<cl_sampler_properties>(m_CoordNormMode),
51-
CL_SAMPLER_ADDRESSING_MODE,
52-
static_cast<cl_sampler_properties>(m_AddrMode),
53-
CL_SAMPLER_FILTER_MODE,
54-
static_cast<cl_sampler_properties>(m_FiltMode),
48+
const pi_sampler_properties sprops[] = {
49+
PI_SAMPLER_INFO_NORMALIZED_COORDS,
50+
static_cast<pi_sampler_properties>(m_CoordNormMode),
51+
PI_SAMPLER_INFO_ADDRESSING_MODE,
52+
static_cast<pi_sampler_properties>(m_AddrMode),
53+
PI_SAMPLER_INFO_FILTER_MODE,
54+
static_cast<pi_sampler_properties>(m_FiltMode),
5555
0};
5656

5757
RT::PiResult errcode_ret = PI_SUCCESS;

0 commit comments

Comments
 (0)