Esempio n. 1
0
    def test_write_registers_are_not_checked_in_units_without_write_lock(self):
        """Test opportune write register access check.

        `self` is this test case.

        """
        in_unit, out_unit = (UnitModel(
            ICaseString(name), 1, ["ALU"], LockInfo(rd_lock, wr_lock),
            []) for name, rd_lock, wr_lock in [("input", False,
                                                False), ("output", True,
                                                         True)])
        proc_desc = ProcessorDesc([in_unit], [FuncUnit(out_unit, [in_unit])],
                                  [], [])
        self.assertEqual(
            simulate([
                HwInstruction(*instr_regs, "ALU")
                for instr_regs in [[["R1"], "R2"], [[], "R1"]]
            ], HwSpec(proc_desc)), [
                BagValDict(cp_util) for cp_util in [{
                    ICaseString("input"): [InstrState(0)]
                }, {
                    ICaseString("input"): [InstrState(1)],
                    ICaseString("output"): [InstrState(0)]
                }, {
                    ICaseString("output"): [InstrState(1)]
                }]
            ])
Esempio n. 2
0
    def test_hazard(self):
        """Test structural hazards in a unified memory architecture.

        `self` is this test case.

        """
        in_unit, out_unit = (UnitModel(
            ICaseString(name), 1, ["ALU", "MEM"], LockInfo(rd_lock, wr_lock),
            mem_acl) for name, rd_lock, wr_lock, mem_acl in [(
                "input", True, False,
                ["ALU", "MEM"]), ("output", False, True, ["MEM"])])
        proc_desc = ProcessorDesc([in_unit], [FuncUnit(out_unit, [in_unit])],
                                  [], [])
        self.assertEqual(
            simulate([
                HwInstruction([], out_reg, "ALU") for out_reg in ["R1", "R2"]
            ], HwSpec(proc_desc)), [
                BagValDict(cp_util) for cp_util in [{
                    ICaseString("input"): [InstrState(0)]
                }, {
                    ICaseString("output"): [InstrState(0)],
                    ICaseString("input"): [InstrState(1)]
                }, {
                    ICaseString("output"): [InstrState(1)]
                }]
            ])
Esempio n. 3
0
    def test_all_candidate_instructions_are_offered_to_the_destinaton_unit(
            self):
        """Test candidate instructions aren't shortlisted.

        `self` is this test case.

        """
        in_unit, out_unit = (UnitModel(ICaseString(name), width,
                                       ["ALU", "MEM"],
                                       LockInfo(rd_lock, wr_lock), mem_acl)
                             for name, width, rd_lock, wr_lock, mem_acl in [(
                                 "input", 3, True, False,
                                 []), ("output", 2, False, True, ["MEM"])])
        proc_desc = ProcessorDesc([in_unit], [FuncUnit(out_unit, [in_unit])],
                                  [], [])
        self.assertEqual(
            simulate([
                HwInstruction([], *instr_params) for instr_params in
                [["R1", "MEM"], ["R2", "MEM"], ["R3", "ALU"]]
            ], HwSpec(proc_desc)), [
                BagValDict(cp_util) for cp_util in [{
                    ICaseString("input"):
                    map(InstrState, [0, 1, 2])
                }, {
                    ICaseString("output"):
                    map(InstrState, [0, 2]),
                    ICaseString("input"):
                    [InstrState(1, StallState.STRUCTURAL)]
                }, {
                    ICaseString("output"): [InstrState(1)]
                }]
            ])
Esempio n. 4
0
    def test_mem_ACL_is_correctly_matched_against_instructions(self):
        """Test comparing memory ACL against instructions.

        `self` is this test case.

        """
        res_util = (BagValDict(
            {ICaseString("full system"): [InstrState(instr)]})
                    for instr in [0, 1])
        assert simulate(
            [
                HwInstruction([], out_reg, ICaseString("ALU"))
                for out_reg in ["R1", "R2"]
            ],
            HwSpec(
                processor_utils.load_proc_desc({
                    "units": [{
                        units.UNIT_NAME_KEY: "full system",
                        units.UNIT_WIDTH_KEY: 2,
                        units.UNIT_CAPS_KEY: ["ALU"],
                        **{
                            attr: True
                            for attr in [
                                units.UNIT_RLOCK_KEY, units.UNIT_WLOCK_KEY
                            ]
                        }, units.UNIT_MEM_KEY: ["ALU"]
                    }],
                    "dataPath": []
                }))) == list(res_util)
