diff --git a/include/flamegpu/simulation/CUDASimulation.h b/include/flamegpu/simulation/CUDASimulation.h index b7fdf8757..eca346b8e 100644 --- a/include/flamegpu/simulation/CUDASimulation.h +++ b/include/flamegpu/simulation/CUDASimulation.h @@ -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 /** @@ -250,17 +258,6 @@ class CUDASimulation : public Simulation { template std::vector 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 @@ -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) diff --git a/include/flamegpu/simulation/Simulation.h b/include/flamegpu/simulation/Simulation.h index cbdc069c2..74a279c33 100644 --- a/include/flamegpu/simulation/Simulation.h +++ b/include/flamegpu/simulation/Simulation.h @@ -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; diff --git a/src/flamegpu/runtime/HostAPI.cu b/src/flamegpu/runtime/HostAPI.cu index 00f75c115..3534d81b3 100644 --- a/src/flamegpu/runtime/HostAPI.cu +++ b/src/flamegpu/runtime/HostAPI.cu @@ -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); } /** diff --git a/src/flamegpu/simulation/CUDASimulation.cu b/src/flamegpu/simulation/CUDASimulation.cu index 98a00c807..d48bfcc61 100644 --- a/src/flamegpu/simulation/CUDASimulation.cu +++ b/src/flamegpu/simulation/CUDASimulation.cu @@ -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); @@ -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); diff --git a/tests/test_cases/simulation/test_cuda_simulation.cu b/tests/test_cases/simulation/test_cuda_simulation.cu index 2bf17e28e..137b39eaf 100644 --- a/tests/test_cases/simulation/test_cuda_simulation.cu +++ b/tests/test_cases/simulation/test_cuda_simulation.cu @@ -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(VARIABLE_NAME); - AgentVector pop(a, static_cast(AGENT_COUNT)); - for (int _i = 0; _i < AGENT_COUNT; ++_i) { - AgentVector::Agent i = pop[_i]; - i.setVariable(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(agent.getStateVariablePtr(ModelData::DEFAULT_STATE, VARIABLE_NAME)) + _i, sizeof(int), cudaMemcpyDeviceToHost); - EXPECT_EQ(host, _i * MULTIPLIER); - host = _i * 2; - cudaMemcpy(reinterpret_cast(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(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