Skip to content

Commit ebd6ed1

Browse files
jgavillalobosErickOF
authored andcommitted
Add compression block to TLM TB
1 parent 5c2dbc0 commit ebd6ed1

File tree

7 files changed

+121
-13
lines changed

7 files changed

+121
-13
lines changed

modules/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ EDGE_DIR=../edge-detector
2626
GRAY_DIR=../rgb2gray
2727
FILTER_DIR=../filter
2828
UNIFICATION_DIR=../unification
29+
COMPRESSION_DIR=../compression
2930

30-
SRCDIRS=$(SRCDIR) $(EDGE_DIR)/src $(GRAY_DIR)/src $(FILTER_DIR)/src $(UNIFICATION_DIR)/src
31-
INCDIR+=-I$(EDGE_DIR)/include -I$(GRAY_DIR)/include -I$(FILTER_DIR)/include -I$(UNIFICATION_DIR)/include
31+
SRCDIRS=$(SRCDIR) $(EDGE_DIR)/src $(GRAY_DIR)/src $(FILTER_DIR)/src $(UNIFICATION_DIR)/src $(COMPRESSION_DIR)/src
32+
INCDIR+=-I$(EDGE_DIR)/include -I$(GRAY_DIR)/include -I$(FILTER_DIR)/include -I$(UNIFICATION_DIR)/include -I$(COMPRESSION_DIR)/include
3233
endif # USING_TLM_TB_EN
3334

3435
ifdef INCLUDE_OPENCV

modules/compression/include/ips_jpg_pv_model.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,26 @@ SC_MODULE (jpg_output) {
8181
image[i]=image[i]-128;
8282
}
8383
int number_of_blocks = image_rows*image_cols/(BLOCK_ROWS*BLOCK_COLS);
84+
printf("number_of_block %0d ROWS %0d COLS %0d\n", number_of_blocks, BLOCK_ROWS, BLOCK_COLS);
85+
#ifndef USING_TLM_TB_EN
8486
int block_output[number_of_blocks][BLOCK_ROWS*BLOCK_COLS] = {0};
8587
int block_output_size[number_of_blocks] = {0};
88+
#else
89+
int** block_output = new int*[number_of_blocks];
90+
int* block_output_size = new int[number_of_blocks];
91+
for (int i = 0; i < number_of_blocks; i++)
92+
{
93+
block_output[i] = new int[BLOCK_ROWS * BLOCK_COLS];
94+
}
95+
for (int i = 0; i < number_of_blocks; i++)
96+
{
97+
block_output_size[i] = 0;
98+
for (int j = 0; j < BLOCK_ROWS * BLOCK_COLS; j++)
99+
{
100+
block_output[i][j] = 0;
101+
}
102+
}
103+
#endif // USING_TLM_TB_EN
86104
int block_counter = 0;
87105
*output_size = 0;
88106
for(int row=0; row<image_rows; row+=BLOCK_ROWS) {
@@ -105,6 +123,14 @@ SC_MODULE (jpg_output) {
105123
image[output_counter]=eob;
106124
output_counter++;
107125
}
126+
#ifdef USING_TLM_TB_EN
127+
for (int i = 0; i < number_of_blocks; i++)
128+
{
129+
delete[] block_output[i];
130+
}
131+
delete[] block_output;
132+
delete[] block_output_size;
133+
#endif // USING_TLM_TB_EN
108134
}
109135

110136
void dct(int row_offset, int col_offset) {

modules/compression/src/ips_jpg_pv_testbench.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#ifndef USING_TLM_TB_EN
12
#ifdef IPS_JPG_PV_EN
23
#define int64 systemc_int64
34
#define uint64 systemc_uint64
@@ -91,3 +92,4 @@ int sc_main(int, char*[]) {
9192

9293
}
9394
#endif // IPS_JPG_PV_EN
95+
#endif // USING_TLM_TB_EN

modules/router/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ ifdef USING_TLM_ROUTER_TB_EN
6262
LFLAGS += -DUSING_TLM_ROUTER_TB_EN
6363
endif # USING_TLM_TB_EN
6464

65+
ifdef IPS_JPG_PV_EN
66+
CFLAGS += -DIPS_JPG_PV_EN
67+
LFLAGS += -DIPS_JPG_PV_EN
68+
endif # IPS_JPG_PV_EN
69+
6570
.PHONY: print-all
6671
print-all:
6772
@echo "Incdir is $(INCDIR)"

modules/router/run_all.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
case $1 in
44
"save_log")
5-
make RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 USING_TLM_TB_EN=1 all > output.log
5+
make RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 all > output.log
66
;;
77
"print_all")
8-
make RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 USING_TLM_TB_EN=1 print-all
8+
make RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 print-all
99
;;
1010
"compile")
11-
make RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 USING_TLM_TB_EN=1 compile
11+
make RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 compile
1212
;;
1313
"router_tb")
1414
make RGB2GRAY_PV_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_ROUTER_TB_EN=1 USING_TLM_TB_EN=1 all > output.log
@@ -17,6 +17,6 @@ case $1 in
1717
make RGB2GRAY_PV_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_ROUTER_TB_EN=1 USING_TLM_TB_EN=1 all > output.log
1818
;;
1919
*)
20-
make RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 USING_TLM_TB_EN=1 all
20+
make RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 all
2121
;;
2222
esac