Esempio n. 5
0
    def test_instructions_flow_seamlessly(self):
        """Test instructions are moved successfully along the pipeline.

        `self` is this test case.

        """
        big_input, small_input1, mid1, small_input2, mid2, out_unit = (
            UnitModel(ICaseString(name), width, ["ALU"], LockInfo(
                rd_lock, wr_lock), []) for name, width, rd_lock, wr_lock in
            [("big input", 4, True, False), ("small input 1", 1, True, False),
             ("middle 1", 1, False, False), ("small input 2", 1, True, False),
             ("middle 2", 2, False, False), ("output", 2, False, True)])
        proc_desc = ProcessorDesc([big_input, small_input1, small_input2], [
            FuncUnit(out_unit, [big_input, mid2])], [], starmap(FuncUnit, [
                [mid2, [mid1, small_input2]], [mid1, [small_input1]]]))
        self.assertEqual(simulate(
            [HwInstruction([], out_reg, "ALU") for out_reg in
             ["R1", "R2", "R3", "R4", "R5", "R6"]],
            HwSpec(proc_desc)), [BagValDict(cp_util) for cp_util in [
                {ICaseString("big input"): map(InstrState, [0, 1, 2, 3]),
                 ICaseString("small input 1"): [InstrState(4)],
                 ICaseString("small input 2"): [InstrState(5)]},
                {ICaseString("big input"): (InstrState(
                    instr, StallState.STRUCTURAL) for instr in [2, 3]),
                 ICaseString("output"): map(InstrState, [0, 1]),
                 ICaseString("middle 1"): [InstrState(4)],
                 ICaseString("middle 2"): [InstrState(5)]},
                {ICaseString("output"): map(InstrState, [2, 3]),
                 ICaseString("middle 2"):
                 starmap(InstrState, [[5, StallState.STRUCTURAL], [4]])},
                {ICaseString("output"): map(InstrState, [4, 5])}]])
Esempio n. 6
0
    def test_RLock_in_unit_before_WLock(self):
        """Test detecting RAW hazards with read locks in earlier units.

        `self` is this test case.

        """
        in_unit, mid, out_unit = (UnitModel(ICaseString(name), 1, ["ALU"],
                                            LockInfo(rd_lock, wr_lock), [])
                                  for name, rd_lock, wr_lock in [(
                                      "input", False,
                                      False), ("middle", True,
                                               False), ("output", False,
                                                        True)])
        proc_desc = ProcessorDesc([in_unit], [FuncUnit(out_unit, [mid])], [],
                                  [FuncUnit(mid, [in_unit])])
        self.assertEqual(
            simulate([
                HwInstruction(*instr_regs, "ALU")
                for instr_regs in [[[], "R1"], [["R1"], "R2"]]
            ], HwSpec(proc_desc)), [
                BagValDict(cp_util) for cp_util in [{
                    ICaseString("input"): [InstrState(0)]
                }, {
                    ICaseString("input"): [InstrState(1)],
                    ICaseString("middle"): [InstrState(0)]
                }, {
                    ICaseString("middle"): [InstrState(1, StallState.DATA)],
                    ICaseString("output"): [InstrState(0)]
                }, {
                    ICaseString("middle"): [InstrState(1)]
                }, {
                    ICaseString("output"): [InstrState(1)]
                }]
            ])
Esempio n. 7
0
    def test_sim(self, prog, cpu, util_tbl):
        """Test executing a program.

        `self` is this test case.
        `prog` is the program to run.
        `cpu` is the processor to run the program on.
        `util_tbl` is the expected utilization table.

        """
        assert simulate([HwInstruction(*regs, ICaseString(categ)) for
                         *regs, categ in prog], HwSpec(cpu)) == [
                             BagValDict(inst_util) for inst_util in util_tbl]
Esempio n. 8
0
    def test_mem_util_in_earlier_inputs_affects_later_ones(self):
        """Test propagation of memory utilization among inputs.

        `self` is this test case.

        """
        full_sys_unit = UnitModel(ICaseString("full system"), 2, ["ALU"],
                                  LockInfo(True, True), ["ALU"])
        res_util = (BagValDict(
            {ICaseString("full system"): [InstrState(instr)]})
                    for instr in [0, 1])
        assert simulate(
            [HwInstruction([], out_reg, "ALU") for out_reg in ["R1", "R2"]],
            HwSpec(ProcessorDesc([], [], [full_sys_unit],
                                 []))) == list(res_util)
Esempio n. 9
0
    def test_hazard(self):
        """Test detecting RAR hazards.

        `self` is this test case.

        """
        proc_desc = ProcessorDesc([], [], [
            UnitModel(ICaseString(TEST_DIR), 2, ["ALU"], LockInfo(True, True),
                      [])
        ], [])
        self.assertEqual(
            simulate([
                HwInstruction(["R1"], out_reg, "ALU")
                for out_reg in ["R2", "R3"]
            ], HwSpec(proc_desc)),
            [BagValDict({ICaseString(TEST_DIR): map(InstrState, [0, 1])})])
