Question

My goal is to develop and implement a green algorithm for some special situation. I have developed two algorithms for the same.

One is having large no. of memory accesses(load and store). The pattern is some time coalesced and some time non-coalesced. I am assuming a worst case where most of the access will result in cache failure. See sample Code snippet a).

Another is having large no. of calculations, roughly equivalent to the code snippet b) below.

How do I estimate power consumption in each case. Which one is more energy efficient and why?

Platform: I will be running these codes on Intel I3 processor, with Windows 7, with 4 GB DRAM, 3 MB Cache.

Note: I do not want to use any external power meter. Also please ignore if you find the code not doing any constructive job. This is because it is only fraction of the complete algorithm.

UPDATE:

It is difficult but not impossible. One can very well calculate the cost incurred in reading DRAMs and doing multiplications by an ALU of the CPU. The only thing is one must have required knowledge of electronics of DRAMS and CPU, which I am lacking at this point of time. At least in worst case I think this can very well be established. Worst case means no coalesced access, no compiler optimization.

If you can estimate the cost of accessing DRAM and doing a float multiplication , then why is it impossible for estimating the current, hence a rough idea of power during these operations? Also see me post, I am not asking how much power consumption is there, rather I am asking which code is consuming less/more power or which one is more energy efficient?

a) for(i=0; i<1000000; i++)

  {

  a[i]= b[i]; //a, b floats in RAM.  

  {




 b) for(i=1; i<1000000; i++)

  {

   float j= j * i;  //j has some value. which is used later in the program , not  
                    // shown here    

  {
Was it helpful?

Solution

To measure the actual power consumption you should use add an electricity meter to your power supply (remove the batteries if using a notebook).

Note that you will measure the power consumption of the entire system, so make sure to avoid nuisance parameters (any other system activity, i.e. anti-virus updates, graphical desktop environment, indexing services, (internal) hardware devices), perform measurements repeatedly, with and without your algorithms running to cancel out "background" consumption. If possible use an embedded system.


Concerning your algorithms, the actual energy efficiency depends not only on the C code but also on the performance of the compiler and also the runtime behavior in interaction with the surrounding system. However, here are some resources what you can do as developer to help on this:

Especially take a look on the paragraph Tools in above "Checklist", as it lists some tools that may help you on rough estimates (based on application profiling). It lists (besides others):

  • Perfmon
  • PwrTest/Windows Driver Kit
  • Windows Event Viewer (Timer tick change events, Microsoft-Windows-Kernel-PowerDiagnostic log)
  • Intel PowerInformer
  • Windows ETW (performance monitoring framework)
  • Intel Application Energy Toolkit

OTHER TIPS

Like commenters pointed out, try using a power meter. Estimating power usage even from raw assembly code is difficult if not impossible on modern superscalar architectures.

As long as only the CPU and memory are involved, you can assume power consumption is proportional to runtime.

This may not be 100% accurate, but as near as you can get without an actual measurement.

You can try using some CPU monitoring tools to see which algorithm heats your CPU more. It won't give you solid data but will show whether there is significant difference between these two algorithms in terms of power consumption.

Here I assume that the major power consumer is CPU and algorithms do not require heavy I/O.

Well, I have done with my preliminary research and discussions with electronics majors.

A rough idea can be get by considering two factors:

1- Currents involved: more current, more power dissipation.

2- Power Dissipation due to clock rate. Power dissipation varies with the square of the frequency.

In Snippet a) the DRAMs and memories hardly take much current, so the power dissipation will be very small during each

  a[i]= b[i];

operation. The above operation is nothing but data read and write.

Also the clocking for memories is usually very small as compared to CPU. While CPU is clocked at 3 GHz, memory is clocked at about 133MHz or so. (Not all components are running at rated clock). Thus power dissipation is lower because of lower clock.

In snippet b), It can be seen that I am doing more calculations. This will involve more power dissipation because of several order higher clock frequency.

Another factor is multiplication itself would comprise of several order higher no. of cycles as compared to data read write (provided memory is coalesced).

Also, it would be great to have an option for measuring or getting a rough idea of power dissipation ("code energy" )for some code as shown below(the color represent how energy efficient your code is, Red being very poor, and green being highly energy efficient ):

enter image description here

In short given today's technologies it is not very difficult for softwares to estimate power like this (and possibly taking many other parameters, in addition to how I described above). This will be useful for faster development and evaluation of green algorithms.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top