Skip to content

pynvml

Attributes

fastvideo.third_party.pynvml.NVML_VALUE_NOT_AVAILABLE_uint module-attribute

NVML_VALUE_NOT_AVAILABLE_uint = c_uint(-1)

Field Identifiers.

All Identifiers pertain to a device. Each ID is only used once and is guaranteed never to change.

Classes

fastvideo.third_party.pynvml.NVMLError

Bases: Exception

Functions

fastvideo.third_party.pynvml.NVMLError.__new__
__new__(typ, value)

Maps value to a proper subclass of NVMLError. See _extractNVMLErrorsAsClasses function for more details

Source code in fastvideo/third_party/pynvml.py
def __new__(typ, value):
    '''
    Maps value to a proper subclass of NVMLError.
    See _extractNVMLErrorsAsClasses function for more details
    '''
    if typ == NVMLError:
        typ = NVMLError._valClassMapping.get(value, typ)
    obj = Exception.__new__(typ)
    obj.value = value
    return obj

Functions

fastvideo.third_party.pynvml.convertStrBytes

convertStrBytes(func)

In python 3, strings are unicode instead of bytes, and need to be converted for ctypes Args from caller: (1, 'string', <main.c_nvmlDevice_t at 0xFFFFFFFF>) Args passed to function: (1, b'string', <main.c_nvmlDevice_t at 0xFFFFFFFF)>


Returned from function: b'returned string' Returned to caller: 'returned string'

Source code in fastvideo/third_party/pynvml.py
def convertStrBytes(func):
    '''
    In python 3, strings are unicode instead of bytes, and need to be converted for ctypes
    Args from caller: (1, 'string', <__main__.c_nvmlDevice_t at 0xFFFFFFFF>)
    Args passed to function: (1, b'string', <__main__.c_nvmlDevice_t at 0xFFFFFFFF)>
    ----
    Returned from function: b'returned string'
    Returned to caller: 'returned string'
    '''
    @wraps(func)
    def wrapper(*args, **kwargs):
        # encoding a str returns bytes in python 2 and 3
        args = [arg.encode() if isinstance(arg, str) else arg for arg in args]
        res = func(*args, **kwargs)
        # In python 2, str and bytes are the same
        # In python 3, str is unicode and should be decoded.
        # Ctypes handles most conversions, this only effects c_char and char arrays.
        if isinstance(res, bytes):
            if isinstance(res, str):
                return res
            return res.decode()
        return res

    if sys.version_info >= (3,):
        return wrapper
    return func