modules/router/src/img_target.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ struct img_target: sc_module
165165
switch(cmd) {
166166
case tlm::TLM_READ_COMMAND: {
167167
unsigned char* response_data_ptr;
168-
response_data_ptr = (unsigned char*)malloc(len);
168+
response_data_ptr = new unsigned char[len];
169169
this->do_when_read_transaction(response_data_ptr, len, addr);
170170
//Add read according to length
171171
//-----------DEBUG-----------

modules/router/src/tb_edge_detector_tlm.cpp

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ using namespace std;
3434
#include "ips_filter_tlm.hpp"
3535
#include "sobel_edge_detector_tlm.hpp"
3636
#include "unification_pv_model.hpp"
37+
#include "ips_jpg_pv_model.hpp"
3738
#include "img_initiator.cpp"
3839

39-
#if !defined(RGB2GRAY_PV_EN) || !defined(EDGE_DETECTOR_AT_EN)
40-
#error "Not all the required macros (RGB2GRAY_PV_EN and EDGE_DETECTOR_LT_EN) are defined is defined."
40+
#if !defined(RGB2GRAY_PV_EN) || !defined(IPS_FILTER_LT_EN) || !defined(EDGE_DETECTOR_AT_EN) || !defined(IMG_UNIFICATE_PV_EN) || !defined(IPS_JPG_PV_EN)
41+
#error "Not all the required macros (RGB2GRAY_PV_EN, IPS_FILTER_LT_EN, EDGE_DETECTOR_AT_EN, IMG_UNIFICATE_PV_EN and IPS_JPG_PV_EN) are defined."
4142
#endif
4243

4344
SC_MODULE(Tb_top)
@@ -50,6 +51,7 @@ SC_MODULE(Tb_top)
5051
img_initiator *filter_initiator;
5152
ips_filter_tlm *filter_DUT;
5253
img_unification_module* unification_DUT;
54+
jpg_output *jpg_comp_DUT;
5355

5456
SC_CTOR(Tb_top)
5557
{
@@ -61,6 +63,7 @@ SC_MODULE(Tb_top)
6163
filter_initiator = new img_initiator("filter_initiator");
6264
filter_DUT = new ips_filter_tlm("filter_DUT");
6365
unification_DUT = new img_unification_module("unification_DUT");
66+
jpg_comp_DUT = new jpg_output("jpg_comp_DUT", IMAG_ROWS, IMAG_COLS);
6467

6568
sobel_initiator->start_img_initiators();
6669
sobel_initiator->set_delays(sc_time(10, SC_NS), sc_time(10, SC_NS));
@@ -96,6 +99,11 @@ SC_MODULE(Tb_top)
9699
int current_number_of_pixels = 0;
97100
float next_target_of_completion = 10.0;
98101

102+
int local_group_count;
103+
int compression_output_size = 0;
104+
105+
signed char* compression_results;
106+
99107
colorImage = imread("../../tools/datagen/src/imgs/car.jpg", IMREAD_UNCHANGED);
100108

101109
if (colorImage.empty())
@@ -170,7 +178,7 @@ SC_MODULE(Tb_top)
170178

171179
for (int i = 0; i < IMAG_ROWS; i++)
172180
{
173-
int local_group_count = 0;
181+
local_group_count = 0;
174182
for (int j = 0; j < IMAG_COLS; j++)
175183
{
176184
unsigned char* read_ptr;
@@ -233,7 +241,7 @@ SC_MODULE(Tb_top)
233241

234242
for (int i = 0; i < IMAG_ROWS; i++)
235243
{
236-
int local_group_count = 0;
244+
local_group_count = 0;
237245
for (int j = 0; j < IMAG_COLS; j++)
238246
{
239247
unsigned char* local_window_ptr = new unsigned char[9];
@@ -314,7 +322,7 @@ SC_MODULE(Tb_top)
314322

315323
for (int i = 0; i < IMAG_ROWS; i++)
316324
{
317-
int local_group_count = 0;
325+
local_group_count = 0;
318326
for (int j = 0; j < IMAG_COLS; j++)
319327
{
320328
unsigned char* local_window_ptr = new unsigned char[16];
@@ -398,6 +406,8 @@ SC_MODULE(Tb_top)
398406
}
399407
}
400408

409+
dbgprint("Finished calculating sobel gradients of the image");
410+
401411
// Sanity check that the image was written in memory as expected
402412
for (int i = 0; i < IMAG_ROWS; i++)
403413
{
@@ -434,9 +444,13 @@ SC_MODULE(Tb_top)
434444
}
435445
}
436446

447+
local_count = 0;
448+
current_number_of_pixels = 0;
449+
next_target_of_completion = 10.0;
450+
437451
for (int i = 0; i < IMAG_ROWS; i++)
438452
{
439-
int local_group_count = 0;
453+
local_group_count = 0;
440454
for (int j = 0; j < IMAG_COLS; j++)
441455
{
442456
unsigned char* read_ptr;
@@ -495,6 +509,8 @@ SC_MODULE(Tb_top)
495509
}
496510
}
497511

512+
dbgprint("Finished with the unification of the magnitude of the gradients of the image");
513+
498514
// Sanity check that the image was written in memory as expected
499515
for (int i = 0; i < IMAG_ROWS; i++)
500516
{
@@ -506,6 +522,64 @@ SC_MODULE(Tb_top)
506522
}
507523
}
508524

525+
local_count = 0;
526+
current_number_of_pixels = 0;
527+
next_target_of_completion = 10.0;
528+
529+
for (int i = 0; i < IMAG_ROWS; i++)
530+
{
531+
local_group_count = 0;
532+
for (int j = 0; j < IMAG_COLS; j++)
533+
{
534+
if (local_count == 0)
535+
{
536+
unsigned char* read_ptr;
537+
local_read = new unsigned char[8];
538+
539+
dbgprint("Before doing a read in TB");
540+
memory_initiator->read(read_ptr, IMG_INPROCESS_A + ((i * IMAG_COLS) + (local_group_count * 8 * sizeof(char))), 8 * sizeof(char));
541+
dbgprint("After doing a read in TB");
542+
memcpy(local_read, read_ptr, 8 * sizeof(char));
543+
}
544+
545+
jpg_comp_DUT->input_pixel((int)*(local_read + local_count), i, j);
546+
547+
if (local_count == 8)
548+
{
549+
local_count = 0;
550+
local_group_count++;
551+
}
552+
}
553+
}
554+
555+
jpg_comp_DUT->jpeg_compression(&compression_output_size);
556+
557+
local_count = 0;
558+
local_group_count = 0;
559+
compression_results = new signed char[compression_output_size];
560+
for (int i = 0; i < compression_output_size; i++)
561+
{
562+
jpg_comp_DUT->output_byte(compression_results, i);
563+
564+
dbgprint("Data_returned compression_result: %0d", *(compression_results + i));
565+
566+
local_count++;
567+
568+
if ((local_count == 8))
569+
{
570+
local_results = reinterpret_cast<unsigned char*>(compression_results + (local_group_count * 8 * sizeof(char)));
571+
dbgprint("Before doing a write in TB");
572+
sanity_check_address(IMG_COMPRESSED + (local_group_count * 8 * sizeof(char)), IMG_COMPRESSED, IMG_COMPRESSED + IMG_COMPRESSED_SZ);
573+
memory_initiator->write(local_results, IMG_COMPRESSED + (local_group_count * 8 * sizeof(char)), 8 * sizeof(char));
574+
dbgprint("After doing a write in TB");
575+
local_count = 0;
576+
local_group_count++;
577+
}
578+
579+
}
580+
581+
dbgprint("Finished with the compression of the image");
582+
509583
imwrite("grayImagePrevMem.jpg", grayImagePrevMem);
510584
imwrite("grayImageAfterMem.jpg", grayImageAfterMem);
511585
imwrite("filteredImagePrevMem.jpg", filteredImagePrevMem);

0 commit comments

Comments
 (0)