Before porting the SteerSuite to CUDA code, I have to fully understand how SteerSuite works.
From http://www.magix.ucla.edu/steersuite/, you can download the code.
There are seven projects in the SteerSuite solution, pprAI, simpleAI, steerlib, steersim, steerbench, steertool, and glfw. Most of the work will rely on the first three projects which includes the underlying data structure storing agents and obstacles, and how each agent move with the help of the AI.
First of all, all the data are stored in the
GridDatabase2D class, in the form of an array of
SpatialDatabaseItemPtr. And each item can either be an agent or an obstacle, depending on the initial options. Beside this array, another array of
GridCell stores the identical database, but only the pointers to the original data. The whole geometry is divided into this array of
GridCell, and if agents and obstacles are close enough, their pointers will be store in a
GridCell.
Every time, each agent is updated by using corresponding AIs, either simpleAI or pprAI. First step, each agent will read its neighborhood information from the whole database, then do the corresponding computation, at last, the new position will be written back to the agent, and the content of
GridCell will be changed as well as the position changes of the agents.
By examining the simpleAI, pprAI, and steerlib projects, there are six subclasses of
SpatialDatabaseItem, i.e. S
impleAgent, PPRAgent, BoxObstacle, CircleObstacle, and OrientedBoxObstacle. Now I will only take care of
SimpleAgent.
In
SimpleAgent, there are
_position, _velocity, _forward, _enabled, _radius, and
_goalQueue as the class members. Because some of them uses self-defined data like
Util::Point, Util::Vector and standard template library like
std::queue<SteerLib::AgentGoalInfo>, I have to use float3 and array instead.
The basic routine will be that first copying data from host to device, then updating each agent in parallel at device side, finally copying the modified data back.
If this method does not work well, it may be worth trying rewrite database part completely in CUDA. Let us see.