numenta/nupic.core — pull request #273 by breznak (2014-12-27 23:09:14+00:00)
Title: c++ compiler optimizations

This PR adds C++ speed optimizations, quite aggressive but well supported by both compilers.
`-Ofast` : C++ compiler optimizations > -O3
`-march=native` : enables SSE specific for the machine

Benchmark:
* I did a fairy simple benchmark on `SP.compute()` (`nupic.bindings.algorithms.SpatialPooler`, 100 iterations) - small improvement
* `TP.compute()` (`nupic.research.TP10X2`, 10k iterations) - cca 25% improvement in `Cells4.compute()`!
* I didn't test other methods yet (any good candidates?)
* each with 10 repetitions

Example:
No opt:
`nupic_py27mmm@mmm-U2442:~/nupic/nupic-source$ python -m cProfile -s cumtime sp_large.py
New seed generated as: 5579 called by line 98 -> testCompute1
352731 function calls (350799 primitive calls) in 37.648 seconds

Ordered by: cumulative time

ncalls tottime percall cumtime percall filename:lineno(function)
1 0.040 0.040 37.649 37.649 sp_large.py:27()
1 0.573 0.573 37.399 37.399 sp_large.py:48(testCompute1)
10000 0.178 0.000 34.923 0.003 TP10X2.py:288(compute)
10000 0.015 0.000 28.951 0.003 algorithms.py:2690(compute)
10000 28.936 0.003 28.936 0.003 {_algorithms.Cells4_compute}
10000 2.062 0.000 5.599 0.001 TP.py:1261(computeOutput)
10000 3.493 0.000 3.493 0.000 {method 'astype' of 'numpy.ndarray' objects}
1 0.000 0.000 1.673 1.673 algorithms.py:3108(__init__)
1 1.672 1.672 1.672 1.672 {_algorithms.SpatialPooler_initialize}
1 0.000 0.000 0.230 0.230 TP10X2.py:74(__init__)
`

with this PR:
`nupic_py27mmm@mmm-U2442:~/nupic/nupic-source$ python -m cProfile -s cumtime sp_large.py
New seed generated as: 8410 called by line 98 -> testCompute1
352731 function calls (350799 primitive calls) in 20.827 seconds

Ordered by: cumulative time

ncalls tottime percall cumtime percall filename:lineno(function)
1 0.018 0.018 20.828 20.828 sp_large.py:27()
1 0.304 0.304 20.604 20.604 sp_large.py:48(testCompute1)
10000 0.098 0.000 18.550 0.002 TP10X2.py:288(compute)
10000 0.008 0.000 15.384 0.002 algorithms.py:2690(compute)
10000 15.376 0.002 15.376 0.002 {_algorithms.Cells4_compute}
10000 1.095 0.000 2.965 0.000 TP.py:1261(computeOutput)
10000 1.846 0.000 1.846 0.000 {method 'astype' of 'numpy.ndarray' objects}
1 0.000 0.000 1.656 1.656 algorithms.py:3108(__init__)
1 1.656 1.656 1.656 1.656 {_algorithms.SpatialPooler_initialize}
1 0.002 0.002 0.101 0.101 __init__.py:106()
1 0.000 0.000 0.093 0.093 TP10X2.py:74(__init__)
`

TODO:
[ ] @david-ragazzi I noticed all optimizations were removed from the build-files (?), is it enough to place it here, or must be added to `setup.py` in nupic? Also, there was a (left-over?) `-O3` flag for OSX.
[ ] @rhyolight the `-march=native` flag will break the binary artifacts imho; but I think the user should get the best-possible experience(performance) when they compile this repo. So we could override the `-mtune` to some reasonable default in nupic repo `setup.py` where the artifacts are published ?

Fixes #192