How to use the pyopencl.get_platforms function in pyopencl

To help you get started, we’ve selected a few pyopencl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github inducer / pyopencl / pyopencl / tools.py View on Github external
found = False
        for obj in objs:
            if identifier.lower() in (obj.name + ' ' + obj.vendor).lower():
                return obj
        if not found:
            raise RuntimeError("object '%s' not found" % identifier)

    if plat_dev_string:
        result = []

        for entry in plat_dev_string.split(";"):
            lhsrhs = entry.split(":")

            if len(lhsrhs) == 1:
                platform = find_cl_obj(cl.get_platforms(), lhsrhs[0])
                result.append((platform, platform.get_devices()))

            elif len(lhsrhs) != 2:
                raise RuntimeError("invalid syntax of PYOPENCL_TEST")
            else:
                plat_str, dev_strs = lhsrhs

                platform = find_cl_obj(cl.get_platforms(), plat_str)
                devs = platform.get_devices()
                result.append(
                        (platform,
                            [find_cl_obj(devs, dev_id)
                                for dev_id in dev_strs.split(",")]))

        return result
github inducer / pyopencl / pyopencl / tools.py View on Github external
else:
                plat_str, dev_strs = lhsrhs

                platform = find_cl_obj(cl.get_platforms(), plat_str)
                devs = platform.get_devices()
                result.append(
                        (platform,
                            [find_cl_obj(devs, dev_id)
                                for dev_id in dev_strs.split(",")]))

        return result

    else:
        return [
                (platform, platform.get_devices())
                for platform in cl.get_platforms()]
github bkerler / opencl_brute / Library / opencl.py View on Github external
def __init__(self, platformNum, debug=0, write_combined_file=False, maxWorkgroupSize=60000, inv_memory_density=1, N_value=15):
        printif(debug,"Using Platform %d:" % platformNum)
        devices = cl.get_platforms()[platformNum].get_devices()
        self.platform_number=platformNum
        # Show devices for the platform, and adjust workgroup size
        # Create the context for GPU/CPU
        self.workgroupsize = maxWorkgroupSize
        # Adjust workgroup size so that we don't run out of RAM:
        # As with bench_sCrypt.py, not really working!
        self.sworkgroupsize = self.determineWorkgroupsize(N_value)
        self.inv_memory_density=inv_memory_density
        self.ctx = cl.Context(devices)
        self.queue = cl.CommandQueue(self.ctx)
        self.debug=debug

        for device in devices:
            printif(debug, '--------------------------------------------------------------------------')
            printif(debug, ' Device - Name: '+ device.name)
            printif(debug, ' Device - Type: '+ cl.device_type.to_string(device.type))
github viennacl / pyviennacl-dev / examples / benchmarks.py View on Github external
def get_cl_devices():
    return [x for platform in cl.get_platforms() for x in platform.get_devices()]
github maweigert / gputools / gputools / core / ocldevice.py View on Github external
def get_all_info(self):
        platforms = pyopencl.get_platforms()
        s = "\n-------- available devices -----------\n"
        for p in platforms:
            s += "platform: \t%s\n"%p.name
            printNames = [["CPU", pyopencl.device_type.CPU],
                          ["GPU", pyopencl.device_type.GPU]]
            for name, identifier in printNames:
                s += "device type: \t%s\n"%name
                try:
                    for d in p.get_devices(identifier):
                        s += "\t%s \n"%d.name
                except:
                    s += "nothing found: \t%s\n"%name

        infoKeys = ['NAME', 'GLOBAL_MEM_SIZE',
                    'GLOBAL_MEM_SIZE', 'MAX_MEM_ALLOC_SIZE',
                    'LOCAL_MEM_SIZE', 'IMAGE2D_MAX_WIDTH',
github zhouzq-thu / Python-GPU-Info / OpenCLInfo.py View on Github external
def openclInfo():
    """Print OpenCL information.
    """
    platforms = cl.get_platforms()
    print('There are {:d} platform(s) detected:\n'.format(len(platforms)))
    print(70 * '-')
    for platform_id, platform in enumerate(platforms):
        print('Platform:             ', platform.name)
        print('Vendor:               ', platform.vendor)
        print('Version:              ', platform.version)
        print('Number of devices:    ', len(platform.get_devices()))
        print('  ' + 68 * '-')
        for device_id, device in enumerate(platform.get_devices()):
            printDeviceInfo(platform_id, device_id, prefix='  ')
            print('  ' + 68 * '-')
github freethenation / OpenCLNoise / openclnoise / filterstack.py View on Github external
def get_devices(self):
        platforms = cl.get_platforms()
        if len(platforms) < 1: 
            log.error("No OpenCL platforms found!")
            return []
        if len(platforms) > 1:
            log.warn("{0} OpenCL platforms were found. Selecting the first one.".format(len(platforms)))
        devices = platforms[0].get_devices()
        return devices
github SasView / sasview / src / sas / qtgui / Perspectives / Fitting / GPUOptions.py View on Github external
def _get_clinfo():
    """
    Read in information about available OpenCL infrastructure
    """
    clinfo = []
    cl_platforms = []
    try:
        import pyopencl as cl
        cl_platforms = cl.get_platforms()
    except ImportError:
        print("pyopencl import failed. Using only CPU computations")
    except cl.LogicError as e:
        print(e.value)

    p_index = 0
    for cl_platform in cl_platforms:
        d_index = 0
        cl_platforms = cl_platform.get_devices()
        for cl_platform in cl_platforms:
            if len(cl_platforms) > 1 and len(cl_platforms) > 1:
                combined_index = ":".join([str(p_index), str(d_index)])
            elif len(cl_platforms) > 1:
                combined_index = str(p_index)
            else:
                combined_index = str(d_index)
github kklmn / xrt / xrt / backends / raycing / myopencl.py View on Github external
def set_cl(self, targetOpenCL=raycing.targetOpenCL,
               precisionOpenCL=raycing.precisionOpenCL):
        if (targetOpenCL == self.lastTargetOpenCL) and\
                (precisionOpenCL == self.lastPrecisionOpenCL):
            return
        self.lastTargetOpenCL = targetOpenCL
        self.lastPrecisionOpenCL = precisionOpenCL
        if not isOpenCL:
            raise EnvironmentError("pyopencl is not available!")
        else:
            try:
                cl_platforms = cl.get_platforms()
            except:
                targetOpenCL = None
                raise EnvironmentError("Unknown error. OpenCL disabled")
            if isinstance(targetOpenCL, (tuple, list)):
                iDevice = []
                targetOpenCL = list(targetOpenCL)
                if isinstance(targetOpenCL[0], int):
                    nPlatform, nDevice = targetOpenCL
                    platform = cl_platforms[nPlatform]
                    try:
                        dev = platform.get_devices()[nDevice]
                        iDevice.extend([dev])
                    except:
                        pass
                else:
                    for target in targetOpenCL:
github cherab / core / cherab / tools / inversions / opencl / opencl_utils.py View on Github external
def get_first_device(platforms=None, device_type=None):
    """
    Returns the first OpenCL device of specified type available in specified OpenCL platforms

    :param list platforms: List of pyopencl.Platform instances. Default value: `platforms=None` (all available OpenCL platfroms).
    :param pyopencl.device_type device_type: OpenCL device type (GPU, ACCELERATOR, or both).
        Default value: `device_type=None` (GPU or accelerator).

    :return: The pyopencl.Device instance corresponding to the first device available in the specified OpenCL platforms.
    """
    if not _has_pyopencl:
        raise RuntimeError("The pyopencl module is required to run get_first_device() function.")
    device_type = device_type or cl.device_type.GPU | cl.device_type.ACCELERATOR
    if platforms is None:
        platforms = cl.get_platforms()
    for platform in platforms:
        devices = platform.get_devices(device_type=device_type)
        if len(devices):
            device = devices[0]
            print("Selected OpenCL device: %s %s\n" % (device.get_info(cl.device_info.VENDOR), device.get_info(cl.device_info.NAME)))
            return device
    print("\nThere are no devices of specified type\n")

    return None