Skip to content

Commit

Permalink
Breaking Change: Removed CUDASimulation::getAgent()/getCUDAAgent()/ge…
Browse files Browse the repository at this point in the history
…tCUDAMessage()

These features were not intended for release, users should not have direct access to internal objects (detail namespace). Roughly equivalent functionality is available via DeviceAgentVector within the HostAPI.

fixup
  • Loading branch information
Robadob committed Dec 12, 2022
1 parent 46e99e7 commit 313e1dc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 59 deletions.
27 changes: 16 additions & 11 deletions include/flamegpu/simulation/CUDASimulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,17 @@ class CUDASimulation : public Simulation {
* Requires internal access to scan/scatter singletons
*/
friend class HostAgentAPI;
friend class HostAPI;
/**
* Requires internal access to getCUDAAgent()
*/
friend class detail::SimRunner;
friend class CUDAEnsemble;
#ifdef FLAMEGPU_VISUALISATION
/**
* Requires internal access to getCUDAAgent()
*/
friend class visualiser::ModelVis;
friend struct visualiser::ModelVisData;
#endif
/**
Expand Down Expand Up @@ -250,17 +258,6 @@ class CUDASimulation : public Simulation {
template<typename T>
std::vector<T> getEnvironmentPropertyArray(const std::string& property_name);
#endif
/**
* Returns the manager for the specified agent
* @todo remove? this is mostly internal methods that modeller doesn't need access to
*/
detail::CUDAAgent& getCUDAAgent(const std::string &agent_name) const;
detail::AgentInterface &getAgent(const std::string &name) override;
/**
* Returns the manager for the specified agent
* @todo remove? this is mostly internal methods that modeller doesn't need access to
*/
detail::CUDAMessage& getCUDAMessage(const std::string &message_name) const;
/**
* @return A mutable reference to the cuda model specific configuration struct
* @see Simulation::applyConfig() Should be called afterwards to apply changes
Expand Down Expand Up @@ -372,6 +369,14 @@ class CUDASimulation : public Simulation {
void printHelp_derived() override;

private:
/**
* Returns the manager for the specified agent
*/
detail::CUDAAgent& getCUDAAgent(const std::string& agent_name) const;
/**
* Returns the manager for the specified message
*/
detail::CUDAMessage& getCUDAMessage(const std::string& message_name) const;
/**
* Reinitalises random generation for this model and all submodels
* @param seed New random seed (this updates stored seed in config)
Expand Down
1 change: 0 additions & 1 deletion include/flamegpu/simulation/Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ class Simulation {
virtual void getPopulationData(AgentVector& population, const std::string& state_name = ModelData::DEFAULT_STATE) = 0;

virtual const RunLog &getRunLog() const = 0;
virtual detail::AgentInterface &getAgent(const std::string &name) = 0;

Config &SimulationConfig();
const Config &getSimulationConfig() const;
Expand Down
2 changes: 1 addition & 1 deletion src/flamegpu/runtime/HostAPI.cu
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ HostAgentAPI HostAPI::agent(const std::string &agent_name, const std::string &st
if (state == agt->second.end()) {
THROW exception::InvalidAgentState("Agent '%s' in model description hierarchy does not contain state '%s'.\n", agent_name.c_str(), state_name.c_str());
}
return HostAgentAPI(*this, agentModel.getAgent(agent_name), state_name, agentOffsets.at(agent_name), state->second);
return HostAgentAPI(*this, agentModel.getCUDAAgent(agent_name), state_name, agentOffsets.at(agent_name), state->second);
}

/**
Expand Down
16 changes: 0 additions & 16 deletions src/flamegpu/simulation/CUDASimulation.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,6 @@ void CUDASimulation::getPopulationData(AgentVector& population, const std::strin
it->second->getPopulationData(population, state_name);
gpuErrchk(cudaDeviceSynchronize());
}

detail::CUDAAgent& CUDASimulation::getCUDAAgent(const std::string& agent_name) const {
CUDAAgentMap::const_iterator it;
it = agent_map.find(agent_name);
Expand All @@ -1391,21 +1390,6 @@ detail::CUDAAgent& CUDASimulation::getCUDAAgent(const std::string& agent_name) c

return *(it->second);
}

detail::AgentInterface& CUDASimulation::getAgent(const std::string& agent_name) {
// Ensure singletons have been initialised
initialiseSingletons();

auto it = agent_map.find(agent_name);

if (it == agent_map.end()) {
THROW exception::InvalidCudaAgent("CUDA agent ('%s') not found, in CUDASimulation::getAgent().",
agent_name.c_str());
}

return *(it->second);
}

detail::CUDAMessage& CUDASimulation::getCUDAMessage(const std::string& message_name) const {
CUDAMessageMap::const_iterator it;
it = message_map.find(message_name);
Expand Down
30 changes: 0 additions & 30 deletions tests/test_cases/simulation/test_cuda_simulation.cu
Original file line number Diff line number Diff line change
Expand Up @@ -291,36 +291,6 @@ TEST(TestCUDASimulation, SetGetPopulationData_InvalidAgent) {
EXPECT_THROW(c.setPopulationData(pop), exception::InvalidAgent);
EXPECT_THROW(c.getPopulationData(pop), exception::InvalidAgent);
}
TEST(TestCUDASimulation, GetAgent) {
ModelDescription m(MODEL_NAME);
AgentDescription a = m.newAgent(AGENT_NAME);
m.newLayer(LAYER_NAME).addAgentFunction(a.newFunction(FUNCTION_NAME, SetGetFn));
a.newVariable<int>(VARIABLE_NAME);
AgentVector pop(a, static_cast<unsigned int>(AGENT_COUNT));
for (int _i = 0; _i < AGENT_COUNT; ++_i) {
AgentVector::Agent i = pop[_i];
i.setVariable<int>(VARIABLE_NAME, _i);
}
CUDASimulation c(m);
c.SimulationConfig().steps = 1;
c.setPopulationData(pop);
c.simulate();
detail::AgentInterface &agent = c.getAgent(AGENT_NAME);
for (int _i = 0; _i < AGENT_COUNT; ++_i) {
int host = 0;
cudaMemcpy(&host, reinterpret_cast<int*>(agent.getStateVariablePtr(ModelData::DEFAULT_STATE, VARIABLE_NAME)) + _i, sizeof(int), cudaMemcpyDeviceToHost);
EXPECT_EQ(host, _i * MULTIPLIER);
host = _i * 2;
cudaMemcpy(reinterpret_cast<int*>(agent.getStateVariablePtr(ModelData::DEFAULT_STATE, VARIABLE_NAME)) + _i, &host, sizeof(int), cudaMemcpyHostToDevice);
}
c.simulate();
agent = c.getAgent(AGENT_NAME);
for (int _i = 0; _i < AGENT_COUNT; ++_i) {
int host = 0;
cudaMemcpy(&host, reinterpret_cast<int*>(agent.getStateVariablePtr(ModelData::DEFAULT_STATE, VARIABLE_NAME)) + _i, sizeof(int), cudaMemcpyDeviceToHost);
EXPECT_EQ(host, _i * 2 * MULTIPLIER);
}
}

TEST(TestCUDASimulation, Step) {
// Test that step does a single step
Expand Down

0 comments on commit 313e1dc

Please sign in to comment.