예제 #1
0
def main():
    """Read the configuration and run the network"""

    args = parse_args()

    # Heaps are sized for the j11_v2 network. Changing the network will
    # require updating network_heap_size and param_heap_size
    config_file = '../test/testvecs/config/infer/tidl_config_j11_v2.txt'

    configuration = Configuration()
    configuration.read_from_file(config_file)
    configuration.enable_api_trace = False
    configuration.num_frames = args.num_frames

    # Heap sizes for this network determined using Configuration.showHeapStats
    configuration.param_heap_size = (3 << 20)
    configuration.network_heap_size = (20 << 20)

    num_dsp = Executor.get_num_devices(DeviceType.DSP)
    num_eve = Executor.get_num_devices(DeviceType.EVE)

    if num_dsp == 0 or num_eve == 0:
        print('This example requires EVEs and DSPs.')
        return

    enable_time_stamps("2eo_opt_timestamp.log", 16)
    run(num_eve, num_dsp, configuration)
예제 #2
0
def main():
    """Read the configuration and run the network"""

    args = parse_args()

    # Heaps are sized for the j11_v2 network. Changing the network will
    # require updating network_heap_size and param_heap_size
    config_file = '../test/testvecs/config/infer/tidl_config_j11_v2.txt'

    configuration = Configuration()
    configuration.read_from_file(config_file)
    configuration.enable_api_trace = False
    configuration.num_frames = args.num_frames

    num_dsp = Executor.get_num_devices(DeviceType.DSP)
    num_eve = Executor.get_num_devices(DeviceType.EVE)

    if num_dsp == 0 and num_eve == 0:
        print('No TIDL API capable devices available')
        return

    enable_time_stamps("1eo_timestamp.log", 16)
    run(num_eve, num_dsp, configuration)

    return
예제 #3
0
def run(num_eve, num_dsp, c):
    """ Run the network on the specified device type and number of devices"""

    print('Running on {} EVEs, {} DSPs'.format(num_eve, num_dsp))

    dsp_device_ids = set(
        [DeviceId.ID0, DeviceId.ID1, DeviceId.ID2, DeviceId.ID3][0:num_dsp])
    eve_device_ids = set(
        [DeviceId.ID0, DeviceId.ID1, DeviceId.ID2, DeviceId.ID3][0:num_eve])

    c.layer_index_to_layer_group_id = {
        12: DSP_LAYER_GROUP_ID,
        13: DSP_LAYER_GROUP_ID,
        14: DSP_LAYER_GROUP_ID
    }

    try:
        print('TIDL API: performing one time initialization ...')

        eve = Executor(DeviceType.EVE, eve_device_ids, c, EVE_LAYER_GROUP_ID)
        dsp = Executor(DeviceType.DSP, dsp_device_ids, c, DSP_LAYER_GROUP_ID)

        num_eve_eos = eve.get_num_execution_objects()
        num_dsp_eos = dsp.get_num_execution_objects()

        eops = []
        num_pipe = max(num_eve_eos, num_dsp_eos)
        for i in range(num_pipe):
            eops.append(
                ExecutionObjectPipeline(
                    [eve.at(i % num_eve_eos),
                     dsp.at(i % num_dsp_eos)]))

        allocate_memory(eops)

        # Open input, output files
        f_in = open(c.in_data, 'rb')
        f_out = open(c.out_data, 'wb')

        print('TIDL API: processing input frames ...')

        num_eops = len(eops)
        for frame_index in range(c.num_frames + num_eops):
            eop = eops[frame_index % num_eops]

            if eop.process_frame_wait():
                write_output(eop, f_out)

            if read_frame(eop, frame_index, c, f_in):
                eop.process_frame_start_async()

        f_in.close()
        f_out.close()

        free_memory(eops)
    except TidlError as err:
        print(err)
