cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
vonbk
Observer
Observer
9,839 Views
Registered: ‎11-21-2009

Huge BRAM usage

Jump to solution

Hi all,

 

I'm the newbie with Vivado HLS tool ( my version is 2013.1)

 

I declared the huffman_code2_t as follows:

 

//------------------------------------------ Below ---------------------------------

 

typedef ap_uint<1> data1bit_t;
typedef ap_uint<2> data2bit_t;
typedef ap_uint<3> data3bit_t;
typedef ap_uint<4> data4bit_t;
typedef ap_uint<5> data5bit_t;
typedef ap_uint<6> data6bit_t;
typedef ap_uint<16> data16bit_t;
typedef ap_uint<17> data17bit_t;
typedef unsigned char index_t;
typedef unsigned char code_t;
typedef hls::stream<data16bit_t> stream;
 
typedef struct {
data1bit_t mincode1bit;
index_t idx_1bit; 
data2bit_t mincode2bit;
index_t idx_2bit; 
data3bit_t mincode3bit;
index_t idx_3bit; 
data4bit_t mincode4bit;
index_t idx_4bit; 
data5bit_t mincode5bit;
index_t idx_5bit; 
data16bit_t bitmask; 
data16bit_t cur_mincode;
unsigned char codelen[16]; 
code_t code[256]; 
} huffman_code2_t;

 

//------------------------------------------ Above ---------------------------------

 

And I also declared huffman_code[4] variable at test.cpp as follow

 

//---------------------------------------- Below ---------------------------------------

huffman_code2_t  huffman_code[4];

//---------------------------------------- Above ---------------------------------------

 

The synthesis result reported that HLS mapped huffman_code[4] into 12BRAM elements

This result is so surprised, since the bitwidth of  mincode1bit, mincode2bit ... are smaller than 16bits.

I think that  HLS should map these variables to LUT instead of BRAM.

I tried to achieve my expected result with some ways ( tcl, #pragma ) but I could not get the 

expected result yet ( mapping small field into LUT)

 

Would you please teach me what I should do ?

 

Attached is my test code and synthesis result.

 

Best regards,

vonbk

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
debrajr
Moderator
Moderator
13,993 Views
Registered: ‎04-17-2011
Use below directives to use LUT instead of BRAM for your array resource
set_directive_resource -core RAM_1P_LUTRAM test huffman_code
#pragma HLS resource variable=huffman_code core=RAM_1P_LUTRAM

Refer UG902 for more details.
Regards,
Debraj
----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------

View solution in original post

4 Replies
vonbk
Observer
Observer
9,836 Views
Registered: ‎11-21-2009

This website rejected my tgz file %_%

 

Following is test.cpp code

 

#include "huffman_type.h"

huffman_code2_t  huffman_code[4];

int test(stream &in_stream, stream &out_stream) {
    int i;
    int j;
    huffman_code2_t *ptr;
    for(i=0;i<4;i++) {
        ptr = &huffman_code[i];
        ptr->mincode1bit = in_stream.read();
        ptr->idx_1bit    = in_stream.read();
        ptr->mincode2bit = in_stream.read();
        ptr->idx_2bit    = in_stream.read();
        ptr->mincode3bit = in_stream.read();
        ptr->idx_3bit    = in_stream.read();
        ptr->mincode4bit = in_stream.read();
        ptr->idx_4bit    = in_stream.read();
        ptr->mincode5bit = in_stream.read();
        ptr->idx_5bit    = in_stream.read();
        ptr->bitmask     = in_stream.read();


        for(j=0;j<256;j++) {
            ptr->code[j] = in_stream.read();
        }

        out_stream.write(ptr->mincode1bit );
        out_stream.write(ptr->idx_1bit    );
        out_stream.write(ptr->mincode2bit );
        out_stream.write(ptr->idx_2bit    );
        out_stream.write(ptr->mincode3bit );
        out_stream.write(ptr->idx_3bit    );
        out_stream.write(ptr->mincode4bit );
        out_stream.write(ptr->idx_4bit    );
        out_stream.write(ptr->mincode5bit );
        out_stream.write(ptr->idx_5bit    );
        out_stream.write(ptr->bitmask     );


        for(j=0;j<256;j++) {
            out_stream.write(ptr->code[j]); 
        }
    }
    return 0;   
}

 

Next is main_tb.cpp

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char* argv[]) {
    return 0;
}

 And Vivado run.tcl script

 

catch {eval exec "uname -m"} machine_name
catch {eval exec "uname -s"} kernel_name
catch {eval exec "vivado_hls -r"} vivado_hls_home
catch {eval exec "pwd" } current_dir

if {$machine_name == "x86_64" && $kernel_name == "Linux"} {
    set gcc_lib $vivado_hls_home/lnx64/tools/gcc/lib64
} elseif {$machine_name == "i686" && $kernel_name == "Linux"} {
    set gcc_lib $vivado_hls_home/lnx32/tools/gcc/lib
} else {
    set gcc_lib $vivado_hls_home/msys/lib/gcc/mingw32/4.6.2
}
set ::env(LD_LIBRARY_PATH) $gcc_lib:$::env(LD_LIBRARY_PATH)

# Create the design project
open_project prj -reset

# Define the top level function for hardware synthesis
set_top test
# Select the files for hardware synthesis
add_files test.cpp

# Select the files required for the testbench
add_files -tb main_tb.cpp

# Set the name of the solution for this design
open_solution "solution1"

# Select the FPGA 
set_part "xc7z020clg484-1"
create_clock -period "150MHz"

# Set flags
set csim_flag 1
if { [info exists ::env(csim_flag)] } {
    set csim_flag $::env(csim_flag)
}
set csynth_flag 1
if { [info exists ::env(csynth_flag)] } {
    set csynth_flag $::env(csynth_flag)
}
set cosim_flag 0
if { [info exists ::env(cosim_flag)] } {
    set cosim_flag $::env(cosim_flag)
}
set export_flag 1
if { [info exists ::env(export_flag)] } {
    set export_flag $::env(export_flag)
}

puts "csim_design start"

if { $csim_flag == 1 } {
    # Vivado HLS commands for C simulation
    csim_design -mflags -j4 -O -argv "${current_dir}/lena100.jpg"
}
puts "csim_design done"
if { $csynth_flag == 1 } {
    # Vivado HLS commands for C to RTL synthesis
    csynth_design
}

if { $cosim_flag == 1 } {
    # Vivado HLS commands for RTL simulation
    cosim_design
}

if { $export_flag == 1 } {
    # Vivado HLS commands for RTL implementation
    export_design
}

exit

 Please generate the result with vivado_hls -f run.tcl

0 Kudos
debrajr
Moderator
Moderator
13,994 Views
Registered: ‎04-17-2011
Use below directives to use LUT instead of BRAM for your array resource
set_directive_resource -core RAM_1P_LUTRAM test huffman_code
#pragma HLS resource variable=huffman_code core=RAM_1P_LUTRAM

Refer UG902 for more details.
Regards,
Debraj
----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------

View solution in original post

vonbk
Observer
Observer
9,799 Views
Registered: ‎11-21-2009

Hi Debraj,

 

Your solution works perfectly.

 

I have futher question, if I want HLS map one field of huffman_code on BRAM such as huffman_code[N].code 

What should I do ?

 

Best regards,

vonbk

0 Kudos
debrajr
Moderator
Moderator
9,780 Views
Registered: ‎04-17-2011
Refer to the UG902 and look for RAM_1P_BRAM. It would ensure that the array is implemented as BRAM.
Regards,
Debraj
----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
0 Kudos