Skip to content

Commit

Permalink
Work around older (4.8/4.9) gcc issues on Ubuntu (thanks @larsmans)
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Nov 30, 2015
1 parent bbfa646 commit e12f38a
Show file tree
Hide file tree
Showing 22 changed files with 100 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/c_wrapper/buffer.cpp
Expand Up @@ -18,7 +18,7 @@ buffer::get_sub_region(size_t orig, size_t size, cl_mem_flags flags) const
cl_buffer_region reg = {orig, size};

auto mem = retry_mem_error([&] {
return pyopencl_call_guarded(clCreateSubBuffer, this, flags,
return pyopencl_call_guarded(clCreateSubBuffer, PYOPENCL_CL_CASTABLE_THIS, flags,
CL_BUFFER_CREATE_TYPE_REGION, &reg);
});
return new_buffer(mem);
Expand Down
10 changes: 5 additions & 5 deletions src/c_wrapper/command_queue.cpp
Expand Up @@ -13,7 +13,7 @@ template void print_buf<cl_command_queue>(

command_queue::~command_queue()
{
pyopencl_call_guarded_cleanup(clReleaseCommandQueue, this);
pyopencl_call_guarded_cleanup(clReleaseCommandQueue, PYOPENCL_CL_CASTABLE_THIS);
}

generic_info
Expand All @@ -22,15 +22,15 @@ command_queue::get_info(cl_uint param_name) const
switch ((cl_command_queue_info)param_name) {
case CL_QUEUE_CONTEXT:
return pyopencl_get_opaque_info(context, CommandQueue,
this, param_name);
PYOPENCL_CL_CASTABLE_THIS, param_name);
case CL_QUEUE_DEVICE:
return pyopencl_get_opaque_info(device, CommandQueue, this, param_name);
return pyopencl_get_opaque_info(device, CommandQueue, PYOPENCL_CL_CASTABLE_THIS, param_name);
case CL_QUEUE_REFERENCE_COUNT:
return pyopencl_get_int_info(cl_uint, CommandQueue,
this, param_name);
PYOPENCL_CL_CASTABLE_THIS, param_name);
case CL_QUEUE_PROPERTIES:
return pyopencl_get_int_info(cl_command_queue_properties,
CommandQueue, this, param_name);
CommandQueue, PYOPENCL_CL_CASTABLE_THIS, param_name);
default:
throw clerror("CommandQueue.get_info", CL_INVALID_VALUE);
}
Expand Down
2 changes: 1 addition & 1 deletion src/c_wrapper/command_queue.h
Expand Up @@ -19,7 +19,7 @@ class command_queue : public clobj<cl_command_queue> {
: clobj(q)
{
if (retain) {
pyopencl_call_guarded(clRetainCommandQueue, this);
pyopencl_call_guarded(clRetainCommandQueue, PYOPENCL_CL_CASTABLE_THIS);
}
}
PYOPENCL_INLINE
Expand Down
10 changes: 5 additions & 5 deletions src/c_wrapper/context.cpp
Expand Up @@ -33,7 +33,7 @@ context::get_version(cl_context ctx, int *major, int *minor)

context::~context()
{
pyopencl_call_guarded_cleanup(clReleaseContext, this);
pyopencl_call_guarded_cleanup(clReleaseContext, PYOPENCL_CL_CASTABLE_THIS);
}

generic_info
Expand All @@ -42,13 +42,13 @@ context::get_info(cl_uint param_name) const
switch ((cl_context_info)param_name) {
case CL_CONTEXT_REFERENCE_COUNT:
return pyopencl_get_int_info(cl_uint, Context,
this, param_name);
PYOPENCL_CL_CASTABLE_THIS, param_name);
case CL_CONTEXT_DEVICES:
return pyopencl_get_opaque_array_info(device, Context,
this, param_name);
PYOPENCL_CL_CASTABLE_THIS, param_name);
case CL_CONTEXT_PROPERTIES: {
auto result = pyopencl_get_vec_info(
cl_context_properties, Context, this, param_name);
cl_context_properties, Context, PYOPENCL_CL_CASTABLE_THIS, param_name);
pyopencl_buf<generic_info> py_result(result.len() / 2);
size_t i = 0;
for (;i < py_result.len();i++) {
Expand Down Expand Up @@ -96,7 +96,7 @@ context::get_info(cl_uint param_name) const
#if PYOPENCL_CL_VERSION >= 0x1010
case CL_CONTEXT_NUM_DEVICES:
return pyopencl_get_int_info(cl_uint, Context,
this, param_name);
PYOPENCL_CL_CASTABLE_THIS, param_name);
#endif