예제 #4
0
def run(num_eve, num_dsp, configuration):
    """ Run the network on the specified device type and number of devices"""

    print('Running network across {} EVEs, {} DSPs'.format(num_eve, num_dsp))

    dsp_device_ids = set(
        [DeviceId.ID0, DeviceId.ID1, DeviceId.ID2, DeviceId.ID3][0:num_dsp])
    eve_device_ids = set(
        [DeviceId.ID0, DeviceId.ID1, DeviceId.ID2, DeviceId.ID3][0:num_eve])

    # Heap sizes for this network determined using Configuration.showHeapStats
    configuration.param_heap_size = (3 << 20)
    configuration.network_heap_size = (20 << 20)

    try:
        print('TIDL API: performing one time initialization ...')

        # Collect all EOs from EVE and DSP executors
        eos = []

        if len(eve_device_ids) != 0:
            eve = Executor(DeviceType.EVE, eve_device_ids, configuration, 1)
            for i in range(eve.get_num_execution_objects()):
                eos.append(eve.at(i))

        if len(dsp_device_ids) != 0:
            dsp = Executor(DeviceType.DSP, dsp_device_ids, configuration, 1)
            for i in range(dsp.get_num_execution_objects()):
                eos.append(dsp.at(i))

        allocate_memory(eos)

        # Open input, output files
        f_in = open(configuration.in_data, 'rb')
        f_out = open(configuration.out_data, 'wb')

        print('TIDL API: processing input frames ...')

        num_eos = len(eos)
        for frame_index in range(configuration.num_frames + num_eos):
            execution_object = eos[frame_index % num_eos]

            if execution_object.process_frame_wait():
                report_time(execution_object)
                write_output(execution_object, f_out)

            if read_frame(execution_object, frame_index, configuration, f_in):
                execution_object.process_frame_start_async()

        f_in.close()
        f_out.close()

        free_memory(eos)
    except TidlError as err:
        print(err)
예제 #5
0
def run(device_type, num_devices, configuration):
    """ Run the network on a single device and dump output of each layer"""

    print('Running network on {} {}'.format(num_devices, device_type))

    device_ids = set([DeviceId.ID0])

    try:
        print('TIDL API: performing one time initialization ...')

        executor = Executor(device_type, device_ids, configuration, 1)

        # Collect all EOs from EVE and DSP executors
        eos = []
        for i in range(executor.get_num_execution_objects()):
            eos.append(executor.at(i))

        allocate_memory(eos)

        # Open input, output files
        f_in = open(configuration.in_data, 'rb')

        print('TIDL API: processing input frames ...')

        num_eos = len(eos)
        for frame_index in range(configuration.num_frames + num_eos):
            execution_object = eos[frame_index % num_eos]

            if execution_object.process_frame_wait():
                execution_object.write_layer_outputs_to_file()

            if read_frame(execution_object, frame_index, configuration, f_in):
                execution_object.process_frame_start_async()

        f_in.close()

        free_memory(eos)
    except TidlError as err:
        print(err)
예제 #6
0
def main():
    """Read the configuration and run the network"""
    #logging.basicConfig(level=logging.INFO)

    args = parse_args()

    config_file = '../test/testvecs/config/infer/tidl_config_j11_v2.txt'
    labels_file = '../imagenet/imagenet_objects.json'

    configuration = Configuration()
    configuration.read_from_file(config_file)

    if os.path.isfile(args.input_file):
        configuration.in_data = args.input_file
    else:
        print('Input image {} does not exist'.format(args.input_file))
        return
    print('Input: {}'.format(args.input_file))

    num_eve = Executor.get_num_devices(DeviceType.EVE)
    num_dsp = Executor.get_num_devices(DeviceType.DSP)

    if num_eve == 0 and num_dsp == 0:
        print('No TIDL API capable devices available')
        return

    # use 1 EVE or DSP since input is a single image
    # If input is a stream of images, feel free to use all EVEs and/or DSPs
    if num_eve > 0:
        num_eve = 1
        num_dsp = 0
    else:
        num_dsp = 1

    run(num_eve, num_dsp, configuration, labels_file)

    return
예제 #7
0
def main():
    """ Parse arguments, read configuration and run network"""

    parser = argparse.ArgumentParser(
        description='Dump output of each network layer to file.')
    parser.add_argument(
        '-c',
        '--config_file',
        default='../test/testvecs/config/infer/tidl_config_j11_v2.txt',
        help='Path to TIDL config file')

    args = parser.parse_args()

    # Run network for 1 frame since we interested in intermediate layer outputs
    num_frames = 1

    # Read configuration from file
    configuration = Configuration()
    configuration.read_from_file(args.config_file)
    configuration.enable_layer_dump = True
    configuration.num_frames = num_frames

    num_dsp = Executor.get_num_devices(DeviceType.DSP)
    num_eve = Executor.get_num_devices(DeviceType.EVE)

    if num_dsp == 0 and num_eve == 0:
        print('No TIDL API capable devices available')
        return

    if num_eve > 0:
        device_type = DeviceType.EVE
    else:
        device_type = DeviceType.DSP

    # Since we are dumping layer outputs, just run on one device
    run(device_type, 1, configuration)
예제 #8
0
def main():
    """Read the configuration and run the network"""

    args = parse_args()

    config_file = '../test/testvecs/config/infer/tidl_config_mnist_lenet.txt'
    labels_file = '../test/testvecs/input/digits10_labels_10x1.y'

    configuration = Configuration()
    configuration.read_from_file(config_file)

    num_eve = Executor.get_num_devices(DeviceType.EVE)
    num_dsp = 0

    if num_eve == 0:
        print('MNIST network currently supported only on EVE')
        return

    run(num_eve, num_dsp, configuration, labels_file)

    return
