Exemple #1
0
 def test_parse2(self):
     s = '(cache (line_count 2)(line_size 4)(associativity 2)'
     s += '(access_time 2)(cycle_time 3)'
     s += '(policy bad)(write_back false)(memory (main)))'
     l = lex.Lexer(mocks.MockFile(s))
     with self.assertRaises(lex.ParseError):
         memory.parse_memory(l)
Exemple #2
0
def get_memory_list(db, mem, mod, baseline, replace):
    """Get the specified memory.
    mem is the name of the memory to get.
    mod is the model.
    baseline is the name of the file containing a baseline memory.
    replace is the memory to use as the main memory (or None).
    Returns the memory to simulate.
    """
    if mem == 'model':
        # Use the subsystem from the model.
        ml = mod.memory
    elif mem == 'baseline':
        # Use the baseline subsystem.
        with open(baseline, 'r') as f:
            ml = memory.parse_memory_list(lex.Lexer(f))
    elif mem == 'best':
        # Use the best subsystem.
        ml = get_best(db, mod)
    else:
        print('ERROR: invalid memory selected:', mem)
        sys.exit(-1)

    if replace:
        with open(replace, 'r') as f:
            mod.memory = memory.parse_memory(lex.Lexer(f))
        for m in ml.memories:
            ptr = m
            while not isinstance(ptr.get_next(), MainMemory):
                ptr = ptr.get_next()
            ptr.set_next(mod.memory)

    return ml
Exemple #3
0
 def test_parse(self):
     s = "(dram (frequency 1024)(cas_cycles 1)(rcd_cycles 2)"
     s += "(rp_cycles 3)(wb_cycles 4)(page_size 8)(page_count 16)"
     s += "(width 2)(burst_size 2)(open_page false)(ddr false))"
     l = lex.Lexer(mocks.MockFile(s))
     result = memory.parse_memory(l)
     self.assertEqual(str(result), s)
Exemple #4
0
 def test_parse(self):
     s = '(split (offset 128)(bank0 (join))(bank1 (join))'
     s += '(memory (ram)))'
     l = lex.Lexer(mocks.MockFile(s))
     result = memory.parse_memory(l)
     expected = '(split (offset 128)(bank0 (join))(bank1 (join))'
     expected += '(memory (main)))'
     self.assertEqual(str(result), expected)
Exemple #5
0
 def test_parse(self):
     s = '(spm (word_size 8)(size 1024)(access_time 3)(cycle_time 4)'
     s += '(memory (ram (word_size 4)(latency 100))))'
     l = lex.Lexer(mocks.MockFile(s))
     result = memory.parse_memory(l)
     expected = '(spm (word_size 8)(size 1024)'
     expected += '(access_time 3)(cycle_time 4)'
     expected += '(memory (main)))'
     self.assertEqual(str(result), expected)
Exemple #6
0
 def test_parse1(self):
     s = '(cache (line_count 2)(line_size 4)(associativity 2)'
     s += '(access_time 2)(cycle_time 3)'
     s += '(policy fifo)(write_back false)(memory (ram)))'
     l = lex.Lexer(mocks.MockFile(s))
     result = memory.parse_memory(l)
     expected = '(cache (line_count 2)(line_size 4)(associativity 2)'
     expected += '(access_time 2)(cycle_time 3)'
     expected += '(policy fifo)(write_back false)(memory (main)))'
     self.assertEqual(str(result), expected)
Exemple #7
0
 def test_offset(self):
     s = '(offset (value 2)(bank (join))(memory (ram)))'
     l = lex.Lexer(mocks.MockFile(s))
     result = memory.parse_memory(l)
     expected = '(offset (value 2)(bank (join))(memory (main)))'
     self.assertEqual(str(result), expected)
Exemple #8
0
 def test_parse(self):
     to_parse = '(xor (value 1024)(bank (join))(memory (ram)))'
     expected = '(xor (value 1024)(bank (join))(memory (main)))'
     l = lex.Lexer(mocks.MockFile(to_parse))
     result = memory.parse_memory(l)
     self.assertEqual(str(result), expected)
Exemple #9
0
 def test_parse(self):
     s = "(shift (value 2)(bank (join))(memory (ram)))"
     l = lex.Lexer(mocks.MockFile(s))
     result = memory.parse_memory(l)
     expected = "(shift (value 2)(bank (join))(memory (main)))"
     self.assertEqual(str(result), expected)
Exemple #10
0
def get_initial_memory(db, m, dist, directory, full):
    """Get the initial subsystem and its total access time.

    This runs from a process in the process pool.
    """

    # Load the model from the database.
    # If not found, we need to collect statistics first.
    state = db.load(m)
    if len(state) == 0:
        if main_context.verbose:
            print('Collecting statistics')
        for b in m.benchmarks:
            mem = m.memory.get_subsystem(b.index)
            sd = dist.get_subsystem_distribution(mem)
            b.collect_stats(directory, sd)
            dist.save(state)
            db.save(m, state)

    # Determine if we should use the best or the initial
    # memory as a starting point.
    if random.randint(0, 7) < 7:
        # Attempt to load the best subsystem from the database.
        # If not found, we need to evaluate it.
        best_name, _, _ = db.get_best(m)
        if best_name:

            # Load statistics from the database.
            state = db.load(m)
            dist.load(state, m)

            # Create the initial memory subsystem.
            lexer = lex.Lexer(StringIO(best_name))
            ml = memory.parse_memory_list(lexer)

            # Load the values for each subsystem.
            values, fstats = get_subsystem_values(db, m, ml, directory, full)
            return ml, values, fstats
    else:
        # Start from a random location.
        while True:     # Loop until we get a valid subsystem.
            ml = m.memory.clone()
            for b in m.benchmarks:
                name = db.get_random(m, b.index)
                if name:
                    lexer = lex.Lexer(StringIO(name))
                    ml.update(memory.parse_memory(lexer))
            cost = ml.get_cost(m.machine, full)
            if cost.fits(m.machine.get_max_cost()):
                break
        state = db.load(m)
        dist.load(state, m)
        values, fstats = get_subsystem_values(db, m, ml, directory, full)
        return ml, values, fstats

    # Get the current value.
    if main_context.verbose:
        print('Initial Memory: {}'.format(m.memory))
    ml = m.memory.clone()
    best_value, fstats = get_subsystem_values(db, m, ml, directory, full)
    total = get_total_value(db, m, ml, best_value, fstats)

    if not full:
        verify_model(db, m, ml, directory, total)

    db.insert_best(m, str(ml), total, ml.get_cost(m.machine, full))
    if main_context.verbose:
        print('Memory: {}'.format(ml))
        print('Value:  {}'.format(total))
        print('Cost:   {}'.format(ml.get_cost(m.machine, full)))
    return get_initial_memory(db, m, dist, directory, full)
Exemple #11
0
 def test_parse(self):
     s = "(option (memory0 (ram (latency 100)))"
     s += "(memory1 (ram (latency 200))))"
     l = lex.Lexer(mocks.MockFile(s))
     result = memory.parse_memory(l)
     self.assertEqual(str(result), "(ram (word_size 4)(latency 100))")
Exemple #12
0
 def test_parse(self):
     s = '(prefetch (stride -8)(memory (ram)))'
     l = lex.Lexer(mocks.MockFile(s))
     result = memory.parse_memory(l)
     expected = '(prefetch (stride -8)(memory (main)))'
     self.assertEqual(str(result), expected)