Skip to content

Commit

Permalink
Added support for cl_device_topology_amd device-info (CL_DEVICE_TOPOL…
Browse files Browse the repository at this point in the history
…OGY_AMD parameter).
  • Loading branch information
Shane-J-Latham committed Jun 13, 2016
1 parent fd9f311 commit 4882455
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 5 deletions.
6 changes: 6 additions & 0 deletions cl_types.h
Expand Up @@ -105,6 +105,12 @@ typedef struct _cl_buffer_region {

/* cl_ext.h */

typedef union
{
struct { cl_uint type; cl_uint data[5]; } raw;
struct { cl_uint type; cl_char unused[17]; cl_char bus; cl_char device; cl_char function; } pcie;
} cl_device_topology_amd;

/*
typedef cl_ulong cl_device_partition_property_ext;
typedef cl_uint cl_image_pitch_info_qcom;
Expand Down
1 change: 1 addition & 0 deletions pyopencl/__init__.py
Expand Up @@ -165,6 +165,7 @@
Image,
Sampler,
GLTexture,
DeviceTopologyAmd,
)

if _cl.have_gl():
Expand Down
46 changes: 46 additions & 0 deletions pyopencl/cffi_cl.py
Expand Up @@ -169,6 +169,8 @@ def create_inst(val):

if type_ == 'char*':
ret = _ffi_pystr(value)
elif type_ == 'cl_device_topology_amd*':
ret = DeviceTopologyAmd(value.pcie.bus, value.pcie.device, value.pcie.function)
elif type_.startswith('char*['):
ret = list(map(_ffi_pystr, value))
_lib.free_pointer_array(info.value, len(value))
Expand Down Expand Up @@ -1980,4 +1982,48 @@ def __init__(self, context, flags, texture_target, miplevel, texture, dims=None)

# }}}

class DeviceTopologyAmd(object):
# Hack around fmt.__dict__ check in test_wrapper.py
__dict__ = {}
__slots__ = ('ptr',)

def __init__(self, bus=0, device=0, function=0):
self.ptr = _ffi.new("cl_device_topology_amd*")
self.bus = bus
self.device = device
self.function = function

def _check_range(self, value, prop=None):
if (value < -127) or (value > 127):
raise ValueError("Value %s not in range [-127, 127].")

@_cffi_property('pcie')
def _pcie(self):
return self.ptr

@property
def bus(self):
return self._pcie.bus

@bus.setter
def bus(self, value):
self._check_range(value)
self._pcie.bus = value

@property
def device(self):
return self._pcie.device

@device.setter
def device(self, value):
self._pcie.device = value

@property
def function(self):
return self._pcie.function

@function.setter
def function(self, value):
self._pcie.function = value

# vim: foldmethod=marker
11 changes: 11 additions & 0 deletions src/c_wrapper/clhelper.h
Expand Up @@ -243,4 +243,15 @@ operator<<(std::ostream &stm, const cl_image_format &fmt)
return stm;
}

#ifdef CL_DEVICE_TOPOLOGY_AMD
static PYOPENCL_INLINE std::ostream&
operator<<(std::ostream &stm, const cl_device_topology_amd &topol)
{
stm << "pcie.bus: " << topol.pcie.bus
<< ",\npcie.device: " << topol.pcie.device
<< ",\npcie.function: " << topol.pcie.function
<< ",\npcie.type: " << topol.pcie.type;
return stm;
}
#endif
#endif
30 changes: 25 additions & 5 deletions src/c_wrapper/device.cpp
Expand Up @@ -28,6 +28,27 @@ device::~device()
#endif
}

#ifdef CL_DEVICE_TOPOLOGY_AMD
template<typename... ArgTypes>
PYOPENCL_USE_RESULT static PYOPENCL_INLINE generic_info
get_device_topology_amd(ArgTypes&&... args)
{
const char * tpname = "cl_device_topology_amd*";
cl_device_topology_amd value;
const char * fname = "clGetDeviceInfo";
call_guarded(clGetDeviceInfo, fname, args..., size_arg(value), nullptr);
generic_info info;
info.dontfree = 0;
info.opaque_class = CLASS_NONE;
info.type = tpname;
info.value = cl_memdup(&value);
return info;
}

#define pyopencl_get_device_topology_amd(...) get_device_topology_amd(__VA_ARGS__)

#endif

generic_info
device::get_info(cl_uint param_name) const
{
Expand Down Expand Up @@ -227,11 +248,10 @@ device::get_info(cl_uint param_name) const
case CL_DEVICE_PROFILING_TIMER_OFFSET_AMD:
return DEV_GET_INT_INF(cl_ulong);
#endif
/* FIXME
#ifdef CL_DEVICE_TOPOLOGY_AMD
case CL_DEVICE_TOPOLOGY_AMD:
#endif
*/
#ifdef CL_DEVICE_TOPOLOGY_AMD
case CL_DEVICE_TOPOLOGY_AMD:
return pyopencl_get_device_topology_amd(PYOPENCL_CL_CASTABLE_THIS, param_name);
#endif
#ifdef CL_DEVICE_THREAD_TRACE_SUPPORTED_AMD
case CL_DEVICE_THREAD_TRACE_SUPPORTED_AMD:
return DEV_GET_INT_INF(cl_bool);
Expand Down
9 changes: 9 additions & 0 deletions test/test_wrapper.py
Expand Up @@ -293,6 +293,15 @@ def test_image_format_constructor():
assert iform.channel_data_type == cl.channel_type.FLOAT
assert not iform.__dict__

def test_device_topology_amd_constructor():
# doesn't need image support to succeed
topol = cl.DeviceTopologyAmd(3,4,5)

assert topol.bus == 3
assert topol.device == 4
assert topol.function == 5

assert not topol.__dict__

def test_nonempty_supported_image_formats(ctx_factory):
context = ctx_factory()
Expand Down

0 comments on commit 4882455

Please sign in to comment.