Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: FLAMEGPU/FLAMEGPU2
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4d2ea07b01870276daa2edc24098de70c37304b8
Choose a base ref
..
head repository: FLAMEGPU/FLAMEGPU2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e4919f8a2fd7071593709cd240b814f42448b106
Choose a head ref
Showing with 48 additions and 1 deletion.
  1. +1 −1 src/flamegpu/gpu/CUDASimulation.cu
  2. +47 −0 tests/test_cases/runtime/test_spatial_agent_sort.cu
2 changes: 1 addition & 1 deletion src/flamegpu/gpu/CUDASimulation.cu
Original file line number Diff line number Diff line change
@@ -520,7 +520,7 @@ void CUDASimulation::spatialSortAgent_async(const std::string& funcName, const s
// Calculate max bit (cub::DeviceRadixSort end bit is exclusive and 0-indexed)
// https://math.stackexchange.com/a/160299/126129
const int max_bit = static_cast<int>(floor(log2(gridDim.x * gridDim.y * gridDim.z))) + 1;
host_api->agent(agentName).sort_async<unsigned int>("_auto_sort_bin_index", HostAgentAPI::Asc, 0, max_bit, stream, streamId);
host_api->agent(agentName, state).sort_async<unsigned int>("_auto_sort_bin_index", HostAgentAPI::Asc, 0, max_bit, stream, streamId);
}

bool CUDASimulation::step() {
47 changes: 47 additions & 0 deletions tests/test_cases/runtime/test_spatial_agent_sort.cu
Original file line number Diff line number Diff line change
@@ -108,6 +108,53 @@ TEST(AutomaticSpatialAgentSort, SortEveryStep) {
EXPECT_EQ(expectedResult, finalOrder);
}

// Initialises a reverse-sorted population without the state "default" and checks that it is correctly sorted after one step
// This relates to bug #861
TEST(AutomaticSpatialAgentSort, SortEveryStep_no_default) {
// Define model
ModelDescription model("model");
AgentDescription& agent = model.newAgent("agent");
agent.newVariable<int>("initial_order");
agent.newState("foobar");
agent.newVariable<float>("x");
agent.newVariable<float>("y");
agent.newVariable<float>("z");
MessageSpatial3D::Description& locationMessage = model.newMessage<MessageSpatial3D>("location");
locationMessage.setMin(-5, -5, -5);
locationMessage.setMax(5, 5, 5);
locationMessage.setRadius(0.2f);
AgentFunctionDescription& dummyFunc = agent.newFunction("dummySpatialFunc", dummySpatialFunc_3D);
dummyFunc.setMessageInput("location");
LayerDescription& layer = model.newLayer();
layer.addAgentFunction(dummyFunc);

// Init pop
AgentVector pop(agent, AGENT_COUNT);
for (int i = 0; i < static_cast<int>(AGENT_COUNT); i++) {
AgentVector::Agent instance = pop[i];
instance.setVariable<int>("initial_order", i);
instance.setVariable<float>("x", static_cast<float>(-i));
instance.setVariable<float>("y", static_cast<float>(-i));
instance.setVariable<float>("z", static_cast<float>(-i));
}

// Setup Model
CUDASimulation cudaSimulation(model);
cudaSimulation.setPopulationData(pop, "foobar");

// Execute step fn
EXPECT_NO_THROW(cudaSimulation.step());

// Check results
cudaSimulation.getPopulationData(pop, "foobar");
std::vector<int> finalOrder;
for (AgentVector::Agent instance : pop) {
finalOrder.push_back(instance.getVariable<int>("initial_order"));
}
std::vector<int> expectedResult{ 3, 2, 1, 0 };
EXPECT_EQ(expectedResult, finalOrder);
}

// Initialises a reverse-sorted population and checks that it is correctly sorted after one step
TEST(AutomaticSpatialAgentSort, SortEveryStep_vec2) {
// Define model