Пример #1
0
 def create_run_metadata(self):
     step_stats = step_stats_pb2.StepStats(dev_stats=[
         step_stats_pb2.DeviceStepStats(
             device='cpu:0',
             node_stats=[step_stats_pb2.NodeExecStats(node_name='hello')])
     ])
     return config_pb2.RunMetadata(function_graphs=[
         config_pb2.RunMetadata.FunctionGraphs(
             pre_optimization_graph=graph_pb2.GraphDef(
                 node=[node_def_pb2.NodeDef(name='foo')]))
     ],
                                   step_stats=step_stats)
Пример #2
0
 def testTraceFileStepStatsProto(self):
     trace_file = os.path.join(self.get_temp_dir(),
                               'testTraceFileStepStatsProto_tracefile')
     params = test_util.get_params('testTraceFileStepStatsProto')._replace(
         trace_file=trace_file, use_chrome_trace_format=False)
     self._train_and_eval_local(params)
     self.assertGreater(os.stat(trace_file).st_size, 0)
     with open(trace_file) as f:
         step_stats = step_stats_pb2.StepStats()
         # The following statement should not raise an exception.
         contents = f.read()
         text_format.Merge(contents, step_stats)
Пример #3
0
  def testPerStepTrace(self):
    run_options = config_pb2.RunOptions(
        trace_level=config_pb2.RunOptions.FULL_TRACE)
    run_outputs = config_pb2.RunOutputs()

    with ops.device('/cpu:0'):
      with session.Session() as sess:
        sess.run(constant_op.constant(1.0))
        self.assertTrue(not run_outputs.HasField('step_stats'))

        sess.run(constant_op.constant(1.0), run_outputs=run_outputs)
        self.assertTrue(not run_outputs.HasField('step_stats'))

        sess.run(constant_op.constant(1.0),
                 options=run_options,
                 run_outputs=run_outputs)
        self.assertTrue(run_outputs.HasField('step_stats'))

        step_stats = step_stats_pb2.StepStats()
        self.assertEquals(len(step_stats.dev_stats), 0)

        step_stats.CopyFrom(run_outputs.step_stats)
        self.assertEquals(len(step_stats.dev_stats), 1)
Пример #4
0
def instruction_trace(tracepath, sim_result, hw_specs, sim_params):
    step_stats = step_stats_pb2.StepStats()
    opu_dev_stats = step_stats.dev_stats.add()
    opu_dev_stats.device = "INSTRUCTIONS - OPU"
    cpu_dev_stats = step_stats.dev_stats.add()
    cpu_dev_stats.device = "INSTRUCTIONS - CPU"

    resources = _create_resources(
        step_stats, {
            ITX: sim_params.arch_params.num_rings,
            DRAM: sim_params.arch_params.num_memory_channels,
            IO_PORT: sim_params.arch_params.num_io_ports,
        })

    uarch_devices = {}

    pc_to_instr = {
        i.instruction.pc: i.instruction
        for i in sim_result.instructions
    }

    for i, inst in enumerate(sim_result.instructions):
        _add_resource_nodes(
            sim_params, resources, inst, {
                ITX: inst.interconnects,
                DRAM: inst.dram_channels,
                IO_PORT: inst.io_ports,
            })

        if inst.pc not in pc_to_instr:
            print(inst)
            print(pc_to_instr)
            raise ValueError("Something wrong: {0} {1} ".format(
                tracepath, inst))
        name = get_instr_name(pc_to_instr[inst.pc])

        node = opu_dev_stats.node_stats.add()
        op_name = name

        if pc_to_instr[inst.pc].node.HasField(
                lgf_pb2.LNF.bundle.DESCRIPTOR.name):
            op_name += (" [" + ", ".join(
                n.WhichOneof("node")
                for n in pc_to_instr[inst.pc].node.bundle.subgraph.nodes) +
                        "]")

        for unit in inst.unit_name:
            if unit not in uarch_devices:
                instr_dev_stats = step_stats.dev_stats.add()
                instr_dev_stats.device = "UARCH - " + unit
                uarch_devices[unit] = instr_dev_stats
        _add_uarch_nodes(sim_params, uarch_devices, inst, name)

        try:
            tensor_name = pc_to_instr[inst.pc].tensor_name or pc_to_instr[
                inst.pc].dest_addr[0].info.name
        except IndexError:
            tensor_name = "unknown"

        dep_instr_names = []
        for dep_pc_diff in pc_to_instr[inst.pc].dependent_pcs_distance:
            dep_pc = inst.pc - dep_pc_diff
            if dep_pc in pc_to_instr:
                dep_instr_names.append(get_instr_name(pc_to_instr[dep_pc]))

        node.node_name = "[{0}] - {1}".format(inst.pc, tensor_name)
        node.timeline_label = TIMELINE_LABEL_FORMAT.format(
            node.node_name, op_name, ", ".join(dep_instr_names))
        node.all_start_micros = clocks_to_nanos(inst.start_clk, sim_params)
        node.all_end_rel_micros = clocks_to_nanos(inst.duration_clks,
                                                  sim_params)

    trace = timeline.Timeline(step_stats=step_stats)
    with open(tracepath, "w") as f:
        f.write(trace.generate_chrome_trace_format())

    return trace