def get_info():
    global selected_device, selected_platform, context, KERNELS_DEFS
    info = {
            "version.cl_header"     : pyopencl.get_cl_header_version(),
            "opengl"                : pyopencl.have_gl(),
            #"kernels"               : KERNELS_DEFS.keys()
            }
    updict(info, "pyopencl", get_pyopencl_info())
    if selected_platform:
        updict(info, "platform", {
            "name"          : selected_platform.name,
            "vendor"        : selected_platform.vendor,
            "devices"       : len(selected_platform.get_devices()),
            })
    if selected_device:
        if hasattr(selected_device, "opencl_c_version"):
            info["device.opencl_c_version"] = getattr(selected_device, "opencl_c_version")
        updict(info, "device", {
            "type"                      : device_type(selected_device),
            "name"                      : selected_device.name.strip(),
            "version"                   : selected_device.version,
            "max_work_group_size"       : selected_device.max_work_group_size,
            "max_work_item_dimensions"  : selected_device.max_work_item_dimensions,
            "max_work_item_sizes"       : selected_device.max_work_item_sizes,
            "max-size"                  : selected_device_max_size})
    return info
def get_info():
    global selected_device, selected_platform, context, KERNELS_DEFS
    info = {"version"               : pyopencl.version.VERSION,
            "version.text"          : pyopencl.VERSION_TEXT,
            "version.status"        : pyopencl.VERSION_STATUS,
            "version.cl_header"     : pyopencl.get_cl_header_version(),
            "opengl"                : pyopencl.have_gl(),
            #"kernels"               : KERNELS_DEFS.keys()
            }
    if selected_platform:
        info.update({
            "platform.name"         : selected_platform.name,
            "platform.vendor"       : selected_platform.vendor,
            "platform.devices"      : len(selected_platform.get_devices()),
            })
    if selected_device:
        if hasattr(selected_device, "opencl_c_version"):
            info["device.opencl_c_version"] = getattr(selected_device, "opencl_c_version")
        info.update({
            "device.type"           : device_type(selected_device),
            "device.name"           : selected_device.name.strip(),
            "device.version"        : selected_device.version,
            "device.max_work_group_size"        : selected_device.max_work_group_size,
            "device.max_work_item_dimensions"   : selected_device.max_work_item_dimensions,
            "device.max_work_item_sizes"        : selected_device.max_work_item_sizes})
    return info
    def buildCopImageDataTexture(self):
        if not cl.have_gl():
            raise BaseException("No OpenGL interop !!!")

        if self.node:
            # bind texture from current compy node
            cl_image_buffer = self.node.getCookedData()

            glBindTexture(GL_TEXTURE_2D, self.node_gl_tex_id)
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, self.node.xRes(),  self.node.yRes(), 0, GL_RGB, GL_FLOAT, None)


            logger.debug("Node size to display: %s %s" % (self.node.xRes(), self.node.yRes()))

            node_gl_texture = cl.GLTexture(hou.openclContext(), cl.mem_flags.WRITE_ONLY, GL_TEXTURE_2D, 0, self.node_gl_tex_id, 2) 

            # Aquire OpenGL texture object
            cl.enqueue_acquire_gl_objects(hou.openclQueue(), [node_gl_texture])
            
            # copy OpenCL buffer to OpenGl texture
            cl.enqueue_copy_image(hou.openclQueue(), cl_image_buffer, node_gl_texture, (0,0), (0,0), (self.node.xRes(), self.node.yRes()), wait_for=None)

            # Release OpenGL texturte object
            cl.enqueue_release_gl_objects(hou.openclQueue(), [node_gl_texture])
            hou.openclQueue().finish()

            glGenerateMipmap(GL_TEXTURE_2D)  #Generate mipmaps now!!!
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
            glBindTexture(GL_TEXTURE_2D, 0)
	def __init__(self, gpuOnly=True, sharedGlContext=False, hidePlatformDetails=False):
		super(BaseCalculator, self).__init__()
		self.platform = cl.get_platforms()[0]
		self.devices = self.platform.get_devices()

		if not hidePlatformDetails:
			for platform in cl.get_platforms():
				for device in platform.get_devices():
					print("===============================================================")
					print("Platform name:", platform.name)
					print("Platform profile:", platform.profile)
					print("Platform vendor:", platform.vendor)
					print("Platform version:", platform.version)
					print("---------------------------------------------------------------")
					print("Device name:", device.name)
					print("Device type:", cl.device_type.to_string(device.type))
					print("Device memory: ", device.global_mem_size//1024//1024, 'MB')
					print("Device max clock speed:", device.max_clock_frequency, 'MHz')
					print("Device compute units:", device.max_compute_units)
					print("Device max work group size:", device.max_work_group_size)
					print("Device max work item sizes:", device.max_work_item_sizes)

		properties = None
		if sharedGlContext:
			assert cl.have_gl()
			properties = get_gl_sharing_context_properties()

		devices = self.devices
		if gpuOnly and len(self.devices) > 1:
			devices = [self.devices[1]]

		self.context = cl.Context(properties=properties, devices=devices)

		self.queue = None
Exemple #5
0
    def loadclData(self):
        mf = cl.mem_flags
        print cl.have_gl()


        #Setup vertex buffer objects and share them with OpenCL as GLBuffers
        self.arrvbo.bind()
        print "bau"
        self.arr_cl = cl.GLBuffer(self.ctx, mf.READ_WRITE, int(self.arrvbo.buffer))
        print "bau"
        self.colvbo.bind()
        print "bau"
        self.col_cl = cl.GLBuffer(self.ctx, mf.READ_WRITE, int(self.colvbo.buffer))
        
        self.randarr_cl = cl.Buffer(self.ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=self.randarr)
        self.arrvbo.unbind()
        self.colvbo.unbind()
        self.queue.finish()

        # set up the list of GL objects to share with opencl
        self.gl_objects = [self.arr_cl, self.col_cl]
def get_cl_context(gl_context):
    """Creates a CL context, with or without given GL context."""
    if gl_context is not None: # ... with OpenGL interop?
        with gl_context:
            assert cl.have_gl(), "GL interoperability not enabled."
            from pyopencl.tools import get_gl_sharing_context_properties
            cl_platform = cl.get_platforms()[0]
            cl_properties = [(cl.context_properties.PLATFORM, cl_platform)] + get_gl_sharing_context_properties()
            cl_devices = [cl_platform.get_devices()[-1]]  # Only one is allowed!
            cl_context = cl.Context(properties=cl_properties, devices=cl_devices)
    else: # ... or in stand-alone mode, CL context without GL?
        cl_platform = cl.get_platforms()[0]  # @UndefinedVariable
        cl_properties = [(cl.context_properties.PLATFORM, cl_platform)]
        cl_devices = [cl_platform.get_devices()[-1]]  # Only one is allowed!
        cl_context = cl.Context(properties=cl_properties, devices=cl_devices)
    return cl_context
	def __init__(self, gpuOnly=True, sharedGlContext=False):
		super(BaseCalculator, self).__init__()
		self.platform = cl.get_platforms()[0]
		self.devices = self.platform.get_devices()

		properties = None
		if sharedGlContext:
			assert cl.have_gl()
			properties = get_gl_sharing_context_properties()

		devices = self.devices
		if gpuOnly and len(self.devices) > 1:
			devices = [self.devices[0]]

		self.context = cl.Context(properties=properties, devices=devices)

		self.queue = None
            print(l)

    cls_const_ext = const_ext_lookup.get(cls, {})
    for name in sorted(dir(cls)):
        if not name.startswith("_") and not name in ["to_string", "names", "values"]:
            print("    .. attribute :: %s" % name)

            if name in cls_const_ext:
                for l in get_extra_lines(cls_const_ext[name]):
                    print("    " + l)

    print("    .. method :: to_string(value)")
    print()
    print("        Returns a :class:`str` representing *value*.")
    print()
    print("        .. versionadded:: 0.91")
    print()


if not cl.have_gl():
    print(".. warning::")
    print()
    print("    This set of PyOpenCL documentation is incomplete because it")
    print("    was generated on a PyOpenCL build that did not support OpenGL.")
    print()

print(".. This is an automatically generated file. DO NOT EDIT")
print()
for cls in cl.CONSTANT_CLASSES:
    doc_class(cls)
# Author: Jérôme Kieffer
# -----------------------------------------------------------------------------
""" Definition of OpenCL interaction using pyopencl """

from __future__ import division, print_function
import sys
from ..util import logger

try:
    import pyopencl, pyopencl.array
    from pyopencl.tools import get_gl_sharing_context_properties
except ImportError:
    logger.error("Unable to import PyOpenCL. Please install it from: http://pypi.python.org/pypi/pyopencl")
    pyopencl = None

if not pyopencl.have_gl():
    logger.error("PyOpenCL is installed but was compiled with OpenGL support. Unusable !")
    pyopencl = None

def get_OCL_context():
    """
    Retrieves the OpenCL context
    """
    if not pyopencl:
        raise RuntimeError("OpenCL unuseable")
    ctx = None
    if sys.platform == "darwin":
        ctx = pyopencl.Context(properties=get_gl_sharing_context_properties(),
                         devices=[])
    else:
        # Some OSs prefer clCreateContextFromType, some prefer
def log_version_info():
    log.info("PyOpenCL loaded, header version: %s, GL support: %s",
             ".".join([str(x) for x in pyopencl.get_cl_header_version()]), pyopencl.have_gl())
Exemple #11
0
	def have_gl(self):
		return cl.have_gl()	
Exemple #12
0
import sys
from ..gloo import gl, texture, buffer
from ..util import logger
from threading import Semaphore

try:
    import pyopencl
    import pyopencl.array
    from pyopencl.tools import get_gl_sharing_context_properties
except ImportError:
    logger.warning("Unable to import PyOpenCL. "
                   "Please install it from:"
                   " http://pypi.python.org/pypi/pyopencl")
    pyopencl = None

if pyopencl and not pyopencl.have_gl():
    logger.warning("PyOpenCL is installed but was compiled"
                   " without OpenGL support.")
    pyopencl = None


def _make_context(platform_id=None, device_id=None):
    """
    Actually creates a context and return its ids'

    Parameters
    ----------
    platform_id : platform number
        int
    device_id : device number in the platform
        int
from lib.engine.application import application
from lib.engine.keyboard.flyaroundHandler import flyaroundHandler
from lib.simulation_scene import simulation_scene
from lib.particle_gravity_cl import particle_gravity_cl
import pyopencl as cl
from math import pi,sqrt,cos,sin
import numpy
import random

assert cl.have_gl()
class gravity_bh_controller():
	def __init__(self,app,c_obj_n):
		self.app = app
		self.scene = simulation_scene()

		self.c_obj_n = c_obj_n
		self.gravity = particle_gravity_cl()
		self.scene.objects.append(self.gravity)

	def prepare(self):
		# todo: this look hacky... better integrate
		# camera information into framework ...
		self.app.camera_position = [25.117134754661578, -4.4148233243429074, -20.328067450210863]
		self.app.camera_rotation = [5.428706140512919, 6.169773848846253, 5.428706140512919, 6.169773848846253]
		self.app._initM44()

		self.app.keyboard = flyaroundHandler
		self.app.destruct = self.destruct
		self.app.scene = self.scene.render

		print "load %d objects into particle_gravity" % self.c_obj_n
Exemple #14
0
def log_version_info():
    log.info("PyOpenCL loaded, header version: %s, GL support: %s",
             ".".join([str(x) for x in pyopencl.get_cl_header_version()]),
             pyopencl.have_gl())
Exemple #15
0
""" Definition of OpenCL interaction using pyopencl """

from __future__ import division, print_function
import sys
from ..util import logger

try:
    import pyopencl, pyopencl.array
    from pyopencl.tools import get_gl_sharing_context_properties
except ImportError:
    logger.error(
        "Unable to import PyOpenCL. Please install it from: http://pypi.python.org/pypi/pyopencl"
    )
    pyopencl = None

if not pyopencl.have_gl():
    logger.error(
        "PyOpenCL is installed but was compiled with OpenGL support. Unusable !"
    )
    pyopencl = None


def get_OCL_context():
    """
    Retrieves the OpenCL context
    """
    if not pyopencl:
        raise RuntimeError("OpenCL unuseable")
    ctx = None
    if sys.platform == "darwin":
        ctx = pyopencl.Context(properties=get_gl_sharing_context_properties(),
Exemple #16
0
        ]:
            print("    .. attribute :: %s" % name)

            if name in cls_const_ext:
                for ln in get_extra_lines(cls_const_ext[name]):
                    print("    " + ln)

    print("    .. method :: to_string(value)")
    print()
    print("        Returns a :class:`str` representing *value*.")
    print()
    print("        .. versionadded:: 0.91")
    print()


if not cl.have_gl():
    print(".. warning::")
    print()
    print("    This set of PyOpenCL documentation is incomplete because it")
    print("    was generated on a PyOpenCL build that did not support OpenGL.")
    print()

import inspect

CONSTANT_CLASSES = [
    getattr(cl, name) for name in dir(cl) if inspect.isclass(getattr(cl, name))
    and name[0].islower() and name not in ["zip", "map", "range"]
]

print(".. This is an automatically generated file. DO NOT EDIT")
print()