IMO, not using any optimization flags with C is somewhat arbitrary, since the compiler writers could have just decided that by default we'll do thing X, Y, and Z, and then you'd need to turn them off explicitly. FWIW, without -O, with -O, and with -O4, I get 2500ms, 1500ms, and 550ms respectively. I didn't bother to look at the .S to see the code improvements. (Of course, I edited the code to output the results, othe…
Optimizing the Particle Life: From 400 to 4M particles
41–50 of 71 posts
Re: Optimizing the Particle Life: From 400 to 4M particles
#42Earlier quoted context omitted.
There's no lack of "pixel-level performance optimisations" on GPUs, and just because basically the whole world seems to think that graphics programming == using some rasterisation library like OpenGL or DX or Vulkan or whatever for realtime applications, doesn't mean you're forced to use it or that that's all there is. Just fire up OpenCL (or CUDA, if you must) and start executing some data-parallel kernels.
Is vulkan strictly a rasterization library? I thought you could also do numeric calculations with compute shaders.
Re: Optimizing the Particle Life: From 400 to 4M particles
#43The thing that strikes me as particularly weird about this is the use of numpy there. In other languages, they're using native code. In python they're reaching out to numpy, which is a great library, but not awesome inside a hot loop unless you're keeping the operation you're carrying out within numpy itself. This means, right in that hot loop, they're doing a lot of translating of numbers between python representati…
This is the problem that Numba was designed to solve. https://numba.readthedocs.io/en/stable/user/5minguide.html
Numba is designed to speed up code where looping is unavoidable, i.e. the code can't be (easily) expressed as array OPs.
Re: Optimizing the Particle Life: From 400 to 4M particles
#44Re: Optimizing the Particle Life: From 400 to 4M particles
#45IMO, not using any optimization flags with C is somewhat arbitrary, since the compiler writers could have just decided that by default we'll do thing X, Y, and Z, and then you'd need to turn them off explicitly. FWIW, without -O, with -O, and with -O4, I get 2500ms, 1500ms, and 550ms respectively. I didn't bother to look at the .S to see the code improvements. (Of course, I edited the code to output the results, othe…
One optimization for the C code is to put "f" suffixes on the floating point constants. For example convert this line: t[i] += 0.02 * (float)j; to: t[i] += 0.02f * (float)j; I believe this helps because 0.02 is a double and doing double * float and then converting the result to float can produce a different answer to just doing float * float. The compiler has to do the slow version because that's what you asked for.…
In principle, not quite. The real/unavoidable(-by-the-compiler) problem is that 0.02 is a not a diadic rational (not representable exactly as some integer over a power of two). So its representation (rounded to 52 bits) as a double is a different real number than its representation (rounded to 23 bits) as a float. (This is the same problem as rounding pi or e to a double/float, but people tend to forget that it applies to all diadic irrationals, not just regular irrationals.)
If, instead of `0.02f` you replaced `0.02` with `(double)0.02f` or `0.015625`, the optimization should in theory still apply (although missed optimization complier bugs are of course possible).
Re: Optimizing the Particle Life: From 400 to 4M particles
#46Earlier quoted context omitted.
This is the problem that Numba was designed to solve. https://numba.readthedocs.io/en/stable/user/5minguide.html
No. The problem in this post can be vectorized (== expressed as array OPs) with idiomatic numpy, making it very fast (see sibling comment). Numba is designed to speed up code where looping is unavoidable, i.e. the code can't be (easily) expressed as array OPs.
Re: Optimizing the Particle Life: From 400 to 4M particles
#47The thing that strikes me as particularly weird about this is the use of numpy there. In other languages, they're using native code. In python they're reaching out to numpy, which is a great library, but not awesome inside a hot loop unless you're keeping the operation you're carrying out within numpy itself. This means, right in that hot loop, they're doing a lot of translating of numbers between python representati…
Re: Optimizing the Particle Life: From 400 to 4M particles
#48[deleted]
Re: Optimizing the Particle Life: From 400 to 4M particles
#49Earlier quoted context omitted.
No. The problem in this post can be vectorized (== expressed as array OPs) with idiomatic numpy, making it very fast (see sibling comment). Numba is designed to speed up code where looping is unavoidable, i.e. the code can't be (easily) expressed as array OPs.
Negative again, a series of array operations which are individually idiomatic numpy like this will run very very fast in numba as it can coalesce the ops into a single pass through memory. Numpy can't do this and has to pass through the array for each individually array operation. There's nothing wrong with straight numpy but if you want it compiled-C fast for the whole ensemble of array ops, you need a JIT.
Do you have a source for this? I have not seen it in the numba docs.