Skip to content

Commit 7bc48c3

Browse files
committed
BugFix: Agent variables would not be synced to device if HostAgentCreation was interruped by DeviceAgentVector.
1 parent 11c7c9e commit 7bc48c3

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

src/flamegpu/runtime/agent/DeviceAgentVector_impl.cu

+4-14
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,15 @@ void DeviceAgentVector_impl::_insert(size_type pos, size_type count) {
190190
h_ptr[i] = cuda_agent.nextID();
191191
}
192192
}
193-
_changedAfter(ID_VARIABLE_NAME, pos);
194193
} else {
195194
THROW exception::InvalidOperation("Internal agent ID variable was not found, "
196195
"in DeviceAgentVector_impl._insert().");
197196
}
198197
}
198+
// Update change detail for all variables
199+
for (const auto& [v, _] : agent->variables) {
200+
_changedAfter(v, pos);
201+
}
199202
// No unbound buffers, return
200203
if (unbound_buffers.empty())
201204
return;
@@ -239,19 +242,6 @@ void DeviceAgentVector_impl::_insert(size_type pos, size_type count) {
239242
if (unbound_host_buffer_size != _size) {
240243
THROW exception::InvalidOperation("Unbound buffers have gone out of sync, in DeviceAgentVector::_insert().\n");
241244
}
242-
// Update change detail for all variables
243-
for (const auto& v : agent->variables) {
244-
// Does it exist in change map
245-
auto change = change_detail.find(v.first);
246-
if (change == change_detail.end()) {
247-
change_detail.emplace(v.first, std::pair<size_type, size_type>{pos, _size});
248-
} else {
249-
// Inclusive min bound
250-
change->second.first = change->second.first > pos ? pos : change->second.first;
251-
// Exclusive max bound
252-
change->second.second = _size;
253-
}
254-
}
255245
}
256246
void DeviceAgentVector_impl::_erase(size_type pos, size_type count) {
257247
// No unbound buffers, return

tests/test_cases/runtime/agent/test_host_agent_creation.cu

+1-1
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ TEST(HostAgentCreationTest, AgentID_Consistent_Combined) {
860860
}
861861
FLAMEGPU_AGENT_FUNCTION(AgentID_Consistent_Agent, flamegpu::MessageNone, flamegpu::MessageNone) {
862862
FLAMEGPU->setVariable<id_t>("id_copy_from_device", FLAMEGPU->getID());
863-
FLAMEGPU->setVariable<id_t>("id_copy_copy_from_device", FLAMEGPU->getVariable<id_t>("id_copy_copy_from_device"));
863+
FLAMEGPU->setVariable<id_t>("id_copy_copy_from_device", FLAMEGPU->getVariable<id_t>("id_copy"));
864864
return flamegpu::ALIVE;
865865
}
866866
FLAMEGPU_STEP_FUNCTION(AgentID_Consistent_Step_Agent) {

0 commit comments

Comments
 (0)