pystella/__init__.py
def choose_device_and_make_context(platform_choice=None, device_choice=None):
    """
    A wrapper that chooses a device and creates a :class:`pyopencl.Context` on
    a particular device.

    :arg platform_choice: An integer or string specifying which
        :class:`pyopencl.Platform` to choose.
        Defaults to *None*, in which case the environment variables
        ``PYOPENCL_CTX`` or ``PYOPENCL_TEST`` are queried.
        If none of the above are specified, then the first platform is chosen.

    :arg device_choice: An integer or string specifying which
        :class:`pyopencl.Device` to run on.
        Defaults to *None*, in which case a device is chosen according to the
        node-local MPI rank.
        (Note that this requires initializing MPI, i.e., importing ``mpi4py.MPI``.)

    :returns: A :class:`pyopencl.Context`.
    """

    import pyopencl as cl

    if platform_choice is None:
        import os
        if "PYOPENCL_CTX" in os.environ:
            ctx_spec = os.environ["PYOPENCL_CTX"]
            platform_choice = ctx_spec.split(":")[0]
    else:
        platform_choice = str(platform_choice)

    from pyopencl.tools import get_test_platforms_and_devices
    platform, devices = get_test_platforms_and_devices(platform_choice)[0]
    num_devices = len(devices)
    logger.info(f"platform {platform.name} with {num_devices} devices selected")

    try:
        # sort devices based on their unique pci bus id
        devices = sorted(devices, key=lambda dev: dev.pci_bus_id_nv)
    except:  # noqa
        logger.info("Non-NVIDIA platform; no pci_bus_id_nv attribute to sort on.")

    if device_choice is None:
        from mpi4py import MPI
        comm = MPI.COMM_WORLD.Split_type(MPI.COMM_TYPE_SHARED)
        local_rank = comm.Get_rank()
        comm.Free()
        device_choice = local_rank % num_devices

    dev = devices[device_choice]

    from socket import getfqdn
    host_dev_info = f"on host {getfqdn()}: chose {dev.name} number {device_choice}"
    if "NVIDIA" in platform.name:
        host_dev_info += f" with pci_bus_id_nv={dev.pci_bus_id_nv}"
    logger.info(host_dev_info)

    return cl.Context([dev])

    A wrapper that chooses a device and creates a :class:`pyopencl.Context` on
    a particular device.

    :arg platform_choice: An integer or string specifying which
        :class:`pyopencl.Platform` to choose.
        Defaults to *None*, in which case the environment variables
        ``PYOPENCL_CTX`` or ``PYOPENCL_TEST`` are queried.
        If none of the above are specified, then the first platform is chosen.

    :arg device_choice: An integer or string specifying which
        :class:`pyopencl.Device` to run on.
        Defaults to *None*, in which case a device is chosen according to the
        node-local MPI rank.
        (Note that this requires initializing MPI, i.e., importing ``mpi4py.MPI``.)

    :returns: A :class:`pyopencl.Context`.
    
A wrapper that chooses a device and creates a :class:`pyopencl.Context` on
a particular device.
A wrapper that chooses a device and creates a : class : ` pyopencl . Context ` on a particular device .
def choose_device_and_make_context(platform_choice=None, device_choice=None):
    import pyopencl as cl
    if platform_choice is None:
        import os
        if "PYOPENCL_CTX" in os.environ:
            ctx_spec = os.environ["PYOPENCL_CTX"]
            platform_choice = ctx_spec.split(":")[0]
    else:
        platform_choice = str(platform_choice)
    from pyopencl.tools import get_test_platforms_and_devices
    platform, devices = get_test_platforms_and_devices(platform_choice)[0]
    num_devices = len(devices)
    logger.info(f"platform {platform.name} with {num_devices} devices selected")
    try:
        devices = sorted(devices, key=lambda dev: dev.pci_bus_id_nv)
    except:  
        logger.info("Non-NVIDIA platform; no pci_bus_id_nv attribute to sort on.")
    if device_choice is None:
        from mpi4py import MPI
        comm = MPI.COMM_WORLD.Split_type(MPI.COMM_TYPE_SHARED)
        local_rank = comm.Get_rank()
        comm.Free()
        device_choice = local_rank % num_devices
    dev = devices[device_choice]
    from socket import getfqdn
    host_dev_info = f"on host {getfqdn()}: chose {dev.name} number {device_choice}"
    if "NVIDIA" in platform.name:
        host_dev_info += f" with pci_bus_id_nv={dev.pci_bus_id_nv}"
    logger.info(host_dev_info)
    return cl.Context([dev])