예제 #9
0
def run(num_eve, num_dsp, configuration, labels_file):
    """ Run the network on the specified device type and number of devices"""

    logging.info('Running network across {} EVEs, {} DSPs'.format(
        num_eve, num_dsp))

    dsp_device_ids = set(
        [DeviceId.ID0, DeviceId.ID1, DeviceId.ID2, DeviceId.ID3][0:num_dsp])
    eve_device_ids = set(
        [DeviceId.ID0, DeviceId.ID1, DeviceId.ID2, DeviceId.ID3][0:num_eve])

    # Heap sizes for this network determined using Configuration.showHeapStats
    configuration.param_heap_size = (3 << 20)
    configuration.network_heap_size = (20 << 20)

    try:
        logging.info('TIDL API: performing one time initialization ...')

        # Collect all EOs from EVE and DSP executors
        eos = []

        if eve_device_ids:
            eve = Executor(DeviceType.EVE, eve_device_ids, configuration, 1)
            for i in range(eve.get_num_execution_objects()):
                eos.append(eve.at(i))

        if dsp_device_ids:
            dsp = Executor(DeviceType.DSP, dsp_device_ids, configuration, 1)
            for i in range(dsp.get_num_execution_objects()):
                eos.append(dsp.at(i))

        eops = []
        num_eos = len(eos)
        for j in range(PIPELINE_DEPTH):
            for i in range(num_eos):
                eops.append(ExecutionObjectPipeline([eos[i]]))

        allocate_memory(eops)

        # open labels file
        with open(labels_file) as json_file:
            labels_data = json.load(json_file)

        configuration.num_frames = 1
        logging.info('TIDL API: processing {} input frames ...'.format(
            configuration.num_frames))

        num_eops = len(eops)
        for frame_index in range(configuration.num_frames + num_eops):
            eop = eops[frame_index % num_eops]

            if eop.process_frame_wait():
                process_output(eop, labels_data)

            if read_frame(eop, frame_index, configuration):
                eop.process_frame_start_async()

        free_memory(eops)

    except TidlError as err:
        print(err)
예제 #10
0
def run(num_eve, num_dsp, configuration, labels_file):
    """ Run the network on the specified device type and number of devices"""

    print('Running network across {} EVEs, {} DSPs'.format(num_eve, num_dsp))

    dsp_device_ids = set(
        [DeviceId.ID0, DeviceId.ID1, DeviceId.ID2, DeviceId.ID3][0:num_dsp])
    eve_device_ids = set(
        [DeviceId.ID0, DeviceId.ID1, DeviceId.ID2, DeviceId.ID3][0:num_eve])

    # Heap sizes for this network determined using Configuration.showHeapStats
    configuration.param_heap_size = (3 << 20)
    configuration.network_heap_size = (20 << 20)

    try:
        print('TIDL API: performing one time initialization ...')

        # Collect all EOs from EVE and DSP executors
        eos = []

        if eve_device_ids:
            eve = Executor(DeviceType.EVE, eve_device_ids, configuration, 1)
            for i in range(eve.get_num_execution_objects()):
                eos.append(eve.at(i))

        if dsp_device_ids:
            dsp = Executor(DeviceType.DSP, dsp_device_ids, configuration, 1)
            for i in range(dsp.get_num_execution_objects()):
                eos.append(dsp.at(i))

        eops = []
        num_eos = len(eos)
        for j in range(PIPELINE_DEPTH):
            for i in range(num_eos):
                eops.append(ExecutionObjectPipeline([eos[i]]))

        allocate_memory(eops)

        # Open input, output files
        f_in = open(configuration.in_data, 'rb')
        f_labels = open(labels_file, 'rb')

        input_size = os.path.getsize(configuration.in_data)
        configuration.num_frames = int(
            input_size / (configuration.height * configuration.width))

        print('TIDL API: processing {} input frames ...'.format(
            configuration.num_frames))

        num_eops = len(eops)
        num_errors = 0
        for frame_index in range(configuration.num_frames + num_eops):
            eop = eops[frame_index % num_eops]

            if eop.process_frame_wait():
                num_errors += process_output(eop, f_labels)

            if read_frame(eop, frame_index, configuration, f_in):
                eop.process_frame_start_async()

        f_in.close()
        f_labels.close()

        free_memory(eops)

        if num_errors == 0:
            print("mnist PASSED")
        else:
            print("mnist FAILED")

    except TidlError as err:
        print(err)