def test_read_then_write(self):
    p = package.Package('the_package')

    temp_dir = tempfile.TemporaryDirectory()
    results_path = os.path.join(temp_dir.name, 'results.textproto')
    results = lec_characterizer_pb2.LecTiming()
    results.ir_function = 'single_op_OP_ADD'

    # Add one un-touched test case, and add one that should be appended to.
    proto_byte = xls_type_pb2.TypeProto()
    proto_byte.type_enum = xls_type_pb2.TypeProto.BITS
    proto_byte.bit_count = 8
    proto_short = xls_type_pb2.TypeProto()
    proto_short.type_enum = xls_type_pb2.TypeProto.BITS
    proto_short.bit_count = 16

    test_case = results.test_cases.add()
    param = test_case.function_type.parameters.add()
    param.CopyFrom(proto_short)
    param = test_case.function_type.parameters.add()
    param.CopyFrom(proto_short)
    test_case.function_type.return_type.CopyFrom(proto_short)

    test_case = results.test_cases.add()
    param = test_case.function_type.parameters.add()
    param.CopyFrom(proto_byte)
    param = test_case.function_type.parameters.add()
    param.CopyFrom(proto_byte)
    test_case.function_type.return_type.CopyFrom(proto_byte)
    test_case.exec_times_us.extend([1, 3, 7])
    test_case.average_us = 3

    with gfile.open(results_path, 'w') as f:
      f.write(text_format.MessageToString(results))

    num_iters = 16
    byte_type = p.get_bits_type(8)
    self.lc.run(
        op=op_pb2.OpProto.OP_ADD,
        samples=[([byte_type, byte_type], byte_type)],
        num_iters=num_iters,
        cell_library_textproto=self.cell_lib_text,
        results_path=results_path,
        lec_fn=lambda a, b, c, d: True)

    results = lec_characterizer_pb2.LecTiming()
    with gfile.open(results_path, 'r') as f:
      text_format.Parse(f.read(), results)

    self.assertEqual(results.ir_function, 'single_op_OP_ADD')
    self.assertLen(results.test_cases, 2)
    for test_case in results.test_cases:
      if test_case.function_type.return_type.bit_count == 16:
        self.assertEmpty(test_case.exec_times_us)
      else:
        self.assertLen(test_case.exec_times_us, 3 + num_iters)
Exemple #2
0
  def test_appends_to_existing(self):
    results = lec_characterizer_pb2.LecTiming()
    results.ir_function = 'single_op_OP_ADD'

    # Add one un-touched test case, and add one that should be appended to.
    proto_short = xls_type_pb2.TypeProto(
        type_enum=xls_type_pb2.TypeProto.BITS, bit_count=16)

    test_case = results.test_cases.add()
    test_case.function_type.parameters.add().CopyFrom(proto_short)
    test_case.function_type.parameters.add().CopyFrom(proto_short)
    test_case.function_type.return_type.CopyFrom(proto_short)
    test_case.exec_times_us.extend([1, 3, 7])
    test_case.average_us = 3

    num_iters = 16
    self._lc.run(
        results=results,
        op=op_pb2.OpProto.OP_ADD,
        function_type=test_case.function_type,
        num_iters=num_iters,
        cell_library_textproto=self._cell_lib_text,
        lec_fn=lambda a, b, c, d: True,
        results_fn=lambda x: None)

    self.assertLen(test_case.exec_times_us, 3 + num_iters)
Exemple #3
0
  def test_handles_tuples(self):
    num_iters = 16
    results = lec_characterizer_pb2.LecTiming()
    tuple_type = xls_type_pb2.TypeProto(
        type_enum=xls_type_pb2.TypeProto.TypeEnum.TUPLE)
    tuple_type.tuple_elements.add().CopyFrom(self._byte_type)
    tuple_type.tuple_elements.add().CopyFrom(self._byte_type)
    tuple_type.tuple_elements.add().CopyFrom(self._byte_type)

    function_type = xls_type_pb2.FunctionTypeProto()
    function_type.parameters.add().CopyFrom(self._byte_type)
    function_type.parameters.add().CopyFrom(self._byte_type)
    function_type.parameters.add().CopyFrom(self._byte_type)
    function_type.return_type.CopyFrom(tuple_type)

    self._lc.run(
        results=results,
        op=op_pb2.OpProto.OP_TUPLE,
        function_type=function_type,
        num_iters=num_iters,
        cell_library_textproto=self._cell_lib_text,
        lec_fn=lambda a, b, c, d: True,
        results_fn=lambda x: None)

    self.assertLen(results.test_cases, 1)
    test_case = results.test_cases[0]
    self.assertLen(test_case.exec_times_us, num_iters)
Exemple #4
0
  def setUp(self):
    super().setUp()
    server_path = runfiles.get_path('xls/synthesis/dummy_synthesis_server_main')
    self._port = portpicker.pick_unused_port()
    self._synthesis_server = subprocess.Popen(
        [server_path, '--port={}'.format(self._port)], self._port)

    cell_lib_path = runfiles.get_path(self._CELL_LIBRARY_PATH)
    with gfile.open(cell_lib_path, 'r') as f:
      self._cell_lib_text = f.read()

    self._lc = lec_characterizer.LecCharacterizer('localhost:{}'.format(
        self._port))

    self._byte_type = xls_type_pb2.TypeProto(
        type_enum=xls_type_pb2.TypeProto.BITS, bit_count=8)
Exemple #5
0
def main(argv):
    if len(argv) > 3:
        raise app.UsageError('Too many command-line arguments.')

    # Read in the results file to see what configs to test.
    results = lc_pb2.LecTiming()
    if FLAGS.results_path and gfile.exists(FLAGS.results_path):
        with gfile.open(FLAGS.results_path, 'r') as fd:
            results = text_format.ParseLines(fd, lc_pb2.LecTiming())

    with gfile.open(FLAGS.cell_library_textproto_path, 'r') as fd:
        cell_library_textproto = fd.read()

    lc = lc_mod.LecCharacterizer(FLAGS.synthesis_server_address)

    for width in FLAGS.widths:
        bits_type = xls_type_pb2.TypeProto(
            type_enum=xls_type_pb2.TypeProto.BITS, bit_count=int(width))

        function_type = xls_type_pb2.FunctionTypeProto()
        function_type.parameters.add().CopyFrom(bits_type)
        function_type.parameters.add().CopyFrom(bits_type)
        function_type.return_type.CopyFrom(bits_type)

        test_case = None
        for result_case in results.test_cases:
            # Find or create a matching test case for this function type.
            if result_case.function_type == function_type:
                test_case = result_case

        if test_case is None:
            test_case = results.test_cases.add()
            test_case.function_type.CopyFrom(function_type)

        runs_left = FLAGS.runs_per_type - len(test_case.exec_times_us)
        if runs_left > 0:
            lc.run(results, op_pb2.OpProto.Value(FLAGS.op), function_type,
                   int(runs_left), cell_library_textproto, z3_lec.run,
                   _save_results)