Skip to content

Commit 343935b

Browse files
authored
Merge pull request #5 from ErickOF/feature-filter_module
Adding LT model + PV model documentation
2 parents 9dff8ec + fbe4ac0 commit 343935b

File tree

5 files changed

+261
-35
lines changed

5 files changed

+261
-35
lines changed

modules/Makefile

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,19 @@ LIBDIR=-L. -L$(SYSTEMC)/lib-linux64
2020
SOURCES := $(wildcard $(SRCDIR)/*.cpp)
2121
INCLUDES := $(wildcard $(INCDIR)/*.hpp)
2222
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
23-
FV_OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.i)
2423

25-
$(BINDIR)/$(TARGET): $(OBJECTS)
24+
$(BINDIR)/$(TARGET): clean $(OBJECTS)
2625
@$(LD) $(OBJECTS) $(LFLAGS) $(LIBS) $(LIBDIR) -o $@
27-
@echo "Linked $@ completed!"
2826

2927
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
3028
@$(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
31-
@echo "Compilation $< in $@"
32-
33-
fv_run: $(FV_OBJECTS)
34-
cbmc $(FV_OBJECTS) --function sc_main
35-
36-
$(FV_OBJECTS): $(OBJDIR)/%.i : $(SRCDIR)/%.cpp
37-
@$(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
38-
@echo "FV compilation $< in $@"
3929

4030
.PHONY: clean
4131
clean:
42-
@rm -f $(OBJECTS)
43-
@echo "Clean done."
32+
@rm -rf obj
33+
@rm -f $(TARGET)
34+
@mkdir -p obj
35+
36+
compile: $(BINDIR)/$(TARGET)
4437

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

modules/filter/Makefile

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,52 @@ INCLUDES += INCLUDES_STB
1010

1111
# Defining preprocessor directive for debug
1212
ifdef IPS_DEBUG_EN
13-
CFLAGS += -DIPS_DEBUG_EN
14-
LFLAGS += -DIPS_DEBUG_EN
13+
CFLAGS += -DIPS_DEBUG_EN
14+
LFLAGS += -DIPS_DEBUG_EN
1515
endif # IPS_DEBUG_EN
1616

1717
# Defining preprocessor directive for dumping enable
1818
ifdef IPS_DUMP_EN
19-
CFLAGS += -DIPS_DUMP_EN
20-
LFLAGS += -DIPS_DUMP_EN
19+
CFLAGS += -DIPS_DUMP_EN
20+
LFLAGS += -DIPS_DUMP_EN
2121
endif # IPS_DUMP_EN
2222

23-
# Defining preprocessor directive for test mode one window random
24-
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
2823

2924
# Defining preprocessor directive for test mode one wildcard normal
3025
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
26+
CFLAGS += -DTEST_MODE_ONE_WINDOW -DTEST_MODE_ONE_WINDOW_NORMAL
27+
LFLAGS += -DTEST_MODE_ONE_WINDOW -DTEST_MODE_ONE_WINDOW_NORMAL
3328
endif # TEST_MODE_ONE_WINDOW_NORMAL
3429

30+
# Defining preprocessor directive for test mode one window random
31+
ifdef TEST_MODE_ONE_WINDOW_RANDOM
32+
CFLAGS += -DTEST_MODE_ONE_WINDOW -DTEST_MODE_ONE_WINDOW_RANDOM
33+
LFLAGS += -DTEST_MODE_ONE_WINDOW -DTEST_MODE_ONE_WINDOW_RANDOM
34+
endif # TEST_MODE_ONE_WINDOW_RANDOM
35+
36+
# Defining preprocessor directive for model - by default PV model
37+
ifdef IPS_FILTER_LT_EN
38+
CFLAGS += -DIPS_FILTER_LT_EN
39+
LFLAGS += -DIPS_FILTER_LT_EN
40+
else # IPS_FILTER_AT_EN
41+
ifdef IPS_FILTER_AT_EN
42+
CFLAGS += -DIPS_FILTER_AT_EN
43+
LFLAGS += -DIPS_FILTER_AT_EN
44+
else # IPS_FILTER_CA_EN
45+
ifdef IPS_FILTER_CA_EN
46+
CFLAGS += -DIPS_FILTER_CA_EN
47+
LFLAGS += -DIPS_FILTER_CA_EN
48+
else # IPS_FILTER_PV_EN
49+
CFLAGS += -DIPS_FILTER_PV_EN
50+
LFLAGS += -DIPS_FILTER_PV_EN
51+
endif # IPS_FILTER_CA_EN
52+
endif # IPS_FILTER_AT_EN
53+
endif # IPS_FILTER_LT_EN
3554

3655
# Run the compiled file
3756
run:
38-
@./test
57+
@./test
3958

4059
# Show waveform
4160
waveform:
42-
@gtkwave ips_filter.vcd
61+
@gtkwave ips_filter.vcd
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#ifndef IPS_FILTER_LT_MODEL_HPP
2+
#define IPS_FILTER_LT_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* img_window_tmp;
33+
OUT* kernel;
34+
OUT* result_ptr;
35+
36+
// Event to trigger the filter execution
37+
sc_event event;
38+
39+
//-----------------------------Internal Methods-----------------------------
40+
void exec_filter();
41+
void init();
42+
43+
public:
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(IN* img_window, OUT* result);
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+
while (true)
89+
{
90+
// Wait to peform the convolution
91+
wait(this->event);
92+
93+
// Default value for the result depending on the output datatype
94+
*(this->result_ptr) = (OUT) 0;
95+
96+
// Perform the convolution
97+
for (i = 0; i < N; ++i)
98+
for (j = 0; j < N; ++j)
99+
*(this->result_ptr) += this->kernel[i * N + j] * this->img_window_tmp[i * N + j];
100+
}
101+
}
102+
103+
/**
104+
* @brief Filtering image
105+
*
106+
* @param img_window - image window to filter
107+
* @param result - resultant pixel
108+
*/
109+
template <typename IN, typename OUT, uint8_t N>
110+
void Filter<IN, OUT, N>::filter(IN* img_window, OUT* result)
111+
{
112+
size_t i;
113+
size_t j;
114+
115+
// Default value for the result depending on the output datatype
116+
this->result_ptr = result;
117+
118+
// Perform the convolution
119+
for (i = 0; i < N; ++i)
120+
for (j = 0; j < N; ++j)
121+
this->img_window_tmp[i * N + j] = (OUT) img_window[i * N + j];
122+
123+
this->event.notify(DELAY_TIME, SC_NS);
124+
}
125+
126+
/**
127+
* @brief Initializes a kernel of N x N with default value of 1 / (N^2)
128+
*
129+
*/
130+
template <typename IN, typename OUT, uint8_t N>
131+
void Filter<IN, OUT, N>::init()
132+
{
133+
// Init a kernel of N x N with default value of 1 / (N * N)
134+
this->kernel = new OUT[N * N];
135+
std::fill_n(this->kernel, N * N, ((OUT) 1) / ((OUT) N * N));
136+
// Init image window of N x N with default value of 1 / (N * N)
137+
this->img_window_tmp = new OUT[N * N];
138+
#ifdef IPS_DEBUG_EN
139+
// Print the initialized kernel
140+
SC_REPORT_INFO(this->name(), "init result");
141+
size_t i, j;
142+
143+
for (i = 0; i < N; ++i)
144+
{
145+
for (j = 0; j < N; ++j)
146+
{
147+
std::cout << "[" << this->kernel[i * N + j] << "]";
148+
149+
#ifdef IPS_DUMP_EN
150+
// Adding the signals to the waveform
151+
std::ostringstream var_name;
152+
var_name << "kernel_" << i << "_" << j;
153+
sc_trace(this->wf, this->kernel[i * N + j], var_name.str());
154+
#endif // IPS_DUMP_EN
155+
}
156+
157+
std::cout << std::endl;
158+
}
159+
#endif // IPS_DEBUG_EN
160+
}
161+
#endif // IPS_FILTER_LT_MODEL_HPP

modules/filter/include/ips_filter_pv_model.hpp

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
#ifndef IPS_FILTER_FILTER_HPP
2-
#define IPS_FILTER_FILTER_HPP
1+
#ifndef IPS_FILTER_PV_MODEL_HPP
2+
#define IPS_FILTER_PV_MODEL_HPP
33
#ifdef IPS_DEBUG_EN
44
#include <iostream>
55
#endif // IPS_DEBUG_ENi
66
#ifdef IPS_DUMP_EN
77
#include <sstream>
88
#endif // IPS_DUMP_EN
99
#include <systemc.h>
10-
#include <vector>
1110

1211

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+
*/
1324
template <typename IN = sc_uint<8>, typename OUT = sc_uint<8>, uint8_t N = 3>
1425
SC_MODULE(Filter)
1526
{
@@ -23,11 +34,21 @@ SC_MODULE(Filter)
2334
* @brief Default constructor for Filter
2435
*/
2536
SC_CTOR(Filter);
26-
//template <typename IN, typename OUT, uint8_t N>
2737
#ifdef IPS_DUMP_EN
38+
/**
39+
* @brief Construct a new Filter object
40+
*
41+
* @param name - name of the module
42+
* @param wf - waveform file pointer
43+
*/
2844
Filter(sc_core::sc_module_name name, sc_core::sc_trace_file* wf)
2945
: sc_core::sc_module(name), wf(wf)
3046
#else
47+
/**
48+
* @brief Construct a new Filter object
49+
*
50+
* @param name - name of the module
51+
*/
3152
Filter(sc_core::sc_module_name name) : sc_core::sc_module(name)
3253
#endif // IPS_DUMP_EN
3354
{
@@ -39,26 +60,39 @@ SC_MODULE(Filter)
3960
void init_kernel();
4061
};
4162

63+
/**
64+
* @brief Filtering image
65+
*
66+
* @param img_window - image window to filter
67+
* @param result - resultant pixel
68+
*/
4269
template <typename IN, typename OUT, uint8_t N>
4370
void Filter<IN, OUT, N>::filter(IN* img_window, OUT& result)
4471
{
4572
size_t i;
4673
size_t j;
4774

75+
// Default value for the result depending on the output datatype
4876
result = (OUT) 0;
4977

78+
// Perform the convolution
5079
for (i = 0; i < N; ++i)
5180
for (j = 0; j < N; ++j)
5281
result += this->kernel[i * N + j] * ((OUT) img_window[i * N + j]);
5382
}
5483

84+
/**
85+
* @brief Initializes a kernel of N x N with default value of 1 / (N^2)
86+
*
87+
*/
5588
template <typename IN, typename OUT, uint8_t N>
5689
void Filter<IN, OUT, N>::init_kernel()
5790
{
5891
// Init a kernel of N x N with default value of 1 / (N * N)
5992
this->kernel = new OUT[N * N];
6093
std::fill_n(this->kernel, N * N, ((OUT) 1) / ((OUT) N * N));
6194
#ifdef IPS_DEBUG_EN
95+
// Print the initialized kernel
6296
SC_REPORT_INFO(this->name(), "init_kernel result");
6397
size_t i, j;
6498

@@ -69,6 +103,7 @@ void Filter<IN, OUT, N>::init_kernel()
69103
std::cout << "[" << this->kernel[i * N + j] << "]";
70104

71105
#ifdef IPS_DUMP_EN
106+
// Adding the signals to the waveform
72107
std::ostringstream var_name;
73108
var_name << "kernel_" << i << "_" << j;
74109
sc_trace(this->wf, this->kernel[i * N + j], var_name.str());
@@ -79,4 +114,4 @@ void Filter<IN, OUT, N>::init_kernel()
79114
}
80115
#endif // IPS_DEBUG_EN
81116
}
82-
#endif // IPS_FILTER_FILTER_HPP
117+
#endif // IPS_FILTER_PV_MODEL_HPP

0 commit comments

Comments
 (0)