Skip to content

Commit

Permalink
Merge pull request #28 from mourra950/secondary
Browse files Browse the repository at this point in the history
Secondary
  • Loading branch information
mourra950 committed Jan 1, 2024
2 parents 099292a + 143e6dc commit 85d2ab3
Show file tree
Hide file tree
Showing 38 changed files with 25,097 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cmake.sourceDirectory": "E:/Github/Siemens-System-Level-Modelling-of-ASDLA-Graduation-Project/examples/SystemC"
}
Binary file added data/Pt/model2.pt
Binary file not shown.
Binary file added data/image_samples/img_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/mnist/t10k-images-idx3-ubyte
Binary file not shown.
Binary file added data/mnist/t10k-images-idx3-ubyte.gz
Binary file not shown.
Binary file added data/mnist/t10k-labels-idx1-ubyte
Binary file not shown.
Binary file added data/mnist/t10k-labels-idx1-ubyte.gz
Binary file not shown.
Binary file added data/mnist/train-images-idx3-ubyte
Binary file not shown.
Binary file added data/mnist/train-images-idx3-ubyte.gz
Binary file not shown.
Binary file added data/mnist/train-labels-idx1-ubyte
Binary file not shown.
Binary file added data/mnist/train-labels-idx1-ubyte.gz
Binary file not shown.
1 change: 1 addition & 0 deletions examples/Cmake/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
20 changes: 20 additions & 0 deletions examples/Cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.18)
project(SystemCExample CXX)


# Find the SystemC package
find_package(SystemCLanguage CONFIG REQUIRED)

set (CMAKE_CXX_STANDARD ${SystemC_CXX_STANDARD} CACHE STRING
"C++ standard to build all targets. Supported values are 98, 11, 14, and 17.")

set (CMAKE_CXX_STANDARD_REQUIRED ${SystemC_CXX_STANDARD_REQUIRED} CACHE BOOL
"The with CMAKE_CXX_STANDARD selected C++ standard is a requirement.")



# Create an executable for your SystemC project
add_executable(systemc_example main.cpp)

# Link the SystemC library with your project
target_link_libraries(systemc_example SystemC::systemc)
14 changes: 14 additions & 0 deletions examples/Cmake/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <systemc.h>

SC_MODULE(hello_world) {
SC_CTOR(hello_world) {}
void say_hello() {
cout << "Hello World.\n";
}
};

int sc_main(int argc, char* argv[]) {
hello_world hello("HELLO");
hello.say_hello();
return(0);
}
1 change: 1 addition & 0 deletions examples/SystemC_Ctorch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
23 changes: 23 additions & 0 deletions examples/SystemC_Ctorch/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/systemc-2.3.4/src"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22621.0",
"compilerPath": "cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
97 changes: 97 additions & 0 deletions examples/SystemC_Ctorch/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"files.associations": {
"iostream": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"valarray": "cpp",
"vector": "cpp",
"xstring": "cpp",
"string": "cpp",
"algorithm": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"exception": "cpp",
"filesystem": "cpp",
"format": "cpp",
"fstream": "cpp",
"functional": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ostream": "cpp",
"queue": "cpp",
"random": "cpp",
"ranges": "cpp",
"ratio": "cpp",
"set": "cpp",
"shared_mutex": "cpp",
"span": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"strstream": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"utility": "cpp",
"variant": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"__nullptr": "cpp",
"__locale": "cpp"
}
}
52 changes: 52 additions & 0 deletions examples/SystemC_Ctorch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
cmake_minimum_required(VERSION 3.18)
project(Final_SystemC CXX)

#Find package fetch libraries and give an error when unable to find either of this packages
find_package(SystemCLanguage CONFIG REQUIRED)
find_package(Torch REQUIRED)
find_package(OpenCV REQUIRED)

include_directories( ${OpenCV_INCLUDE_DIRS} ${Torch_INCLUDE_DIRS} ${SystemCLanguage_INCLUDE_DIRS} )


# Add your source files and cpp files needed
add_executable(
Final_SystemC
Final_SystemC.cpp
Initiator.cpp
InitiatorThread.cpp
Target.cpp
extension.cpp
)

