diff --git a/doc/make_constants.py b/doc/make_constants.py index 77e97462ac0e4829e27b8f883ff103d2a819aaaa..2160c3c607cf5d3ece954339442927b13e97ba5e 100644 --- a/doc/make_constants.py +++ b/doc/make_constants.py @@ -1,14 +1,35 @@ import pyopencl as cl +ctxp = cl.context_properties +ext_lookup = { + ctxp: { + ctxp.GL_CONTEXT_KHR: "cl_khr_gl_sharing", + ctxp.EGL_DISPLAY_KHR: "cl_khr_gl_sharing", + ctxp.GLX_DISPLAY_KHR: "cl_khr_gl_sharing", + ctxp.WGL_HDC_KHR: "cl_khr_gl_sharing", + ctxp.CGL_SHAREGROUP_KHR: "cl_khr_gl_sharing", + } + } + def doc_class(cls): print ".. class :: %s" % cls.__name__ print if cls.__name__.startswith("gl_"): print " Only available when PyOpenCL is compiled with GL support. See :func:`have_gl`." print + + cls_ext = ext_lookup.get(cls, {}) for i in sorted(dir(cls)): if not i.startswith("_") and not i == "to_string": print " .. attribute :: %s" % i + value = getattr(cls, i) + + if value in cls_ext: + print + print " Available with the ``%s`` extension." % ( + cls_ext[value]) + print + print " .. method :: to_string(value)" print print " Returns a :class:`str` representing *value*." diff --git a/doc/source/misc.rst b/doc/source/misc.rst index f7883f7c66c433de8374b2c6179adad548acc5bb..2cb720d63e85f76a931c86fc51bbc8f13c7cc90f 100644 --- a/doc/source/misc.rst +++ b/doc/source/misc.rst @@ -71,6 +71,10 @@ Version 0.92 Version 0.92 is currently under development. You can get snapshots from PyOpenCL's git version control. +* Add support for the + `cl_khr_gl_sharin `_ + extension. + Version 0.91.5 -------------- diff --git a/examples/matrix-multiply.py b/examples/matrix-multiply.py index 3dff0ff1a353392c5e295b3e3a5881b618a970f6..791bd0e9e77956ad3a9501375b8d77a81ffbff78 100644 --- a/examples/matrix-multiply.py +++ b/examples/matrix-multiply.py @@ -149,10 +149,10 @@ else: b_height = a_width b_width = 50*block_size - h_a = numpy.random.rand(a_height, a_width).astype(numpy.float32) h_b = numpy.random.rand(a_width, a_height).astype(numpy.float32) h_c = numpy.empty((a_height, a_height)).astype(numpy.float32) +print h_a.shape, h_b.shape mf = cl.mem_flags @@ -163,6 +163,7 @@ kernel_params = {"block_size": block_size, prg = cl.Program(ctx, kernel_code % kernel_params, ).build(options="-cl-mad-enable -cl-fast-relaxed-math") kernel = prg.matrixMul +#print prg.binaries[0] #def __call__(self, queue, tgt, src, shape): # w, h = shape @@ -193,7 +194,7 @@ event = kernel(queue, (a_height,a_height), d_c_buf, d_a_buf, d_b_buf, event.wait() t1 = time() -count = 2 +count = 20 for i in range(count): event = kernel(queue, (a_height,a_height), d_c_buf, d_a_buf, d_b_buf, cl.LocalMemory(4* block_size**2), @@ -202,7 +203,6 @@ for i in range(count): event.wait() -#print event.profile.end - event.profile.start gpu_time = time()-t1 @@ -223,7 +223,7 @@ print "COMPUTE ", gpu_time/count print "COMPUTE2 ", (event.profile.end-event.profile.start)*1e-9 gflop = h_c.size * (a_width * 2.) / (1000**3.) -gflops = gflop / gpu_time +gflops = gflop / (gpu_time/count) print "gflops:", gflops do_cpu = False diff --git a/src/wrapper/wrap_cl.cpp b/src/wrapper/wrap_cl.cpp index 5175c279ede8e120ca01baf8f455043db88724ce..a9d948b341d34ab11a3e71c5b6429075be242db1 100644 --- a/src/wrapper/wrap_cl.cpp +++ b/src/wrapper/wrap_cl.cpp @@ -213,6 +213,13 @@ BOOST_PYTHON_MODULE(_cl) { py::class_ cls("context_properties", py::no_init); ADD_ATTR(CONTEXT_, PLATFORM); +#if defined(cl_khr_gl_sharing) && (cl_khr_gl_sharing >= 1) + ADD_ATTR( ,GL_CONTEXT_KHR); + ADD_ATTR( ,EGL_DISPLAY_KHR); + ADD_ATTR( ,GLX_DISPLAY_KHR); + ADD_ATTR( ,WGL_HDC_KHR); + ADD_ATTR( ,CGL_SHAREGROUP_KHR); +#endif } { diff --git a/src/wrapper/wrap_cl.hpp b/src/wrapper/wrap_cl.hpp index 52fbf54ce2e5bd9bdf3c4a587f8cb453e620b718..8fd478a80926ab9bc05b08a8583597be0c3a0373 100644 --- a/src/wrapper/wrap_cl.hpp +++ b/src/wrapper/wrap_cl.hpp @@ -317,6 +317,10 @@ namespace pyopencl case CL_INVALID_BUFFER_SIZE: return "invalid buffer size"; case CL_INVALID_MIP_LEVEL: return "invalid mip level"; +#if defined(cl_khr_gl_sharing) && (cl_khr_gl_sharing >= 1) + case CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR: return "invalid gl sharegroup reference number"; +#endif + default: return "invalid error code"; } } @@ -591,6 +595,13 @@ namespace pyopencl switch (key) { case CL_CONTEXT_PLATFORM: +#if defined(cl_khr_gl_sharing) && (cl_khr_gl_sharing >= 1) + 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( handle_from_new_ptr(new platform( @@ -618,13 +629,12 @@ namespace pyopencl - context *create_context(py::object py_devices, py::object py_properties, - py::object py_dev_type) + + std::vector parse_context_properties( + py::object py_properties) { - // parse context properties - cl_context_properties *props_ptr = 0; std::vector props; - + if (py_properties.ptr() != Py_None) { PYTHON_FOREACH(prop_tuple, py_properties) @@ -634,8 +644,16 @@ namespace pyopencl cl_context_properties prop = py::extract(prop_tuple[0]); props.push_back(prop); - - if (prop == CL_CONTEXT_PLATFORM) + + if (prop == CL_CONTEXT_PLATFORM +#if defined(cl_khr_gl_sharing) && (cl_khr_gl_sharing >= 1) + || prop == CL_GL_CONTEXT_KHR + || prop == CL_EGL_DISPLAY_KHR + || prop == CL_GLX_DISPLAY_KHR + || prop == CL_WGL_HDC_KHR + || prop == CL_CGL_SHAREGROUP_KHR +#endif + ) { py::extract value(prop_tuple[1]); props.push_back( @@ -645,9 +663,24 @@ namespace pyopencl throw error("Context", CL_INVALID_VALUE, "invalid context property"); } props.push_back(0); - props_ptr = props.empty( ) ? NULL : &props.front(); } + return props; + } + + + + + context *create_context(py::object py_devices, py::object py_properties, + py::object py_dev_type) + { + // parse context properties + std::vector props + = parse_context_properties(py_properties); + + cl_context_properties *props_ptr + = props.empty( ) ? NULL : &props.front(); + cl_int status_code; cl_context ctx;