Skip to content

Commit 89a7490

Browse files
jgavillalobosErickOF
authored andcommitted
Add unification module to the chain of transactions
1 parent 82877d0 commit 89a7490

File tree

9 files changed

+131
-36
lines changed

9 files changed

+131
-36
lines changed

modules/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ ifdef USING_TLM_TB_EN
2525
EDGE_DIR=../edge-detector
2626
GRAY_DIR=../rgb2gray
2727
FILTER_DIR=../filter
28+
UNIFICATION_DIR=../unification
2829

29-
SRCDIRS=$(SRCDIR) $(EDGE_DIR)/src $(GRAY_DIR)/src $(FILTER_DIR)/src
30-
INCDIR+=-I$(EDGE_DIR)/include -I$(GRAY_DIR)/include -I$(FILTER_DIR)/include
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
3132
endif # USING_TLM_TB_EN
3233

3334
ifdef INCLUDE_OPENCV
Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
#ifndef ADDRESSMAP_H
22
#define ADDRESSMAP_H
33

4-
#define IMG_FILTER_KERNEL 0x00000003u
5-
#define SOBEL_INPUT_0 0x00000027u
6-
#define SOBEL_INPUT_1 0x0000002Fu
7-
#define SOBEL_OUTPUT 0x00000030u
8-
#define MEM_START 0x00000034u
9-
#define IMG_INPUT 0x00000034u
10-
#define IMG_INPROCESS_A 0x000E1034u
11-
#define IMG_INPROCESS_B 0x0012C034u
12-
#define IMG_INPROCESS_C 0x001C2034u
13-
#define IMG_COMPRESSED 0x00258034u
4+
#define IMG_FILTER_KERNEL 0x00000003u
5+
#define SOBEL_INPUT_0 0x00000027u
6+
#define SOBEL_INPUT_1 0x0000002Fu
7+
#define SOBEL_OUTPUT 0x00000030u
8+
#define IMG_INPUT 0x00000034u
9+
#define IMG_INPROCESS_A 0x000E1034u
10+
#define IMG_INPROCESS_B 0x0012C034u
11+
#define IMG_INPROCESS_C 0x001C2034u
12+
#define IMG_COMPRESSED 0x00258034u
13+
14+
#define IMG_INPUT_SZ 0x000E1000u
15+
#define IMG_INPROCESS_A_SZ 0x0004B000u
16+
#define IMG_INPROCESS_B_SZ 0x00096000u
17+
#define IMG_INPROCESS_C_SZ 0x00096000u
18+
#define IMG_COMPRESSED_SZ 0x0004B000u
19+
20+
#define MEM_START IMG_INPUT
21+
#define MEM_FINISH IMG_COMPRESSED + IMG_COMPRESSED_SZ
1422

1523
#endif // ADDRESSMAP_H

modules/router/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ ifdef IPS_FILTER_LT_EN
5252
LFLAGS += -DIPS_FILTER_LT_EN
5353
endif # IPS_FILTER_LT_EN
5454

55+
ifdef IMG_UNIFICATE_PV_EN
56+
CFLAGS += -DIMG_UNIFICATE_PV_EN
57+
LFLAGS += -DIMG_UNIFICATE_PV_EN
58+
endif # UNIFICATE_PV_EN
59+
5560
.PHONY: print-all
5661
print-all:
5762
@echo "Incdir is $(INCDIR)"

modules/router/run_all.sh

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

33
case $1 in
44
"save_log")
5-
make RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_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 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 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 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 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 USING_TLM_TB_EN=1 compile
1212
;;
1313
*)
14-
make RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_TB_EN=1 all
14+
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
1515
;;
1616
esac

