Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding feature TLM router #24

Merged
merged 37 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
92b18fd
Fix/Generalize Initiator
RMorales25 Jul 7, 2024
ed3b320
Fix/Generalize Target
RMorales25 Jul 8, 2024
1036999
Add makefile and other needed files
RMorales25 Jul 8, 2024
1f37f25
Fix compilation issue with missing file
jgavillalobos Jul 9, 2024
a4c31a9
Copy work from communication module
jgavillalobos Jul 9, 2024
c9d2c1b
Delete unrequired files
jgavillalobos Jul 9, 2024
8a8db0e
Change folder for newer version of systemc
jgavillalobos Jul 9, 2024
7100a18
Update Makefile to use other folders for the reused blocks
jgavillalobos Jul 9, 2024
0ae2449
Add new dbgprint function to show file and line from which a print is…
jgavillalobos Jul 9, 2024
575daf4
Add bash script to make easier runs
jgavillalobos Jul 9, 2024
00982c7
Add RGB2GRAY module for testing with TLM
jgavillalobos Jul 11, 2024
a7013da
Use AT model of edge_detector instead of LT
jgavillalobos Jul 11, 2024
4090bfa
Fix wrong values being writen in the jpg files
jgavillalobos Jul 11, 2024
54e27de
Fix bad values assigning to resulting image
jgavillalobos Jul 11, 2024
b561085
Change how the delays of initiator and target are used
jgavillalobos Jul 11, 2024
7df8821
Use normal access to RGB2GRAY module instead of TLM
jgavillalobos Jul 12, 2024
ffc5b74
Include memory for storing the data using TLM transactions
jgavillalobos Jul 12, 2024
ddf95ad
Remove unrequired local references
jgavillalobos Jul 12, 2024
8ca3cf7
Add Filter block to TLM TB
jgavillalobos Jul 13, 2024
82877d0
Add sanity check to ensure that the image is being written as expecte…
jgavillalobos Jul 14, 2024
89a7490
Add unification module to the chain of transactions
jgavillalobos Jul 14, 2024
60b0970
Add img_router and testbench
RMorales25 Jul 14, 2024
da9d700
Fix target to respond using a thread method
RMorales25 Jul 14, 2024
a95d859
Clean and fix initiator to not wait for write responses
RMorales25 Jul 14, 2024
12623bb
clean Here prints
RMorales25 Jul 14, 2024
5c2dbc0
makefile and run_all for router tb
RMorales25 Jul 14, 2024
ebd6ed1
Add compression block to TLM TB
jgavillalobos Jul 14, 2024
8a315e7
Add router to global tb
RMorales25 Jul 14, 2024
af1afba
Add transaction ID tracking
RMorales25 Jul 14, 2024
2607c75
Add transaction ID tracking
RMorales25 Jul 14, 2024
fc430d9
fixes after rebase
RMorales25 Jul 14, 2024
ca4e985
Use RGB noisy image in TB
jgavillalobos Jul 15, 2024
93d2794
Fixing includes + h to hpp + split src from headers
ErickOF Jul 20, 2024
6be6b6e
Fixing python code
ErickOF Jul 21, 2024
46cfcf2
Adding missing name of endif
ErickOF Jul 21, 2024
3bbbff8
Fixing inestability issues in router code
ErickOF Jul 21, 2024
5bd3fd0
Adding memory leakage test commands
ErickOF Jul 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions modules/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ BINDIR=./
INCDIR=-I. -I./include -I$(SYSTEMC)/include -Ibasic_protocol -I$(SYSTEMC)/include/tlm_core/tlm_2
LIBDIR=-L. -L$(SYSTEMC)/lib-linux64

ifdef USING_TLM_TB_EN
ErickOF marked this conversation as resolved.
Show resolved Hide resolved
EDGE_DIR=../edge-detector
GRAY_DIR=../rgb2gray
FILTER_DIR=../filter
UNIFICATION_DIR=../unification
COMPRESSION_DIR=../compression

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

ifdef INCLUDE_OPENCV
# Target
LIBS+=-lopencv_imgcodecs -lopencv_core -lopencv_highgui -lopencv_imgproc
Expand All @@ -35,15 +46,29 @@ LFLAGS += $(shell pkg-config --libs opencv4)
endif # INCLUDE_OPENCV_PKG
endif # INCLUDE_OPENCV

