N-Body Simulation

  Рет қаралды 85,554

a2flo

a2flo

Күн бұрын

This was written to demonstrate and test the compute toolchain/implementation I'm currently working on for my master's thesis (github.com/a2f.... With this it is possible to compile the same C++17 code to CUDA/PTX, OpenCL/SPIR/SPIR-V, Metal and Vulkan/SPIR-V, thus running on a multitude of GPUs and CPUs on different platforms. To achieve this, I'm using a modified clang/llvm/libc++ 4.0 toolchain and a layer of host and device side code that makes it possible to address everything the same way. This demo in particular shows the use of local/shared memory buffers, local memory barriers, OpenGL buffer sharing, loop unrolling and that high performance computing is indeed possible with this toolchain.
The N-body simulation is largely based on http.developer.... with some additional optimizations.
More information on N-body simulations: en.wikipedia.o...
Code for this demo: github.com/a2f...
Current performance stats (in benchmark mode):
* P6000: ~8400 gflops (--count 262144 --tile-size 512)
* GP100: ~7600 gflops (--count 262144 --tile-size 512)
* GTX 970: ~2770 gflops (--count 131072 --tile-size 256)
* GTX 780: ~2350 gflops (--count 131072 --tile-size 512)
* GTX 1050 Ti: ~1675 gflops (--count 262144 --tile-size 256)
* R9 285: ~850 gflops (--count 131072 --tile-size 64)
* GTX 750: ~840 gflops (--count 65536 --tile-size 256)
* GT 650M: ~375 gflops (--count 65536 --tile-size 512)
* HD 530: ~242 gflops (--count 65536 --tile-size 128)
* HD 4600: ~235 gflops (--count 65536 --tile-size 80)
* i7-6700: ~195 gflops (--count 32768 --tile-size 1024)
* HD 4000: ~165 gflops (--count 32768 --tile-size 128)
* iPhone A10: ~131 gflops (--count 32768 --tile-size 512)
* i7-5820K: ~105 gflops (--count 32768 --tile-size 8)
* i7-4770: ~80 gflops (--count 32768 --tile-size 8)
* i7-3615QM: ~38 gflops (--count 32768 --tile-size 8)
* i7-950: ~29 gflops (--count 32768 --tile-size 4)
* iPhone A8: ~28 gflops (--count 16384 --tile-size 512)
* iPad A7: ~20 gflops (--count 16384 --tile-size 512)
Stats from this video:
* N = 131072, damping = 0.9983, softening = 0.01
* since this is an O(n^2) algorithm, this results in 131072^2 = 17179869184 body/body interactions per iteration
* the initial body setup is a hollow sphere (or on-sphere), with body velocities set to the center
* with rendering and video capturing, performance is degraded a little and one iteration of this simulation took about 175ms (w/o rendering/capturing it would be ~155ms)
* with N = 65536 this runs in realtime on a GTX 780 (~38ms per iteration with rendering)
* the 1x runtime of this video is slightly above 1 hour, the video is shown in 16x speed-up, with camera rotations at 3x (to not cause that much confusion ;))

