290 likes | 464 Views
Agent Simulations on Graphics Hardware. Timothy Johnson - twjohnson@students.latrobe.edu.au Supervisor: Dr. John Rankin. Outline. Agent Simulations Graphics Hardware System Model Planning Code Generation Simulation Analysis Examples Performance. Agent Simulations.
E N D
Agent Simulations on Graphics Hardware Timothy Johnson - twjohnson@students.latrobe.edu.au Supervisor: Dr. John Rankin
Outline • Agent Simulations • Graphics Hardware • System • Model • Planning • Code Generation • Simulation • Analysis • Examples • Performance
Agent Simulations • Simulations with hundreds or thousands of software agents • Agent-based simulations are becoming increasingly more popular [1] • Each entity simulated at the individual microscopic level • Emergence of interesting complex behaviour at the macroscopic level • Fields: air traffic control, disaster management, biology, crime analysis, economics, pedestrian dynamics, military simulations, etc • Problems • Expensive and time consuming to develop • Limited in scope by available processing power
Graphics Hardware • Graphical Processing Units (GPUs) are outstripping Central Processing Units (CPUs) in terms of raw performance [2] • Performance gap continuing to widen • Example • Intel Core i7-4930K [$679][187.2 GFLOPS] • NVIDIA GTX 780 [$639][3977 GFLOPS] • Programming Difficulties • Dealing with hundreds or thousands of cores and threads • Data synchronisation • Memory architecture • Data transfer between CPU and GPU • Shortage of high quality learning resources Prices retrieved from pccasegear.com on 04/11/2013
Idea • Increase processing power, allowing more agents to be simulated than previously possible • Make a system that does not require the user to perform GPU programming
System Overview Model Planning Code Generation Simulation Analysis
System Overview Model Planning Code Generation Simulation Analysis
Model • Resources – Items agents interact with • Apple, Bread, Car, Gold, Water • Attributes – Represent aspects of agents • Age, Height, Health, Hunger, Energy • Rules – Specify how an agent can interact with the world • Move, Use, Harvest, Trade, Combine • Goals – Define the agent’s behaviour during simulation • Maximize Attributes, Maximize Resources • Agent Types – Built up with Attributes, Rules and Goals • Farmer, Duck, Bee, Policeman • Communities – Consists of one or more Agent Types • Town, Beehive, Sports team
MODEL: Duck simulation • Resources • Bugs • Bread • Attributes • Hunger • Rules • Use (Bread, Hunger, -5) • Use (Bugs, Hunger, -3) • Harvest (Bread) • Harvest (Bugs) • Goals • Minimize Attribute (Hunger)
System Overview Model Planning Code Generation Simulation Analysis
Planning • User enters resources, attributes, rules, goals, agents, communities into our tool • System then automatically links goals and rules to create plans Goal One Rule One Rule Two Rule Three
PLANNING: DUCK SIMULATION Rule Use (Bread, Hunger, -5) Rule Use (Bugs, Hunger, -3) Goal Minimize Attribute (Hunger) Rule Harvest (Bread) Rule Harvest (Bugs)
System Overview Model Planning Code Generation Simulation Analysis
Code generation • OpenCL code kernels are created for each agent type defined • OpenCL is programmed through a subset of C with its own extensions • Can run on both NVIDIA and AMD GPUs • Algorithm • For each agent type • Create a new kernel • Prepare some initial definitions and kernel arguments • Iterate through each plan created in the previous stage • Generate segments of code for each rule in each plan • By automatically generated optimised code, we manage to hide the difficulties of GPGPU from the user
Code Generation: DUCK SIMULATION Goal Minimize Attribute (Hunger) Rule Use (Bread, Hunger, -5) Rule Use (Bugs, Hunger, -3) Rule Harvest (Bread) Rule Harvest (Bugs)
System Overview Model Planning Code Generation Simulation Analysis
Simulation • Code kernels are compiled • Data is generated on the CPU • Data is transferred across to GPU memory • Each agent to be simulated is assigned its own thread • Simulation begins to run
SIMULATION: DUCK SIMULATION Yellow = Ducks, Green = Bugs, Blue = Bread
System Overview Model Planning Code Generation Simulation Analysis
Analysis • All data from the simulation, including agent positions, attribute values, resource values, plans chosen, etc can be output to file during runtime • After the simulation run has completed, this data can then be analysed externally by other tools
Scenarios Farming Simulation [3] Bee Simulation [4] Factory Simulation
Performance Testing • Two versions of the “Farming Simulation” created • GPU version using our system • Custom CPU-optimised version • Tests carried out on four GPUs and four CPUs • Two laptop machines and two desktop machines • Millisecond per update and frame rates were calculated • Testing found modern GPUs are faster than CPUs in most cases
Beyond Simulations • Movies • Games • Advertisements
Questions? Timothy Johnson - twjohnson@students.latrobe.edu.au Supervisor: Dr. John Rankin References: [1] Chan, W. K. V., Son Y. J., Macal, C. M., Agent-based simulation tutorial - simulation of emergent behavior and differences between agent-based simulation and discrete-event simulation, In Proceedings of the Winter Simulation Conference, WSC '10, 135-150, 2010. [2] Luebke, D., Humphreys, G., How GPUs Work, Computer, 40 (2), 96-100, 2007. [3] Johnson, T. W. C., Rankin, J. R., Parallel Agent Systems on a GPU for use with Simulations and Games, In Proceedings of the 1st International Conference on Computing, Information Systems and Communications, CISCO '01, 229-235, 2012. [4] Johnson, T. W. C., Rankin, J. R., User Friendly Agent-Oriented Simulation Builder, In Proceedings of the 8th International Conference on Information Technology and Applications, ICITA '08, 2013.