-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
209 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
201 changes: 201 additions & 0 deletions
201
tests/test_cases/runtime/test_environment_directed_graph.cu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
/** | ||
* Tests of: Environment Directed Graph functionality | ||
* This combines testing of all features as they are quite tightly linked | ||
* | ||
* Tests cover: | ||
* > Host set/get | ||
* > Host get default | ||
* > Device get | ||
* > Device get default | ||
* > Host validation (todo) | ||
* > Device validation (todo) | ||
*/ | ||
|
||
#include "flamegpu/flamegpu.h" | ||
#include "flamegpu/runtime/environment/EnvironmentDirectedGraph/EnvironmentDirectedGraphDescription.cuh" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
namespace flamegpu { | ||
const unsigned int EDGE_COUNT = 10; | ||
const unsigned int VERTEX_COUNT = 10; | ||
FLAMEGPU_HOST_FUNCTION(hostfn_HostSetGet_Edge) { | ||
auto graph = FLAMEGPU->environment.getDirectedGraph("graph"); | ||
graph.setEdgeCount(EDGE_COUNT); | ||
// Check default matches | ||
for (unsigned int i = 0; i < EDGE_COUNT; ++i) { | ||
EXPECT_EQ(graph.getEdgeProperty<float>("edge", i), 12.0f); | ||
} | ||
// Set all values | ||
for (unsigned int i = 0; i < EDGE_COUNT; ++i) { | ||
graph.setEdgeProperty<float>("edge", i, 14.0f + i); | ||
} | ||
// Check set values match | ||
for (unsigned int i = 0; i < EDGE_COUNT; ++i) { | ||
EXPECT_EQ(graph.getEdgeProperty<float>("edge", i), 14.0f + i); | ||
} | ||
graph.setEdgeCount(EDGE_COUNT * 2); | ||
// Check default matches | ||
for (unsigned int i = 0; i < EDGE_COUNT * 2; ++i) { | ||
EXPECT_EQ(graph.getEdgeProperty<float>("edge", i), 12.0f); | ||
} | ||
} | ||
TEST(EnvironmentDirectedGraphTest, HostSetGet_Edge) { | ||
ModelDescription model("test"); | ||
model.newAgent("agent"); | ||
auto &graph = model.Environment().newDirectedGraph("graph"); | ||
graph.newEdgeProperty<float>("edge", 12.0f); | ||
model.newLayer().addHostFunction(hostfn_HostSetGet_Edge); | ||
} | ||
|
||
FLAMEGPU_HOST_FUNCTION(hostfn_HostSetGet_Vertex) { | ||
auto graph = FLAMEGPU->environment.getDirectedGraph("graph"); | ||
graph.setVertexCount(VERTEX_COUNT); | ||
// Check default matches | ||
for (unsigned int i = 0; i < VERTEX_COUNT; ++i) { | ||
EXPECT_EQ(graph.getVertexProperty<int>("vertex", i), 12.0f); | ||
} | ||
// Set all values | ||
for (unsigned int i = 0; i < VERTEX_COUNT; ++i) { | ||
graph.setVertexProperty<int>("vertex", i, 14 + static_cast<int>(i)); | ||
} | ||
// Check set values match | ||
for (unsigned int i = 0; i < VERTEX_COUNT; ++i) { | ||
EXPECT_EQ(graph.getVertexProperty<int>("vertex", i), 14.0f + i); | ||
} | ||
graph.setVertexCount(VERTEX_COUNT * 2); | ||
// Check default matches | ||
for (unsigned int i = 0; i < VERTEX_COUNT * 2; ++i) { | ||
EXPECT_EQ(graph.getVertexProperty<int>("vertex", i), 12.0f); | ||
} | ||
} | ||
TEST(EnvironmentDirectedGraphTest, HostSetGet_Vertex) { | ||
ModelDescription model("test"); | ||
model.newAgent("agent"); | ||
auto& graph = model.Environment().newDirectedGraph("graph"); | ||
graph.newVertexProperty<int>("vertex", 5); | ||
model.newLayer().addHostFunction(hostfn_HostSetGet_Edge); | ||
} | ||
FLAMEGPU_HOST_FUNCTION(hostfn_DeviceGet_Edge) { | ||
auto graph = FLAMEGPU->environment.getDirectedGraph("graph"); | ||
graph.setEdgeCount(EDGE_COUNT); | ||
// Set all values | ||
for (unsigned int i = 0; i < EDGE_COUNT; ++i) { | ||
graph.setEdgeProperty<float>("edge", i, 14.0f + i); | ||
} | ||
} | ||
FLAMEGPU_AGENT_FUNCTION(DeviceGet_Edge, MessageNone, MessageNone) { | ||
auto graph = FLAMEGPU->environment.getDirectedGraph("graph"); | ||
const float t = graph.getEdgeProperty<float>("edge", FLAMEGPU->getThreadIndex()); | ||
FLAMEGPU->setVariable<unsigned int>("tid", FLAMEGPU->getThreadIndex()); | ||
FLAMEGPU->setVariable<float>("edge_value", t); | ||
return flamegpu::ALIVE; | ||
} | ||
TEST(EnvironmentDirectedGraphTest, DeviceGet_Edge) { | ||
ModelDescription model("test"); | ||
auto &agent = model.newAgent("agent"); | ||
agent.newVariable<float>("edge_value", 0.0f); | ||
agent.newVariable<unsigned int>("tid", 0); | ||
agent.newFunction("DeviceGet_Edge", DeviceGet_Edge); | ||
auto& graph = model.Environment().newDirectedGraph("graph"); | ||
graph.newEdgeProperty<float>("edge", 12.0f); | ||
model.newLayer().addHostFunction(hostfn_DeviceGet_Edge); | ||
model.newLayer().addAgentFunction(DeviceGet_Edge); | ||
|
||
CUDASimulation sim(model); | ||
AgentVector pop(agent, EDGE_COUNT); | ||
sim.setPopulationData(pop); | ||
sim.step(); | ||
sim.getPopulationData(pop); | ||
// Check result matches | ||
for (const auto &p : pop) { | ||
EXPECT_EQ(p.getVariable<float>("edge_value"), 14.0f + p.getVariable<unsigned int>("tid")); | ||
} | ||
} | ||
FLAMEGPU_HOST_FUNCTION(hostfn_DeviceGetDefault_Edge) { | ||
auto graph = FLAMEGPU->environment.getDirectedGraph("graph"); | ||
graph.setEdgeCount(EDGE_COUNT); | ||
} | ||
TEST(EnvironmentDirectedGraphTest, DeviceGetDefault_Edge) { | ||
ModelDescription model("test"); | ||
auto& agent = model.newAgent("agent"); | ||
agent.newVariable<float>("edge_value", 0.0f); | ||
agent.newVariable<unsigned int>("tid", 0); | ||
agent.newFunction("DeviceGet_Edge", DeviceGet_Edge); | ||
auto& graph = model.Environment().newDirectedGraph("graph"); | ||
graph.newEdgeProperty<float>("edge", 12.0f); | ||
model.newLayer().addHostFunction(hostfn_DeviceGetDefault_Edge); | ||
model.newLayer().addAgentFunction(DeviceGet_Edge); | ||
|
||
CUDASimulation sim(model); | ||
AgentVector pop(agent, EDGE_COUNT); | ||
sim.setPopulationData(pop); | ||
sim.step(); | ||
sim.getPopulationData(pop); | ||
// Check result matches | ||
for (const auto& p : pop) { | ||
EXPECT_EQ(p.getVariable<float>("edge_value"), 12.0f); | ||
} | ||
} | ||
FLAMEGPU_HOST_FUNCTION(hostfn_DeviceGet_Vertex) { | ||
auto graph = FLAMEGPU->environment.getDirectedGraph("graph"); | ||
graph.setVertexCount(VERTEX_COUNT); | ||
// Set all values | ||
for (unsigned int i = 0; i < VERTEX_COUNT; ++i) { | ||
graph.setVertexProperty<int>("vertex", i, 14 + static_cast<int>(i)); | ||
} | ||
} | ||
FLAMEGPU_AGENT_FUNCTION(DeviceGet_Vertex, MessageNone, MessageNone) { | ||
auto graph = FLAMEGPU->environment.getDirectedGraph("graph"); | ||
const float t = graph.getVertexProperty<int>("vertex", FLAMEGPU->getThreadIndex()); | ||
FLAMEGPU->setVariable<unsigned int>("tid", FLAMEGPU->getThreadIndex()); | ||
FLAMEGPU->setVariable<int>("vertex_value", t); | ||
return flamegpu::ALIVE; | ||
} | ||
TEST(EnvironmentDirectedGraphTest, DeviceGet_Vertex) { | ||
ModelDescription model("test"); | ||
auto& agent = model.newAgent("agent"); | ||
agent.newVariable<int>("vertex_value", 0u); | ||
agent.newVariable<unsigned int>("tid", 0); | ||
agent.newFunction("DeviceGet_Vertex", DeviceGet_Vertex); | ||
auto& graph = model.Environment().newDirectedGraph("graph"); | ||
graph.newVertexProperty<int>("vertex", 12); | ||
model.newLayer().addHostFunction(hostfn_DeviceGet_Vertex); | ||
model.newLayer().addAgentFunction(DeviceGet_Vertex); | ||
|
||
CUDASimulation sim(model); | ||
AgentVector pop(agent, VERTEX_COUNT); | ||
sim.setPopulationData(pop); | ||
sim.step(); | ||
sim.getPopulationData(pop); | ||
// Check result matches | ||
for (const auto& p : pop) { | ||
EXPECT_EQ(p.getVariable<int>("vertex_value"), 14 + static_cast<int>(p.getVariable<unsigned int>("tid"))); | ||
} | ||
} | ||
FLAMEGPU_HOST_FUNCTION(hostfn_DeviceGetDefault_Vertex) { | ||
auto graph = FLAMEGPU->environment.getDirectedGraph("graph"); | ||
graph.setVertexCount(VERTEX_COUNT); | ||
} | ||
TEST(EnvironmentDirectedGraphTest, DeviceGetDefault_Vertex) { | ||
ModelDescription model("test"); | ||
auto& agent = model.newAgent("agent"); | ||
agent.newVariable<int>("vertex_value", 0u); | ||
agent.newVariable<unsigned int>("tid", 0); | ||
agent.newFunction("DeviceGet_Vertex", DeviceGet_Vertex); | ||
auto& graph = model.Environment().newDirectedGraph("graph"); | ||
graph.newVertexProperty<int>("vertex", 12); | ||
model.newLayer().addHostFunction(hostfn_DeviceGetDefault_Vertex); | ||
model.newLayer().addAgentFunction(DeviceGet_Vertex); | ||
|
||
CUDASimulation sim(model); | ||
AgentVector pop(agent, VERTEX_COUNT); | ||
sim.setPopulationData(pop); | ||
sim.step(); | ||
sim.getPopulationData(pop); | ||
// Check result matches | ||
for (const auto& p : pop) { | ||
EXPECT_EQ(p.getVariable<int>("vertex_value"), 12); | ||
} | ||
} | ||
} // namespace flamegpu |