Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

Uniform Random Noise Generation problem

Aaron_A_
Beginner
366 Views

I'm trying to generate some random uniform noise using IPP but am stuck.  The IppsRandUniState_64f is not fully defined, so I'm not sure how to allocate the necessary memory.  In the past in IPP, one used RandUniformInitAlloc, but this is deprecated and gone.  I can't find any examples, so if someone can point out how to allocate and free the memory for the random state variable it would be greatly appreciated.

My code:

		Ipp64f* phaseArr = ippsMalloc_64f(halfLen+1);
		int randUniSize;
		ippsRandUniformGetSize_64f(&randUniSize);
		IppsRandUniState_64f* ipRandState = (IppsRandUniState_64f*)ippMalloc_8u(randUniSize);

		ippsRandUniformInit_64f(ipRandState, 0, 2*M_PI, clock());
		ippsRandUniform_64f(phaseArr, halfLen+1, ipRandState);
		if( ipRandState )
			ippFree(ipRandState);

Edit: Simple fix.  4th line of code fixed and it compiles fine.

0 Kudos
1 Reply
Igor_A_Intel
Employee
366 Views

Hi Aaron,

your understanding is absolutely correct: starting from 9.0 version IPP doesn't make any internal memory allocations - all of them must be done at the application side. The algorithm is very simple -

1) query required amount of memory for internal spec/state structure

2) allocate this memory at the app side

3) init this memory with the corresponding IPP function 

4) then use corresponding processing function

5) free this memory at the app side when your app doesn't need this functionality any more

I slightly modified your example in order to show that it works properly:

#include <stdio.h>
#include "ipp.h"

#define LEN 15

int main(void){
    int halfLen = LEN;
    Ipp64f* phaseArr = ippsMalloc_64f(halfLen+1);
    int randUniSize;

    ippsRandUniformGetSize_64f(&randUniSize);
    IppsRandUniState_64f* ipRandState = (IppsRandUniState_64f*)ippMalloc(randUniSize);

    ippsRandUniformInit_64f(ipRandState, 0, IPP_2PI, 0);
    ippsRandUniform_64f(phaseArr, halfLen+1, ipRandState);
    if( ipRandState )
    {
        ippFree(ipRandState);
    }
    for (int i = 0; i < halfLen + 1; i++ )
    {
        printf("phaseArr[%d] = %f\n", i, phaseArr);
    }
    ippsFree( phaseArr);
    return 0;
}

output:

phaseArr[0] = 2.212923
phaseArr[1] = 4.827087
phaseArr[2] = 5.894064
phaseArr[3] = 0.542820
phaseArr[4] = 0.041538
phaseArr[5] = 3.993393
phaseArr[6] = 1.864890
phaseArr[7] = 5.064686
phaseArr[8] = 3.053310
phaseArr[9] = 6.279690
phaseArr[10] = 4.524316
phaseArr[11] = 3.683678
phaseArr[12] = 6.067083
phaseArr[13] = 2.589079
phaseArr[14] = 2.736621
phaseArr[15] = 5.487123
Press any key to continue . . .
 

regards, Igor

0 Kudos
Reply