Skip to content

Commit

Permalink
Bugfix: Compilation failure, if using MsgArray3D moore iteration arra…
Browse files Browse the repository at this point in the history
…y getVariable()

Extends existing tests to check this works properly.
  • Loading branch information
Robadob committed Feb 2, 2022
1 parent c97c08c commit 7dc09cd
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ T MessageArray3D::In::WrapFilter::Message::getVariable(const char(&variable_name
}
#endif
// get the value from curve using the stored hashes and message index.
T value = detail::curve::Curve::getMessageArrayVariable<T, N>(variable_name, this->_parent.combined_hash, index, array_index);
T value = detail::curve::Curve::getMessageArrayVariable<T, N>(variable_name, this->_parent.combined_hash, index_1d, array_index);
return value;
}
template<typename T, unsigned int N>
Expand All @@ -797,7 +797,7 @@ T MessageArray3D::In::Filter::Message::getVariable(const char(&variable_name)[M]
}
#endif
// get the value from curve using the stored hashes and message index.
T value = detail::curve::Curve::getMessageArrayVariable<T, N>(variable_name, this->_parent.combined_hash, index, array_index);
T value = detail::curve::Curve::getMessageArrayVariable<T, N>(variable_name, this->_parent.combined_hash, index_1d, array_index);
return value;
}