Пікірлер: 147
@taiyc3
@taiyc3 2 жыл бұрын
this looks exactly like the cosmic web! amazing!!! xP
@oystercatcher943
@oystercatcher943 Жыл бұрын
Amazing stuff. I'm doing similar on a GPU helped by much fasters GPUs since 2015. I'm also planning to use a space partitioning optimisation but it runs fairly fast with 10-20K particles right now which seems amazing when its O(N^2). I found it was easy to get particles thrown off using forces ~1/(R^2) so I used something like 1/(R^2+0.001) and got less thrown off particles. Looking at your code, it looks like this is indeed similar to your softening factor but you use 1/(R+soft_factor)^2. Its good I wasn't totally hacking it when I did this. I guess the factor needed is proportional to the magnitudes of R
@PinkeySuavo
@PinkeySuavo 5 жыл бұрын
It looks like galaxies superclusters, wtf. Aren't these simulations giving us a look on how the universe was created?
@sirrcharles1869
@sirrcharles1869 2 жыл бұрын
They do
@rajinfootonchuriquen
@rajinfootonchuriquen 2 жыл бұрын
Maybe when they make a theory of quantum gravity
@Joao-uj9km
@Joao-uj9km Жыл бұрын
Yes, that's literally what they're simulating :)
@JacobNax
@JacobNax 9 ай бұрын
This is a useless simulation. You can see an abstract pattern that matches the galaxy superclusters due to how particles attract eachother but it doesn't simulate actual gravity.
@PinkeySuavo
@PinkeySuavo 9 ай бұрын
why doesnt it?@@JacobNax
@resbizhou1488
@resbizhou1488 5 жыл бұрын
Amazing work! I‘ve been doing something similar since last year......
@asdf-mu8zi
@asdf-mu8zi 2 жыл бұрын
It just shaped heatmap of universe.. amazing
@Geomasterthesecond
@Geomasterthesecond 6 ай бұрын
No idea what you're talking about that's not the heat map of the universe
@radhakrishnamohanty3807
@radhakrishnamohanty3807 2 жыл бұрын
Seems like a super cluster of galaxies ...
@daerhiel
@daerhiel 2 жыл бұрын
It seems it doesn't include the particle collisions, is it?
@MrRenanwill
@MrRenanwill 2 жыл бұрын
Why?
@pixelprincess9
@pixelprincess9 5 жыл бұрын
Very cool! Question for the creator: are you taking Dark Matter and Dark Energy into account or are you just using Newtonian physics? Thanks!
@a2flo
@a2flo 5 жыл бұрын
Just plain old Newtonian with some softening/damping: developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch31.html
@brucesimonson4581
@brucesimonson4581 4 жыл бұрын
What happens in this simulation as time goes to infinity?
@RmX.
@RmX. 3 жыл бұрын
Same what happens in space
@brucesimonson4581
@brucesimonson4581 3 жыл бұрын
Asking out of curiosity: does this excellent model and graphic simulation lead to a big crunch, big chill, or big rip, by including the Hubble constant, mass density, and dark energy pressure and its density as parameters? (see en.m.wikipedia.org/wiki/Big_Rip ) It would be interesting to model each of these scenarios, and watch their simulations in this software. Again, awesome work and presentation.
@a2flo
@a2flo 2 жыл бұрын
This is just plain old Newtonian gravity. Anything fancier than this would not nearly run as fast (or would require much more compute resources). So, in this case, everything would eventually just coalesce into a single point. Fancier simulations: www.illustris-project.org kzbin.info/www/bejne/iGjRh2mAerJ6d9E
@kahlzun
@kahlzun 2 жыл бұрын
As it shows in the video, everything is collapsing into the central point
@mixer0014
@mixer0014 2 жыл бұрын
@@a2flo Have you tried giving the particles some initial velocities? When angular momentum is introduced at the beginning it will be preserved and result in a spinning structure at the end. But It won’t work when there is friction.
@양익서-g8j
@양익서-g8j 4 ай бұрын
인간의 의식은 수많은 항성과 블랙홀의 중성미자 소립자 양자들의 끊임없는 움직임과 소멸로 생긴 부분도 있겠죠.
@ph08nyx
@ph08nyx 2 жыл бұрын
Похоже на планетарную туманность, но на сколько мы их можем наблюдать, они не схлопываются в одну точку, как в этой симуляции, а продолжают расширяться и рассеиваться.
@Rayvenor
@Rayvenor 2 жыл бұрын
Потому что это не симуляция галактики.
@MsAlfred1996
@MsAlfred1996 4 жыл бұрын
Can I please use some part of this as an intro a series of educational videos I'm working at now ? (I'm not even gonna be paid, it's not for profit)
@a2flo
@a2flo 4 жыл бұрын
Yes, it's licensed under CC BY.
@MsAlfred1996
@MsAlfred1996 4 жыл бұрын
@@a2flo Thank you
@jareknowak8712
@jareknowak8712 2 жыл бұрын
Yep, thats how it all started. Been there, done that. I should still have some pictures on my old laptop.
@Frommerman
@Frommerman 2 жыл бұрын
I thought this was a cool 2d sim. Then you started rotating it
@playfra5004
@playfra5004 2 жыл бұрын
Cool video! Could you tell me the code and what program are you using to run it? Thank you.
@hamsterdam1942
@hamsterdam1942 2 жыл бұрын
Looking at the description before asking was never an option
@blaze-pn6fk
@blaze-pn6fk 4 жыл бұрын
Great work 👏👏
@tanishqajk6514
@tanishqajk6514 3 жыл бұрын
Add soothing music! Lovely simulation How should I get started here?
@a2flo
@a2flo 2 жыл бұрын
kzbin.info/www/bejne/rJKUoJyln9N6qKM goes well with it ;)
@kgtc
@kgtc 7 жыл бұрын
Oh my looks like we need to get an FPGA for this! For now get an RX 480 4GB for the 5.5 TFlops for cheap.
@orderofchaos8680
@orderofchaos8680 2 жыл бұрын
Any pattern emerges from chaos?
@DiamondSane
@DiamondSane 2 жыл бұрын
yes. still it's a chaotic pattern
@pixelapse9613
@pixelapse9613 Жыл бұрын
@@DiamondSane or is it
@dielaughing73
@dielaughing73 5 ай бұрын
Many, as you see
@boRegah
@boRegah Жыл бұрын
One would think 3 bodies are plenty
@eeronat
@eeronat 6 ай бұрын
This is a good metaphor for immigration reform. (Too much coffee?)
@MartinMizner
@MartinMizner 2 жыл бұрын
He is literally simulating our universe
@laurencevanhelsuwe3052
@laurencevanhelsuwe3052 2 жыл бұрын
Pretty. I wrote something similar (with about 1000x fewer objects) on my Amiga 1000 back in.. oh.. it must have been 1986 (in 68000 assembler.. had to be for speed - the result was a smooth animation).
@a2flo
@a2flo 2 жыл бұрын
The only way is up :) I'm already getting ~20x the performance on a 3090 vs the 780 I made this video on + run this with a million bodies at somewhat decent speed.
@pablouuuu
@pablouuuu 9 жыл бұрын
D:
@MisterTrayser
@MisterTrayser 2 жыл бұрын
Thats the proof that we are in simulation If we already have such computing power, in 100 years we will be able to make universe with all physic forces
@the18thdoctor3
@the18thdoctor3 2 жыл бұрын
I don’t think you know what “proof” means
@thealbinotadpole2878
@thealbinotadpole2878 Жыл бұрын
Thats called a "hunch", not a proof.
@MisterTrayser
@MisterTrayser Жыл бұрын
@@thealbinotadpole2878 confirmation, ok. Don't hang on every word
@thealbinotadpole2878
@thealbinotadpole2878 Жыл бұрын
@@MisterTrayser It still doesn't confirm anything. You could call it supporting evidence, but it cannot prove anything.
@hangyeoljung4254
@hangyeoljung4254 4 жыл бұрын
Why did my professor give me this stuff to my software assignments...
@wolfboyft
@wolfboyft 2 жыл бұрын
How is the particles-"'colliding"'-and-flying-away-at-'insane-'speeds effect mitigated in this simulation? Lovely btw, absolutely magnificient, just the kind of thing I like to see.
@bitw1se
@bitw1se 2 жыл бұрын
I would guess using the "velocity damping" and "softening" he's written about in his stats
@orionsuniversepart2932
@orionsuniversepart2932 2 жыл бұрын
Kinda looks like a simulation of the universe.
@vidstige
@vidstige 2 жыл бұрын
In other videos I've seen that he describes that he uses "dampening" (where a force opposite to the velocity and proportional to the velocity is applied) and "softening" (where the distance between particles are artificially increased, avoiding the harshest accelerations).
@phivpap8632
@phivpap8632 2 жыл бұрын
Did you find a concrete solution to this? I'm kinda facing that issue in my sim :(
@phivpap8632
@phivpap8632 2 жыл бұрын
@@vidstige Wouldn't "dampening" cause orbit decay and thus more collisions?
@genkidama7385
@genkidama7385 2 жыл бұрын
would be interesting to do the inverse, starting from known body positions, and calculating their evolution backwards in time.
@PrzemysawUznanski
@PrzemysawUznanski 2 жыл бұрын
just reverse the speed vectors...
@puddle.studios
@puddle.studios Жыл бұрын
@@PrzemysawUznanski i dont think that would work but you could just reverse the simulation
@vke6077
@vke6077 Жыл бұрын
I think this is not possible. You can get to a certain position in many ways, no?
@TransoceanicOutreach
@TransoceanicOutreach Жыл бұрын
Approximations make it impossible for this particular sim.
@bronson4574
@bronson4574 Жыл бұрын
Not possible, too much chaos on the system
7 жыл бұрын
Cool compute video. Would you mind telling that how did you count flops in kernel code? For example, did you count rsqrt/fma as 1 flop? Did you count only compute time or did you include drawing time too? How many flops per particle-particle? I'm just trying to compare my RX550 with OpenCL nbody to this and to know if I'm calculating right.
@a2flo
@a2flo 7 жыл бұрын
github.com/a2flo/floor_examples/blob/master/nbody/src/nbody.cpp#L25 Since rsqrt is executed in hardware (on all h/w afaik) it's counted as a single flop, fma is counted as 2 flops, in total you get 19 flops per particle/particle interaction. Drawing time is excluded (in the table at least), because nothing is being drawn in benchmark mode. What is included in the time however is any kind of synchronization and global/local memory transfers (since we obviously need that to do anything). Note that AMD is doing particularly bad with nbody (you get about 25% the theoretical #flops that is possible on that hardware, at least on GCN 1.2, I haven't tested this with Polaris/Vega yet). On all other hardware you get about 50% the theoretical #flops (NVIDIA pre-Pascal, Intel GPUs, Apple/PowerVR since A9/A10), or 70% since Pascal.
7 жыл бұрын
Thank you. I think amd has put less sqrt or special function core density than nvidia and intel. I just tried a mad only kernel which is unrolled for pipelining could use 90 percent but when sqrt is included it drops badly as if there is only 1 sqrt unit per 32 arithmetic logic units
7 жыл бұрын
Also you can see same thing in userbenchmark site too. In pure shader performance(or mad mul add) rx550 is faster than gt1030 but in its nbody part its slower by a large margin. Certainly sqrt density of amd is much less than nvidia but has more cores to tolerate to some degree which is useful only when implementing own sqrt functions.
@a2flo
@a2flo 7 жыл бұрын
rsqrt throughtput on GCN is the same as on NVIDIA since Maxwell (1/4 "speed"). So that shouldn't be the issue (even if it was much slower, it still wouldn't be the significant part). As far as I can tell, the performance issues originate from less local memory bandwidth and synchronization costs (there are 2 local/full barriers for every 256 bodies, and N * 16 bytes local memory writes + reads per work-group).
7 жыл бұрын
I heard that nvidia kepler series did not have enough data bandwidth to feed all cores concurrently. Does this mean amd is even worse and optimized for mainly "register" usage, hence, for embarrasingly parallel algorithms that don't rely on sync performance?
@JohnSmith-ps6on
@JohnSmith-ps6on 8 жыл бұрын
Great stuff.
@makismakiavelis5718
@makismakiavelis5718 5 жыл бұрын
Wow. I was going to make a joke along these lines: _"Easy, I can do this with my outdated computer. I just need 25 years to render"_ I was surprised to see that they used a GTX 780 and my GPU is a GTX 780Ti... I wonder what CPU they used.
@ctorange
@ctorange 3 жыл бұрын
If I understand correctly, it ran solely on their GPU. I think one purpose of their compute toolchain is that it can run on a GPU or CPU independently. Presumably it takes advantage of GPU-specific features when it runs on a GPU.
@makismakiavelis5718
@makismakiavelis5718 3 жыл бұрын
@@ctorange That's really interesting but you reminded my comment from 1 year ago and that made my sad. My 780Ti died and with the GPU prices going crazy the past few months I was forced to unearth my 10 year old Radeon HD6450...
@nathanhelmburger
@nathanhelmburger 2 жыл бұрын
This would be so cool to see in 3d in VR....
@mrgoodpeople
@mrgoodpeople 2 жыл бұрын
you need add a dark energy!
@crowxe
@crowxe 2 жыл бұрын
Damn.. i can watch the progress of these videos for hours
@jonathanbaincosmologyvideo3868
@jonathanbaincosmologyvideo3868 Жыл бұрын
Very impressive. Notice how nothing like a solar system forms with just gravity alone. No natural ecliptic plane. I did a 9-body- simulation of the solar system with the emphasis on individual accuracy of each body, rather than the monstrous numbers of objects you got here. Link to follow.
@jonathanbaincosmologyvideo3868
@jonathanbaincosmologyvideo3868 Жыл бұрын
kzbin.info/www/bejne/enSYm4RsbbqSr6s
@singadorito7802
@singadorito7802 2 жыл бұрын
So... This is what IC 1101 looks like...
@gatoradeee
@gatoradeee 8 жыл бұрын
trippin off acid
@VinniusHKruger
@VinniusHKruger 5 ай бұрын
What kind of collision ? 100% elastic ?
@VinniusHKruger
@VinniusHKruger 5 ай бұрын
Looks like crab supernova.
@arithene
@arithene 2 жыл бұрын
So scary
@ORGOrange
@ORGOrange 7 ай бұрын
2:09 uhhhh
@maciejjedrzejczyk9028
@maciejjedrzejczyk9028 Жыл бұрын
Bigbang simulation ;D
@francomay3963
@francomay3963 Жыл бұрын
i could see my house from there
@EddieVBlueIsland
@EddieVBlueIsland 6 жыл бұрын
Looks like the " game of life" in 3D and gravitational bias. Nice work.
@Kergan63
@Kergan63 2 жыл бұрын
What are the initial conditions? I mean : why the bubble initially expands?
@a2flo
@a2flo 2 жыл бұрын
github.com/a2flo/floor_examples/blob/f71b0683708edb190f21de24ed573219361ba6ee/nbody/src/main.cpp#L492 :) Initial collapse is due to their initial velocity (though with a 0 velocity, this would still collapse, just more slowly). Expansion happens, because the velocities are very high and point in all directions once all/most bodies hit the center + velocities are larger than the mutual attraction, so this doesn't clump up initially.
@MrRenanwill
@MrRenanwill 2 жыл бұрын
O feel like being god
@tomjerry84
@tomjerry84 6 жыл бұрын
Looks like how the universe works
@DeMooniC
@DeMooniC 4 жыл бұрын
except is not expanding and is way smaller but yeah
@hamidaminirad
@hamidaminirad 4 жыл бұрын
No. It looks exactly the way the universe doesn't work. Nothing is rotating there and nothing is expanding there. But everything is collapsing again and again, in a straight line.
@SimulatingPhysics
@SimulatingPhysics 4 жыл бұрын
These simulations are very cool. But they completely lack numerical precision. Energy doesn't conserve in this simulations, although it is a fundamental physical law. Dark matter effects aren't implemented, and they have a big impact on galaxies rotation.
@tomjerry84
@tomjerry84 4 жыл бұрын
Rafael Lol, of course I know it😉😉
@GeneticResearch
@GeneticResearch Жыл бұрын
The simulation of the big bang, the following cosmic web and the big crunch at once.
@Noor.1011
@Noor.1011 2 жыл бұрын
بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ قُلْ هُوَ اللَّهُ أَحَدٌ (1) اللَّهُ الصَّمَدُ (2) لَمْ يَلِدْ وَلَمْ يُولَدْ (3) وَلَمْ يَكُنْ لَهُ كُفُوًا أَحَدٌ (4)
@mehmetalivat
@mehmetalivat 2 жыл бұрын
These verses are real and are the words of the creator who establishes the dynamics of the universe you live in. As for this simulation, it works within a limited computation, which is far from the truth for the actual galactic system. I understand your feelings, but this is not the place to share.
@Noor.1011
@Noor.1011 2 жыл бұрын
@@mehmetalivat My brother , I shared the the words because of a beautiful secret i am keeping for myself.
@petterlarsson7257
@petterlarsson7257 Жыл бұрын
this is basically a big bounce scenario lol
@student369
@student369 11 ай бұрын
Do you have any tutorial of GADGET-2 or GADGET-4 and AREPO?
@Leo_1157
@Leo_1157 2 жыл бұрын
How can i use this? Or where i have to use your Github codes?
@nicolasribeiro7914
@nicolasribeiro7914 2 жыл бұрын
Universe sandbox ³ looking great
@kris_soju
@kris_soju 3 жыл бұрын
Me a bachelor degree getting this Assignments
@AZ-be4hg
@AZ-be4hg 2 жыл бұрын
Any formulas?
@danielmichalski2436
@danielmichalski2436 Жыл бұрын
Oh no! The big crunch :D
@javiermachin1
@javiermachin1 2 жыл бұрын
This video deserves millions of views. Thanks for sharing.
@busterdafydd3096
@busterdafydd3096 3 жыл бұрын
I bet those doesn't deal with collisions
@muuubiee
@muuubiee 3 жыл бұрын
I think you have to do a distance check, so it'd be easy to add colissions.
@a2flo
@a2flo 2 жыл бұрын
Nope, it doesn't. But star collisions are also very unlikely. I would assume the number of star deaths/births is much greater than the number of star collisions, and I'm not simulating that either.
@TheMohan1986
@TheMohan1986 6 жыл бұрын
yeah wow, cos the universe is not sensitive to initial conditions, and is typically restricted... Great use of a solver software with clustering coefficients to describe how the universe truly began. You took no chances with that huh
@toshibamaster2210
@toshibamaster2210 4 жыл бұрын
somewhere you can find a portable version visual studio where it can be run quickly or even the image of the system disk so that it can be started immediately
@Pauly421
@Pauly421 4 жыл бұрын
Omg thats so cool! How do I run this program? :)
@CursedKyuubi
@CursedKyuubi 2 жыл бұрын
Beautiful are art piece, with great computing tech/person behind it. Nice work
@OriruBastard
@OriruBastard 2 жыл бұрын
Oh shit, it's starting form a brain! Hurry, turn it off before it gains consciousness! =0
Chaos and the Three Body Problem
9:10
Eliza Diggins
Рет қаралды 167 М.
Making an N-Body Simulation
9:03
Deadlock
Рет қаралды 13 М.
Please Help This Poor Boy 🙏
00:40
Alan Chikin Chow
Рет қаралды 17 МЛН
This is NVIDIA’s new GPU - Blackwell NVL72 Rack
12:58
Linus Tech Tips
Рет қаралды 1,6 МЛН
Realtime 2D Gravity Simulation
12:31
Brendan Galea
Рет қаралды 411 М.
Comparison of the Most Painful Punishments
15:42
ECHOES
Рет қаралды 2,1 МЛН
The Study No One Talks About
15:30
Video Advice
Рет қаралды 1,8 МЛН
Nvidia CUDA in 100 Seconds
3:13
Fireship
Рет қаралды 1,3 МЛН
Soft Body Physics Explained
10:47
Gonkee
Рет қаралды 535 М.
Newton’s three-body problem explained - Fabio Pacucci
5:31
N-body Simulations
30:43
Tatsuya Akiba
Рет қаралды 411