From d620bea112ae89eb19791bc1a606c34caaa6b4e1 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Tue, 21 Mar 2023 03:24:53 -0700 Subject: [PATCH 1/4] updates scc --- CMakeLists.txt | 44 +++++++++++++------------------------------- scc | 2 +- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c9016c..64f6a3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,6 @@ include(GNUInstallDirs) include(BuildType) include(clang-format) -set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -34,7 +33,7 @@ endif() include(ConanInline) conan_check() -set(CONAN_BOOST_OPTIONS +set(BOOST_OPTIONS boost:fPIC=True boost:shared=True boost:header_only=False @@ -61,44 +60,27 @@ boost:without_timer=True boost:without_type_erasure=True boost:without_wave=True ) -set(CONAN_PACKAGES boost/1.75.0) -set(CONAN_SETTINGS ${CONAN_BOOST_OPTIONS}) -if(NOT DEFINED ENV{SYSTEMC_HOME}) - set(CONAN_PACKAGES ${CONAN_PACKAGES} - systemc/2.3.3 - systemc-cci/1.0.0 - ) - set(CONAN_SETTINGS ${CONAN_SETTINGS} - #systemc:phase_cb=False - systemc-cci:shared=False - ) +set(CONAN_PACKAGE_LIST fmt/8.0.1 spdlog/1.9.2 zlib/1.2.11 boost/1.75.0 yaml-cpp/0.7.0 jsoncpp/1.9.5 lz4/1.9.3) +set(CONAN_PACKAGE_OPTIONS fmt:header_only=True spdlog:header_only=True ${BOOST_OPTIONS}) +if(NOT USE_CWR_SYSTEMC AND NOT USE_NCSC_SYSTEMC AND NOT DEFINED ENV{SYSTEMC_HOME}) + set(CONAN_PACKAGE_LIST ${CONAN_PACKAGE_LIST} systemc/2.3.3 systemc-cci/1.0.0) + set(CONAN_PACKAGE_OPTIONS ${CONAN_PACKAGE_OPTIONS} systemc-cci:shared=False) endif() -conan_configure(REQUIRES ${CONAN_PACKAGES} +conan_configure(REQUIRES ${CONAN_PACKAGE_LIST} GENERATORS cmake_find_package - OPTIONS ${CONAN_SETTINGS} + OPTIONS ${CONAN_PACKAGE_OPTIONS} ) conan_install() -conan_setup(TARGETS) - +set(CONAN_CMAKE_SILENT_OUTPUT ON) # This line finds the boost lib and headers. set(Boost_NO_BOOST_CMAKE ON) # Don't do a find_package in config mode before searching for a regular boost install. find_package(Boost COMPONENTS program_options system thread REQUIRED) -# set-up SystemC and SCV include(SystemCPackage) -if(SystemC_FOUND) - include_directories(${SystemC_INCLUDE_DIRS}) - link_directories(${SystemC_LIBRARY_DIRS}) -else() - message( FATAL_ERROR "SystemC library not found." ) -endif() - -if(CCI_FOUND) - include_directories(${CCI_INCLUDE_DIRS}) - link_directories(${CCI_LIBRARY_DIRS}) -#else() - #message( FATAL_ERROR "SystemC CCI library not found." ) -endif() +find_package(spdlog REQUIRED) +find_package(fmt REQUIRED) +find_package(yaml-cpp REQUIRED) +find_package(lz4 REQUIRED) add_subdirectory(scc) add_subdirectory(vp_components) diff --git a/scc b/scc index 1b28dad..b4b551c 160000 --- a/scc +++ b/scc @@ -1 +1 @@ -Subproject commit 1b28dadcb3510550fea0d7c383511e502bae2582 +Subproject commit b4b551cc427d6156acbfdf81f2263c062325a231 From 965a10c2f2adb206b66eaf074eb4c80f43cccfd0 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Fri, 24 Mar 2023 02:23:34 -0700 Subject: [PATCH 2/4] updates router_example2 to use SCC module --- router_example2.py | 17 +++++++++-------- scc | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/router_example2.py b/router_example2.py index 8e8dd5e..8d33985 100644 --- a/router_example2.py +++ b/router_example2.py @@ -3,30 +3,31 @@ import logging from cppyy import gbl as cpp import pysysc import pysysc.structural as struct +import pysysc.scc as scc from pysysc.structural import Connection, Module, Signal, Simulation ############################################################################### # setup and load ############################################################################### -logging.basicConfig(level=logging.INFO) +logging.basicConfig(level=logging.DEBUG) build_type='Debug' ############################################################################### myDir = os.path.dirname( os.path.realpath(__file__)) pysysc.load_systemc() ############################################################################### logging.debug("Loading SC-Components lib") -pysysc.add_include_path(os.path.join(myDir, 'scc/src/sysc')) -pysysc.add_include_path(os.path.join(myDir, 'scc/src/common')) -pysysc.add_include_path(os.path.join(myDir, 'scc/third_party')) -pysysc.add_library('scc_sysc.h', os.path.join(myDir, 'build/%s/scc/src/sysc/libscc-sysc.so'%build_type)) +#pysysc.add_include_path(os.path.join(myDir, '../install/include')) +#pysysc.add_library('scc_util.h', os.path.join(myDir, '../install/lib64/libscc-util.so')) +#pysysc.add_library('scc_sysc.h', os.path.join(myDir, '../install/lib64/libscc-sysc.so')) +scc.load_lib(os.path.join(myDir, '../install')) ############################################################################### logging.debug("Loading Components lib") pysysc.add_include_path(os.path.join(myDir, 'vp_components')) -pysysc.add_library('components.h', os.path.join(myDir, 'build/%s/vp_components/libvp_components.so'%build_type)) +pysysc.add_library('components.h', os.path.join(myDir, 'build/vp_components/libvp_components.so')) ############################################################################### # configure ############################################################################### -Simulation.setup(logging.root.level) +scc.setup(logging.root.level) ############################################################################### # instantiate ############################################################################### @@ -51,6 +52,6 @@ struct.dump_structure() simcontext = cpp.sc_core.sc_get_curr_simcontext() objects = cpp.sc_core.sc_get_top_level_objects(simcontext) if __name__ == "__main__": - Simulation.configure(enable_vcd=True) + scc.configure(enable_trace=True) Simulation.run() logging.debug("Done") diff --git a/scc b/scc index b4b551c..ed55606 160000 --- a/scc +++ b/scc @@ -1 +1 @@ -Subproject commit b4b551cc427d6156acbfdf81f2263c062325a231 +Subproject commit ed556064a949af1d78dea923721fbc2717f38f67 From 775872b190e10551ce905feaadba08bd4d80e98e Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Fri, 24 Mar 2023 02:43:31 -0700 Subject: [PATCH 3/4] updates scc --- scc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scc b/scc index ed55606..d6b718c 160000 --- a/scc +++ b/scc @@ -1 +1 @@ -Subproject commit ed556064a949af1d78dea923721fbc2717f38f67 +Subproject commit d6b718cebd9712374b0fbe145da2920800480fac From fcd60ef6603274e5a4bd04ca7085d0b30a7bb9f7 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Fri, 22 Nov 2024 15:44:08 +0100 Subject: [PATCH 4/4] updates build instruction and SCC to latest version --- .gitignore | 5 ++- .vscode/launch.json | 29 +++++++++++++++ .vscode/settings.json | 14 +++++++ .vscode/tasks.json | 32 ++++++++++++++++ CMakeLists.txt | 7 ++-- README.md | 27 ++++++++++---- modules.py | 86 ++++++++++++++++++++++++------------------- router_example.py | 44 +++++++++++++--------- router_example2.py | 30 +++++++-------- scc | 2 +- 10 files changed, 193 insertions(+), 83 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore index 959b5eb..0329c82 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,7 @@ /.settings /*.vcd /*.png -/*.dot \ No newline at end of file +/*.dot +/*.fst +/*.ftr +/.venv \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..98acc30 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + // 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": [ + { + "name": "Python Debugger: router_example.py", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/router_example.py", + "console": "integratedTerminal" + }, + { + "name": "Python Debugger: router_example2.py", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/router_example2.py", + "console": "integratedTerminal" + }, + { + "name": "Python Debugger: modules.py", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/modules.py", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..879f973 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "editor.rulers": [ + { + "column": 140, + "comment": "clang-format" + } + ], + "editor.formatOnSave": true, + "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd", + "cmake.buildDirectory": "${workspaceFolder}/build", + "[jsonc]": { + "editor.defaultFormatter": "vscode.json-language-features" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..c287503 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,32 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "router_example", + "type": "shell", + "command": "python3 router_example.py", + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + { + "label": "router_example2", + "type": "shell", + "command": "python3 router_example2.py", + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + { + "label": "modules", + "type": "shell", + "command": "python3 modules.py", + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 64f6a3d..7c59fda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ include(clang-format) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(CMAKE_CXX_STANDARD 17) include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) @@ -63,8 +64,8 @@ boost:without_wave=True set(CONAN_PACKAGE_LIST fmt/8.0.1 spdlog/1.9.2 zlib/1.2.11 boost/1.75.0 yaml-cpp/0.7.0 jsoncpp/1.9.5 lz4/1.9.3) set(CONAN_PACKAGE_OPTIONS fmt:header_only=True spdlog:header_only=True ${BOOST_OPTIONS}) if(NOT USE_CWR_SYSTEMC AND NOT USE_NCSC_SYSTEMC AND NOT DEFINED ENV{SYSTEMC_HOME}) - set(CONAN_PACKAGE_LIST ${CONAN_PACKAGE_LIST} systemc/2.3.3 systemc-cci/1.0.0) - set(CONAN_PACKAGE_OPTIONS ${CONAN_PACKAGE_OPTIONS} systemc-cci:shared=False) + set(CONAN_PACKAGE_LIST ${CONAN_PACKAGE_LIST} systemc/2.3.4) + set(CONAN_PACKAGE_OPTIONS ${CONAN_PACKAGE_OPTIONS} systemc:shared=True) endif() conan_configure(REQUIRES ${CONAN_PACKAGE_LIST} GENERATORS cmake_find_package @@ -84,7 +85,7 @@ find_package(lz4 REQUIRED) add_subdirectory(scc) add_subdirectory(vp_components) -add_subdirectory(top) +#add_subdirectory(top) # CTest is a testing tool that can be used to test your project. # enable_testing() diff --git a/README.md b/README.md index cf0c91d..d9e0f4a 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,29 @@ A simple C++/SystemC/CMake project to test pysysc # How to build -> Currently only Linux and MacOS are tested +> Currently only Linux and MacOS are tested. +The install instruction below assume using bash. ``` +git clone --recursive -b develop https://git.minres.com/SystemC/PySysC-SC.git cd PySysC-SC -mkdir build -cd build -conan install .. --build=missing -cmake -DBUILD_SHARED_LIBS=ON .. -cmake --build . +python3 -mvenv .venv +. .venv/bin/activate +pip install "conan<2.0" +cmake -S . -B build -DBUILD_SHARED_LIBS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON +cmake --build build -j24 +export SYSTEMC_HOME=$(grep -A1 rootpath_systemc\] build/conanbuildinfo.txt | tail -1) +export STDCXX=17 +pip install "cppyy<3.0" +pip install https://github.com/Minres/PySysC/tarball/master +pip install scc/contrib/pysysc/ +python3 router_example.py +python3 router_example2.py +python3 modules.py ``` - +These steps clone the PySysC-SC repository and builds the shared libraries using conan 1.x. +This also downloads and builds SYSTEMC (as a conan package). +Then it installs the python packages cppyy, PySysC, and PySysC.SCC using the same settings as the cmake build. +Eventually it runs the 3 examples. diff --git a/modules.py b/modules.py index f202049..e526b5b 100644 --- a/modules.py +++ b/modules.py @@ -4,48 +4,43 @@ # SPDX-License-Identifier: Apache-2.0 # -import os.path import logging -import cppyy -from cppyy import gbl as cpp +import os.path + import pysysc +import pysysc.scc as scc +from cppyy import gbl as cpp from pysysc.structural import Connection, Module, Signal, Simulation ############################################################################### # setup and load ############################################################################### logging.basicConfig(level=logging.DEBUG) -build_type='Debug' ############################################################################### -myDir = os.path.dirname( os.path.realpath(__file__)) -pysysc.read_config_from_conan(os.path.join(myDir, 'build/%s/conanfile.txt'%build_type), build_type) -pysysc.load_systemc() +myDir = os.path.dirname(os.path.realpath(__file__)) +pysysc.load_systemc(17) ############################################################################### logging.debug("Loading SC-Components lib") -# pysysc.add_include_path(os.path.join(myDir, 'scc/incl')) -# pysysc.add_library('scc.h', os.path.join(myDir, 'build/%s/lib/libscc.so'%build_type)) -pysysc.add_include_path(os.path.join(myDir, 'scc/src/common')) -pysysc.add_library('scc_util.h', os.path.join(myDir, 'build/%s/scc/src/common/libscc-util.so'%build_type)) -pysysc.add_include_path(os.path.join(myDir, 'scc/third_party')) -pysysc.add_include_path(os.path.join(myDir, 'scc/third_party/scv-tr/src')) -pysysc.add_library('scv-tr.h', os.path.join(myDir, 'build/%s/scc/third_party/scv-tr/src/libscv-tr.so'%build_type)) -pysysc.add_include_path(os.path.join(myDir, 'scc/src/sysc')) -pysysc.add_library('scc_sysc.h', os.path.join(myDir, 'build/%s/scc/src/sysc/libscc-sysc.so'%build_type)) -pysysc.add_include_path(os.path.join(myDir, 'scc/src/components')) -cppyy.include('scc_components.h') +scc.load_lib(myDir) ############################################################################### logging.debug("Loading Components lib") -pysysc.add_include_path(os.path.join(myDir, 'vp_components')) -pysysc.add_library('components.h', os.path.join(myDir, 'build/%s/vp_components/libvp_components.so'%build_type)) - +pysysc.add_include_path(os.path.join(myDir, "vp_components")) +pysysc.add_library("components.h", "libvp_components.so", myDir) +############################################################################### +# configure +############################################################################### +scc.setup(logging.root.level) +scc.configure(enable_trace=False) ############################################################################### # define toplevel class ############################################################################### num_of_mem = 4 from pysysc.sysc import ScModule + + class TopModule(ScModule): - + def __init__(self, name): ScModule.__init__(self, name) ############################################################################### @@ -54,47 +49,62 @@ class TopModule(ScModule): self.clk_gen = Module(cpp.ClkGen).create("clk_gen") self.rst_gen = Module(cpp.ResetGen).create("rst_gen") self.initiator = Module(cpp.Initiator).create("initiator") - self.memories = [Module(cpp.Memory).create("mem%d"%idx) for idx in range(0,num_of_mem)] + self.memories = [ + Module(cpp.Memory).create("mem%d" % idx) for idx in range(0, num_of_mem) + ] self.router = Module(cpp.Router[num_of_mem]).create("router") ############################################################################### # connect them ############################################################################### - self.clk = Signal("clk").src(self.clk_gen.clk_o).sink(self.initiator.clk_i).sink(self.router.clk_i) + self.clk = ( + Signal("clk") + .src(self.clk_gen.clk_o) + .sink(self.initiator.clk_i) + .sink(self.router.clk_i) + ) [self.clk.sink(m.clk_i) for m in self.memories] - self.rst = Signal("rst").src(self.rst_gen.reset_o).sink(self.initiator.reset_i).sink(self.router.reset_i) + self.rst = ( + Signal("rst") + .src(self.rst_gen.reset_o) + .sink(self.initiator.reset_i) + .sink(self.router.reset_i) + ) [self.rst.sink(m.reset_i) for m in self.memories] Connection().src(self.initiator.socket).sink(self.router.target_socket) - [Connection().src(self.router.initiator_socket.at(idx)).sink(m.socket) for idx,m in enumerate(self.memories)] + [ + Connection().src(self.router.initiator_socket.at(idx)).sink(m.socket) + for idx, m in enumerate(self.memories) + ] self.ScThread("RunThread") - + def EndOfElaboration(self): print("Elaboration finished") - + def StartOfSimulation(self): print("Simulation started") - + def EndOfSimulation(self): print("Simulation finished") def RunThread(self): print("Starting RunThread") - while(cpp.sc_core.sc_time_stamp()