Comments (3)
That's pretty good for exp. For log
it is usually helpful to take advantage of the fact that most CPUs can usually domain/range reduce for you to just one multiple of two. Specifically, any IEEE float (single, double, probably even half-precision) has an exponent field which tells you the logarithm base 2 up to the mantissa field. So, if yo are willing to assume IEEE float representation then you only actually need a good fast approximation of log_2
on [1/2,1)
or [1,2)
. (log base e
of course is just re-scaled log_2
).
In the past I've done the mantissa part with a mixture of Taylor series for near 1 and Padé approximants for further away. That got down to about 60 to 17 cycles on Intel core2 series from Nehalem to Skylake, respectively, for a 1e-7 relative error single precision log, anyway.
There may be a faster approach than Taylor/Padé, but it seemed very likely the "IEEE exponent field" trick would be applicable to whatever you do if you're willing to assume IEEE. I also perused your references and didn't see it mentioned. They seem more exp
-focused, but log
is generally more poorly optimized by various stdlibs/vendors in my experience.
(edit: clarified performance mention in time and accuracy)
from laser.
Well, when you do get to log, I suggest as a starting point these blog posts from some Ebay guy. {That material didn't exist back when I was figuring this out for myself :-) } :
https://www.ebayinc.com/stories/blogs/tech/fast-approximate-logarithms-part-i-the-basics/
https://www.ebayinc.com/stories/blogs/tech/fast-approximate-logarithms-part-ii-rounding-error/
https://www.ebayinc.com/stories/blogs/tech/fast-approximate-logarithms-part-iii-the-formulas/
He never really mentions Padé approximants, though his rational approximations are similar. He argues for a [3/4, 6/4) interval. (As mentioned, any [t,2t) works - whatever gets you a fast, well approximated "shifted mantissa".) Seems like if you have all this Intel-specific SIMD code, assuming IEEE (even little-endian IEEE) is not much of a stretch.
Particularly with log, there can be unavoidable speed/accuracy trade-offs. So, you may want to have a Nim call that accepts a target precision (and conceivably even returns an error estimate), and then just default it to 23 bits for float32 and 51 bits for float64 and let the call-site use a larger error when faster performance is desired and in-context lower accuracy is acceptable.
from laser.
Log focus is coming, I didn't get to that yet.
from laser.
Related Issues (20)
- Create a benchmark script
- Transpose does not scale well with multithread
- Devel regression "object constructor needs an object type" HOT 1
- Fast image loading primitives
- Fused assignation shortcut
- [GEMM] Enhance serial implementation HOT 1
- gemm_strided: error: always_inline function '_mm256_setzero_pd' requires target feature 'xsave' HOT 1
- performance of gemm_strided vs numpy HOT 1
- System Profile Dual Xeon Gold 6154
- Regression on GEMM allocation HOT 3
- NUMA-aware memory allocation and computation
- [Lux] Multithreading for JIT code
- [GEMM] Significant performance regression (divided by 5) HOT 2
- [Gemm] Nim devel compiler gets stuck when compiling older commits HOT 1
- parallel reduction HOT 6
- [Showstopper regression] emit does not generate proper symbol HOT 1
- [Benchmarks] Cleanup fp_reduction_latency benchmarks
- Mysterious 2x perf regression on GEMM HOT 2
- performance of avx512 bit ops and popcounts HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laser.