def choose_device_and_make_context ( platform_choice = None , device_choice = None ) : import pyopencl as cl if platform_choice is None : import os if "PYOPENCL_CTX" in os . environ : ctx_spec = os . environ [ "PYOPENCL_CTX" ] platform_choice = ctx_spec . split ( ":" ) [ 0 ] else : platform_choice = str ( platform_choice ) from pyopencl . tools import get_test_platforms_and_devices platform , devices = get_test_platforms_and_devices ( platform_choice ) [ 0 ] num_devices = len ( devices ) logger . info ( f"platform {platform.name} with {num_devices} devices selected" ) try : devices = sorted ( devices , key = lambda dev : dev . pci_bus_id_nv ) except : logger . info ( "Non-NVIDIA platform; no pci_bus_id_nv attribute to sort on." ) if device_choice is None : from mpi4py import MPI comm = MPI . COMM_WORLD . Split_type ( MPI . COMM_TYPE_SHARED ) local_rank = comm . Get_rank ( ) comm . Free ( ) device_choice = local_rank % num_devices dev = devices [ device_choice ] from socket import getfqdn host_dev_info = f"on host {getfqdn()}: chose {dev.name} number {device_choice}" if "NVIDIA" in platform . name : host_dev_info += f" with pci_bus_id_nv={dev.pci_bus_id_nv}" logger . info ( host_dev_info ) return cl . Context ( [ dev ] )
A wrapper that chooses a device and creates a :class:`pyopencl.Context` on
a particular device.
A wrapper that chooses a device and creates a : class : ` pyopencl . Context ` on a particular device .
"""
    A wrapper that chooses a device and creates a :class:`pyopencl.Context` on
    a particular device.

    :arg platform_choice: An integer or string specifying which
        :class:`pyopencl.Platform` to choose.
        Defaults to *None*, in which case the environment variables
        ``PYOPENCL_CTX`` or ``PYOPENCL_TEST`` are queried.
        If none of the above are specified, then the first platform is chosen.

    :arg device_choice: An integer or string specifying which
        :class:`pyopencl.Device` to run on.
        Defaults to *None*, in which case a device is chosen according to the
        node-local MPI rank.
        (Note that this requires initializing MPI, i.e., importing ``mpi4py.MPI``.)

    :returns: A :class:`pyopencl.Context`.
    """ # sort devices based on their unique pci bus id
 # noqa

None
platform_choice
An integer or string specifying which
:class:`pyopencl.Platform` to choose.
Defaults to *None*, in which case the environment variables
``PYOPENCL_CTX`` or ``PYOPENCL_TEST`` are queried.
If none of the above are specified, then the first platform is chosen.
An integer or string specifying which : class : ` pyopencl . Platform ` to choose . Defaults to * None * in which case the environment variables ` ` PYOPENCL_CTX ` ` or ` ` PYOPENCL_TEST ` ` are queried . If none of the above are specified then the first platform is chosen .
device_choice
An integer or string specifying which
:class:`pyopencl.Device` to run on.
Defaults to *None*, in which case a device is chosen according to the
node-local MPI rank.
(Note that this requires initializing MPI, i.e., importing ``mpi4py.MPI``.)
An integer or string specifying which : class : ` pyopencl . Device ` to run on . Defaults to * None * in which case a device is chosen according to the node - local MPI rank . ( Note that this requires initializing MPI i . e . importing ` ` mpi4py . MPI ` ` . )