diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index b5c5687535adb65790810d76cda4ca12c0af60f4..ceab9b2b803f15d91777a8f138a5101a85e7e3a0 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -285,9 +285,7 @@ def _add_functionality(): # {{{ Platform def platform_repr(self): - return "<pyopencl.Platform '%s' at TODO>" % (self.name) - # TODO int_ptr - #return "<pyopencl.Platform '%s' at 0x%x>" % (self.name, self.int_ptr) + return "<pyopencl.Platform '%s' at 0x%x>" % (self.name, self.int_ptr) Platform.__repr__ = platform_repr @@ -296,11 +294,8 @@ def _add_functionality(): # {{{ Device def device_repr(self): - return "<pyopencl.Device '%s' on TODO at TODO>" % ( - self.name.strip()) - # TODO - # return "<pyopencl.Device '%s' on '%s' at 0x%x>" % ( - # self.name.strip(), self.platform.name.strip(), self.int_ptr) + return "<pyopencl.Device '%s' on '%s' at 0x%x>" % ( + self.name.strip(), self.platform.name.strip(), self.int_ptr) Device.__repr__ = device_repr @@ -309,8 +304,7 @@ def _add_functionality(): # {{{ Context def context_repr(self): - return 'TODO' - #return "<pyopencl.Context at TODO on %s>" % (", ".join(repr(dev) for dev in self.devices)) + return "<pyopencl.Context at TODO on %s>" % (", ".join(repr(dev) for dev in self.devices)) # return "<pyopencl.Context at 0x%x on %s>" % (self.obj_ptr, # ", ".join(repr(dev) for dev in self.devices)) diff --git a/pyopencl/cffi_cl.py b/pyopencl/cffi_cl.py index 408f3e5f1399e3ecf1e4452db1338170469b6f68..35ccb5cc2809bd42539043599a01d9bb4fd9a641 100644 --- a/pyopencl/cffi_cl.py +++ b/pyopencl/cffi_cl.py @@ -1,3 +1,4 @@ +from pyopencl._cl import bitlog2, PooledBuffer, MemoryPool import warnings import os.path @@ -214,12 +215,15 @@ def _parse_context_properties(properties): raise RuntimeError("Context", status_code.INVALID_VALUE, "property tuple must have length 2") prop, value = prop_tuple props.append(prop) - if prop == _lib.CL_CONTEXT_PLATFORM: - props.append(_ffi.cast('cl_context_properties', value.data())) - - else: # TODO_PLAT CL_WGL_HDC_KHR and morecc + if prop == context_properties.PLATFORM: + props.append(value.int_ptr) + # elif prop == context_properties.WGL_HDC_KHR: + # raise NotImplementedError() + #elif + else: # TODO_PLAT CL_WGL_HDC_KHR and more raise RuntimeError("Context", status_code.INVALID_VALUE, "invalid context property") props.append(0) + #c_props = [_ffi.new('cl_context_properties *', prop) for prop in props] return _ffi.new('cl_context_properties[]', props) diff --git a/src/c_wrapper/Makefile b/src/c_wrapper/Makefile index 10dbd9d07f14a28af23923711cd5319caf314242..07e3a47ff86c2e04e4b4bad0f5efab7cc77ef1ea 100644 --- a/src/c_wrapper/Makefile +++ b/src/c_wrapper/Makefile @@ -1,5 +1,5 @@ all: - g++ -c -Wall -DPYOPENCL_PRETEND_CL_VERSION=4112 -Werror -fpic wrap_cl.cpp wrap_constants.cpp + g++ -c -Wall -DHAVE_GL=1 -DPYOPENCL_PRETEND_CL_VERSION=4112 -fpic wrap_cl.cpp wrap_constants.cpp g++ -shared -o libwrapcl.so wrap_cl.o wrap_constants.o cp libwrapcl.so ../../pyopencl/ cp wrap_cl_core.h ../../pyopencl/wrap_cl_core.h diff --git a/src/c_wrapper/wrap_cl.cpp b/src/c_wrapper/wrap_cl.cpp index 85021d7fe202f54dfd57cfd61634352d76d64e17..715cf3e5b46d876e1a2fa992e559b30c0a022d44 100644 --- a/src/c_wrapper/wrap_cl.cpp +++ b/src/c_wrapper/wrap_cl.cpp @@ -771,52 +771,53 @@ generic_info get_info(cl_device_info param_name) const } - // case CL_CONTEXT_PROPERTIES: - // { - // std::vector<cl_context_properties> result; - // PYOPENCL_GET_VEC_INFO(Context, m_context, param_name, result); - - // py::list py_result; - // for (size_t i = 0; i < result.size(); i+=2) - // { - // cl_context_properties key = result[i]; - // py::object value; - // switch (key) - // { - // case CL_CONTEXT_PLATFORM: - // { - // value = py::object( - // handle_from_new_ptr(new platform( - // reinterpret_cast<cl_platform_id>(result[i+1])))); - // break; - // } - - // #if defined(PYOPENCL_GL_SHARING_VERSION) && (PYOPENCL_GL_SHARING_VERSION >= 1) - // #if defined(__APPLE__) && defined(HAVE_GL) - // case CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE: - // #else - // case CL_GL_CONTEXT_KHR: - // case CL_EGL_DISPLAY_KHR: - // case CL_GLX_DISPLAY_KHR: - // case CL_WGL_HDC_KHR: - // case CL_CGL_SHAREGROUP_KHR: - // #endif - // value = py::object(result[i+1]); - // break; - - // #endif - // case 0: - // break; - - // default: - // throw error("Context.get_info", CL_INVALID_VALUE, - // "unknown context_property key encountered"); - // } + case CL_CONTEXT_PROPERTIES: + { + + std::vector<cl_context_properties> result; + PYOPENCL_GET_VEC_INFO(Context, m_context, param_name, result); + std::vector<generic_info> py_result; + for (size_t i = 0; i < result.size(); i+=2) + { + cl_context_properties key = result[i]; + if(key == 0) + break; + generic_info info; + info.opaque_class = CLASS_NONE; + switch (key) + { + case CL_CONTEXT_PLATFORM: + { + info.opaque_class = CLASS_PLATFORM; + info.type = "void *"; + info.value = new platform(reinterpret_cast<cl_platform_id>(result[i+1])); + break; + } + +#if defined(PYOPENCL_GL_SHARING_VERSION) && (PYOPENCL_GL_SHARING_VERSION >= 1) +#if defined(__APPLE__) && defined(HAVE_GL) + case CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE: +#else + case CL_GL_CONTEXT_KHR: + case CL_EGL_DISPLAY_KHR: + case CL_GLX_DISPLAY_KHR: + case CL_WGL_HDC_KHR: + case CL_CGL_SHAREGROUP_KHR: +#endif + info.type = "cl_context_properties *"; + info.value = (void*)result[i+1]; + break; - // py_result.append(py::make_tuple(result[i], value)); - // } - // return py_result; - // } +#endif + default: + throw error("Context.get_info", CL_INVALID_VALUE, + "unknown context_property key encountered"); + } + + py_result.push_back(info); + } + PYOPENCL_GET_ARRAY_INFO(generic_info, py_result); + } #if PYOPENCL_CL_VERSION >= 0x1010 case CL_CONTEXT_NUM_DEVICES: