def test_cache_write_four_core_same_access(): op_list = [(1, 0b100000100001), (1, 0b1000000110000), (1, 0b1100000100111), (1, 0b10000000110011)] simulator = Simulator(data=None, num_cores=4) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[1].op_stream = FakeOpStream(op_list) simulator.procs[2].op_stream = FakeOpStream(op_list) simulator.procs[3].op_stream = FakeOpStream(op_list) simulator.run()
def test_cache_fetch_from_memory_only(): op_list = [(0, 0b100000100001), (0, 0b1000000110000), (0, 0b1100000100111), (0, 0b10000000110011)] op_list1 = [(0, 0b100001100001), (0, 0b1000001110000), (0, 0b1100001100111), (0, 0b10000001110011)] simulator = Simulator(data=None, protocol='dragon', num_cores=2) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[1].op_stream = FakeOpStream(op_list1) simulator.run() assert simulator.counter == len(op_list) * 101 + 1 # the extra 1 cycle is spent competing for bus ownership
def test_cache_read_four_core_same_access(): op_list = [(0, 0b100000100001), (0, 0b1000000110000), (0, 0b1100000100111), (0, 0b10000000110011)] simulator = Simulator(data=None, protocol='dragon', num_cores=4) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[1].op_stream = FakeOpStream(op_list) simulator.procs[2].op_stream = FakeOpStream(op_list) simulator.procs[3].op_stream = FakeOpStream(op_list) simulator.run()
def test_correctness_of_bus_invalidation_update_counting(): op_list = [(0, 0b100000100001), (0, 0b1000000110000), (0, 0b1100000100111), (0, 0b10000000110011)] op_list1 = [(2, 10), (1, 0b100000100001)] simulator = Simulator(data=None, num_cores=2) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[1].op_stream = FakeOpStream(op_list1) simulator.run() assert simulator.bus.total_bus_invalidation_or_updates == 1
def test_interleaving_cache_write_from_different_caches(): op_list = [(0, 0b100000100001), (1, 0b100000100001)] op_list1 = [(2, 10), (1, 0b100000100001)] simulator = Simulator(data=None, num_cores=2) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[1].op_stream = FakeOpStream(op_list1) simulator.run() assert simulator.procs[1].counter == 101 + simulator.procs[1].cache.block_size // 4 * 2 + 2 assert simulator.procs[1].total_compute_cycles == 10
def test_cache_read_block_while_other_cache_fetching_same_block_from_mem(): op_list = [(0, 0b100000100001), (0, 0b1000000110000), (0, 0b1100000100111), (0, 0b10000000110011)] op_list1 = [(2, 10), (0, 0b100000100001)] simulator = Simulator(data=None, num_cores=2) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[1].op_stream = FakeOpStream(op_list1) simulator.run() assert simulator.procs[1].counter == 100 + simulator.procs[1].cache.block_size // 4 * 2 + 1 assert simulator.counter == 100 + simulator.procs[1].cache.block_size // 4 * 2 + (len(op_list) - 1) * 101
def test_correctness_of_total_bus_traffic_counting(): op_list = [(0, 0b100000100001), (0, 0b1000000110000), (0, 0b1100000100111), (0, 0b10000000110011)] op_list1 = [(2, 10), (0, 0b100000100001)] simulator = Simulator(data=None, num_cores=2) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[1].op_stream = FakeOpStream(op_list1) simulator.run() cache0 = simulator.procs[0].cache assert simulator.bus.total_bus_traffic == cache0.block_size * 1
def test_cache_direct_hit_only(): op_list = [(0, 0b100000100001), (0, 0b1000000110000), (0, 0b100000100111), (0, 0b1000000110011)] simulator = Simulator(protocol='dragon', data=None, num_cores=1) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[0].cache.data[1] = np.matrix([ [1, SC, 0], [2, SC, 0] ]) simulator.run() assert simulator.counter == len(op_list)
def test_cache_store_direct_hit(): op_list = [(1, 0b100000100001), (1, 0b1000000110000), (1, 0b100000100111), (1, 0b1000000110011)] simulator = Simulator(data=None, num_cores=1) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[0].cache.data[1] = np.matrix([ [1, EXCLUSIVE, 0], [2, MODIFIED, 0] ]) simulator.run() assert simulator.counter == len(op_list) assert np.all(simulator.procs[0].cache.data[1][:, 1] == MODIFIED)
def test_counting_total_private_accesses(): op_list = [(0, 0b100000100001), (0, 0b1000000110000), (0, 0b1100000100111), (0, 0b10000000110011)] op_list1 = [(2, 10), (1, 0b100000100001), (0, 0b1000000110000)] simulator = Simulator(data=None, num_cores=2) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[1].op_stream = FakeOpStream(op_list1) simulator.run() cache0 = simulator.procs[0].cache cache1 = simulator.procs[1].cache assert cache0.total_private_accesses == 4 assert cache1.total_private_accesses == 1 assert cache1.total_access_count == 2
def test_bus_read_x_to_full_cacheset_does_not_evict_block_if_block_present(home_array, remote_array, home_array_after): op_list_raw = [(1, 11, 1, 1)] op_list1 = [] simulator = Simulator(data=None, num_cores=2) op_list = [(x[0], simulator.procs[0].cache.get_address_from_pieces(*x[1:])) for x in op_list_raw] simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[1].op_stream = FakeOpStream(op_list1) simulator.procs[0].cache.data[1] = np.matrix(home_array) simulator.procs[1].cache.data[1] = np.matrix(remote_array) simulator.run() assert np.array_equal(simulator.procs[0].cache.data[1], home_array_after)
def test_cache_store_hit_from_bus_or_mem(cache_set_array, number_of_mem_access, dest_block_states): op_list_raw = [(1, 11, 1, 1), (1, 22, 1, 1)] op_list1 = [] simulator = Simulator(data=None, num_cores=2) op_list = [(x[0], simulator.procs[0].cache.get_address_from_pieces(*x[1:])) for x in op_list_raw] simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[1].op_stream = FakeOpStream(op_list1) simulator.procs[1].cache.data[1] = np.matrix(cache_set_array) simulator.run() assert np.array_equal(simulator.procs[1].cache.data[1][:, 1], dest_block_states) assert simulator.counter == (len(op_list) - number_of_mem_access) * ( simulator.procs[0].cache.block_size // 4 * 2 + 1) + number_of_mem_access * 101
def test_cache_write_block_while_other_cache_fetching_same_block_from_mem(): op_list = [(0, 0b100000100001), (0, 0b1000000110000), (0, 0b1100000100111), (0, 0b10000000110011)] op_list1 = [(2, 10), (1, 0b100000100001)] simulator = Simulator(data=None, protocol='dragon', num_cores=2) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[1].op_stream = FakeOpStream(op_list1) simulator.run() assert simulator.procs[1].counter == 100 + simulator.procs[1].cache.block_size // 4 * 2 + 2 assert simulator.counter == 101 + simulator.procs[1].cache.block_size // 4 * 2 + (len(op_list) - 1) * 101 assert simulator.procs[0].total_load_instructions == 4 assert simulator.procs[0].total_store_instructions == 0 assert simulator.procs[1].total_load_instructions == 0 assert simulator.procs[1].total_store_instructions == 1
def test_another(home_array, remote_array, home_array_after): op_list_raw = [(1, 11, 1, 1)] op_list1 = [] simulator = Simulator(data=None, num_cores=2) op_list = [(x[0], simulator.procs[0].cache.get_address_from_pieces(*x[1:])) for x in op_list_raw] simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[1].op_stream = FakeOpStream(op_list1) simulator.procs[0].cache.data[1] = np.matrix(home_array) simulator.procs[1].cache.data[1] = np.matrix(remote_array) simulator.run() assert np.array_equal(simulator.procs[0].cache.data[1], home_array_after) assert simulator.procs[0].counter == 1
def test_cache_direct_hit_only(): op_list = [(0, 0b100000100001), (0, 0b1000000110000), (0, 0b100000100111), (0, 0b1000000110011)] simulator = Simulator(data=None, num_cores=1) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[0].cache.data[1] = np.matrix([ [1, 1, 0], [2, 1, 0] ]) simulator.run() assert simulator.procs[0].cache.total_access_count == len(op_list) assert simulator.procs[0].cache.cache_miss_count == 0 assert simulator.counter == len(op_list) assert np.array_equal(simulator.procs[0].cache.data[1], [ [2, 1, 0], [1, 1, 0] ])
def test_incoming_read_x_wait_for_local_read(): op_list = [(1, 0b100000100001)] op_list1 = [(0, 0b100000100001)] simulator = Simulator(data=None, num_cores=2) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[1].op_stream = FakeOpStream(op_list1) simulator.procs[0].cache.data[1] = np.matrix([ [0, 0, 0], [0, 0, 0] ]) simulator.procs[1].cache.data[1] = np.matrix([ [1, EXCLUSIVE, 0], [0, 0, 0] ]) simulator.run() assert simulator.counter == 18 assert simulator.procs[0].counter == 18 assert simulator.procs[1].counter == 1
def test_all_other_3_with_shared_block(): op_list = [(0, 0b100000100001), (0, 0b1000000110000), (0, 0b1100000100111), (0, 0b10000000110011)] simulator = Simulator(data=None, num_cores=4) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[1].cache.data[1] = np.matrix([[1, 1, 0], [2, 1, 0]]) simulator.procs[2].cache.data[1] = np.matrix([[1, 1, 0], [2, 1, 0]]) simulator.procs[3].cache.data[1] = np.matrix([[1, 1, 0], [2, 1, 0]]) simulator.bus.bus_master = simulator.procs[0].cache result, payload = simulator.bus.send_read_X_req(simulator.procs[0].cache, 0b100000100001) assert result assert payload > 0 assert np.array_equal(simulator.procs[1].cache.data[1], [[1, INVALID, 0], [2, 1, 0]]) assert np.array_equal(simulator.procs[2].cache.data[1], [[1, INVALID, 0], [2, 1, 0]]) assert np.array_equal(simulator.procs[3].cache.data[1], [[1, INVALID, 0], [2, 1, 0]])
def test_3_of_3_locked(lock_type): op_list = [(0, 0b100000100001), (0, 0b1000000110000), (0, 0b1100000100111), (0, 0b10000000110011)] simulator = Simulator(data=None, num_cores=4) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.procs[1].cache.data[1] = np.matrix([[1, 1, lock_type], [2, 1, 0]]) simulator.procs[2].cache.data[1] = np.matrix([[1, 1, lock_type], [2, 1, 0]]) simulator.procs[3].cache.data[1] = np.matrix([[1, 1, lock_type], [2, 1, 0]]) simulator.bus.bus_master = simulator.procs[0].cache result, payload = simulator.bus.send_read_X_req(simulator.procs[0].cache, 0b100000100001) assert not result assert payload == 0 assert np.array_equal(simulator.procs[1].cache.data[1], [[1, 1, lock_type], [2, 1, 0]]) assert np.array_equal(simulator.procs[2].cache.data[1], [[1, 1, lock_type], [2, 1, 0]]) assert np.array_equal(simulator.procs[3].cache.data[1], [[1, 1, lock_type], [2, 1, 0]])
#def firebase_seer_consumer(message, msg_idx): # """Sends Seer messages to firebase.""" # if msg_idx >= 0: # if msg_idx == 1: # for idx, j in enumerate(message): # db.child(NAMESPACE).child('live_report').child(msg_idx).child(idx).set({j: message[j]}) # else: # _ = db.child(NAMESPACE).child('live_report').child(msg_idx).set(message) config = {"context": "tests/data", "FPS": 60, "DLW": 10, "duration": 10} config["map"] = "camera_map.drawio" #config["map"] = "three_room_map.drawio" simulation = Simulator(config) scenario_helper = ScenarioCreationHelper(simulation) assertion_helper = AssertionHelper(simulation) #simulation.add_des_system(Seer.init([firebase_seer_consumer], 0.05, False),) scenario_helper.add_camera('robot') scenario_helper.add_camera('robot2') scenario_helper.add_camera('robot3') scenario_helper.add_approximation_ability() scenario_helper.add_detection_ability() scenario_helper.add_ability_to_navigate() pois_tag = 'intersection1, intersection2, patientRoom2, patientRoom3, patientRoom4, intersection2, robotHome' scenario_helper.add_script_ability() pois = pois_tag.replace(' ', '').split(',')
import simulator.systems.EnergyConsumptionDESProcessor as energySystem import simulator.systems.ManageObjects as ObjectManager import simulator.systems.ClawDESProcessor as ClawProcessor import simulator.systems.ScriptEventsDES as ScriptSystem import simulator.systems.GotoDESProcessor as NavigationSystem import simulator.systems.SeerPlugin as Seer from simulator.components.Script import Script from main import Simulator from utils.Firebase import db, clean_old_simulation # Create a simulation with config simulator = Simulator(sys.argv[1]) # Some simulator objects width, height = simulator.window_dimensions # window = simulator.window eventStore = simulator.KWARGS['EVENT_STORE'] exitEvent = simulator.EXIT_EVENT env = simulator.ENV NAMESPACE = 'hospital' clean_old_simulation(NAMESPACE) build_report = simulator.build_report db.child(NAMESPACE).child('logs').set(build_report) extra_instructions = [ (NavigationSystem.GotoInstructionId, NavigationSystem.goInstruction), (ClawProcessor.GrabInstructionTag, ClawProcessor.grabInstruction),
def test_cpu_only_job(): simulator = Simulator() simulator.run() assert simulator.counter == 0x27 * 3 assert simulator.procs[1].total_compute_cycles == 0x27 * 3
def test_cache_store_fetch_from_memory_only(): op_list = [(1, 0b100000100001), (1, 0b1000000110000), (1, 0b1100000100111), (1, 0b10000000110011)] simulator = Simulator(data=None, num_cores=1) simulator.procs[0].op_stream = FakeOpStream(op_list) simulator.run() assert simulator.counter == len(op_list) * 101 + 200