]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - tidl/tidl-api.git/blobdiff - examples/pybind/two_eo_per_frame.py
Add option to specify object classes list file
[tidl/tidl-api.git] / examples / pybind / two_eo_per_frame.py
index c6b16c6dd42abb508eb9d1be97732a30aef4faef..a1cd58c0dc9d547b94a6980f31c8b14ae0162499 100755 (executable)
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 # THE POSSIBILITY OF SUCH DAMAGE.
 
+""" Process frames using ExecutionObjectPipeline.
+    Each ExecutionObjectPipeline processes a single frame.
+"""
+
+import argparse
 
 from tidl import DeviceId, DeviceType, Configuration, TidlError
 from tidl import Executor, ExecutionObjectPipeline
-from tidl import allocate_memory, free_memory
+from tidl import allocate_memory, free_memory, enable_time_stamps
 
-from tidl_app_utils import read_frame, write_output, report_time
+from tidl_app_utils import read_frame, write_output
 
-import argparse
 
-def main(config_file, num_frames):
-    c = Configuration()
-    c.read_from_file(config_file)
-    c.enable_api_trace = False
-    c.num_frames = num_frames
+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):
+    if num_dsp == 0 or num_eve == 0:
         print('This example required EVEs and DSPs.')
         return
 
-    run(num_eve, num_dsp, c)
+    enable_time_stamps("2eo_timestamp.log", 16)
+    run(num_eve, num_dsp, configuration)
 
-    return
+# Run layer group 1 on EVE, 2 on DSP
+EVE_LAYER_GROUP_ID = 1
+DSP_LAYER_GROUP_ID = 2
 
 def run(num_eve, num_dsp, c):
     """ Run the network on the specified device type and number of devices"""
@@ -62,16 +81,9 @@ def run(num_eve, num_dsp, c):
     eve_device_ids = set([DeviceId.ID0, DeviceId.ID1,
                           DeviceId.ID2, DeviceId.ID3][0:num_eve])
 
-    EVE_LAYER_GROUP_ID = 1
-    DSP_LAYER_GROUP_ID = 2
-    c.layer_index_to_layer_group_id = {12:DSP_LAYER_GROUP_ID, 
-                                       13:DSP_LAYER_GROUP_ID, 
-                                       14:DSP_LAYER_GROUP_ID};
-    
-    # Heap sizes for this network determined using Configuration.showHeapStats
-    c.param_heap_size   = (3 << 20)
-    c.network_heap_size = (20 << 20)
-
+    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 ...')
@@ -85,13 +97,13 @@ def run(num_eve, num_dsp, c):
         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)]))
+            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_in = open(c.in_data, 'rb')
         f_out = open(c.out_data, 'wb')
 
 
@@ -99,36 +111,37 @@ def run(num_eve, num_dsp, c):
 
         num_eops = len(eops)
         for frame_index in range(c.num_frames+num_eops):
-            eop = eops [frame_index % num_eops]
+            eop = eops[frame_index % num_eops]
 
-            if (eop.process_frame_wait()):
-                report_time(eop)
+            if eop.process_frame_wait():
                 write_output(eop, f_out)
 
-            if (read_frame(eop, frame_index, c, f_in)):
+            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)
+        print(err)
 
-    return
 
-if __name__ == '__main__':
-    parser = argparse.ArgumentParser(description=
-                       'Process frames using ExecutionObjectPipeline. '
-                       'Each ExecutionObjectPipeline processes a single frame')
+DESCRIPTION = 'Process frames using ExecutionObjectPipeline. '\
+              'Each ExecutionObjectPipeline processes a single frame'
+
+def parse_args():
+    """Parse input arguments"""
+
+    parser = argparse.ArgumentParser(description=DESCRIPTION)
     parser.add_argument('-n', '--num_frames',
                         type=int,
-                        default=1,
+                        default=16,
                         help='Number of frames to process')
     args = parser.parse_args()
 
-    # Heaps are sized for the j11_v2 network. Changing the network will
-    # require updating network_heap_size and param_heap_size
-    main('../test/testvecs/config/infer/tidl_config_j11_v2.txt', 
-         args.num_frames)
+    return args
+
+
+if __name__ == '__main__':
+    main()