Esempio n. 10
0
def compile_program(prog: Iterable[ProgInstruction],
                    isa: Mapping[str, object]) -> List[HwInstruction]:
    """Compile the program using the given instruction set.

    `prog` is the program to compile.
    `isa` is the instruction set containing upper-case instructions.
    The function validates and translates the given program into a
    sequence that can be directly fed into a processor understanding the
    given instruction set and returns that sequence. The function raises an
    UndefElemError if an unsupported instruction is encountered.

    """
    return [
        HwInstruction(prog_instr.sources, prog_instr.destination,
                      _get_cap(isa, prog_instr)) for prog_instr in prog
    ]
Esempio n. 11
0
    def test_unsupported_instruction_stalls_pipeline(
            self, valid_prog, util_tbl):
        """Test executing an invalid instruction after a valid program.

        `self` is this test case.
        `valid_prog` is a sequence of valid instructions.
        `util_tbl` is the utilization table.

        """
        prog = starmap(lambda in_regs, out_reg, categ:
                       HwInstruction(in_regs, out_reg, ICaseString(categ)),
                       chain(valid_prog, [([], "R14", "MEM")]))
        ex_chk = raises(StallError, simulate, tuple(prog), HwSpec(
            read_proc_file("processors", "singleALUProcessor.yaml")))
        test_utils.chk_error(
            [test_utils.ValInStrCheck(ex_chk.value.processor_state, [
                BagValDict(cp_util) for cp_util in util_tbl])], ex_chk.value)
Esempio n. 12
0
    def test_instructions_are_loaded_to_lexicographically_inputs_first(self):
        """Test instructions are fed into sorted input units.

        `self` is this test case.

        """
        in_unit, out_unit = (UnitModel(ICaseString(name), 1, ["ALU"], LockInfo(
            rd_lock, wr_lock), mem_acl) for name, rd_lock, wr_lock, mem_acl in
                             [("input 1", True, False, []),
                              ("output 1", False, True, ["ALU"])])
        proc_desc = ProcessorDesc(
            [in_unit], [FuncUnit(out_unit, [in_unit])], [UnitModel(ICaseString(
                "input 2"), 1, ["ALU"], LockInfo(True, False), [])], [])
        self.assertEqual(simulate(
            [HwInstruction([], "R1", "ALU")], HwSpec(proc_desc)), [BagValDict(
                cp_util) for cp_util in [{ICaseString("input 1"): [InstrState(
                    0)]}, {ICaseString("output 1"): [InstrState(0)]}]])
Esempio n. 13
0
    def test_hazard(self, instr_regs):
        """Test detecting data hazards.

        `self` is this test case.
        `instr_regs` are the registers accessed by each instruction.

        """
        full_sys_unit = UnitModel(ICaseString(TEST_DIR), 2, ["ALU"],
                                  LockInfo(True, True), [])
        assert simulate(
            [HwInstruction(*regs, "ALU") for regs in instr_regs],
            HwSpec(ProcessorDesc([], [], [full_sys_unit], []))) == [
                BagValDict(cp_util) for cp_util in [{
                    ICaseString(TEST_DIR):
                    itertools.starmap(InstrState, [[0], [1, StallState.DATA]])
                }, {
                    ICaseString(TEST_DIR): [InstrState(1)]
                }]
            ]
Esempio n. 14
0
    def test_only_mem_access_instructions_are_checked(self):
        """Test always allowing instructions without memory access.

        `self` is this test case.

        """
        in_unit, out_unit = (UnitModel(ICaseString(name), 2, ["ALU", "MEM"],
                                       LockInfo(rd_lock, wr_lock), mem_acl)
                             for name, rd_lock, wr_lock, mem_acl in [(
                                 "input", True, False,
                                 []), ("output", False, True, ["MEM"])])
        proc_desc = ProcessorDesc([in_unit], [FuncUnit(out_unit, [in_unit])],
                                  [], [])
        self.assertEqual(
            simulate([
                HwInstruction([], *instr_params)
                for instr_params in [["R1", "MEM"], ["R2", "ALU"]]
            ], HwSpec(proc_desc)), [
                BagValDict({ICaseString(unit): map(InstrState, [0, 1])})
                for unit in ["input", "output"]
            ])