set (CMAKE_CXX_STANDARD 17 ${SystemC_CXX_STANDARD} CACHE STRING
"C++ standard to build all targets. Supported values are 98, 11, 14, and 17.")
set (CMAKE_CXX_STANDARD_REQUIRED ${SystemC_CXX_STANDARD_REQUIRED} CACHE BOOL
"The with CMAKE_CXX_STANDARD selected C++ standard is a requirement.")
set(source_dir "${CMAKE_CURRENT_SOURCE_DIR}")
set(destination_dir "${CMAKE_CURRENT_BINARY_DIR}")
include_directories(${destination_dir})
# copies data folders needed and insert them in the destination appointed to and make it easy to reference data relative to the project
file(COPY ${source_dir}/image_samples DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${source_dir}/Pt DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${source_dir}/mnist DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(Final_SystemC
PUBLIC ${OpenCV_LIBS}
PUBLIC "${TORCH_LIBRARIES}"
${SystemC_LIBRARIES}
PRIVATE SystemC::systemc

)





if (MSVC)
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
add_custom_command(TARGET Final_SystemC
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
$<TARGET_FILE_DIR:Final_SystemC>)
endif (MSVC)
48 changes: 48 additions & 0 deletions examples/SystemC_Ctorch/Final_SystemC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <iostream>
#include <string>
#include <memory>
#include <vector>
#include <torch/script.h>
#include <torch/torch.h>
#include <torch/nn.h>
#include <torch/optim.h>
#include <torch/data/example.h>
#include <torch/csrc/jit/serialization/import.h>
#include "systemc.h"
#include "tlm.h"
#include "tlm_utils/simple_initiator_socket.h"
#include "tlm_utils/simple_target_socket.h"
#include <opencv2/opencv.hpp>
#include <random>
#include <fstream>
#include <ctime>
#include "json/json.hpp"
#include "Initiator.h"
#include "Target.h"

using json = nlohmann::json;
using namespace std;
using namespace sc_core;
using namespace tlm;

void setMKLThreads()
{
int numThreads = 4; // Set the desired number of threads
torch::set_num_threads(numThreads);
}

int sc_main(int argc, char *argv[])
{
cout << "\nOmar1\n";

setMKLThreads();
// Create instances of the initiator and target modules and give a name to the instance
Initiator initiator("initiator");
Target target("target");
// Connect the sockets
initiator.init_socket.bind(target.target_socket);
// Start simulation
sc_start();
system("pause");
return 0;
}
12 changes: 12 additions & 0 deletions examples/SystemC_Ctorch/Initiator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "extension.cpp"
#include "Initiator.h"
using json = nlohmann::json;
using namespace std;
using namespace sc_core;
using namespace tlm;
using namespace torch;

Initiator::Initiator(sc_core::sc_module_name name) : sc_module(name), init_socket("init_socket")
{
SC_THREAD(sendDataThread);
}
37 changes: 37 additions & 0 deletions examples/SystemC_Ctorch/Initiator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once
#ifndef INITIATOR_H
#define INITIATOR_H
#include <iostream>
#include <fstream>
#include <string>
#include <memory>
#include <vector>
#include <torch/script.h>
#include <torch/torch.h>
#include <torch/nn.h>
#include <torch/optim.h>
#include <torch/data/example.h>
#include <torch/csrc/jit/serialization/import.h>
#include <opencv2/opencv.hpp>
#include <random>
#include <fstream>
#include <ctime>
#include "systemc.h"
#include "tlm.h"
#include "tlm_utils/simple_initiator_socket.h"
#include "json/json.hpp"
#include "tlm_utils/simple_initiator_socket.h"

using namespace tlm;
using namespace sc_core;

struct Initiator : sc_module
{
tlm_utils::simple_initiator_socket<Initiator> init_socket;

void sendDataThread();

SC_CTOR(Initiator);
};

#endif // INITIATOR_H
28 changes: 28 additions & 0 deletions examples/SystemC_Ctorch/InitiatorThread.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "Initiator.h"
#include "extension.cpp"
using json = nlohmann::json;
using namespace std;
using namespace sc_core;
using namespace tlm;
using namespace torch;

void Initiator::sendDataThread()
{
// Create a generic payload and using custom extension made in extension.cpp
tlm::tlm_generic_payload trans;
my_extension *test_extension_transaction = new my_extension;
// changing the attribute `id` from 0 to 5
test_extension_transaction->id = 5;
// setting the extension
trans.set_extension(test_extension_transaction);
// setting the command
trans.set_command(tlm::TLM_WRITE_COMMAND);
sc_time delay;
// send first time with `id` = 5
init_socket->b_transport(trans, delay);
test_extension_transaction->id = 12;
// send second time with `id` = 12
init_socket->b_transport(trans, delay);

return;
}
Binary file added examples/SystemC_Ctorch/Pt/model2.pt
Binary file not shown.
Loading

0 comments on commit 85d2ab3

Please sign in to comment.