Skip to content

Commit 8e6635b

Browse files
authored
Merge branch 'dev' into branch/rgb2gray-module
2 parents 92bff78 + 25b750a commit 8e6635b

File tree

19 files changed

+10833
-293
lines changed

19 files changed

+10833
-293
lines changed

.gitignore

Lines changed: 234 additions & 229 deletions
Large diffs are not rendered by default.

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

modules/Makefile

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
ifndef USER_DEF_SYSTEMC_DIR
21
SYSTEMC?=$(HOME)/systemc-2.3.3
3-
endif # USER_DEF_SYSTEMC_DIR
42
TARGET?=test
53

64
# Compiler
@@ -19,38 +17,22 @@ BINDIR=./
1917
INCDIR=-I. -I./include -I$(SYSTEMC)/include -Ibasic_protocol -I$(SYSTEMC)/include/tlm_core/tlm_2
2018
LIBDIR=-L. -L$(SYSTEMC)/lib-linux64
2119

22-
ifdef INCLUDE_OPENCV
23-
# Target
24-
LIBS+=-lopencv_imgcodecs -lopencv_core -lopencv_highgui -lopencv_imgproc
25-
26-
# Source directories
27-
INCDIR+=-I$(OPENCV_H_DIR)
28-
LIBDIR+=-L$(OPENCV_SO_DIR)
29-
endif # INCLUDE_OPENCV
30-
3120
SOURCES := $(wildcard $(SRCDIR)/*.cpp)
3221
INCLUDES := $(wildcard $(INCDIR)/*.hpp)
3322
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
34-
FV_OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.i)
3523

36-
$(BINDIR)/$(TARGET): $(OBJECTS)
24+
$(BINDIR)/$(TARGET): clean $(OBJECTS)
3725
@$(LD) $(OBJECTS) $(LFLAGS) $(LIBS) $(LIBDIR) -o $@
38-
@echo "Linked $@ completed!"
3926

4027
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
4128
@$(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
42-
@echo "Compilation $< in $@"
43-
44-
fv_run: $(FV_OBJECTS)
45-
cbmc $(FV_OBJECTS) --function sc_main
46-
47-
$(FV_OBJECTS): $(OBJDIR)/%.i : $(SRCDIR)/%.cpp
48-
@$(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
49-
@echo "FV compilation $< in $@"
5029

5130
.PHONY: clean
5231
clean:
53-
@rm -f $(OBJECTS)
54-
@echo "Clean done."
32+
@rm -rf obj
33+
@rm -f $(TARGET)
34+
@mkdir -p obj
35+
36+
compile: $(BINDIR)/$(TARGET)
5537

56-
all: $(BINDIR)/$(TARGET)
38+
all: compile run

modules/edge-detector/Makefile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
# Adding stb lib for image handling
2-
INCDIR_STB=lib/stb
3-
INCLUDES_STB := $(wildcard $(INCDIR_STB)/*.h)
4-
51
# Include common Makefile
62
include ../Makefile
73

8-
# Include stb lib for compilation
9-
INCLUDES += INCLUDES_STB
4+
ifdef INCLUDE_OPENCV
5+
# Target
6+
LIBS+=-lopencv_imgcodecs -lopencv_core -lopencv_highgui -lopencv_imgproc
7+
8+
# Source directories
9+
INCDIR+=-I/usr/local/include/opencv4
10+
LIBDIR+=-L/usr/local/lib
11+
endif # INCLUDE_OPENCV
1012

1113
# Defining preprocessor directive for debug
1214
ifdef IPS_DEBUG_EN

modules/filter/Makefile

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,65 @@
11
# Adding stb lib for image handling
2-
INCDIR_STB=lib/stb
3-
INCLUDES_STB := $(wildcard $(INCDIR_STB)/*.h)
2+
CFLAGS_OPENCV := $(shell pkg-config --cflags opencv4)
3+
LFLAGS_OPENCV := $(shell pkg-config --libs opencv4)
44

55
# Include common Makefile
66
include ../Makefile
77

88
# Include stb lib for compilation
9-
INCLUDES += INCLUDES_STB
9+
CFLAGS += $(CFLAGS_OPENCV)
10+
LFLAGS += $(LFLAGS_OPENCV)
1011

1112
# Defining preprocessor directive for debug
1213
ifdef IPS_DEBUG_EN
13-
CFLAGS += -DIPS_DEBUG_EN
14-
LFLAGS += -DIPS_DEBUG_EN
14+
CFLAGS += -DIPS_DEBUG_EN
15+
LFLAGS += -DIPS_DEBUG_EN
1516
endif # IPS_DEBUG_EN
1617

1718
# Defining preprocessor directive for dumping enable
1819
ifdef IPS_DUMP_EN
19-
CFLAGS += -DIPS_DUMP_EN
20-
LFLAGS += -DIPS_DUMP_EN
20+
CFLAGS += -DIPS_DUMP_EN
21+
LFLAGS += -DIPS_DUMP_EN
2122
endif # IPS_DUMP_EN
2223

23-
# Defining preprocessor directive for test mode one window random
24+
# Defining preprocessor directive for test modes
25+
ifdef TEST_MODE_IMAGE
26+
CFLAGS += -DTEST_MODE_IMAGE
27+
LFLAGS += -DTEST_MODE_IMAGE
28+
else
2429
ifdef TEST_MODE_ONE_WINDOW_RANDOM
25-
CFLAGS += -DTEST_MODE_ONE_WINDOW -DTEST_MODE_ONE_WINDOW_RANDOM
26-
LFLAGS += -DTEST_MODE_ONE_WINDOW -DTEST_MODE_ONE_WINDOW_RANDOM
27-
endif # TEST_MODE_ONE_WINDOW_RANDOM
28-
29-
# Defining preprocessor directive for test mode one wildcard normal
30+
CFLAGS += -DTEST_MODE_ONE_WINDOW -DTEST_MODE_ONE_WINDOW_RANDOM
31+
LFLAGS += -DTEST_MODE_ONE_WINDOW -DTEST_MODE_ONE_WINDOW_RANDOM
32+
else
3033
ifdef TEST_MODE_ONE_WINDOW_NORMAL
31-
CFLAGS += -DTEST_MODE_ONE_WINDOW -DTEST_MODE_ONE_WINDOW_NORMAL
32-
LFLAGS += -DTEST_MODE_ONE_WINDOW -DTEST_MODE_ONE_WINDOW_NORMAL
34+
CFLAGS += -DTEST_MODE_ONE_WINDOW -DTEST_MODE_ONE_WINDOW_NORMAL
35+
LFLAGS += -DTEST_MODE_ONE_WINDOW -DTEST_MODE_ONE_WINDOW_NORMAL
3336
endif # TEST_MODE_ONE_WINDOW_NORMAL
37+
endif # TEST_MODE_ONE_WINDOW_RANDOM
38+
endif # TEST_MODE_IMAGE
3439

40+
# Defining preprocessor directive for model - by default PV model
41+
ifdef IPS_FILTER_LT_EN
42+
CFLAGS += -DIPS_FILTER_LT_EN
43+
LFLAGS += -DIPS_FILTER_LT_EN
44+
else # IPS_FILTER_AT_EN
45+
ifdef IPS_FILTER_AT_EN
46+
CFLAGS += -DIPS_FILTER_AT_EN
47+
LFLAGS += -DIPS_FILTER_AT_EN
48+
else # IPS_FILTER_CA_EN
49+
ifdef IPS_FILTER_CA_EN
50+
CFLAGS += -DIPS_FILTER_CA_EN
51+
LFLAGS += -DIPS_FILTER_CA_EN
52+
else # IPS_FILTER_PV_EN
53+
CFLAGS += -DIPS_FILTER_PV_EN
54+
LFLAGS += -DIPS_FILTER_PV_EN
55+
endif # IPS_FILTER_CA_EN
56+
endif # IPS_FILTER_AT_EN
57+
endif # IPS_FILTER_LT_EN
3558

3659
# Run the compiled file
3760
run:
38-
@./test
61+
@./test
3962

4063
# Show waveform
4164
waveform:
42-
@gtkwave ips_filter.vcd
65+
@gtkwave ips_filter.vcd

modules/filter/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ Some additional options can used to debug and dump the waveform:
4242
* `IPS_DUMP_EN`: Creates a VCD file with each value of the window and kernel,
4343
and the result.
4444

45+
To compile a specific model, you can use the switches:
46+
47+
* `IPS_FILTER_PV_EN`: Programmer's View model.
48+
* `IPS_FILTER_LT_EN`: Loosely Timed model.
49+
* `IPS_FILTER_AT_EN`: Approximately Timed model.
50+
* `IPS_FILTER_CA_EN`: Cycle Approximate model (pending to be implemented).
51+
4552
### **Compilation**
4653
Runs the `make` command with the corresponding switches to compile.
4754

@@ -58,6 +65,9 @@ make run
5865
```
5966

6067
### **Open Waveform**
68+
69+
Since VCD is not generated, this command will not work for the PV model.
70+
6171
```shell
6272
make waveform
6373
```
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#ifndef IPS_FILTER_AT_MODEL_HPP
2+
#define IPS_FILTER_AT_MODEL_HPP
3+
#ifdef IPS_DEBUG_EN
4+
#include <iostream>
5+
#endif // IPS_DEBUG_ENi
6+
#ifdef IPS_DUMP_EN
7+
#include <sstream>
8+
#endif // IPS_DUMP_EN
9+
#include <systemc.h>
10+
11+
12+
/**
13+
* @brief Filter module.
14+
* It takes care of filtering a image/kernel using a median filter or an
15+
* equivalent convolution like:
16+
* | 1/N^2 ... 1/N^2 | | img(row - N/2, col - N/2) ... img(row + N/2, col + N/2) |
17+
* img(row, col) = | ... ... .... | * | ... ... ... |
18+
* | 1/N^2 ... 1/N^2 | | img(row + N/2, col - N/2) ... img(row + N/2, col + N/2) |
19+
*
20+
* @tparam IN - data type of the inputs
21+
* @tparam OUT - data type of the outputs
22+
* @tparam N - size of the kernel
23+
*/
24+
template <typename IN = sc_uint<8>, typename OUT = sc_uint<8>, uint8_t N = 3>
25+
SC_MODULE(Filter)
26+
{
27+
protected:
28+
//----------------------------Internal Variables----------------------------
29+
#ifdef IPS_DUMP_EN
30+
sc_trace_file* wf;
31+
#endif // IPS_DUMP_EN
32+
OUT* kernel;
33+
34+
// Event to trigger the filter execution
35+
sc_event event;
36+
37+
//-----------------------------Internal Methods-----------------------------
38+
void exec_filter();
39+
void init();
40+
41+
public:
42+
sc_in<IN* > img_window;
43+
sc_out<OUT > result;
44+
/**
45+
* @brief Default constructor for Filter
46+
*/
47+
SC_HAS_PROCESS(Filter);
48+
#ifdef IPS_DUMP_EN
49+
/**
50+
* @brief Construct a new Filter object
51+
*
52+
* @param name - name of the module
53+
* @param wf - waveform file pointer
54+
*/
55+
Filter(sc_core::sc_module_name name, sc_core::sc_trace_file* wf)
56+
: sc_core::sc_module(name), wf(wf)
57+
#else
58+
/**
59+
* @brief Construct a new Filter object
60+
*
61+
* @param name - name of the module
62+
*/
63+
Filter(sc_core::sc_module_name name) : sc_core::sc_module(name)
64+
#endif // IPS_DUMP_EN
65+
{
66+
// Calling this method by default since it is no time consumer
67+
// It is assumed that this kernel is already loaded in the model
68+
// Kernel does not change after synthesis
69+
SC_METHOD(init);
70+
// Thread waiting for the request
71+
SC_THREAD(exec_filter);
72+
}
73+
74+
//---------------------------------Methods---------------------------------
75+
void filter();
76+
};
77+
78+
/**
79+
* @brief Execute the image filtering
80+
*
81+
*/
82+
template <typename IN, typename OUT, uint8_t N>
83+
void Filter<IN, OUT, N>::exec_filter()
84+
{
85+
size_t i;
86+
size_t j;
87+
88+
OUT result_tmp;
89+
90+
while (true)
91+
{
92+
// Wait to peform the convolution
93+
wait(this->event);
94+
95+
// Default value for the result depending on the output datatype
96+
result_tmp = (OUT) 0;
97+
98+
// Getting the image window to filter
99+
IN* img_window_tmp = this->img_window.read();
100+
101+
// Perform the convolution
102+
for (i = 0; i < N; ++i)
103+
for (j = 0; j < N; ++j)
104+
result_tmp += this->kernel[i * N + j] * ((OUT) img_window_tmp[i * N + j]);
105+
106+
this->result.write(result_tmp);
107+
}
108+
}
109+
110+
/**
111+
* @brief Filtering image
112+
*
113+
* @param img_window - image window to filter
114+
* @param result - resultant pixel
115+
*/
116+
template <typename IN, typename OUT, uint8_t N>
117+
void Filter<IN, OUT, N>::filter()
118+
{
119+
this->event.notify(DELAY_TIME, SC_NS);
120+
}
121+
122+
/**
123+
* @brief Initializes a kernel of N x N with default value of 1 / (N^2)
124+
*
125+
*/
126+
template <typename IN, typename OUT, uint8_t N>
127+
void Filter<IN, OUT, N>::init()
128+
{
129+
// Init a kernel of N x N with default value of 1 / (N * N)
130+
this->kernel = new OUT[N * N];
131+
std::fill_n(this->kernel, N * N, ((OUT) 1) / ((OUT) N * N));
132+
133+
#ifdef IPS_DEBUG_EN
134+
// Print the initialized kernel
135+
SC_REPORT_INFO(this->name(), "init result");
136+
size_t i, j;
137+
138+
for (i = 0; i < N; ++i)
139+
{
140+
for (j = 0; j < N; ++j)
141+
{
142+
std::cout << "[" << this->kernel[i * N + j] << "]";
143+
144+
#ifdef IPS_DUMP_EN
145+
// Adding the signals to the waveform
146+
std::ostringstream var_name;
147+
var_name << "kernel_" << i << "_" << j;
148+
sc_trace(this->wf, this->kernel[i * N + j], var_name.str());
149+
#endif // IPS_DUMP_EN
150+
}
151+
152+
std::cout << std::endl;
153+
}
154+
#else
155+
#ifdef IPS_DUMP_EN
156+
size_t i, j;
157+
158+
for (i = 0; i < N; ++i)
159+
{
160+
for (j = 0; j < N; ++j)
161+
{
162+
// Adding the signals to the waveform
163+
std::ostringstream var_name;
164+
var_name << "kernel_" << i << "_" << j;
165+
sc_trace(this->wf, this->kernel[i * N + j], var_name.str());
166+
}
167+
}
168+
#endif // IPS_DUMP_EN
169+
#endif // IPS_DEBUG_EN
170+
}
171+
#endif // IPS_FILTER_AT_MODEL_HPP

0 commit comments

Comments
 (0)