UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor guenselmann
Visitor
309 Views
Registered: ‎12-03-2018

CORDIC IP bit-accurate C-model sqrt memory leak

Jump to solution

Hello,

first of all sorry if I posted this in the wrong category. Not sure where else it belongs.

We are currently developing a hardware-implementation of an image-processing algorithm for which we need to perform a lot of (~50 mil.) square roots on unsigned integers. For this we want to use a pipelined Xilinx CORDIC core, but we are having problems with the bit-accurate c-model. I noticed that the memory usage of my software-reference design rises steadily over the cause of execution until it eventually crashes.

I have narrowed down the cause to be the xip_cordic_v6_0_sqrt function or the way I am using it. It seems to be leaking memory every time it is called and since I input only one 1x1 xip_array_real at a time and call the function millions of times I encounter this problem.

This is the way I am calling the square root function:

 

unsigned short XilinxSqrt::sqrt_cordic(unsigned long input) {
    xip_real mag_in_samp;
    xip_real mag_out_samp;
    
    mag_in_samp = static_cast<xip_real>(input);

    // Set Input Data
    if (xip_cordic_v6_0_xip_array_real_set_data(magin, mag_in_samp, 0) != XIP_STATUS_OK) {
        cerr << "Error in xip_cordic_v6_0_xip_array_real_set_data" << endl;
        exit(2);
    }
    
    // Perform square root
    if (xip_cordic_v6_0_sqrt(cordic_std, magin, magout, 1) != XIP_STATUS_OK) {
        cerr << "ERROR: C model did not complete successfully" << endl;
        if (magin) xip_array_real_destroy(magin);
        if (magout) xip_array_real_destroy(magout);
        xip_cordic_v6_0_destroy(cordic_std);
        exit(2);
    }
    
    // Get output data from the array type
    if (xip_cordic_v6_0_xip_array_real_get_data(magout, &mag_out_samp, 0) != XIP_STATUS_OK) {
        cerr << "Error in xip_cordic_v6_0_xip_array_real_get_data" << endl;
        exit(2);
    }
    
    unsigned short output = mag_out_samp;
    return output;
}

 

magin and magout are pointers created elsewhere:

 

    xip_cordic_v6_0_config config, config_ret; //configuration of the CORDIC core
    xip_cordic_v6_0 *cordic_std; //pointer to the CORDIC core
    xip_array_real *magin = xip_array_real_create(); //input data type
    xip_array_real *magout = xip_array_real_create(); //output data type

 

 

 

At the beginning (before the first sqrt), a CORDIC core is instantiated once similar to the example application and with the following configuration:

 

XilinxSqrt::XilinxSqrt(const bool dbg) {
    if (dbg == true) {
        cout << endl << "Attempting configuration and initialization of Xilinx CORDIC IP bit-accurate C-model..." << endl;
    }
    
    //Apply default config
    xip_status status = xip_cordic_v6_0_default_config(&config);
    if (status != XIP_STATUS_OK) {
        cerr << "ERROR: Could not get C model default configuration" << endl;
        exit(1);
    }
    
    //Set up config for the desired square root
    config.CordicFunction = XIP_CORDIC_V6_0_F_SQRT;
    config.CoarseRotate = 0;
    config.DataFormat = XIP_CORDIC_V6_0_FORMAT_USIG_INT;
    config.PhaseFormat = XIP_CORDIC_V6_0_FORMAT_RAD;
    config.InputWidth = 32;
    config.OutputWidth = 17; //has to be InputWidth/2+1 for square root. MSB will be discarded after calculation
    config.Precision = 0;
    config.RoundMode = XIP_CORDIC_V6_0_ROUND_TRUNCATE;
    config.ScaleComp = XIP_CORDIC_V6_0_SCALE_NONE;

    //Create a CORDIC model object
    cordic_std = xip_cordic_v6_0_create(&config, &msg_print, 0);
    if (status != XIP_STATUS_OK) {
        cerr << "ERROR: Could not create C model state object" << endl;
        exit(1);
    }

    //Can we read back the updated configuration correctly?
    if (xip_cordic_v6_0_get_config(cordic_std, &config_ret) != XIP_STATUS_OK) {
        cerr << "ERROR: Could not retrieve C model configuration" << endl;
        exit(1);
    }
    if (dbg == true) {
        cout << "Configuration:" << endl;
        cout << "Function        = " << config_ret.CordicFunction << endl;
        cout << "Coarse Rotation = " << config_ret.CoarseRotate << endl;
        cout << "Data Format     = " << config_ret.DataFormat << endl;
        cout << "Phase Format    = " << config_ret.PhaseFormat << endl;
        cout << "Input Width     = " << config_ret.InputWidth << endl;
        cout << "Output Width    = " << config_ret.OutputWidth << endl;
        cout << "Iterations      = " << config_ret.Iterations << endl;
        cout << "Precision       = " << config_ret.Precision << endl;
        cout << "Round Mode      = " << config_ret.RoundMode << endl;
        cout << "Scale Comp      = " << config_ret.ScaleComp << endl;
    }
    
    // Create input data packet for Magnitude In
    xip_array_real_reserve_dim(magin, 1); //dimensions are (Number of samples)
    magin->dim_size = 1;
    magin->dim[0] = 1;
    magin->data_size = magin->dim[0];
    if (xip_array_real_reserve_data(magin, magin->data_size) == XIP_STATUS_OK) {
        if (dbg == true)
            cout << "INFO: Reserved memory for request as [" << magin->data_size << "] array " << endl;
    } else {
        cout << "ERROR: Unable to reserve memory for input data packet!" << endl;
        exit(1);
    }

    // Create output data packet for Magnitude Out
    xip_array_real_reserve_dim(magout, 1); //dimensions are (Number of samples)
    magout->dim_size = 1;
    magout->dim[0] = 1;
    magout->data_size = magout->dim[0];
    if (xip_array_real_reserve_data(magout, magout->data_size) == XIP_STATUS_OK) {
        if (dbg == true)
            cout << "INFO: Reserved memory for request as [" << magout->data_size << "] array " << endl;
    } else {
        cout << "ERROR: Unable to reserve memory for output data packet!" << endl;
        exit(1);
    }
    
    if (dbg == true) {
        cout << "Xilinx CORDIC IP core model set up successfully!" << endl << endl;
    }
}

 

 

 

The calculated results are fine; so far they always matched the standard C++ sqrt(). I already tried creating a new CORDIC core every time I need an sqrt and destroying it after, but I get the same memory leakage. Same when I create and free magin and magout every time.

Thanks for reading and any support you may be able to provide!

 

1 Solution

Accepted Solutions
Highlighted
Xilinx Employee
Xilinx Employee
171 Views
Registered: ‎09-18-2018

Re: CORDIC IP bit-accurate C-model sqrt memory leak

Jump to solution

Hi ,

 

This is identified as an issue and is fixed. An AR will be created and released shortly with the patch.

2 Replies
Visitor guenselmann
Visitor
254 Views
Registered: ‎12-03-2018

Re: CORDIC IP bit-accurate C-model sqrt memory leak

Jump to solution

Since this has not been aswered so far, may ask how to get in contact with Xilinx technical support directly? When I log into the Support Center, I cannot find an option to create a new support case. We are using paid (floating) licenses.

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
172 Views
Registered: ‎09-18-2018

Re: CORDIC IP bit-accurate C-model sqrt memory leak

Jump to solution

Hi ,

 

This is identified as an issue and is fixed. An AR will be created and released shortly with the patch.