Tuesday, 1 April 2014

Energy Efficiency for C Programmers

In one of my previous posts  titled "How software goes Green", I had propose that a design for resource efficiency leads to energy efficient software. What can we do as programmer ? Extend this to programming.

As with performance engineering, 70-80% of the energy profile of an application can be addressed by good design (better data structures, better algorithms). The remaining 20-30% needs some support from coding. I would warn the readers that code hand tuning is not the most rewarding process, unless for some reason you are hard pressed to squeeze the last bit of energy consumption out of the application. It is useful in thin infrastructure components and platforms, where their is a lot of functionality but the complexity (perhaps indicated by call stack depth) is low. Or some function/routine is so frqeuently used that it becomes a significant contributor to the overall energy consumption of the software.

Tune code for least runtime instruction cost (not size). As a general the fewer the runtime instructions, the more energy efficient the code will be. Unrolling small loops, were the cost of setting up a loop (initialization condition, exit condition and loop progression) is comparable to the cost of the loop body. Similarly using vector instructions will tak emuch less energy as one instruction does the jpb of many. avoid unwanted memsets, memcopy etc.  Also multi-core is the norm today, not exception. If a large computation can be paralleized across cores, its better to do that rather than run one core to its peak power for longer duration.

You can refer to any code performance tuning material for such examples. 


No comments:

Post a Comment