modules/router/src/memory_tlm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void memory_tlm::do_when_read_transaction(unsigned char*& data, unsigned int dat
2323

2424
for (int i = 0; i < max_data_length; i++)
2525
{
26-
local_data[i] = *(mem_array + address + i);
26+
local_data[i] = *(mem_array + address - MEM_START + i);
2727
}
2828
for (int i = max_data_length; i < 8; i++)
2929
{

modules/router/src/tb_edge_detector_tlm.cpp

Lines changed: 93 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ using namespace std;
2929
#include "ImportantDefines.h"
3030

3131
#include "memory_tlm.hpp"
32-
#include "rgb2gray_tlm.hpp"
32+
#include "rgb2gray_pv_model.hpp"
3333
#include "ips_filter_tlm.hpp"
3434
#include "sobel_edge_detector_tlm.hpp"
35+
#include "unification_pv_model.hpp"
3536
#include "img_initiator.cpp"
3637

3738
#if !defined(RGB2GRAY_PV_EN) || !defined(EDGE_DETECTOR_AT_EN)
@@ -47,6 +48,7 @@ SC_MODULE(Tb_top)
4748
memory_tlm *memory_DUT;
4849
img_initiator *filter_initiator;
4950
ips_filter_tlm *filter_DUT;
51+
img_unification_module* unification_DUT;
5052

5153
SC_CTOR(Tb_top)
5254
{
@@ -57,6 +59,7 @@ SC_MODULE(Tb_top)
5759
memory_DUT = new memory_tlm("memory_DUT");
5860
filter_initiator = new img_initiator("filter_initiator");
5961
filter_DUT = new ips_filter_tlm("filter_DUT");
62+
unification_DUT = new img_unification_module("unification_DUT");
6063

6164
sobel_initiator->start_img_initiators();
6265
sobel_initiator->set_delays(sc_time(10, SC_NS), sc_time(10, SC_NS));
@@ -83,6 +86,7 @@ SC_MODULE(Tb_top)
8386
unsigned char localR, localG, localB;
8487
unsigned short int localResult;
8588
unsigned char* local_results;
89+
unsigned char* local_read;
8690
int local_count = 0;
8791

8892
short int localGradientX, localGradientY;
@@ -178,7 +182,7 @@ SC_MODULE(Tb_top)
178182
rgb2gray_DUT->set_rgb_pixel(localR, localG, localB);
179183
localResult = (unsigned short int)rgb2gray_DUT->obtain_gray_value();
180184

181-
dbgprint("Data_returned: %0d", localResult);
185+
dbgprint("Data_returned gray_result: %0d", localResult);
182186

183187
grayImagePrevMem.at<uchar>(i, j) = (unsigned char)localResult;
184188

@@ -194,6 +198,7 @@ SC_MODULE(Tb_top)
194198
if (local_count == 8)
195199
{
196200
dbgprint("Before doing a write in TB");
201+
sanity_check_address(IMG_INPROCESS_A + ((i * IMAG_COLS) + (local_group_count * 8 * sizeof(char))), IMG_INPROCESS_A, IMG_INPROCESS_A + IMG_INPROCESS_A_SZ);
197202
memory_initiator->write(local_results, IMG_INPROCESS_A + ((i * IMAG_COLS) + (local_group_count * 8 * sizeof(char))), 8 * sizeof(char));
198203
dbgprint("After doing a write in TB");
199204
local_count = 0;
@@ -246,7 +251,7 @@ SC_MODULE(Tb_top)
246251
filter_initiator->read(read_ptr, IMG_FILTER_KERNEL, sizeof(IPS_OUT_TYPE_TB));
247252
dbgprint("After doing a read in TB");
248253
data_returned_ptr = reinterpret_cast<IPS_OUT_TYPE_TB*>(read_ptr);
249-
dbgprint("Data_returned: %f\n", *data_returned_ptr);
254+
dbgprint("Data_returned filtered_result: %f", *data_returned_ptr);
250255

251256
data_returned = *data_returned_ptr;
252257

@@ -274,6 +279,7 @@ SC_MODULE(Tb_top)
274279
if (local_count == 8)
275280
{
276281
dbgprint("Before doing a write in TB");
282+
sanity_check_address(IMG_COMPRESSED + ((i * IMAG_COLS) + (local_group_count * 8 * sizeof(char))), IMG_COMPRESSED, IMG_COMPRESSED + IMG_COMPRESSED_SZ);
277283
memory_initiator->write(local_results, IMG_COMPRESSED + ((i * IMAG_COLS) + (local_group_count * 8 * sizeof(char))), 8 * sizeof(char));
278284
dbgprint("After doing a write in TB");
279285
local_count = 0;
@@ -333,8 +339,8 @@ SC_MODULE(Tb_top)
333339
sobel_initiator->read(read_ptr, SOBEL_OUTPUT, 8 * sizeof(char));
334340
dbgprint("After doing a read in TB");
335341
data_returned_ptr = reinterpret_cast<short int*>(read_ptr);
336-
dbgprint("Data_returned: %0d\n", *data_returned_ptr);
337-
dbgprint("Data_returned: %0d\n", *(data_returned_ptr+1));
342+
dbgprint("Data_returned localGradientX: %0d", *data_returned_ptr);
343+
dbgprint("Data_returned localGradientY: %0d", *(data_returned_ptr+1));
338344

339345
localGradientX = *data_returned_ptr;
340346
localGradientY = *(data_returned_ptr+1);
@@ -357,16 +363,6 @@ SC_MODULE(Tb_top)
357363
else {
358364
detectedImagePrevMemY.at<uchar>(i, j) = (unsigned char)localGradientY;
359365
}
360-
361-
localResult = (unsigned short int)sqrt((float)(pow(localGradientX, 2)) + (float)(pow(localGradientY, 2)));
362-
if (localResult > 255)
363-
{
364-
detectedImagePrevMem.at<uchar>(i, j) = 255;
365-
}
366-
else
367-
{
368-
detectedImagePrevMem.at<uchar>(i, j) = (unsigned char)localResult;
369-
}
370366

371367
if (local_count == 0)
372368
{
@@ -381,10 +377,12 @@ SC_MODULE(Tb_top)
381377
{
382378
write_ptr = local_results;
383379
dbgprint("Before doing a write in TB");
380+
sanity_check_address(IMG_INPROCESS_B + ((i * IMAG_COLS * sizeof(short int)) + (local_group_count * 4 * sizeof(short int))), IMG_INPROCESS_B, IMG_INPROCESS_B + IMG_INPROCESS_B_SZ);
384381
memory_initiator->write(write_ptr, IMG_INPROCESS_B + ((i * IMAG_COLS * sizeof(short int)) + (local_group_count * 4 * sizeof(short int))), 4 * sizeof(short int));
385382
dbgprint("After doing a write in TB");
386383
write_ptr = (local_results + 8);
387384
dbgprint("Before doing a write in TB");
385+
sanity_check_address(IMG_INPROCESS_C + ((i * IMAG_COLS * sizeof(short int)) + (local_group_count * 4 * sizeof(short int))), IMG_INPROCESS_C, IMG_INPROCESS_C + IMG_INPROCESS_C_SZ);
388386
memory_initiator->write(write_ptr, IMG_INPROCESS_C + ((i * IMAG_COLS * sizeof(short int)) + (local_group_count * 4 * sizeof(short int))), 4 * sizeof(short int));
389387
dbgprint("After doing a write in TB");
390388
local_count = 0;
@@ -435,6 +433,78 @@ SC_MODULE(Tb_top)
435433
}
436434
}
437435

436+
for (int i = 0; i < IMAG_ROWS; i++)
437+
{
438+
int local_group_count = 0;
439+
for (int j = 0; j < IMAG_COLS; j++)
440+
{
441+
unsigned char* read_ptr;
442+
short int* gradients_ptr;
443+
unsigned char unification_result;
444+
445+
if (local_count == 0)
446+
{
447+
local_read = new unsigned char[16];
448+
449+
dbgprint("Before doing a read in TB");
450+
memory_initiator->read(read_ptr, IMG_INPROCESS_B + ((i * IMAG_COLS * sizeof(short int)) + (local_group_count * 4 * sizeof(short int))), 4 * sizeof(short int));
451+
dbgprint("After doing a read in TB");
452+
memcpy((local_read ), read_ptr, 4 * sizeof(short int));
453+
dbgprint("Before doing a read in TB");
454+
memory_initiator->read(read_ptr, IMG_INPROCESS_C + ((i * IMAG_COLS * sizeof(short int)) + (local_group_count * 4 * sizeof(short int))), 4 * sizeof(short int));
455+
dbgprint("After doing a read in TB");
456+
memcpy((local_read + (4 * sizeof(short int))), read_ptr, 4 * sizeof(short int));
457+
}
458+
459+
gradients_ptr = reinterpret_cast<short int*>(local_read);
460+
localGradientX = *(gradients_ptr + local_count);
461+
gradients_ptr = reinterpret_cast<short int*>(local_read + (4 * sizeof(short int)));
462+
localGradientY = *(gradients_ptr + local_count);
463+
464+
unification_DUT->unificate_pixel((int)localGradientX, (int)localGradientY, &unification_result);
465+
466+
dbgprint("Data_returned unification_result: %0d", unification_result);
467+
468+
detectedImagePrevMem.at<uchar>(i, j) = unification_result;
469+
470+
if (local_count == 0)
471+
{
472+
local_results = new unsigned char[4];
473+
}
474+
475+
*(local_results + local_count) = unification_result;
476+
477+
local_count++;
478+
479+
if (local_count == 4)
480+
{
481+
dbgprint("Before doing a write in TB");
482+
sanity_check_address(IMG_INPROCESS_A + ((i * IMAG_COLS) + j), IMG_INPROCESS_A, IMG_INPROCESS_A + IMG_INPROCESS_A_SZ);
483+
memory_initiator->write(local_results, IMG_INPROCESS_A + ((i * IMAG_COLS) + (local_group_count * 4 * sizeof(char))), 4 * sizeof(char));
484+
dbgprint("After doing a write in TB");
485+
local_count = 0;
486+
local_group_count++;
487+
}
488+
489+
current_number_of_pixels++;
490+
if (((((float)(current_number_of_pixels)) / ((float)(total_number_of_pixels))) * 100.0) >= next_target_of_completion) {
491+
dbgprint("Image processing completed at %f", next_target_of_completion);
492+
next_target_of_completion += 10.0;
493+
}
494+
}
495+
}
496+
497+
// Sanity check that the image was written in memory as expected
498+
for (int i = 0; i < IMAG_ROWS; i++)
499+
{
500+
for (int j = 0; j < IMAG_COLS; j++)
501+
{
502+
unsigned char* read_ptr;
503+
memory_DUT->backdoor_read(read_ptr, 1 * sizeof(char), IMG_INPROCESS_A + ((i * IMAG_COLS) + j));
504+
detectedImageAfterMem.at<uchar>(i, j) = *read_ptr;
505+
}
506+
}
507+
438508
imwrite("grayImagePrevMem.jpg", grayImagePrevMem);
439509
imwrite("grayImageAfterMem.jpg", grayImageAfterMem);
440510
imwrite("filteredImagePrevMem.jpg", filteredImagePrevMem);
@@ -649,6 +719,14 @@ SC_MODULE(Tb_top)
649719
*(local_window_ptr + 8) = *(read_ptr + 2);
650720
}
651721
}
722+
723+
void sanity_check_address(unsigned int address, unsigned int lower_address_limit, unsigned int upper_address_limit)
724+
{
725+
if (((lower_address_limit != 0) && (address < lower_address_limit)) || (address > upper_address_limit))
726+
{
727+
SC_REPORT_FATAL("TB MEM", "Access to memory crossing boundary");
728+
}
729+
}
652730
};
653731

654732
int sc_main(int, char*[])

modules/unification/include/unification_pv_model.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ SC_MODULE (img_unification_module) {
2323
} // End of Constructor
2424

2525
//------------Methods------------
26-
void unificate_pixel(unsigned char x_pixel, unsigned char y_pixel, unsigned char * unificated_pixel);
26+
void unificate_pixel(int x_pixel, int y_pixel, unsigned char * unificated_pixel);
2727
void unificate_img(unsigned char *x_img, unsigned char *y_img, unsigned char *unificated_img, int img_size, int channels);
2828
int norm(int a, int b);
2929
};

modules/unification/src/unification_pv_model.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//#define USE_INF_NORM
1717
//-------------------------------------------
1818

19-
void img_unification_module::unificate_pixel(unsigned char x_pixel, unsigned char y_pixel, unsigned char * unificated_pixel) {
19+
void img_unification_module::unificate_pixel(int x_pixel, int y_pixel, unsigned char * unificated_pixel) {
2020
//Get the Norm
2121
*unificated_pixel = (unsigned char) this->norm(x_pixel, y_pixel);
2222
}
@@ -25,8 +25,8 @@ void img_unification_module::unificate_img(unsigned char *x_img, unsigned char *
2525
//Iterate over image
2626
for(unsigned char *x = x_img, *y = y_img, *u = unificated_img; x < x_img + img_size && y < y_img + img_size && u < unificated_img + img_size; x+=channels, y+=channels, u+=channels){
2727
unsigned char pixel_magnitude;
28-
unsigned char pixel_x = int(*x);
29-
unsigned char pixel_y = int(*y);
28+
int pixel_x = int(*x);
29+
int pixel_y = int(*y);
3030

3131
this->unificate_pixel(pixel_x, pixel_y, &pixel_magnitude);
3232
*u = pixel_magnitude;

modules/unification/src/unification_tb.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//Description: Simple TB for pixel unification modules
55
//--------------------------------------------------------
66

7+
#ifndef USING_TLM_TB_EN
78
#define STB_IMAGE_IMPLEMENTATION
89
#include "include/stb_image.h"
910
#define STB_IMAGE_WRITE_IMPLEMENTATION
@@ -87,3 +88,5 @@ int sc_main(int, char*[]) {
8788
return 0;// Terminate simulation
8889

8990
}
91+
92+
#endif // #ifdef USING_TLM_TB_EN

0 commit comments

Comments
 (0)