Esempio n. 15
0
    def test_internal_stall_is_detected(self):
        """Test detecting stalls in internal units.

        `self` is this test case.

        """
        in_unit, mid, out_unit = (
            UnitModel(ICaseString(name), width, ["ALU"],
                      LockInfo(rd_lock, wr_lock), []) for
            name, width, rd_lock, wr_lock in [("input", 2, True, False), (
                "middle", 2, False, False), ("output", 1, False, True)])
        proc_desc = ProcessorDesc([in_unit], [FuncUnit(out_unit, [mid])], [],
                                  [FuncUnit(mid, [in_unit])])
        self.assertEqual(simulate(
            [HwInstruction([], out_reg, "ALU") for out_reg in ["R1", "R2"]],
            HwSpec(proc_desc)), [BagValDict(cp_util) for cp_util in [
                {ICaseString("input"): map(InstrState, [0, 1])},
                {ICaseString("middle"): map(InstrState, [0, 1])},
                {ICaseString("middle"): [InstrState(1, StallState.STRUCTURAL)],
                 ICaseString("output"): [InstrState(0)]},
                {ICaseString("output"): [InstrState(1)]}]])
Esempio n. 16
0
    def test_earlier_instructions_are_propagated_first(self):
        """Test earlier instructions are selected first.

        `self` is this test case.

        """
        in_units = [UnitModel(
            ICaseString(name), 1, [categ], LockInfo(True, False), []) for name,
                    categ in [("ALU input", "ALU"), ("MEM input", "MEM")]]
        out_unit = UnitModel(ICaseString("output"), 1, ["ALU", "MEM"],
                             LockInfo(False, True), [])
        proc_desc = ProcessorDesc(
            in_units, [FuncUnit(out_unit, in_units)], [], [])
        self.assertEqual(simulate([HwInstruction(
            *instr_params) for instr_params in [[[], "R12", "MEM"], [
                ["R11", "R15"], "R14", "ALU"]]], HwSpec(proc_desc)), [
                    BagValDict(inst_util) for inst_util in
                    [{ICaseString("MEM input"): [InstrState(0)],
                      ICaseString("ALU input"): [InstrState(1)]},
                     {ICaseString("output"): [InstrState(0)], ICaseString(
                         "ALU input"): [InstrState(1, StallState.STRUCTURAL)]},
                     {ICaseString("output"): [InstrState(1)]}]])
Esempio n. 17
0
    def test_hazard(self, in_width, in_mem_util, out_unit_params, extra_util):
        """Test detecting structural hazards.

        `self` is this test case.
        `in_width` is the width of the input unit.
        `in_mem_util` is the list of input unit capabilities requiring
                      memory utilization.
        `out_unit_params` are the creation parameters of output units.
        `extra_util` is the extra utilization beyond the second clock
                     pulse.

        """
        in_unit = UnitModel(ICaseString("input"), in_width, ["ALU"],
                            LockInfo(True, False), in_mem_util)
        out_units = (UnitModel(ICaseString(name), width, ["ALU"],
                               LockInfo(False, True), mem_access)
                     for name, width, mem_access in out_unit_params)
        out_units = (FuncUnit(out_unit, [in_unit]) for out_unit in out_units)
        cp1_util = {ICaseString("input"): map(InstrState, range(in_width))}
        assert simulate(
            [HwInstruction([], out_reg, "ALU") for out_reg in ["R1", "R2"]],
            HwSpec(ProcessorDesc([in_unit], out_units, [], []))) == list(
                map(BagValDict, more_itertools.prepend(cp1_util, extra_util)))
Esempio n. 18
0
    def test_util_tbl_exists_in_StallError(self):
        """Test dumping the utilizaiton table in stall errors.

        `self` is this test case.

        """
        long_input, mid, short_input, out_unit = (
            UnitModel(ICaseString(name), 1, ["ALU"],
                      LockInfo(rd_lock, wr_lock), []) for name, rd_lock,
            wr_lock in [("long input", False, False), ("middle", False, False),
                        ("short input", False, False), ("output", True, True)])
        proc_desc = ProcessorDesc([long_input, short_input], [FuncUnit(
            out_unit, [mid, short_input])], [], [FuncUnit(mid, [long_input])])
        with self.assertRaises(StallError) as ex_chk:
            simulate([HwInstruction(*instr_regs, "ALU") for instr_regs in
                      [[[], "R1"], [["R1"], "R2"]]], HwSpec(proc_desc))
        self.assertEqual(ex_chk.exception.processor_state, [
            BagValDict(cp_util) for cp_util in
            [{ICaseString("long input"): [InstrState(0)], ICaseString(
                "short input"): [InstrState(1)]},
             {ICaseString("middle"): [InstrState(0)], ICaseString("output"):
              [InstrState(1, StallState.DATA)]},
             {ICaseString("middle"): [InstrState(0, StallState.STRUCTURAL)],
              ICaseString("output"): [InstrState(1, StallState.DATA)]}]])