Ejemplo n.º 1
0
    def prepare_macc(self, offset, input, filter):
        # Fill input store
        yield ((SET, Constants.REG_INPUT_NUM_WORDS, len(input) // 4, 0), 0)
        for i in range(0, len(input), 4):
            packed = pack_vals(*input[i:i + 4])
            yield ((SET, Constants.REG_SET_INPUT, packed, 0), 0)

        # Fill filter store
        yield ((SET, Constants.REG_FILTER_NUM_WORDS, len(filter) // 4, 0), 0)
        for i in range(0, len(filter), 4):
            packed = pack_vals(*filter[i:i + 4])
            yield ((SET, Constants.REG_SET_FILTER, packed, 0), 0)

        # Set input offset
        yield ((SET, Constants.REG_INPUT_OFFSET, offset, 0), 0)
Ejemplo n.º 2
0
        def op_generator():
            # Set offset and activation min/max
            yield ((SET, Constants.REG_OUTPUT_OFFSET, -128, 0), 0)
            yield ((SET, Constants.REG_OUTPUT_MIN, -128, 0), 0)
            yield ((SET, Constants.REG_OUTPUT_MAX, 127, 0), 0)

            # Set Bias, Multipliers and shifts into store
            yield from self.set_output_params_store([
                (2598, 1170510491, -8),
                (2193, 2082838296, -9),
                (-18945, 1368877765, -9),
                (1851, 1661334583, -8),
            ])

            # Check some input and output values - should use all params twice
            yield from self.check_post_process(
                [-15150, -432, 37233, -294, -14403, 95, 37889, -566], [
                    pack_vals(-128, -125, -105, -123),
                    pack_vals(-128, -124, -104, -124)
                ])

            # Reset store and do this again
            yield ((SET, Constants.REG_OUTPUT_PARAMS_RESET, 0, 0), 0)
            yield from self.set_output_params_store([
                (1994, 1384690194, -8),
                (1467, 1177612918, -8),
                (1198, 1352351843, -8),
                (-3353, 1708212360, -9),
            ])
            yield from self.check_post_process([
                3908,
                153,
                2981,
                -9758,
                3721,
                -145,
                2912,
                -9791,
            ], [
                pack_vals(-113, -125, -118, -128),
                pack_vals(-114, -125, -118, -128)
            ])
Ejemplo n.º 3
0
 def op_generator():
     seed(4321)
     offset = randint(-128, 127)
     # Let it run through the stores once first
     input = [randint(-128, 127) for _ in range(160)]
     filter = [randint(-128, 127) for _ in range(160)]
     yield from self.prepare_macc(offset, input, filter)
     yield from self.check_macc(offset, input, filter)
     # Reset the input store with new values, leave the filter store
     input = [randint(-128, 127) for _ in range(160)]
     yield ((SET, Constants.REG_INPUT_NUM_WORDS, len(input) // 4, 0), 0)
     for i in range(0, len(input), 4):
         packed = pack_vals(*input[i:i + 4])
         yield ((SET, Constants.REG_SET_INPUT, packed, 0), 0)
     # Let it run through once more with new input values
     yield from self.check_macc(offset, input, filter)
Ejemplo n.º 4
0
    def test_it_does_more(self):
        dut = self.dut

        # Make random inputs
        inputs = [random.randrange(256) for _ in range(25 * 16)]

        # Transform inputs to expected outputs
        def group(lst, size):
            return [lst[i:i + size] for i in range(0, len(lst), size)]
        expected = []
        for sixteen_bytes in group(inputs, 16):
            expected_words_as_bytes = zip(*group(sixteen_bytes, 4))
            expected_words = [pack_vals(*word)
                              for word in expected_words_as_bytes]
            expected += expected_words

        # Run the test
        self.add_process(lambda: (yield from self.send_inputs(inputs)))
        self.run_sim(lambda: (yield from self.check_expected(expected)), False)
Ejemplo n.º 5
0
 def p(a, b, c, d):
     return pack_vals(a, b, c, d, offset=-128)
Ejemplo n.º 6
0
 def b(a, b, c, d):
     return pack_vals(a, b, c, d, offset=0)