ifndef USING_TLM_TB_EN
ErickOF marked this conversation as resolved.
Show resolved Hide resolved
SOURCES := $(wildcard $(SRCDIR)/*.cpp)
INCLUDES := $(wildcard $(INCDIR)/*.hpp)
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
else
ErickOF marked this conversation as resolved.
Show resolved Hide resolved
SOURCES = $(wildcard *.cpp) $(foreach DIR, $(SRCDIRS), $(wildcard $(DIR)/*.cpp))
SOURCES_WITHOUT_PATH = $(notdir $(SOURCES))
INCLUDES := $(wildcard $(INCDIR)/*.hpp)
OBJECTS = $(SOURCES_WITHOUT_PATH:%.cpp=$(OBJDIR)/%.o)

VPATH = $(sort $(dir $(SOURCES)))
endif # USING_TLM_TB_EN

$(BINDIR)/$(TARGET): clean $(OBJECTS)
@$(LD) $(OBJECTS) $(LFLAGS) $(LIBS) $(LIBDIR) -o $@

ifndef USING_TLM_TB_EN
ErickOF marked this conversation as resolved.
Show resolved Hide resolved
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
@$(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
else
ErickOF marked this conversation as resolved.
Show resolved Hide resolved
$(OBJECTS): $(OBJDIR)/%.o : %.cpp
@$(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
endif # USING_TLM_TB_EN

.PHONY: clean
clean:
Expand Down
46 changes: 46 additions & 0 deletions modules/communication/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Include common Makefile
include ../Makefile

# Defining preprocessor directive for debug
ifdef IPS_DEBUG_EN
CFLAGS += -DIPS_DEBUG_EN
LFLAGS += -DIPS_DEBUG_EN
endif # IPS_DEBUG_EN

# Defining preprocessor directive for dumping enable
ifdef IPS_DUMP_EN
CFLAGS += -DIPS_DUMP_EN
LFLAGS += -DIPS_DUMP_EN
endif # IPS_DUMP_EN

# Defining preprocessor directive for normalizing the resulting magnitude
ifdef TEST_NORMALIZE_MAGNITUDE
CFLAGS += -DTEST_NORMALIZE_MAGNITUDE
LFLAGS += -DTEST_NORMALIZE_MAGNITUDE
endif # TEST_NORMALIZE_MAGNITUDE

# Defining preprocessor directive for using PV model
ifdef EDGE_DETECTOR_PV_EN
CFLAGS += -DEDGE_DETECTOR_PV_EN
LFLAGS += -DEDGE_DETECTOR_PV_EN
endif # EDGE_DETECTOR_PV_EN

# Defining preprocessor directive for using PV model
ifdef EDGE_DETECTOR_LT_EN
CFLAGS += -DEDGE_DETECTOR_LT_EN
LFLAGS += -DEDGE_DETECTOR_LT_EN
endif # EDGE_DETECTOR_LT_EN

# Defining preprocessor directive for using PV model
ifdef EDGE_DETECTOR_AT_EN
CFLAGS += -DEDGE_DETECTOR_AT_EN
LFLAGS += -DEDGE_DETECTOR_AT_EN
endif # EDGE_DETECTOR_AT_EN

# Run the compiled file
run:
@./test

# Show waveform
waveform:
@gtkwave edge_detector.vcd
ErickOF marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 43 additions & 0 deletions modules/communication/include/sobel_edge_detector_lt_model.hpp
ErickOF marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifdef EDGE_DETECTOR_LT_EN
#ifndef SOBEL_EDGE_DETECTOR_HPP
#define SOBEL_EDGE_DETECTOR_HPP

#include <systemc.h>

SC_MODULE(Edge_Detector)
{

int localWindow[3][3];

const int sobelGradientX[3][3] = {{-1, 0, 1},
{-2, 0, 2},
{-1, 0, 1}};
const int sobelGradientY[3][3] = {{-1, -2, -1},
{ 0, 0, 0},
{ 1, 2, 1}};

int resultSobelGradientX;
int resultSobelGradientY;

sc_event gotLocalWindow, finishedSobelGradientX, finishedSobelGradientY;

SC_CTOR(Edge_Detector)
{
SC_THREAD(compute_sobel_gradient_x);
SC_THREAD(compute_sobel_gradient_y);
}

void set_local_window(int window[3][3]);

void compute_sobel_gradient_x();

void compute_sobel_gradient_y();

int obtain_sobel_gradient_x();

int obtain_sobel_gradient_y();

};

#endif // SOBEL_EDGE_DETECTOR_HPP
#endif // EDGE_DETECTOR_LT_EN
28 changes: 28 additions & 0 deletions modules/communication/include/sobel_edge_detector_tlm.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef SOBEL_EDGE_DETECTOR_TLM_HPP
#define SOBEL_EDGE_DETECTOR_TLM_HPP
#include <systemc.h>

using namespace sc_core;
using namespace sc_dt;
using namespace std;

#include <tlm.h>
#include <tlm_utils/simple_initiator_socket.h>
#include <tlm_utils/simple_target_socket.h>
#include <tlm_utils/peq_with_cb_and_phase.h>

#include "sobel_edge_detector_lt_model.hpp"
#include "img_target.hpp"

//Extended Unification TLM
struct sobel_edge_detector_tlm : public Edge_Detector, public img_target
{
SC_CTOR(sobel_edge_detector_tlm): Edge_Detector(Edge_Detector::name()), img_target(img_target::name()) {
}

//Override do_when_transaction functions
virtual void do_when_read_transaction(unsigned char*& data);
virtual void do_when_write_transaction(unsigned char*& data);

};
#endif // SOBEL_EDGE_DETECTOR_TLM_HPP
225 changes: 225 additions & 0 deletions modules/communication/src/img_initiator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@


#ifndef IMG_INITIATOR_CPP
#define IMG_INITIATOR_CPP

#include "transaction_memory_manager.hpp"

#include <systemc.h>
using namespace sc_core;
using namespace sc_dt;
using namespace std;

#include <tlm.h>
#include <tlm_utils/simple_initiator_socket.h>
#include <tlm_utils/simple_target_socket.h>
#include <tlm_utils/peq_with_cb_and_phase.h>

//const char* tlm_enum_names[] = {"TLM_ACCEPTED", "TLM_UPDATED", "TLM_COMPLETED"};

// Initiator module generating generic payload transactions
struct img_initiator: sc_module
ErickOF marked this conversation as resolved.
Show resolved Hide resolved
{
// TLM2.0 Socket
tlm_utils::simple_initiator_socket<img_initiator> socket;

//Memory Manager for transaction memory allocation
mm memory_manager;

//Address for this Initiator
unsigned int address;
unsigned char* data;
unsigned int data_length;

//Pointer to transaction in progress
tlm::tlm_generic_payload* pending_transaction;

//Payload event queue with callback and phase
tlm_utils::peq_with_cb_and_phase<img_initiator> m_peq;

//Events
sc_event transaction_received_e;

//Delay
sc_time write_delay = sc_time(10, SC_NS);
sc_time read_delay = sc_time(10,SC_NS);

//Constructor
SC_CTOR(img_initiator)
: socket("socket"), pending_transaction(0), m_peq(this, &img_initiator::peq_cb) // Construct and name socket
{
// Register callbacks for incoming interface method calls
socket.register_nb_transport_bw(this, &img_initiator::nb_transport_bw);
}

//Method to send_reading transaction and wait for response
void read (int*& data, unsigned int address, unsigned int data_length){

//Create transaction and allocate it
tlm::tlm_generic_payload* transaction = memory_manager.allocate();

//Set transaction fields
transaction->set_command(tlm::TLM_READ_COMMAND);
transaction->set_address(address);
transaction->set_data_ptr(reinterpret_cast<unsigned char*>(data));
transaction->set_data_length(data_length); //In Bytes
transaction->set_streaming_width(data_length);
transaction->set_byte_enable_ptr(0);
transaction->set_dmi_allowed(false); //Mandatory Initial Value
transaction->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE); //Mandatory Initial Value

//Send transaction
this->send_transaction(transaction);

data = reinterpret_cast<int*>(this->data);
//-----------DEBUG-----------
printf("[DEBUG] Reading at Initiator: ");
for (int i = 0; i < this->pending_transaction->get_data_length()/sizeof(int); ++i){
printf("%02x", *(reinterpret_cast<int*>(this->data)+i));
}
printf("\n");
//-----------DEBUG-----------
}

void write (int*& data, unsigned int address, unsigned int data_length){

//Create transaction and allocate it
tlm::tlm_generic_payload* transaction = memory_manager.allocate();

//Set transaction fields
transaction->set_command(tlm::TLM_WRITE_COMMAND);
transaction->set_address(address);
transaction->set_data_ptr(reinterpret_cast<unsigned char*>(data));
transaction->set_data_length(data_length); //In Bytes
transaction->set_streaming_width(data_length);
transaction->set_byte_enable_ptr(0);
transaction->set_dmi_allowed(false); //Mandatory Initial Value
transaction->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE); //Mandatory Initial Value

//-----------DEBUG-----------
printf("[DEBUG] Writing: ");
for (int i = 0; i < data_length/sizeof(int); ++i){
printf("%02x", *(data+i));
}
printf("\n");
//-----------DEBUG-----------

//Set transaction
this->send_transaction(transaction);
}

void send_transaction(tlm::tlm_generic_payload*& transaction) {

//Transaction Management Variables
tlm::tlm_phase phase;
tlm::tlm_sync_enum status;

//Begin Request
phase = tlm::BEGIN_REQ;
transaction->acquire();
cout << name() << " BEGIN_REQ SENT" << " TRANS ID " << 0 << " at time " << sc_time_stamp() << endl;
pending_transaction = transaction;
status = socket->nb_transport_fw(*transaction, phase, this->write_delay); // Non-blocking transport call

// Check request status returned by target
switch (status) {
//Case 1: Transaction was accepted
case tlm::TLM_ACCEPTED: {
printf("%s:\t %s received -> Transaction ID %d at time %s\n", name(), "TLM_ACCEPTED", 0, sc_time_stamp());
//cout << name() << " TLM_ACCEPTED RECEIVED " << " TRANS ID " << transaction->transaction_id << " at time " << sc_time_stamp() << endl;
check_transaction(*transaction);
transaction->release();
pending_transaction = 0;
//Initiator only cares about sending the transaction, doesnt need to wait for response (non-blocking)
break;
}

//Not implementing Updated and Completed Status
default: {
printf("%s:\t [ERROR] Invalid status received at initiator", name());
break;
}
}

//Wait for response transaction
wait(transaction_received_e);
//-----------DEBUG-----------
printf("[DEBUG1] Reading at Initiator: ");
for (int i = 0; i < this->data_length/sizeof(int); ++i){
printf("%02x", *(reinterpret_cast<int*>(this->data)+i));
}
printf("\n");
//-----------DEBUG-----------

//Increment transaction ID
}


// TLM2 backward path non-blocking transport method
virtual tlm::tlm_sync_enum nb_transport_bw(tlm::tlm_generic_payload& trans,
tlm::tlm_phase& phase, sc_time& delay )
{
//Call event queue
m_peq.notify(trans, phase, delay);
return tlm::TLM_ACCEPTED;
}

//Payload event and queue callback to handle transactions received from target
void peq_cb(tlm::tlm_generic_payload& trans, const tlm::tlm_phase& phase)
{

//printf("%s:\t %s received -> Transaction ID %d from address %x at time %s\n", name(), phase, this->id_extension->transaction_id, trans.get_address(), sc_time_stamp());
//cout << name() << " " <<hex << trans.get_address() << " BEGIN_RESP RECEIVED at " << sc_time_stamp() << endl;
switch (phase) {
case tlm::BEGIN_RESP: {

trans.acquire();
this->data_length = trans.get_data_length();
this->data = new unsigned char[this->data_length];
memcpy(this->data, trans.get_data_ptr(), this->data_length);

this->pending_transaction = &trans; //Set response transaction to return
check_transaction(trans);

//Initiator dont care about confirming resp transaction. So nothing else to do.

//-----------DEBUG-----------
printf("[DEBUG] Reading at Initiator: ");
for (int i = 0; i < trans.get_data_length()/sizeof(int); ++i){
printf("%02x", *(reinterpret_cast<int*>(trans.get_data_ptr())+i));
}
printf("\n");
//-----------DEBUG-----------

transaction_received_e.notify();
//-----------DEBUG-----------
printf("[DEBUG] Reading at Initiator: ");
for (int i = 0; i < this->data_length/sizeof(int); ++i){
printf("%02x", *(reinterpret_cast<int*>(this->data)+i));
}
printf("\n");
//-----------DEBUG-----------
break;
}
default: {
SC_REPORT_FATAL("TLM-2", "Illegal transaction phase received by initiator");
break;
}
}
}

//Function to check transaction integrity
void check_transaction(tlm::tlm_generic_payload& trans)
{
//Check transaction if here

// tlm::tlm_command command = trans.get_command();
// sc_dt::uint64 address = trans.get_address();
// unsigned char* data_ptr = reinterpret_cast<unsigned char*>(trans.get_data_ptr());

// Allow the memory manager to free the transaction object
//trans.release();
}
} ;

#endif
Loading