# Path: studio/util/util.py
# def sixdecode(sval):
#     if isinstance(sval, str):
#         return sval
#     if isinstance(sval, bytes):
#         return sval.decode('utf8')
#     raise TypeError("Unknown type of " + str(sval))


import os
import subprocess
import xml.etree.ElementTree as ET
from studio.util.util import sixdecode
    if gpu_mem_needed is None:
        if strict:
            return [gpu.find('minor_number').text for gpu in gpus if
                    check_gpu_nomem_strict(gpu)]
        return [gpu.find('minor_number').text for gpu in gpus]

    gpu_mem_needed = memstr2int(gpu_mem_needed)

    def check_gpu_mem_strict(gpu):
        return gpu_mem_needed < \
            memstr2int(gpu.find('fb_memory_usage').find('free').text)

    def check_gpu_mem_loose(gpu):
        return (gpu_mem_needed <
                memstr2int(gpu.find('fb_memory_usage').find('total').text)) \
            and check_gpu_nomem_strict(gpu)

    if strict:
        return [gpu.find('minor_number').text
                for gpu in gpus if check_gpu_mem_strict(gpu)]
    return [gpu.find('minor_number').text
            for gpu in gpus if check_gpu_mem_loose(gpu)]


def _get_gpu_info():
    try:
        with subprocess.Popen(['nvidia-smi', '-q', '-x'],
                        stdout=subprocess.PIPE,
                        stderr=subprocess.STDOUT) as smi_proc:
            smi_output, _ = smi_proc.communicate()

# Path: studio/util/util.py
# def sixdecode(sval):
#     if isinstance(sval, str):
#         return sval
#     if isinstance(sval, bytes):
#         return sval.decode('utf8')
#     raise TypeError("Unknown type of " + str(sval))


# Path: studio/util/gpu_util.py
import os
import subprocess
import xml.etree.ElementTree as ET
from studio.util.util import sixdecode

    if gpu_mem_needed is None:
        if strict:
            return [gpu.find('minor_number').text for gpu in gpus if
                    check_gpu_nomem_strict(gpu)]
        return [gpu.find('minor_number').text for gpu in gpus]

    gpu_mem_needed = memstr2int(gpu_mem_needed)

    def check_gpu_mem_strict(gpu):
        return gpu_mem_needed < \
            memstr2int(gpu.find('fb_memory_usage').find('free').text)

    def check_gpu_mem_loose(gpu):
        return (gpu_mem_needed <
                memstr2int(gpu.find('fb_memory_usage').find('total').text)) \
            and check_gpu_nomem_strict(gpu)

    if strict:
        return [gpu.find('minor_number').text
                for gpu in gpus if check_gpu_mem_strict(gpu)]
    return [gpu.find('minor_number').text
            for gpu in gpus if check_gpu_mem_loose(gpu)]


def _get_gpu_info():
    try:
        with subprocess.Popen(['nvidia-smi', '-q', '-x'],
                        stdout=subprocess.PIPE,
                        stderr=subprocess.STDOUT) as smi_proc:
            smi_output, _ = smi_proc.communicate()

            xmlroot = ET.fromstring(sixdecode(smi_output))