# Path: util/util_print.py
# class bcolors:
#     HEADER = '\033[95m'
#     OKBLUE = '\033[94m'
#     OKGREEN = '\033[92m'
#     WARNING = '\033[93m'
#     FAIL = '\033[91m'
#     ENDC = '\033[0m'
#     BOLD = '\033[1m'
#     UNDERLINE = '\033[4m'


import subprocess
import sys
    import os
    import torch
    import torch.backends.cudnn as cudnn
    import subprocess
    import torch
    import random
        import numpy as np
        import torch
from .util_print import str_warning, str_verbose


def _check_gpu_setting_in_use(gpu):
    '''
    check that CUDA_VISIBLE_DEVICES is actually working
    by starting a clean thread with the same CUDA_VISIBLE_DEVICES
    '''
    try:
        which_python = sys.executable
        output = subprocess.check_output(
            'CUDA_VISIBLE_DEVICES=%s %s -c "import torch; print(torch.cuda.device_count())"' % (gpu, which_python), shell=True)
    except subprocess.CalledProcessError as e:
        print(str(e))
    output = output.decode().strip()
    return torch.cuda.device_count() == int(output)


def _check_gpu(gpu):
    msg = subprocess.check_output(
        'nvidia-smi --query-gpu=index,utilization.gpu,memory.used --format=csv,nounits,noheader -i %s' % (gpu,), shell=True)
    msg = msg.decode('utf-8')
    all_ok = True
    for line in msg.split('\n'):
        if line == '':
            break
        stats = [x.strip() for x in line.split(',')]
        gpu = stats[0]
        util = int(stats[1])
        mem_used = int(stats[2])
        if util > 10 or mem_used > 1000:  # util in percentage and mem_used in MiB

# Path: util/util_print.py
# class bcolors:
#     HEADER = '\033[95m'
#     OKBLUE = '\033[94m'
#     OKGREEN = '\033[92m'
#     WARNING = '\033[93m'
#     FAIL = '\033[91m'
#     ENDC = '\033[0m'
#     BOLD = '\033[1m'
#     UNDERLINE = '\033[4m'


# Path: util/util_loadlib.py
import subprocess
import sys
    import os
    import torch
    import torch.backends.cudnn as cudnn
    import subprocess
    import torch
    import random
        import numpy as np
        import torch
from .util_print import str_warning, str_verbose



def _check_gpu_setting_in_use(gpu):
    '''
    check that CUDA_VISIBLE_DEVICES is actually working
    by starting a clean thread with the same CUDA_VISIBLE_DEVICES
    '''
    try:
        which_python = sys.executable
        output = subprocess.check_output(
            'CUDA_VISIBLE_DEVICES=%s %s -c "import torch; print(torch.cuda.device_count())"' % (gpu, which_python), shell=True)
    except subprocess.CalledProcessError as e:
        print(str(e))
    output = output.decode().strip()
    return torch.cuda.device_count() == int(output)


def _check_gpu(gpu):
    msg = subprocess.check_output(
        'nvidia-smi --query-gpu=index,utilization.gpu,memory.used --format=csv,nounits,noheader -i %s' % (gpu,), shell=True)
    msg = msg.decode('utf-8')
    all_ok = True
    for line in msg.split('\n'):
        if line == '':
            break
        stats = [x.strip() for x in line.split(',')]
        gpu = stats[0]
        util = int(stats[1])
        mem_used = int(stats[2])
        if util > 10 or mem_used > 1000:  # util in percentage and mem_used in MiB

            print(str_warning, 'Designated GPU in use: id=%s, util=%d%%, memory in use: %d MiB' % (