Esempio n. 1
0
def test_context_limits():
    #figure out how many contexts we can have on each card:
    cuda_devices = encoder_module.get_cuda_devices()
    ec = getattr(encoder_module, "Encoder")
    MAX_ENCODER_CONTEXTS_PER_DEVICE = 64
    log("")
    for encoding in encoder_module.get_encodings():
        for w,h in TEST_DIMENSIONS:
            log("test_context_limits() %s @ %sx%s" % (encoding, w, h))
            src_format = encoder_module.get_colorspaces()[0]
            for device_id, device_info in cuda_devices.items():
                options = {"cuda_device" : device_id}
                encoders = []
                for i in range(MAX_ENCODER_CONTEXTS_PER_DEVICE):
                    e = ec()
                    encoders.append(e)
                    try:
                        e.init_context(w, h, src_format, encoding, 20, 0, options)
                    except Exception, e:
                        log("failed to created context %s on %s: %s" % (i, device_info, e))
                        break
                log("device %s managed %s contexts at %sx%s" % (device_info, len(encoders)-1, w, h))
                for encoder in encoders:
                    try:
                        encoder.clean()
                    except Exception, e:
                        log("encoder cleanup error: %s" % e)
Esempio n. 2
0
def test_context_limits():
    #figure out how many contexts we can have on each card:
    cuda_devices = encoder_module.get_cuda_devices()
    ec = getattr(encoder_module, "Encoder")
    MAX_ENCODER_CONTEXTS_PER_DEVICE = 64
    log("")
    for encoding in encoder_module.get_encodings():
        for w, h in TEST_DIMENSIONS:
            log("test_context_limits() %s @ %sx%s" % (encoding, w, h))
            src_format = encoder_module.get_colorspaces()[0]
            for device_id, device_info in cuda_devices.items():
                options = {"cuda_device": device_id}
                encoders = []
                for i in range(MAX_ENCODER_CONTEXTS_PER_DEVICE):
                    e = ec()
                    encoders.append(e)
                    try:
                        e.init_context(w, h, src_format, encoding, 20, 0,
                                       options)
                    except Exception, e:
                        log("failed to created context %s on %s: %s" %
                            (i, device_info, e))
                        break
                log("device %s managed %s contexts at %sx%s" %
                    (device_info, len(encoders) - 1, w, h))
                for encoder in encoders:
                    try:
                        encoder.clean()
                    except Exception, e:
                        log("encoder cleanup error: %s" % e)
Esempio n. 3
0
def test_parallel_encode():
    cuda_devices = encoder_module.get_cuda_devices()
    ec = getattr(encoder_module, "Encoder")
    encoding = encoder_module.get_encodings()[0]
    log("")
    log("test_parallel_encode() will test one %s encoder using %s encoding on each of %s in parallel"
        % (ec, encoding, cuda_devices))
    w, h = 1920, 1080
    IMAGE_COUNT = 20
    ENCODER_CONTEXTS_PER_DEVICE = 4
    src_format = encoder_module.get_colorspaces()[0]
    log("generating %s images..." % IMAGE_COUNT)
    images = []
    for _ in range(IMAGE_COUNT):
        images += gen_src_images(src_format, w, h, 1)
        sys.stdout.write(".")
        sys.stdout.flush()
    log("%s images generated" % IMAGE_COUNT)
    encoders = []
    for device_id, device_info in cuda_devices.items():
        options = {"cuda_device": device_id}
        for i in range(ENCODER_CONTEXTS_PER_DEVICE):
            e = ec()
            e.init_context(w, h, src_format, encoding, 20, 0, options)
            log("encoder %s for device %s initialized" % (i, device_id))
            info = "%s / encoder %s" % (device_info, i)
            encoders.append((info, e, images))
    log("%s encoders initialized: %s" %
        (len(encoders), [e[1] for e in encoders]))
    threads = []
    i = 0
    for info, encoder, images in encoders:
        name = "Card %s : %s" % (i, info)
        thread = threading.Thread(target=encoding_thread,
                                  name=name,
                                  args=(encoder, src_format, w, h, images,
                                        name))
        threads.append(thread)
        i += 1
    log("%s threads created: %s" % (len(threads), threads))
    log("starting all threads")
    log("")
    for thread in threads:
        thread.start()
    log("%s threads started - waiting for completion" % len(threads))
    for thread in threads:
        thread.join()
    log("all threads ended")
    for _, encoder, _ in encoders:
        encoder.clean()
    log("")
Esempio n. 4
0
def test_parallel_encode():
    from xpra.codecs.nvenc import encoder as encoder_module   #@UnresolvedImport
    cuda_devices = encoder_module.get_cuda_devices()
    ec = getattr(encoder_module, "Encoder")
    encoding = encoder_module.get_encodings()[0]
    print("")
    print("test_parallel_encode() will test one %s encoder using %s encoding on each of %s in parallel" % (ec, encoding, cuda_devices))
    w, h = 1920, 1080
    IMAGE_COUNT = 20
    ENCODER_CONTEXTS_PER_DEVICE = 4
    src_format = encoder_module.get_colorspaces()[0]
    print("generating %s images..." % IMAGE_COUNT)
    images = []
    for _ in range(IMAGE_COUNT):
        images += gen_src_images(src_format, w, h, 1)
        sys.stdout.write(".")
        sys.stdout.flush()
    print("%s images generated" % IMAGE_COUNT)
    encoders = []
    for device_id, device_info in cuda_devices.items():
        options = {"cuda_device" : device_id}
        for i in range(ENCODER_CONTEXTS_PER_DEVICE):
            e = ec()
            e.init_context(w, h, src_format, encoding, 20, 0, options)
            print("encoder %s for device %s initialized" % (i, device_id))
            info = "%s / encoder %s" % (device_info, i)
            encoders.append((info, e, images))
    print("%s encoders initialized: %s" % (len(encoders), [e[1] for e in encoders]))
    threads = []
    i = 0
    for info, encoder, images in encoders:
        name = "Card %s : %s" % (i, info)
        thread = threading.Thread(target=encoding_thread, name=name, args=(encoder, src_format, w, h, images, name))
        threads.append(thread)
        i += 1
    print("%s threads created: %s" % (len(threads), threads))
    print("starting all threads")
    print("")
    for thread in threads:
        thread.start()
    print("%s threads started - waiting for completion" % len(threads))
    for thread in threads:
        thread.join()
    print("all threads ended")
    for _, encoder, _ in encoders:
        encoder.clean()
    print("")