From 8343b0c5d38878b2aeefbd22daa8ce88db7323d4 Mon Sep 17 00:00:00 2001 From: Robert Chisholm Date: Mon, 12 Dec 2022 08:59:03 +0000 Subject: [PATCH] Breaking Change: Removed CUDASimulation::getAgent()/getCUDAAgent() This feature was not intended for release, users should not have direct access to internal objects. Roughly equivalent functionality is available via DeviceAgentVector in the HostAPI. --- include/flamegpu/simulation/CUDASimulation.h | 6 ---- include/flamegpu/simulation/Simulation.h | 1 - src/flamegpu/simulation/CUDASimulation.cu | 26 ---------------- .../simulation/test_cuda_simulation.cu | 30 ------------------- 4 files changed, 63 deletions(-) diff --git a/include/flamegpu/simulation/CUDASimulation.h b/include/flamegpu/simulation/CUDASimulation.h index b7fdf8757..62b26d548 100644 --- a/include/flamegpu/simulation/CUDASimulation.h +++ b/include/flamegpu/simulation/CUDASimulation.h @@ -250,12 +250,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 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/simulation/CUDASimulation.cu b/src/flamegpu/simulation/CUDASimulation.cu index 98a00c807..9dfb2e65a 100644 --- a/src/flamegpu/simulation/CUDASimulation.cu +++ b/src/flamegpu/simulation/CUDASimulation.cu @@ -1380,32 +1380,6 @@ void CUDASimulation::getPopulationData(AgentVector& population, const std::strin gpuErrchk(cudaDeviceSynchronize()); } -detail::CUDAAgent& CUDASimulation::getCUDAAgent(const std::string& agent_name) const { - CUDAAgentMap::const_iterator it; - it = agent_map.find(agent_name); - - if (it == agent_map.end()) { - THROW exception::InvalidCudaAgent("CUDA agent ('%s') not found, in CUDASimulation::getCUDAAgent().", - agent_name.c_str()); - } - - 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