Skip to content

[SYCL] Replaced cl_sampler_properties with pi_sampler_properties #477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions sycl/include/CL/sycl/detail/pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
46 changes: 25 additions & 21 deletions sycl/include/CL/sycl/detail/pi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions sycl/source/detail/pi_opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<pi_bool>(sampler_properties[++i]);
} else if (sampler_properties[i] == PI_SAMPLER_INFO_ADDRESSING_MODE) {
addressingMode = static_cast<pi_sampler_addressing_mode>(sampler_properties[++i]);
} else if (sampler_properties[i] == PI_SAMPLER_INFO_FILTER_MODE) {
filterMode = static_cast<pi_sampler_filter_mode>(sampler_properties[++i]);
} else {
PI_ASSERT(false, "Cannot recognize sampler property");
}
Expand Down
26 changes: 13 additions & 13 deletions sycl/source/detail/sampler_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ sampler_impl::sampler_impl(cl_sampler clSampler, const context &syclContext) {
RT::PiSampler Sampler = pi::cast<RT::PiSampler>(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));
}

Expand All @@ -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<cl_sampler_properties>(m_CoordNormMode),
CL_SAMPLER_ADDRESSING_MODE,
static_cast<cl_sampler_properties>(m_AddrMode),
CL_SAMPLER_FILTER_MODE,
static_cast<cl_sampler_properties>(m_FiltMode),
const pi_sampler_properties sprops[] = {
PI_SAMPLER_INFO_NORMALIZED_COORDS,
static_cast<pi_sampler_properties>(m_CoordNormMode),
PI_SAMPLER_INFO_ADDRESSING_MODE,
static_cast<pi_sampler_properties>(m_AddrMode),
PI_SAMPLER_INFO_FILTER_MODE,
static_cast<pi_sampler_properties>(m_FiltMode),
0};

RT::PiResult errcode_ret = PI_SUCCESS;
Expand Down