Expand Down
34 changes: 32 additions & 2 deletions tests/test_cases/runtime/messaging/test_array_2d.cu
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,10 @@ FLAMEGPU_AGENT_FUNCTION(OutSimpleXY, MessageNone, MessageArray2D) {
const unsigned int x = FLAMEGPU->getVariable<unsigned int>("x");
const unsigned int y = FLAMEGPU->getVariable<unsigned int>("y");
FLAMEGPU->message_out.setVariable("index", index);
FLAMEGPU->message_out.setVariable<unsigned int>("v", x * 3);
FLAMEGPU->message_out.setVariable<unsigned int, 3>("v2", 0, x * 3);
FLAMEGPU->message_out.setVariable<unsigned int, 3>("v2", 1, y * 7);
FLAMEGPU->message_out.setVariable<unsigned int, 3>("v2", 2, y * 11);
FLAMEGPU->message_out.setIndex(x, y);
return ALIVE;
}
Expand All @@ -709,11 +713,19 @@ FLAMEGPU_AGENT_FUNCTION(MooreWTestXYC, MessageArray2D, MessageNone) {
const unsigned int COMRADIUS = FLAMEGPU->environment.getProperty<unsigned int>("COMRADIUS");
// Iterate message list counting how many messages were read.
unsigned int count = 0;
for (const auto &message : FLAMEGPU->message_in.wrap(x, y, COMRADIUS)) {
bool value_success = true;
for (const auto &msg : FLAMEGPU->message_in.wrap(x, y, COMRADIUS)) {
// @todo - check its the correct messages?
count++;
if (msg.getVariable<unsigned int, 3>("v2", 0) != msg.getX() * 3 ||
msg.getVariable<unsigned int, 3>("v2", 1) != msg.getY() * 7 ||
msg.getVariable<unsigned int, 3>("v2", 2) != msg.getY() * 11 ||
msg.getVariable<unsigned int>("v") != msg.getX() * 3) {
value_success = false;
}
}
FLAMEGPU->setVariable<unsigned int>("message_read", count);
FLAMEGPU->setVariable<unsigned int>("value_success", static_cast<unsigned int>(value_success));
return ALIVE;
}

Expand All @@ -735,12 +747,15 @@ void test_moore_wrap_comradius(
// Define the message
MessageArray2D::Description &message = model.newMessage<MessageArray2D>(MESSAGE_NAME);
message.newVariable<unsigned int>("index");
message.newVariable<unsigned int>("v");
message.newVariable<unsigned int, 3>("v2");
message.setDimensions(GRID_WIDTH, GRID_HEIGHT);
AgentDescription &agent = model.newAgent(AGENT_NAME);
agent.newVariable<unsigned int>("index");
agent.newVariable<unsigned int>("x");
agent.newVariable<unsigned int>("y");
agent.newVariable<unsigned int>("message_read", UINT_MAX);
agent.newVariable<unsigned int>("value_success", 0);
// Define the function and layers.
AgentFunctionDescription &outputFunction = agent.newFunction("OutSimpleXY", OutSimpleXY);
outputFunction.setMessageOutput(message);
Expand Down Expand Up @@ -777,6 +792,8 @@ void test_moore_wrap_comradius(
for (AgentVector::Agent instance : population) {
const unsigned int message_read = instance.getVariable<unsigned int>("message_read");
ASSERT_EQ(expected_count, message_read);
const unsigned int value_success = instance.getVariable<unsigned int>("value_success");
ASSERT_EQ(value_success, 1u);
}
} else {
// If the comradius would lead to double message reads, a device error is thrown when SEATBELTS is enabled
Expand Down Expand Up @@ -825,11 +842,19 @@ FLAMEGPU_AGENT_FUNCTION(MooreTestXYC, MessageArray2D, MessageNone) {
const unsigned int COMRADIUS = FLAMEGPU->environment.getProperty<unsigned int>("COMRADIUS");
// Iterate message list counting how many messages were read.
unsigned int count = 0;
for (const auto &message : FLAMEGPU->message_in(x, y, COMRADIUS)) {
bool value_success = true;
for (const auto &msg : FLAMEGPU->message_in(x, y, COMRADIUS)) {
// @todo - check its the correct messages?
count++;
if (msg.getVariable<unsigned int, 3>("v2", 0) != msg.getX() * 3 ||
msg.getVariable<unsigned int, 3>("v2", 1) != msg.getY() * 7 ||
msg.getVariable<unsigned int, 3>("v2", 2) != msg.getY() * 11 ||
msg.getVariable<unsigned int>("v") != msg.getX() * 3) {
value_success = false;
}
}
FLAMEGPU->setVariable<unsigned int>("message_read", count);
FLAMEGPU->setVariable<unsigned int>("value_success", static_cast<unsigned int>(value_success));
return ALIVE;
}

Expand All @@ -851,12 +876,15 @@ void test_mooore_comradius(
// Define the message
MessageArray2D::Description &message = model.newMessage<MessageArray2D>(MESSAGE_NAME);
message.newVariable<unsigned int>("index");
message.newVariable<unsigned int>("v");
message.newVariable<unsigned int, 3>("v2");
message.setDimensions(GRID_WIDTH, GRID_HEIGHT);
AgentDescription &agent = model.newAgent(AGENT_NAME);
agent.newVariable<unsigned int>("index");
agent.newVariable<unsigned int>("x");
agent.newVariable<unsigned int>("y");
agent.newVariable<unsigned int>("message_read", UINT_MAX);
agent.newVariable<unsigned int>("value_success", 0);
// Define the function and layers.
AgentFunctionDescription &outputFunction = agent.newFunction("OutSimpleXY", OutSimpleXY);
outputFunction.setMessageOutput(message);
Expand Down Expand Up @@ -896,6 +924,8 @@ void test_mooore_comradius(
// ASSERT_EQ(message_read, expected_read);
if (message_read == expected_read)
right_count++;
const unsigned int value_success = instance.getVariable<unsigned int>("value_success");
ASSERT_EQ(value_success, 1u);
}
ASSERT_EQ(right_count, population.size());
}
Expand Down
36 changes: 33 additions & 3 deletions tests/test_cases/runtime/messaging/test_array_3d.cu
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,11 @@ FLAMEGPU_AGENT_FUNCTION(OutSimpleXYZ, MessageNone, MessageArray3D) {
const unsigned int x = FLAMEGPU->getVariable<unsigned int>("x");
const unsigned int y = FLAMEGPU->getVariable<unsigned int>("y");
const unsigned int z = FLAMEGPU->getVariable<unsigned int>("z");
FLAMEGPU->message_out.setVariable("index", index);
FLAMEGPU->message_out.setVariable<unsigned int>("index", index);
FLAMEGPU->message_out.setVariable<unsigned int>("v", x * 3);
FLAMEGPU->message_out.setVariable<unsigned int, 3>("v2", 0, x * 3);
FLAMEGPU->message_out.setVariable<unsigned int, 3>("v2", 1, y * 7);
FLAMEGPU->message_out.setVariable<unsigned int, 3>("v2", 2, z * 11);
FLAMEGPU->message_out.setIndex(x, y, z);
return ALIVE;
}
Expand All @@ -805,11 +809,19 @@ FLAMEGPU_AGENT_FUNCTION(MooreWrapTestXYZC, MessageArray3D, MessageNone) {
const unsigned int COMRADIUS = FLAMEGPU->environment.getProperty<unsigned int>("COMRADIUS");
// Iterate message list counting how many messages were read.
unsigned int count = 0;
for (const auto &message : FLAMEGPU->message_in.wrap(x, y, z, COMRADIUS)) {
bool value_success = true;
for (const auto &msg : FLAMEGPU->message_in.wrap(x, y, z, COMRADIUS)) {
// @todo - check its the correct messages?
count++;
if (msg.getVariable<unsigned int, 3>("v2", 0) != msg.getX() * 3 ||
msg.getVariable<unsigned int, 3>("v2", 1) != msg.getY() * 7 ||
msg.getVariable<unsigned int, 3>("v2", 2) != msg.getZ() * 11 ||
msg.getVariable<unsigned int>("v") != msg.getX() * 3) {
value_success = false;
}
}
FLAMEGPU->setVariable<unsigned int>("message_read", count);
FLAMEGPU->setVariable<unsigned int>("value_success", static_cast<unsigned int>(value_success));
return ALIVE;
}

Expand All @@ -832,13 +844,16 @@ void test_moore_wrapped_comradius(
// Define the message
MessageArray3D::Description &message = model.newMessage<MessageArray3D>(MESSAGE_NAME);
message.newVariable<unsigned int>("index");
message.newVariable<unsigned int>("v");
message.newVariable<unsigned int, 3>("v2");
message.setDimensions(GRID_WIDTH, GRID_HEIGHT, GRID_DEPTH);
AgentDescription &agent = model.newAgent(AGENT_NAME);
agent.newVariable<unsigned int>("index");
agent.newVariable<unsigned int>("x");
agent.newVariable<unsigned int>("y");
agent.newVariable<unsigned int>("z");
agent.newVariable<unsigned int>("message_read", UINT_MAX);
agent.newVariable<unsigned int>("value_success", 0);
// Define the function and layers.
AgentFunctionDescription &outputFunction = agent.newFunction("OutSimpleXYZ", OutSimpleXYZ);
outputFunction.setMessageOutput(message);
Expand Down Expand Up @@ -879,6 +894,8 @@ void test_moore_wrapped_comradius(
for (AgentVector::Agent instance : population) {
const unsigned int message_read = instance.getVariable<unsigned int>("message_read");
ASSERT_EQ(expected_count, message_read);
const unsigned int value_success = instance.getVariable<unsigned int>("value_success");
ASSERT_EQ(value_success, 1u);
}
} else {
// If the comradius would lead to double message reads, a device error is thrown when SEATBELTS is enabled
Expand Down Expand Up @@ -935,11 +952,19 @@ FLAMEGPU_AGENT_FUNCTION(MooreTestXYZC, MessageArray3D, MessageNone) {
const unsigned int COMRADIUS = FLAMEGPU->environment.getProperty<unsigned int>("COMRADIUS");
// Iterate message list counting how many messages were read.
unsigned int count = 0;
for (const auto& message : FLAMEGPU->message_in(x, y, z, COMRADIUS)) {
bool value_success = true;
for (const auto& msg : FLAMEGPU->message_in(x, y, z, COMRADIUS)) {
// @todo - check its the correct messages?
count++;
if (msg.getVariable<unsigned int, 3>("v2", 0) != msg.getX() * 3 ||
msg.getVariable<unsigned int, 3>("v2", 1) != msg.getY() * 7 ||
msg.getVariable<unsigned int, 3>("v2", 2) != msg.getZ() * 11 ||
msg.getVariable<unsigned int>("v") != msg.getX() * 3) {
value_success = false;
}
}
FLAMEGPU->setVariable<unsigned int>("message_read", count);
FLAMEGPU->setVariable<unsigned int>("value_success", static_cast<unsigned int>(value_success));
return ALIVE;
}
void test_mooore_comradius(
Expand All @@ -961,13 +986,16 @@ void test_mooore_comradius(
// Define the message
MessageArray3D::Description& message = model.newMessage<MessageArray3D>(MESSAGE_NAME);
message.newVariable<unsigned int>("index");
message.newVariable<unsigned int>("v");
message.newVariable<unsigned int, 3>("v2");
message.setDimensions(GRID_WIDTH, GRID_HEIGHT, GRID_DEPTH);
AgentDescription& agent = model.newAgent(AGENT_NAME);
agent.newVariable<unsigned int>("index");
agent.newVariable<unsigned int>("x");
agent.newVariable<unsigned int>("y");
agent.newVariable<unsigned int>("z");
agent.newVariable<unsigned int>("message_read", UINT_MAX);
agent.newVariable<unsigned int>("value_success", 0);
// Define the function and layers.
AgentFunctionDescription& outputFunction = agent.newFunction("OutSimpleXYZ", OutSimpleXYZ);
outputFunction.setMessageOutput(message);
Expand Down Expand Up @@ -1012,6 +1040,8 @@ void test_mooore_comradius(
// ASSERT_EQ(message_read, expected_read);
if (message_read == expected_read)
right_count++;
const unsigned int value_success = instance.getVariable<unsigned int>("value_success");
ASSERT_EQ(value_success, 1u);
}
ASSERT_EQ(right_count, population.size());
}
Expand Down

0 comments on commit 7dc09cd

Please sign in to comment.