def extract_all_execute_events(events): result = [] for e in events: evt = IpuTraceEvent.FromString(e) if evt.type == IpuTraceEvent.EXECUTE: result += [evt] return result
def testTrain(self): shutil.rmtree("testlogs", True) tu.configure_ipu_system() run_cfg = run_config.RunConfig() classifier = estimator.Estimator(model_fn=model_fn, config=run_cfg, model_dir="testlogs") classifier.train(input_fn=input_fn, steps=16) event_file = glob.glob("testlogs/event*") self.assertTrue(len(event_file) == 1) compile_for_ipu_count = 0 for summary in summary_iterator.summary_iterator(event_file[0]): for val in summary.summary.value: if val.tag == "compile_summary": for evt_str in val.tensor.string_val: evt = IpuTraceEvent.FromString(evt_str) if (evt.type == IpuTraceEvent.COMPILE_END and len( evt.compile_end.compilation_report)) > 0: compile_for_ipu_count += 1 # Initialization graph and main graph self.assertEqual(compile_for_ipu_count, 2)
def _count_ipu_compilations(events): count = 0 for evt_str in events: evt = IpuTraceEvent.FromString(evt_str) if (evt.type == IpuTraceEvent.COMPILE_END and evt.compile_end.compilation_report): count += 1 return count
def _count_ipu_compilations_in_summary(summary): count = 0 for val in summary.value: if val.tag == "ipu_trace": for evt_str in val.tensor.string_val: evt = IpuTraceEvent.FromString(evt_str) if (evt.type == IpuTraceEvent.COMPILE_END and evt.compile_end.compilation_report): count += 1 return count
def extract_all_events(events): """Extract a list containing each event as an event object Args: events: A tensor containing a list of IPU events as protobuf strings Returns: A list containing IpuTraceEvent objects """ result = [] for e in events: evt = IpuTraceEvent.FromString(e) result += [evt] return result
def extract_all_types_from_event_trace(events): """Return a list of the types of each event in an event trace tensor Args: events: A tensor containing a list of IPU events as protobuf strings Returns: A list containing the type of each event """ result = [] for e in events: evt = IpuTraceEvent.FromString(e) result += [evt.type] return result
def extract_all_io_events(events): result = [] for e in events: evt = IpuTraceEvent.FromString(e) if evt.type in [ IpuTraceEvent.HOST_TO_DEVICE_TRANSFER, IpuTraceEvent.DEVICE_TO_HOST_TRANSFER ]: try: payload = js.loads(evt.data_transfer.data_transfer.decode('utf-8')) for t in payload["tensors"]: result += [(evt.type, t["name"])] except UnicodeDecodeError: pass return result
def extract_all_strings_from_event_trace(events): """Extract a concatenation of all data strings from an IPU event trace. Args: events: An array of IPU events as returned from the ``ipu_compile_summary`` operation. Returns: A string containing the concatenation of all of the data fields of the events. """ result = "" for e in events: evt = IpuTraceEvent.FromString(e) result = result + ("-" * 70) + "\n=> @ " + \ time.strftime('%F %T %z', time.localtime(evt.timestamp)) + ": " if evt.type == IpuTraceEvent.COMPILE_BEGIN: evt_str = "Compile begin: " + \ evt.compile_begin.module_name.decode('utf-8') + "\n" elif evt.type == IpuTraceEvent.COMPILE_END: evt_str = "Compile end: " + \ evt.compile_end.module_name.decode('utf-8') + "\n" + \ "Duration: " + str(evt.compile_end.duration) + " us\n" + \ evt.compile_end.compilation_report.decode('utf-8') elif evt.type == IpuTraceEvent.HOST_TO_DEVICE_TRANSFER: evt_str = "Host->Device\n" + \ evt.data_transfer.data_transfer.decode('utf-8') + "\n" elif evt.type == IpuTraceEvent.DEVICE_TO_HOST_TRANSFER: evt_str = "Device->Host\n" + \ evt.data_transfer.data_transfer.decode('utf-8') + "\n" elif evt.type == IpuTraceEvent.LOAD_ENGINE: evt_str = "Load engine: " + \ evt.load_engine.module_name.decode('utf-8') + "\n" elif evt.type == IpuTraceEvent.EXECUTE: evt_str = "Execute: " + \ evt.execute.module_name.decode('utf-8') + "\n" + \ evt.execute.execution_report.decode('utf-8') else: evt_str = "Unknown event" result = result + evt_str + '\n' return result
def extract_all_strings_from_event_trace(events): result = "" for e in events: evt = IpuTraceEvent.FromString(e) try: if evt.type == IpuTraceEvent.COMPILE_BEGIN: pass if evt.type == IpuTraceEvent.COMPILE_END: result = result + evt.compile_end.compilation_report.decode('utf-8') if evt.type == IpuTraceEvent.HOST_TO_DEVICE_TRANSFER: result = result + evt.data_transfer.data_transfer.decode('utf-8') if evt.type == IpuTraceEvent.DEVICE_TO_HOST_TRANSFER: result = result + evt.data_transfer.data_transfer.decode('utf-8') if evt.type == IpuTraceEvent.LOAD_ENGINE: pass if evt.type == IpuTraceEvent.EXECUTE: result = result + evt.execute.execution_report.decode('utf-8') except UnicodeDecodeError: pass return result
def extract_execute_reports(events): """Get a list of all compiler reports in the event list. Args: events: A list of trace event serialized protobufs Returns: A list of tuples containing the module namd and report.""" result = [] for e in events: evt = IpuTraceEvent.FromString(e) if evt.type == IpuTraceEvent.EXECUTE: try: module = evt.execute.module_name.decode('utf-8') rep = evt.execute.execution_report.decode('utf-8') if len(rep) > 0: result += [(module, rep)] except UnicodeDecodeError: pass return result
def extract_all_io_events(events): """Extract a list of all of the IO events from an IPU event trace tensor Args: events: A tensor containing a list of IPU events as protobuf strings Returns: A list containing only IO events as IpuTraceEvent objects """ result = [] for e in events: evt = IpuTraceEvent.FromString(e) if evt.type in [ IpuTraceEvent.HOST_TO_DEVICE_TRANSFER, IpuTraceEvent.DEVICE_TO_HOST_TRANSFER ]: try: payload = json.loads( evt.data_transfer.data_transfer.decode('utf-8')) for t in payload["tensors"]: result += [(evt.type, t["name"])] except UnicodeDecodeError: pass return result
def extract_all_events(events): result = [] for e in events: evt = IpuTraceEvent.FromString(e) result += [evt] return result
def extract_all_types_from_event_trace(events): result = [] for e in events: evt = IpuTraceEvent.FromString(e) result += [evt.type] return result