zlacker

Show HN: Demo of Agent Based Model on GPU with CUDA and OpenGL (Windows/Linux)

submitted by ktt878+(OP) on 2023-12-04 19:34:56 | 55 points 21 comments
[view article] [source] [links] [go to bottom]

Demo of agent based model on GPU with CUDA and OpenGL (Windows/Linux)

Agent instances on GPU memory Uses SSBO for instanced objects (with GLSL 450 shaders) CUDA OpenGL interops Renders with GLFW3 window manager Dynamic camera views in OpenGL (pan,zoom with mouse) Libraries installed using vcpkg

(https://github.com/KienTTran/ABMGPU)

replies(10): >>blurbl+bj >>sgt101+Ir >>TheHid+uB >>m-murp+PI >>m-murp+4J >>TheEzE+UL >>jasonj+gO >>posnet+UW >>morito+u11 >>westur+Ar1
1. blurbl+bj[view] [source] 2023-12-04 21:15:54
>>ktt878+(OP)
What exactly is an "agent based model" in this case? What I see is a lot of triangles moving around, but what exactly drives them?
replies(2): >>3abito+Kn >>ktt878+2p
◧◩
2. 3abito+Kn[view] [source] [discussion] 2023-12-04 21:36:52
>>blurbl+bj
From my understanding it's the term used for Complex Modelling Systems in Social Sciences.
◧◩
3. ktt878+2p[view] [source] [discussion] 2023-12-04 21:44:09
>>blurbl+bj
Hi, thank you for your interest. Agent based model is a term refers to an interaction between multiple object (called agent) with its own property. The triangle is one agent in this case and in this example it moves along a random trajectory (just like people in a crowd). Each triangle also has its own color of its population so agents in the same population will have the same color.
4. sgt101+Ir[view] [source] 2023-12-04 21:57:10
>>ktt878+(OP)
reminds me of the flocking demos 20 years ago...
replies(1): >>ktt878+bV
5. TheHid+uB[view] [source] 2023-12-04 22:53:55
>>ktt878+(OP)
Are the agents independent or are they affected by neighbors? It would be nice to see some classic ABM examples like wolf-sheep population, flocking, and wildfire spread to demonstrate the utility of this.
replies(1): >>ktt878+6U
6. m-murp+PI[view] [source] 2023-12-04 23:33:38
>>ktt878+(OP)
Are the entities interacting in any way here? That's pretty critical for agent based models as they enable complicated/unexpected emergent behavior from simplified rules due to the interactions of the entities.
replies(1): >>ktt878+TU
7. m-murp+4J[view] [source] 2023-12-04 23:34:49
>>ktt878+(OP)
Another related project for ABMs utilizing GPUs: https://docs.flamegpu.com/guide/index.html
replies(1): >>ktt878+ZU
8. TheEzE+UL[view] [source] 2023-12-04 23:48:54
>>ktt878+(OP)
Super cool, curious to see where you take this! I did some work on GPGPU for agent simulations for an RTS years ago ( https://www.youtube.com/watch?v=P4fKJIrv0J8 ). Doing things like pathfinding on the GPU gets tricky, especially taking into account how agents affect paths of other agents. Happy to jam anytime if you're brainstorming applications.
replies(1): >>ktt878+EU
9. jasonj+gO[view] [source] 2023-12-05 00:00:02
>>ktt878+(OP)
You should work on inter-agent interaction next! It's so much fun.

I have played with this a fair amount and put a couple of my experiments in a repo- both slime mold simulation and "particle life".

Here's the repo: https://github.com/jasonjmcghee/compute-shaders

And a video of the slime mold: https://twitter.com/_jason_today/status/1663378736098738177?...

replies(1): >>ktt878+nU
◧◩
10. ktt878+6U[view] [source] [discussion] 2023-12-05 00:38:12
>>TheHid+uB
Right now it's independent. I just want to provide a playground and people can make more with it. Loves your idea though.
◧◩
11. ktt878+nU[view] [source] [discussion] 2023-12-05 00:39:53
>>jasonj+gO
Wow it's amazing visualization. Thanks for suggestion.
◧◩
12. ktt878+EU[view] [source] [discussion] 2023-12-05 00:41:11
>>TheEzE+UL
This's awesome. Happy to know that you're doing the same.
◧◩
13. ktt878+TU[view] [source] [discussion] 2023-12-05 00:42:33
>>m-murp+PI
Yeah they should be interact to each other. Right now I just started with it and want to share so everyone can take advantage in their ways.
◧◩
14. ktt878+ZU[view] [source] [discussion] 2023-12-05 00:43:02
>>m-murp+4J
This is supercool and beyond what I've done. Thanks for sharing.
◧◩
15. ktt878+bV[view] [source] [discussion] 2023-12-05 00:44:20
>>sgt101+Ir
Thanks. It's a nostalgia app haha.
16. posnet+UW[view] [source] 2023-12-05 00:57:39
>>ktt878+(OP)
Another fun one, not sure about accuracy, but the visuals are stunning.

https://youtu.be/dSkxvi9igqQ

https://github.com/chrxh/alien/

replies(1): >>ktt878+s21
17. morito+u11[view] [source] 2023-12-05 01:40:42
>>ktt878+(OP)
If you want to create some pretty effects, add the concept of a velocity-texture which is added to agents velocity as they pass over it. Then let the user draw on the texture. Very cheap way to get interactivity. My own version from before compute shades were a thing (https://moritonal.github.io/force-particles/)
replies(1): >>ktt878+w21
◧◩
18. ktt878+s21[view] [source] [discussion] 2023-12-05 01:50:29
>>posnet+UW
This is brilliant. Thanks for sharing.
◧◩
19. ktt878+w21[view] [source] [discussion] 2023-12-05 01:50:57
>>morito+u11
Thanks for your advice. I will update more in the next version.
20. westur+Ar1[view] [source] 2023-12-05 05:52:08
>>ktt878+(OP)
Could this work in WebGL and/or WebGPU (and/or WebNN) with or without WASM in a browser?

https://stackoverflow.com/questions/48228192/webgl-compute-s...

https://github.com/conda-forge/glfw-feedstock/blob/main/reci...

pyglfw: https://github.com/conda-forge/pyglfw-feedstock/blob/main/re...

- [ ] glfw recipe for emscripten-forge: https://github.com/emscripten-forge/recipes/tree/main/recipe...

Emscripten porting docs > OpenGL ES 2.0/3.0 *, glfw: https://emscripten.org/docs/porting/multimedia_and_graphics/...

WebGPI API > GPUBuffer: https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API

gpuweb/gpuweb: https://github.com/gpuweb/gpuweb

>>38355444 :

> It actually looks like pygame-web (pygbag) supports panda3d and harfang in WASM

Harfang and panda3d do 3D with WebGL, but FWIU not yet agents in SSBO/VBO/GPUBuffer.

SSBO: Shader Storage Buffer Object: https://www.khronos.org/opengl/wiki/Shader_Storage_Buffer_Ob...

/? WebGPU compute: https://www.google.com/search?q=webgpu+compute

"WebGPU Compute Shader Basics" https://webgpufundamentals.org/webgpu/lessons/webgpu-compute...

replies(1): >>ktt878+Y52
◧◩
21. ktt878+Y52[view] [source] [discussion] 2023-12-05 12:47:09
>>westur+Ar1
Basically possible. You have to remove all Cuda code and port C++ code to use glfw with specific library for web. The shader can be reused.
[go to top]