Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
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)