Skip to content

Commit

Permalink
BugFix: Agent variables would not be synced to device if HostAgentCre…
Browse files Browse the repository at this point in the history
…ation was interruped by DeviceAgentVector.
  • Loading branch information
Robadob committed Dec 11, 2024
1 parent 11c7c9e commit 7bc48c3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
18 changes: 4 additions & 14 deletions src/flamegpu/runtime/agent/DeviceAgentVector_impl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,15 @@ void DeviceAgentVector_impl::_insert(size_type pos, size_type count) {
h_ptr[i] = cuda_agent.nextID();
}
}
_changedAfter(ID_VARIABLE_NAME, pos);
} else {
THROW exception::InvalidOperation("Internal agent ID variable was not found, "
"in DeviceAgentVector_impl._insert().");
}
}
// Update change detail for all variables
for (const auto& [v, _] : agent->variables) {
_changedAfter(v, pos);
}
// No unbound buffers, return
if (unbound_buffers.empty())
return;
Expand Down Expand Up @@ -239,19 +242,6 @@ void DeviceAgentVector_impl::_insert(size_type pos, size_type count) {
if (unbound_host_buffer_size != _size) {
THROW exception::InvalidOperation("Unbound buffers have gone out of sync, in DeviceAgentVector::_insert().\n");
}
// Update change detail for all variables
for (const auto& v : agent->variables) {
// Does it exist in change map
auto change = change_detail.find(v.first);
if (change == change_detail.end()) {
change_detail.emplace(v.first, std::pair<size_type, size_type>{pos, _size});
} else {
// Inclusive min bound
change->second.first = change->second.first > pos ? pos : change->second.first;
// Exclusive max bound
change->second.second = _size;
}
}
}
void DeviceAgentVector_impl::_erase(size_type pos, size_type count) {
// No unbound buffers, return
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cases/runtime/agent/test_host_agent_creation.cu
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ TEST(HostAgentCreationTest, AgentID_Consistent_Combined) {
}
FLAMEGPU_AGENT_FUNCTION(AgentID_Consistent_Agent, flamegpu::MessageNone, flamegpu::MessageNone) {
FLAMEGPU->setVariable<id_t>("id_copy_from_device", FLAMEGPU->getID());
FLAMEGPU->setVariable<id_t>("id_copy_copy_from_device", FLAMEGPU->getVariable<id_t>("id_copy_copy_from_device"));
FLAMEGPU->setVariable<id_t>("id_copy_copy_from_device", FLAMEGPU->getVariable<id_t>("id_copy"));
return flamegpu::ALIVE;
}
FLAMEGPU_STEP_FUNCTION(AgentID_Consistent_Step_Agent) {
Expand Down

0 comments on commit 7bc48c3

Please sign in to comment.