cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Observer
Observer
519 Views
Registered: ‎04-08-2019

[Model Composer] Huge BRAM usage when using custom blocks

Jump to solution

Hallo,

I'm trying to working on a Bayer-Sensor video format in Model Composer.

My IP-Core get a bayer-pattern video (BGGR) as input and output. It should apply four diffrent gain values to the coresponding pixel.

For that I build a custom block in C:

#include <stdint.h>
template <int HEIGHT, int WIDTH>
void gain_bayer_bggr(const uint16_t in[HEIGHT][WIDTH], const uint32_t gain, uint16_t out[HEIGHT][WIDTH]) {
	uint16_t gain_b  = (uint16_t)(      gain & 0xFF);
	uint16_t gain_g1 = (uint16_t)((gain>>8)  & 0xFF);
	uint16_t gain_g2 = (uint16_t)((gain>>16) & 0xFF);
	uint16_t gain_r  = (uint16_t)((gain>>24) & 0xFF);

    for (int i = 0; i<HEIGHT; i++) {
		for (int j = 0; j<WIDTH; j++) {
        	#pragma HLS PIPELINE II=1
            if(!(i&1)) {
                if(!(j&1)){
                    out[i][j] = in[i][j]*gain_b;
                } else {
                    out[i][j] = in[i][j]*gain_g1;
                }
            } else {
                if(!(j&1)){
                    out[i][j] = in[i][j]*gain_g2;
                } else {
                    out[i][j] = in[i][j]*gain_r;
                } 
            }
        }
    }
}

My top-level-subsystem has two inputs and one output. One input and the output are defined as axi4-stream (video) mono. At the second input, the gain factor is applyed. The video resolution is 2560 x 720 pixel.

After compiling, the report show me 186% BRAM usage. 

    * Memory: 
    +------------------------+----------------------+---------+----+----+---------+-----+------+-------------+
    |         Memory         |        Module        | BRAM_18K| FF | LUT|  Words  | Bits| Banks| W*Bits*Banks|
    +------------------------+----------------------+---------+----+----+---------+-----+------+-------------+
    |VideoIn_adapter_out1_U  |gain_bayer_bggr_mcud  |     1688|  32|   0|  1843200|   16|     1|     29491200|
    |gain_bayer_bggr_main_U  |gain_bayer_bggr_mcud  |     1688|  32|   0|  1843200|   16|     1|     29491200|
    +------------------------+----------------------+---------+----+----+---------+-----+------+-------------+
    |Total                   |                      |     3376|  64|   0|  3686400|   32|     2|     58982400|
    +------------------------+----------------------+---------+----+----+---------+-----+------+-------------+

Is it possible to work with huge videoresolutions like this?
How can I prevent xmc to save the input image in the ram?

Best regards
Sebastian

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Xilinx Employee
Xilinx Employee
475 Views
Registered: ‎08-11-2017

Hi Sebastian, 

Please take a look at the 2018.3 user guide (UG1262, page 46). You need to explicitly tell the tool that the funciton you are importing supports streaming. The user guide explains what that means. Once you do that, you will see that your BRAM usage will be very little. 

I took your example and added the pragma at the top.

#include <stdint.h>
#pragma XMC SUPPORTS_STREAMING
template <int HEIGHT, int WIDTH>

...

For my device, the desgin uses only 4 BRAMS. 

Please try this and let me know if it works for you. 

Thanks

 

View solution in original post

0 Kudos
2 Replies
Highlighted
Xilinx Employee
Xilinx Employee
476 Views
Registered: ‎08-11-2017

Hi Sebastian, 

Please take a look at the 2018.3 user guide (UG1262, page 46). You need to explicitly tell the tool that the funciton you are importing supports streaming. The user guide explains what that means. Once you do that, you will see that your BRAM usage will be very little. 

I took your example and added the pragma at the top.

#include <stdint.h>
#pragma XMC SUPPORTS_STREAMING
template <int HEIGHT, int WIDTH>

...

For my device, the desgin uses only 4 BRAMS. 

Please try this and let me know if it works for you. 

Thanks

 

View solution in original post

0 Kudos
Highlighted
Observer
Observer
438 Views
Registered: ‎04-08-2019

Hi,

many thanks. Now it works much better.
Not as less resources as a XSG-solution but better.
Sometimes it is better to read a document with open eyes. :-)

Best regards,

Sebastian

0 Kudos