default:
Expand Down
2 changes: 1 addition & 1 deletion src/c_wrapper/context.h
Expand Up @@ -20,7 +20,7 @@ class context : public clobj<cl_context> {
: clobj(ctx)
{
if (retain) {
pyopencl_call_guarded(clRetainContext, this);
pyopencl_call_guarded(clRetainContext, PYOPENCL_CL_CASTABLE_THIS);
}
}
~context();
Expand Down
28 changes: 14 additions & 14 deletions src/c_wrapper/device.cpp
Expand Up @@ -23,7 +23,7 @@ device::~device()
}
#if PYOPENCL_CL_VERSION >= 0x1020
else if (m_ref_type == REF_CL_1_2) {
pyopencl_call_guarded_cleanup(clReleaseDevice, this);
pyopencl_call_guarded_cleanup(clReleaseDevice, PYOPENCL_CL_CASTABLE_THIS);
}
#endif
}
Expand All @@ -32,7 +32,7 @@ generic_info
device::get_info(cl_uint param_name) const
{
#define DEV_GET_INT_INF(TYPE) \
pyopencl_get_int_info(TYPE, Device, this, param_name)
pyopencl_get_int_info(TYPE, Device, PYOPENCL_CL_CASTABLE_THIS, param_name)

switch ((cl_device_info)param_name) {
case CL_DEVICE_TYPE:
Expand All @@ -45,7 +45,7 @@ device::get_info(cl_uint param_name) const
return DEV_GET_INT_INF(cl_uint);

case CL_DEVICE_MAX_WORK_ITEM_SIZES:
return pyopencl_get_array_info(size_t, Device, this, param_name);
return pyopencl_get_array_info(size_t, Device, PYOPENCL_CL_CASTABLE_THIS, param_name);

case CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR:
case CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT:
Expand Down Expand Up @@ -118,10 +118,10 @@ device::get_info(cl_uint param_name) const
case CL_DEVICE_PROFILE:
case CL_DEVICE_VERSION:
case CL_DEVICE_EXTENSIONS:
return pyopencl_get_str_info(Device, this, param_name);
return pyopencl_get_str_info(Device, PYOPENCL_CL_CASTABLE_THIS, param_name);

case CL_DEVICE_PLATFORM:
return pyopencl_get_opaque_info(platform, Device, this, param_name);
return pyopencl_get_opaque_info(platform, Device, PYOPENCL_CL_CASTABLE_THIS, param_name);
#if PYOPENCL_CL_VERSION >= 0x1010
case CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF:
case CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR:
Expand All @@ -136,7 +136,7 @@ device::get_info(cl_uint param_name) const
case CL_DEVICE_HOST_UNIFIED_MEMORY: // deprecated in 2.0
return DEV_GET_INT_INF(cl_bool);
case CL_DEVICE_OPENCL_C_VERSION:
return pyopencl_get_str_info(Device, this, param_name);
return pyopencl_get_str_info(Device, PYOPENCL_CL_CASTABLE_THIS, param_name);
#endif
#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
case CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV:
Expand All @@ -153,21 +153,21 @@ device::get_info(cl_uint param_name) const
case CL_DEVICE_LINKER_AVAILABLE:
return DEV_GET_INT_INF(cl_bool);
case CL_DEVICE_BUILT_IN_KERNELS:
return pyopencl_get_str_info(Device, this, param_name);
return pyopencl_get_str_info(Device, PYOPENCL_CL_CASTABLE_THIS, param_name);
case CL_DEVICE_IMAGE_MAX_BUFFER_SIZE:
case CL_DEVICE_IMAGE_MAX_ARRAY_SIZE:
return DEV_GET_INT_INF(size_t);
case CL_DEVICE_PARENT_DEVICE:
return pyopencl_get_opaque_info(device, Device, this, param_name);
return pyopencl_get_opaque_info(device, Device, PYOPENCL_CL_CASTABLE_THIS, param_name);
case CL_DEVICE_PARTITION_MAX_SUB_DEVICES:
return DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_PARTITION_TYPE:
case CL_DEVICE_PARTITION_PROPERTIES:
return pyopencl_get_array_info(cl_device_partition_property,
Device, this, param_name);
Device, PYOPENCL_CL_CASTABLE_THIS, param_name);
case CL_DEVICE_PARTITION_AFFINITY_DOMAIN:
return pyopencl_get_array_info(cl_device_affinity_domain,
Device, this, param_name);
Device, PYOPENCL_CL_CASTABLE_THIS, param_name);
case CL_DEVICE_REFERENCE_COUNT:
return DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_PREFERRED_INTEROP_USER_SYNC:
Expand Down Expand Up @@ -225,12 +225,12 @@ device::get_info(cl_uint param_name) const
*/
#ifdef CL_DEVICE_BOARD_NAME_AMD
case CL_DEVICE_BOARD_NAME_AMD: ;
return pyopencl_get_str_info(Device, this, param_name);
return pyopencl_get_str_info(Device, PYOPENCL_CL_CASTABLE_THIS, param_name);
#endif
#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
case CL_DEVICE_GLOBAL_FREE_MEMORY_AMD:
return pyopencl_get_array_info(size_t, Device,
this, param_name);
PYOPENCL_CL_CASTABLE_THIS, param_name);
#endif
#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
case CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD:
Expand Down Expand Up @@ -277,10 +277,10 @@ device::create_sub_devices(const cl_device_partition_property *props)
{
// TODO debug print props
cl_uint num_devices;
pyopencl_call_guarded(clCreateSubDevices, this, props, 0, nullptr,
pyopencl_call_guarded(clCreateSubDevices, PYOPENCL_CL_CASTABLE_THIS, props, 0, nullptr,
buf_arg(num_devices));
pyopencl_buf<cl_device_id> devices(num_devices);
pyopencl_call_guarded(clCreateSubDevices, this, props, devices,
pyopencl_call_guarded(clCreateSubDevices, PYOPENCL_CL_CASTABLE_THIS, props, devices,
buf_arg(num_devices));
return buf_to_base<device>(devices, true, device::REF_CL_1_2);
}
Expand Down
2 changes: 1 addition & 1 deletion src/c_wrapper/device.h
Expand Up @@ -33,7 +33,7 @@ class device : public clobj<cl_device_id> {
}
#if PYOPENCL_CL_VERSION >= 0x1020
else if (ref_type == REF_CL_1_2) {
pyopencl_call_guarded(clRetainDevice, this);
pyopencl_call_guarded(clRetainDevice, PYOPENCL_CL_CASTABLE_THIS);
}
#endif

Expand Down
8 changes: 8 additions & 0 deletions src/c_wrapper/error.h
Expand Up @@ -14,6 +14,14 @@

// {{{ error

// See https://github.com/pyopencl/pyopencl/pull/83
#if GCC_VERSION > 50200
#define PYOPENCL_CL_CASTABLE_THIS this
#else
#define PYOPENCL_CL_CASTABLE_THIS data()
#endif


class clerror : public std::runtime_error {
private:
const char *m_routine;
Expand Down
18 changes: 9 additions & 9 deletions src/c_wrapper/event.cpp
Expand Up @@ -40,7 +40,7 @@ event::event(cl_event event, bool retain, event_private *p)
{
if (retain) {
try {
pyopencl_call_guarded(clRetainEvent, this);
pyopencl_call_guarded(clRetainEvent, PYOPENCL_CL_CASTABLE_THIS);
} catch (...) {
m_p->call_finish();
delete m_p;
Expand Down Expand Up @@ -106,25 +106,25 @@ event::release_private() noexcept
event::~event()
{
release_private();
pyopencl_call_guarded_cleanup(clReleaseEvent, this);
pyopencl_call_guarded_cleanup(clReleaseEvent, PYOPENCL_CL_CASTABLE_THIS);
}

generic_info
event::get_info(cl_uint param_name) const
{
switch ((cl_event_info)param_name) {
case CL_EVENT_COMMAND_QUEUE:
return pyopencl_get_opaque_info(command_queue, Event, this, param_name);
return pyopencl_get_opaque_info(command_queue, Event, PYOPENCL_CL_CASTABLE_THIS, param_name);
case CL_EVENT_COMMAND_TYPE:
return pyopencl_get_int_info(cl_command_type, Event,
this, param_name);
PYOPENCL_CL_CASTABLE_THIS, param_name);
case CL_EVENT_COMMAND_EXECUTION_STATUS:
return pyopencl_get_int_info(cl_int, Event, this, param_name);
return pyopencl_get_int_info(cl_int, Event, PYOPENCL_CL_CASTABLE_THIS, param_name);
case CL_EVENT_REFERENCE_COUNT:
return pyopencl_get_int_info(cl_uint, Event, this, param_name);
return pyopencl_get_int_info(cl_uint, Event, PYOPENCL_CL_CASTABLE_THIS, param_name);
#if PYOPENCL_CL_VERSION >= 0x1010
case CL_EVENT_CONTEXT:
return pyopencl_get_opaque_info(context, Event, this, param_name);
return pyopencl_get_opaque_info(context, Event, PYOPENCL_CL_CASTABLE_THIS, param_name);
#endif

default:
Expand All @@ -140,7 +140,7 @@ event::get_profiling_info(cl_profiling_info param) const
case CL_PROFILING_COMMAND_SUBMIT:
case CL_PROFILING_COMMAND_START:
case CL_PROFILING_COMMAND_END:
return pyopencl_get_int_info(cl_ulong, EventProfiling, this, param);
return pyopencl_get_int_info(cl_ulong, EventProfiling, PYOPENCL_CL_CASTABLE_THIS, param);
default:
throw clerror("Event.get_profiling_info", CL_INVALID_VALUE);
}
Expand Down Expand Up @@ -195,7 +195,7 @@ class user_event : public event {
PYOPENCL_INLINE void
set_status(cl_int status)
{
pyopencl_call_guarded(clSetUserEventStatus, this, status);
pyopencl_call_guarded(clSetUserEventStatus, PYOPENCL_CL_CASTABLE_THIS, status);
}
};
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/c_wrapper/event.h
Expand Up @@ -39,7 +39,7 @@ class event : public clobj<cl_event> {
auto func = new rm_ref_t<Func>(std::forward<Func>(_func));
try {
pyopencl_call_guarded(
clSetEventCallback, this, type,
clSetEventCallback, PYOPENCL_CL_CASTABLE_THIS, type,
[] (cl_event, cl_int status, void *data) {
rm_ref_t<Func> *func = static_cast<rm_ref_t<Func>*>(data);
std::thread t([func, status] () {
Expand Down
6 changes: 3 additions & 3 deletions src/c_wrapper/image.cpp
Expand Up @@ -17,7 +17,7 @@ image::get_image_info(cl_image_info param) const
{
switch (param) {
case CL_IMAGE_FORMAT:
return pyopencl_get_int_info(cl_image_format, Image, this, param);
return pyopencl_get_int_info(cl_image_format, Image, PYOPENCL_CL_CASTABLE_THIS, param);
case CL_IMAGE_ELEMENT_SIZE:
case CL_IMAGE_ROW_PITCH:
case CL_IMAGE_SLICE_PITCH:
Expand All @@ -27,7 +27,7 @@ image::get_image_info(cl_image_info param) const
#if PYOPENCL_CL_VERSION >= 0x1020
case CL_IMAGE_ARRAY_SIZE:
#endif
return pyopencl_get_int_info(size_t, Image, this, param);
return pyopencl_get_int_info(size_t, Image, PYOPENCL_CL_CASTABLE_THIS, param);

#if PYOPENCL_CL_VERSION >= 0x1020
// TODO:
Expand All @@ -44,7 +44,7 @@ image::get_image_info(cl_image_info param) const
// }
case CL_IMAGE_NUM_MIP_LEVELS:
case CL_IMAGE_NUM_SAMPLES:
return pyopencl_get_int_info(cl_uint, Image, this, param);
return pyopencl_get_int_info(cl_uint, Image, PYOPENCL_CL_CASTABLE_THIS, param);
#endif
default:
throw clerror("Image.get_image_info", CL_INVALID_VALUE);
Expand Down
2 changes: 1 addition & 1 deletion src/c_wrapper/image.h
Expand Up @@ -19,7 +19,7 @@ class image : public memory_object {
format()
{
if (!m_format.image_channel_data_type) {
pyopencl_call_guarded(clGetImageInfo, this, CL_IMAGE_FORMAT,
pyopencl_call_guarded(clGetImageInfo, PYOPENCL_CL_CASTABLE_THIS, CL_IMAGE_FORMAT,
size_arg(m_format), nullptr);
}
return m_format;
Expand Down
24 changes: 12 additions & 12 deletions src/c_wrapper/kernel.cpp
Expand Up @@ -16,25 +16,25 @@ template void print_buf<cl_kernel>(std::ostream&, const cl_kernel*,

kernel::~kernel()
{
pyopencl_call_guarded_cleanup(clReleaseKernel, this);
pyopencl_call_guarded_cleanup(clReleaseKernel, PYOPENCL_CL_CASTABLE_THIS);
}

generic_info
kernel::get_info(cl_uint param) const
{
switch ((cl_kernel_info)param) {
case CL_KERNEL_FUNCTION_NAME:
return pyopencl_get_str_info(Kernel, this, param);
return pyopencl_get_str_info(Kernel, PYOPENCL_CL_CASTABLE_THIS, param);
case CL_KERNEL_NUM_ARGS:
case CL_KERNEL_REFERENCE_COUNT:
return pyopencl_get_int_info(cl_uint, Kernel, this, param);
return pyopencl_get_int_info(cl_uint, Kernel, PYOPENCL_CL_CASTABLE_THIS, param);
case CL_KERNEL_CONTEXT:
return pyopencl_get_opaque_info(context, Kernel, this, param);
return pyopencl_get_opaque_info(context, Kernel, PYOPENCL_CL_CASTABLE_THIS, param);
case CL_KERNEL_PROGRAM:
return pyopencl_get_opaque_info(program, Kernel, this, param);
return pyopencl_get_opaque_info(program, Kernel, PYOPENCL_CL_CASTABLE_THIS, param);
#if PYOPENCL_CL_VERSION >= 0x1020
case CL_KERNEL_ATTRIBUTES:
return pyopencl_get_str_info(Kernel, this, param);
return pyopencl_get_str_info(Kernel, PYOPENCL_CL_CASTABLE_THIS, param);
#endif
default:
throw clerror("Kernel.get_info", CL_INVALID_VALUE);
Expand All @@ -50,16 +50,16 @@ kernel::get_work_group_info(cl_kernel_work_group_info param,
case CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE:
#endif
case CL_KERNEL_WORK_GROUP_SIZE:
return pyopencl_get_int_info(size_t, KernelWorkGroup, this, dev, param);
return pyopencl_get_int_info(size_t, KernelWorkGroup, PYOPENCL_CL_CASTABLE_THIS, dev, param);
case CL_KERNEL_COMPILE_WORK_GROUP_SIZE:
return pyopencl_get_array_info(size_t, KernelWorkGroup,
this, dev, param);
PYOPENCL_CL_CASTABLE_THIS, dev, param);
case CL_KERNEL_LOCAL_MEM_SIZE:
#if PYOPENCL_CL_VERSION >= 0x1010
case CL_KERNEL_PRIVATE_MEM_SIZE:
#endif
return pyopencl_get_int_info(cl_ulong, KernelWorkGroup,
this, dev, param);
PYOPENCL_CL_CASTABLE_THIS, dev, param);
default:
throw clerror("Kernel.get_work_group_info", CL_INVALID_VALUE);
}
Expand All @@ -72,16 +72,16 @@ kernel::get_arg_info(cl_uint idx, cl_kernel_arg_info param) const
switch (param) {
case CL_KERNEL_ARG_ADDRESS_QUALIFIER:
return pyopencl_get_int_info(cl_kernel_arg_address_qualifier,
KernelArg, this, idx, param);
KernelArg, PYOPENCL_CL_CASTABLE_THIS, idx, param);
case CL_KERNEL_ARG_ACCESS_QUALIFIER:
return pyopencl_get_int_info(cl_kernel_arg_access_qualifier,
KernelArg, this, idx, param);
KernelArg, PYOPENCL_CL_CASTABLE_THIS, idx, param);
case CL_KERNEL_ARG_TYPE_QUALIFIER:
return pyopencl_get_int_info(cl_kernel_arg_type_qualifier,
KernelArg, this, idx, param);
case CL_KERNEL_ARG_TYPE_NAME:
case CL_KERNEL_ARG_NAME:
return pyopencl_get_str_info(KernelArg, this, idx, param);
return pyopencl_get_str_info(KernelArg, PYOPENCL_CL_CASTABLE_THIS, idx, param);
default:
throw clerror("Kernel.get_arg_info", CL_INVALID_VALUE);
}
Expand Down

0 comments on commit e12f38a

Please sign in to comment.