-
Notifications
You must be signed in to change notification settings - Fork 485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arithmetic optimizations #550
Comments
Jibril, a couple of comments:
I hope this makes sense. If so, it'd be great if you added some of 2 and 3 to your PR. One issue with this kind of changes is that we always have many balls in the air in various feature branches (some of them quite long-lived), so there's always the issue of merge conflicts. But that's something we can deal with. |
On a different note: you mention working on a new module. It'd be great if you could give us a bit more details (we can take this offline if needed). The reasons I ask are:
|
@rserban thank you for a prompt and informative response. With regards to the module, I recently joined a team who works on lattice methods for mesoscopic materials modeling (e.g., LDPM for concrete https://github.com/Concrete-Chrono-Development/chrono-concrete). With regards to 3. I see that BULLET ( chrono/src/chrono/collision/bullet/BulletCollision/CollisionShapes/cbtBoxShape.cpp Line 38 in 09caa3e
which makes me think adding double constants should cover most cases.
I will go on and add some of these changes to #549 Thank you |
Hello,
I am developing a new module and taking inspiration from the existing code.
I notice many instances of floating point operations that I find unusual in terms of readability, code duplication, or performance, e.g.,
square roots using
pow(x, 0.5)
and cubic root usingpow(x, 1. / 3.)
instead ofsqrt(x)
andcbrt(x)
chrono/src/chrono_modal/ChModalAssembly.cpp
Line 710 in 09caa3e
powers using
pow(x, N)
instead ofx*x*...
chrono/src/chrono/fea/ChBeamSectionCosserat.cpp
Lines 154 to 158 in 09caa3e
divisions
chrono/src/chrono/core/ChTensors.h
Line 186 in 09caa3e
For 1, I proposed arithmetic modifications for readability and performance #549
For 2. although many modern compilers are usually able to eliminate repeated sub-expressions, or optimize
std::pow
for integer exponents, I found GCC to be much slower for an operation likestd::pow(x, 3)
compared tox*x*x
, even with flag-O3
(e.g., my Ubuntu Release build of Chrono with GCC 13.3.0, and tests on godbolt I could share if there is interest. Only tests with flag-ffast-math
, which allows non-compliant code, showed negligible difference).pow
throughout the code base? Have benchmarks ruled out possible performance hits compared to bare multiplications?For 3. compilers likely won't replace the division by a reciprocal and faster multiplication for values that are not powers of 2 (for the same standard-compliant reasons discussed above).
x / 3.
by multiplications with constants that can be evaluated at compile time, e.g.,x * (1. / 3.)
(I saw plenty of those throughout the code) ? If so, would defining such constant expressions (e.g.CH_1_3
, similar to e.g.CH_PI
inChConstants.h
) be helpful for readability, and systematic replacement ofx / 3.
byx * CH_1_3
preferred?I appreciate your perspective and insight.
I would be more than happy to take on these tasks.
Jibril
The text was updated successfully, but these errors were encountered: