- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there any method to compute sum of powers without using extra space?
P.S. I need this to compute p-norm of the vector.
Link Copied
12 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Here are list of power functions implemented in IPP as per IEEE-754 standard.
http://software.intel.com/sites/products/documentation/hpc/ipp/ipps/ipps_ch12/ch12_Intro.html
Regards,
Naveen Gv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks.
But I need to compute the following:
s = pow(a[0], p) + pow(a[1], p) + ... + pow(a[n - 1], p)
To calculate such a sum I need an extra space because I can't destroy the original content of the array:
1. Use Powx function to compute powers:
b = pow(a, p), i = 0 .. n - 1
2. Use Sumfunction to compute sum:
s = b[0] + b[1] + ... + b[n - 1]
In certain situations I should also compute absolute values before computing powers.
The question was whether I could compute such sums without utilizing an extra space. Do you have any suggestions how to do it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
It does not look easy with IPP function call. If the code cares about the memory use it will cause, can it use a small temporary data block, for example, 128size ofdata? Calculate the first 128 data first, then next 128 data,etc.
Thanks,
Chao
It does not look easy with IPP function call. If the code cares about the memory use it will cause, can it use a small temporary data block, for example, 128size ofdata? Calculate the first 128 data first, then next 128 data,etc.
Thanks,
Chao
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting Chao Y (Intel)
Hello,
It does not look easy with IPP function call. If the code cares about the memory use it will cause, can it use a small temporary data block, for example, 128size ofdata? Calculate the first 128 data first, then next 128 data,etc.
Thanks,
Chao
It does not look easy with IPP function call. If the code cares about the memory use it will cause, can it use a small temporary data block, for example, 128size ofdata? Calculate the first 128 data first, then next 128 data,etc.
Thanks,
Chao
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
MKL vdPowx( n, a, b, y ) support in-place operation. You may call this function, put the out-put value into a, then sum the a value.
Thanks,
Chao
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting Chao Y (Intel)
MKL vdPowx( n, a, b, y ) support in-place operation. You may call this function, put the out-put value into a, then sum the a value.
Thanks,
Chao
double sum = 0.0;
for (int i = 0; i < n; ++i)
{
sum += pow(a, x);
}
But I was hoping to find a way to do it faster by using MKL and IPP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I think it should be possible to achieve that with call of two IPP functions (ippsPowx and ippsSum) something like pseudo code below
// allocate memory for vector ofresulted power values
// n - is lenght of vector
pow_a_x = ippMalloc(n*sizeof(Ipp32f))
Ipp32f x; //value of power you want to raise elements of vector a
//raise eachelements of vector a to power x
ippsPowx_32f_A24(a, x, pow_a_x);
Ipp32f sum;
// compute sum of elements of array pow_a_x
ippsSum_32f(pow_a_x, n, ∑, ippAlgHintAccurate);
Function ippsPowx declared in ippvm.h and function ippsSum decleared in ipps.h file. You will need to link with ipps.lib and ippvm.lib libraries.
Regards,
Vladimir
I think it should be possible to achieve that with call of two IPP functions (ippsPowx and ippsSum) something like pseudo code below
// allocate memory for vector ofresulted power values
// n - is lenght of vector
pow_a_x = ippMalloc(n*sizeof(Ipp32f))
Ipp32f x; //value of power you want to raise elements of vector a
//raise eachelements of vector a to power x
ippsPowx_32f_A24(a, x, pow_a_x);
Ipp32f sum;
// compute sum of elements of array pow_a_x
ippsSum_32f(pow_a_x, n, ∑, ippAlgHintAccurate);
Function ippsPowx declared in ippvm.h and function ippsSum decleared in ipps.h file. You will need to link with ipps.lib and ippvm.lib libraries.
Regards,
Vladimir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting Vladimir Dudnik (Intel)
Hello,
I think it should be possible to achieve that with call of two IPP functions (ippsPowx and ippsSum) something like pseudo code below
// allocate memory for vector ofresulted power values
// n - is lenght of vector
pow_a_x = ippMalloc(n*sizeof(Ipp32f))
Ipp32f x; //value of power you want to raise elements of vector a
//raise eachelements of vector a to power x
ippsPowx_32f_A24(a, x, pow_a_x);
Ipp32f sum;
// compute sum of elements of array pow_a_x
ippsSum_32f(pow_a_x, n, ∑, ippAlgHintAccurate);
Function ippsPowx declared in ippvm.h and function ippsSum decleared in ipps.h file. You will need to link with ipps.lib and ippvm.lib libraries.
Regards,
Vladimir
I think it should be possible to achieve that with call of two IPP functions (ippsPowx and ippsSum) something like pseudo code below
// allocate memory for vector ofresulted power values
// n - is lenght of vector
pow_a_x = ippMalloc(n*sizeof(Ipp32f))
Ipp32f x; //value of power you want to raise elements of vector a
//raise eachelements of vector a to power x
ippsPowx_32f_A24(a, x, pow_a_x);
Ipp32f sum;
// compute sum of elements of array pow_a_x
ippsSum_32f(pow_a_x, n, ∑, ippAlgHintAccurate);
Function ippsPowx declared in ippvm.h and function ippsSum decleared in ipps.h file. You will need to link with ipps.lib and ippvm.lib libraries.
Regards,
Vladimir
Currently I have several alternatives:
1. Allocate full length array and use MKL/IPP in the way similar to the one you proposed.
2. Do it manually. No extra space is required.
3. Allocate small array and compute the sum of powers by blocks (thanks to Chao Y for proposition).
It seems strange that such libraries like MKL and IPP doesn't have required functionality.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh, yes. I did not notice you already consider that variant. But I do not thinkit is really strange that libraries does not have this particular variant implemented as single call. More important they provide you with building blocks which are primitive enough that you may construct any variant. That is more flexible approach, I think.
Vladimir
Vladimir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are right, but in some situations (i.e. like this) there are not enough building blocks to perform required operations efficiently.
P. S. By the way, Intel IPP library has routines for computing L1, L2 or infinity norm, but has no routine to compute the general case (I mean p-norm).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Vitali,
are you bound to MKL/IPP?? Otherwise you could program a simple loop using intrinsics and short vector math library, see compiler documentation. You only need _mm_pow_pd, _mm_add_pd and a final _mm_hadd_pd.
Best regards, TJ
are you bound to MKL/IPP?? Otherwise you could program a simple loop using intrinsics and short vector math library, see compiler documentation. You only need _mm_pow_pd, _mm_add_pd and a final _mm_hadd_pd.
Best regards, TJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting TJ04
Vitali,
are you bound to MKL/IPP?? Otherwise you could program a simple loop using intrinsics and short vector math library, see compiler documentation. You only need _mm_pow_pd, _mm_add_pd and a final _mm_hadd_pd.
Best regards, TJ
are you bound to MKL/IPP?? Otherwise you could program a simple loop using intrinsics and short vector math library, see compiler documentation. You only need _mm_pow_pd, _mm_add_pd and a final _mm_hadd_pd.
Best regards, TJ
I am afraid that I'm bound to MKL+IPP (we don't use Intel Compiler), but in any case thanks for information.
Best regards,
Vitali.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page