pim-simulator removed useless comment
Validate Operations / validate-operations (push) Has been cancelled
Validate Operations / validate-operations (push) Has been cancelled
This commit is contained in:
@@ -206,24 +206,20 @@ fn check_cycle(cpu: &mut CPU, cores_instructions: &[CoreInstructions], send_recv
|
||||
enum CoreState {
|
||||
SendingTo(i32),
|
||||
ReceivingFrom(i32),
|
||||
Working, // Doing math, etc. Not blocked.
|
||||
Working,
|
||||
Halted,
|
||||
}
|
||||
|
||||
// 1. Snapshot the current state of every core
|
||||
let mut states = HashMap::new();
|
||||
|
||||
for core_inst in cores_instructions.iter() {
|
||||
if core_inst.program_counter >= core_inst.instructions.len() {
|
||||
// Assuming we can derive core ID here. If `cores_instructions` doesn't
|
||||
// give you the core ID easily, you might need to enumerate the loop.
|
||||
continue;
|
||||
}
|
||||
|
||||
let Instruction { data, functor } = core_inst.instructions[core_inst.program_counter];
|
||||
let functor_address = functor as usize;
|
||||
|
||||
// get_core_immcore() always seems to return (this_core, target_core)
|
||||
let (this_core, target_core) = data.get_core_immcore();
|
||||
|
||||
if isa_recv(functor_address) {
|
||||
@@ -231,38 +227,31 @@ fn check_cycle(cpu: &mut CPU, cores_instructions: &[CoreInstructions], send_recv
|
||||
} else if isa_send(functor_address) {
|
||||
states.insert(this_core, CoreState::SendingTo(target_core));
|
||||
} else {
|
||||
// Doing other stuff (add, sub, etc). It is NOT blocked.
|
||||
states.insert(this_core, CoreState::Working);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Build the Wait-For Graph
|
||||
let mut wait_for = HashMap::new();
|
||||
|
||||
for (&core_id, state) in states.iter() {
|
||||
match state {
|
||||
CoreState::SendingTo(target_core) => {
|
||||
let target_state = states.get(target_core).unwrap_or(&CoreState::Halted);
|
||||
// We are blocked UNLESS the target is actively receiving from us right now
|
||||
if target_state != &CoreState::ReceivingFrom(core_id) {
|
||||
wait_for.insert(core_id, *target_core);
|
||||
}
|
||||
}
|
||||
CoreState::ReceivingFrom(target_core) => {
|
||||
let target_state = states.get(target_core).unwrap_or(&CoreState::Halted);
|
||||
// We are blocked UNLESS the target is actively sending to us right now
|
||||
if target_state != &CoreState::SendingTo(core_id) {
|
||||
wait_for.insert(core_id, *target_core);
|
||||
}
|
||||
}
|
||||
CoreState::Working | CoreState::Halted => {
|
||||
// A working core is not waiting for anyone.
|
||||
// It has no outgoing edges, which naturally prevents false cycles!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Detect Cycles strictly among blocked cores
|
||||
let mut visited = HashSet::new();
|
||||
|
||||
for &start_core in wait_for.keys() {
|
||||
|
||||
Reference in New Issue
Block a user